##// 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 # Fix this and remove it from base controller.
365 # Fix this and remove it from base controller.
366 # context.repo_name = get_repo_slug(request) # can be empty
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 context.csrf_token = auth.get_csrf_token()
380 context.csrf_token = auth.get_csrf_token()
369 context.backends = rhodecode.BACKENDS.keys()
381 context.backends = rhodecode.BACKENDS.keys()
370 context.backends.sort()
382 context.backends.sort()
@@ -107,6 +107,15 b' def pylons_url_current(*args, **kw):'
107 url.current = pylons_url_current
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 def asset(path, ver=None):
119 def asset(path, ver=None):
111 """
120 """
112 Helper to generate a static asset file path for rhodecode assets
121 Helper to generate a static asset file path for rhodecode assets
@@ -35,16 +35,10 b" return h.url('', **new_args)"
35 ruler_at_chars=0,
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 collapse_all = len(diffset.files) > collapse_when_files_over
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 <style>
42 <style>
49 .wrapper {
43 .wrapper {
50 max-width: 1600px !important;
44 max-width: 1600px !important;
@@ -73,35 +67,33 b' collapse_all = len(diffset.files) > coll'
73
67
74 <div class="diffset">
68 <div class="diffset">
75 <div class="diffset-heading">
69 <div class="diffset-heading">
76 %if diffset.files:
77 <div class="pull-right">
70 <div class="pull-right">
78 <div class="btn-group">
71 <div class="btn-group">
79 <a
72 <a
80 class="btn ${diff_mode == 'sideside' and 'btn-primary'} tooltip"
73 class="btn ${c.diffmode == 'sideside' and 'btn-primary'} tooltip"
81 title="${_('View side by side')}"
74 title="${_('View side by side')}"
82 href="${link_for(diffmode='sideside')}">
75 href="${h.url_replace(diffmode='sideside')}">
83 <span>${_('Side by Side')}</span>
76 <span>${_('Side by Side')}</span>
84 </a>
77 </a>
85 <a
78 <a
86 class="btn ${diff_mode == 'unified' and 'btn-primary'} tooltip"
79 class="btn ${c.diffmode == 'unified' and 'btn-primary'} tooltip"
87 title="${_('View unified')}" href="${link_for(diffmode='unified')}">
80 title="${_('View unified')}" href="${h.url_replace(diffmode='unified')}">
88 <span>${_('Unified')}</span>
81 <span>${_('Unified')}</span>
89 </a>
82 </a>
90 </div>
83 </div>
91 </div>
84 </div>
92 <div class="pull-left">
85 <div class="pull-left">
93 <div class="btn-group">
86 <div class="btn-group">
94 <a
87 <a
95 class="btn"
88 class="btn"
96 href="#"
89 href="#"
97 onclick="$('input[class=filediff-collapse-state]').prop('checked', false); return false">${_('Expand All')}</a>
90 onclick="$('input[class=filediff-collapse-state]').prop('checked', false); return false">${_('Expand All')}</a>
98 <a
91 <a
99 class="btn"
92 class="btn"
100 href="#"
93 href="#"
101 onclick="$('input[class=filediff-collapse-state]').prop('checked', true); return false">${_('Collapse All')}</a>
94 onclick="$('input[class=filediff-collapse-state]').prop('checked', true); return false">${_('Collapse All')}</a>
102 </div>
95 </div>
103 </div>
96 </div>
104 %endif
105 <h2 style="padding: 5px; text-align: center;">
97 <h2 style="padding: 5px; text-align: center;">
106 %if diffset.limited_diff:
98 %if diffset.limited_diff:
107 ${ungettext('%(num)s file changed', '%(num)s files changed', diffset.changed_files) % {'num': diffset.changed_files}}
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 ${diff_ops(filediff)}
124 ${diff_ops(filediff)}
133 </label>
125 </label>
134 ${diff_menu(filediff)}
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 %if not filediff.hunks:
128 %if not filediff.hunks:
137 %for op_id, op_text in filediff['patch']['stats']['ops'].items():
129 %for op_id, op_text in filediff['patch']['stats']['ops'].items():
138 <tr>
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 %if op_id == DEL_FILENODE:
132 %if op_id == DEL_FILENODE:
141 ${_('File was deleted')}
133 ${_('File was deleted')}
142 %elif op_id == BIN_FILENODE:
134 %elif op_id == BIN_FILENODE:
@@ -150,7 +142,7 b' collapse_all = len(diffset.files) > coll'
150 %endif
142 %endif
151 %if over_lines_changed_limit:
143 %if over_lines_changed_limit:
152 <tr class="cb-warning cb-collapser">
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 ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
146 ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
155 <a href="#" class="cb-expand"
147 <a href="#" class="cb-expand"
156 onclick="$(this).closest('table').removeClass('cb-collapsed'); return false;">${_('Show them')}
148 onclick="$(this).closest('table').removeClass('cb-collapsed'); return false;">${_('Show them')}
@@ -163,29 +155,29 b' collapse_all = len(diffset.files) > coll'
163 %endif
155 %endif
164 %if filediff.patch['is_limited_diff']:
156 %if filediff.patch['is_limited_diff']:
165 <tr class="cb-warning cb-collapser">
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 ${_('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>
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 </td>
160 </td>
169 </tr>
161 </tr>
170 %endif
162 %endif
171 %for hunk in filediff.hunks:
163 %for hunk in filediff.hunks:
172 <tr class="cb-hunk">
164 <tr class="cb-hunk">
173 <td ${diff_mode == 'unified' and 'colspan=2' or ''}>
165 <td ${c.diffmode == 'unified' and 'colspan=2' or ''}>
174 ## TODO: dan: add ajax loading of more context here
166 ## TODO: dan: add ajax loading of more context here
175 ## <a href="#">
167 ## <a href="#">
176 <i class="icon-more"></i>
168 <i class="icon-more"></i>
177 ## </a>
169 ## </a>
178 </td>
170 </td>
179 <td ${diff_mode == 'sideside' and 'colspan=3' or ''}>
171 <td ${c.diffmode == 'sideside' and 'colspan=3' or ''}>
180 @@
172 @@
181 -${hunk.source_start},${hunk.source_length}
173 -${hunk.source_start},${hunk.source_length}
182 +${hunk.target_start},${hunk.target_length}
174 +${hunk.target_start},${hunk.target_length}
183 ${hunk.section_header}
175 ${hunk.section_header}
184 </td>
176 </td>
185 </tr>
177 </tr>
186 %if diff_mode == 'unified':
178 %if c.diffmode == 'unified':
187 ${render_hunk_lines_unified(hunk)}
179 ${render_hunk_lines_unified(hunk)}
188 %elif diff_mode == 'sideside':
180 %elif c.diffmode == 'sideside':
189 ${render_hunk_lines_sideside(hunk)}
181 ${render_hunk_lines_sideside(hunk)}
190 %else:
182 %else:
191 <tr class="cb-line">
183 <tr class="cb-line">
General Comments 0
You need to be logged in to leave comments. Login now