##// END OF EJS Templates
diffs: move diffmode to template global context and add it to session...
dan -
r1137:14bd0daf default
parent child Browse files
Show More
@@ -365,6 +365,18 b' def attach_context_attributes(context, r'
365 365 # Fix this and remove it from base controller.
366 366 # context.repo_name = get_repo_slug(request) # can be empty
367 367
368 diffmode = 'sideside'
369 if request.GET.get('diffmode'):
370 if request.GET['diffmode'] == 'unified':
371 diffmode = 'unified'
372 elif request.session.get('diffmode'):
373 diffmode = request.session['diffmode']
374
375 context.diffmode = diffmode
376
377 if request.session.get('diffmode') != diffmode:
378 request.session['diffmode'] = diffmode
379
368 380 context.csrf_token = auth.get_csrf_token()
369 381 context.backends = rhodecode.BACKENDS.keys()
370 382 context.backends.sort()
@@ -107,6 +107,15 b' def pylons_url_current(*args, **kw):'
107 107 url.current = pylons_url_current
108 108
109 109
110 def url_replace(**qargs):
111 """ Returns the current request url while replacing query string args """
112
113 request = get_current_request()
114 new_args = request.GET.mixed()
115 new_args.update(qargs)
116 return url('', **new_args)
117
118
110 119 def asset(path, ver=None):
111 120 """
112 121 Helper to generate a static asset file path for rhodecode assets
@@ -35,16 +35,10 b" return h.url('', **new_args)"
35 35 ruler_at_chars=0,
36 36 )">
37 37 <%
38 # TODO: dan: move this to an argument - and set a cookie so that it is saved
39 # default option for future requests
40 diff_mode = request.GET.get('diffmode', 'sideside')
41 if diff_mode not in ('sideside', 'unified'):
42 diff_mode = 'sideside'
43
44 38 collapse_all = len(diffset.files) > collapse_when_files_over
45 39 %>
46 40
47 %if diff_mode == 'sideside':
41 %if c.diffmode == 'sideside':
48 42 <style>
49 43 .wrapper {
50 44 max-width: 1600px !important;
@@ -73,18 +67,17 b' collapse_all = len(diffset.files) > coll'
73 67
74 68 <div class="diffset">
75 69 <div class="diffset-heading">
76 %if diffset.files:
77 70 <div class="pull-right">
78 71 <div class="btn-group">
79 72 <a
80 class="btn ${diff_mode == 'sideside' and 'btn-primary'} tooltip"
73 class="btn ${c.diffmode == 'sideside' and 'btn-primary'} tooltip"
81 74 title="${_('View side by side')}"
82 href="${link_for(diffmode='sideside')}">
75 href="${h.url_replace(diffmode='sideside')}">
83 76 <span>${_('Side by Side')}</span>
84 77 </a>
85 78 <a
86 class="btn ${diff_mode == 'unified' and 'btn-primary'} tooltip"
87 title="${_('View unified')}" href="${link_for(diffmode='unified')}">
79 class="btn ${c.diffmode == 'unified' and 'btn-primary'} tooltip"
80 title="${_('View unified')}" href="${h.url_replace(diffmode='unified')}">
88 81 <span>${_('Unified')}</span>
89 82 </a>
90 83 </div>
@@ -101,7 +94,6 b' collapse_all = len(diffset.files) > coll'
101 94 onclick="$('input[class=filediff-collapse-state]').prop('checked', true); return false">${_('Collapse All')}</a>
102 95 </div>
103 96 </div>
104 %endif
105 97 <h2 style="padding: 5px; text-align: center;">
106 98 %if diffset.limited_diff:
107 99 ${ungettext('%(num)s file changed', '%(num)s files changed', diffset.changed_files) % {'num': diffset.changed_files}}
@@ -132,11 +124,11 b' collapse_all = len(diffset.files) > coll'
132 124 ${diff_ops(filediff)}
133 125 </label>
134 126 ${diff_menu(filediff)}
135 <table class="cb cb-diff-${diff_mode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}">
127 <table class="cb cb-diff-${c.diffmode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}">
136 128 %if not filediff.hunks:
137 129 %for op_id, op_text in filediff['patch']['stats']['ops'].items():
138 130 <tr>
139 <td class="cb-text cb-${op_class(op_id)}" ${diff_mode == 'unified' and 'colspan=3' or 'colspan=4'}>
131 <td class="cb-text cb-${op_class(op_id)}" ${c.diffmode == 'unified' and 'colspan=3' or 'colspan=4'}>
140 132 %if op_id == DEL_FILENODE:
141 133 ${_('File was deleted')}
142 134 %elif op_id == BIN_FILENODE:
@@ -150,7 +142,7 b' collapse_all = len(diffset.files) > coll'
150 142 %endif
151 143 %if over_lines_changed_limit:
152 144 <tr class="cb-warning cb-collapser">
153 <td class="cb-text" ${diff_mode == 'unified' and 'colspan=3' or 'colspan=4'}>
145 <td class="cb-text" ${c.diffmode == 'unified' and 'colspan=3' or 'colspan=4'}>
154 146 ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
155 147 <a href="#" class="cb-expand"
156 148 onclick="$(this).closest('table').removeClass('cb-collapsed'); return false;">${_('Show them')}
@@ -163,29 +155,29 b' collapse_all = len(diffset.files) > coll'
163 155 %endif
164 156 %if filediff.patch['is_limited_diff']:
165 157 <tr class="cb-warning cb-collapser">
166 <td class="cb-text" ${diff_mode == 'unified' and 'colspan=3' or 'colspan=4'}>
158 <td class="cb-text" ${c.diffmode == 'unified' and 'colspan=3' or 'colspan=4'}>
167 159 ${_('The requested commit is too big and content was truncated.')} <a href="${link_for(fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
168 160 </td>
169 161 </tr>
170 162 %endif
171 163 %for hunk in filediff.hunks:
172 164 <tr class="cb-hunk">
173 <td ${diff_mode == 'unified' and 'colspan=2' or ''}>
165 <td ${c.diffmode == 'unified' and 'colspan=2' or ''}>
174 166 ## TODO: dan: add ajax loading of more context here
175 167 ## <a href="#">
176 168 <i class="icon-more"></i>
177 169 ## </a>
178 170 </td>
179 <td ${diff_mode == 'sideside' and 'colspan=3' or ''}>
171 <td ${c.diffmode == 'sideside' and 'colspan=3' or ''}>
180 172 @@
181 173 -${hunk.source_start},${hunk.source_length}
182 174 +${hunk.target_start},${hunk.target_length}
183 175 ${hunk.section_header}
184 176 </td>
185 177 </tr>
186 %if diff_mode == 'unified':
178 %if c.diffmode == 'unified':
187 179 ${render_hunk_lines_unified(hunk)}
188 %elif diff_mode == 'sideside':
180 %elif c.diffmode == 'sideside':
189 181 ${render_hunk_lines_sideside(hunk)}
190 182 %else:
191 183 <tr class="cb-line">
General Comments 0
You need to be logged in to leave comments. Login now