##// END OF EJS Templates
users: use new session store for temporary settings for users....
marcink -
r3088:fbcbf993 default
parent child Browse files
Show More
@@ -63,6 +63,10 b' def includeme(config):'
63 name='markup_preview',
63 name='markup_preview',
64 pattern='/_markup_preview')
64 pattern='/_markup_preview')
65
65
66 config.add_route(
67 name='store_user_session_value',
68 pattern='/_store_session_attr')
69
66 # register our static links via redirection mechanism
70 # register our static links via redirection mechanism
67 routing_links.connect_redirection_links(config)
71 routing_links.connect_redirection_links(config)
68
72
@@ -444,3 +444,18 b' class HomeView(BaseAppView):'
444 if text:
444 if text:
445 return h.render(text, renderer=renderer, mentions=True)
445 return h.render(text, renderer=renderer, mentions=True)
446 return ''
446 return ''
447
448 @LoginRequired()
449 @CSRFRequired()
450 @view_config(
451 route_name='store_user_session_value', request_method='POST',
452 renderer='string', xhr=True)
453 def store_user_session_attr(self):
454 key = self.request.POST.get('key')
455 val = self.request.POST.get('val')
456
457 existing_value = self.request.session.get(key)
458 if existing_value != val:
459 self.request.session[key] = val
460
461 return 'stored:{}'.format(key)
@@ -357,6 +357,28 b' def attach_context_attributes(context, r'
357 'appenlight.api_public_key', '')
357 'appenlight.api_public_key', '')
358 context.appenlight_server_url = config.get('appenlight.server_url', '')
358 context.appenlight_server_url = config.get('appenlight.server_url', '')
359
359
360 diffmode = {
361 "unified": "unified",
362 "sideside": "sideside"
363 }.get(request.GET.get('diffmode'))
364
365 if diffmode and diffmode != request.session.get('rc_user_session_attr.diffmode'):
366 request.session['rc_user_session_attr.diffmode'] = diffmode
367
368 # session settings per user
369 session_attrs = {
370 # defaults
371 "clone_url_format": "http",
372 "diffmode": "sideside"
373 }
374 for k, v in request.session.items():
375 pref = 'rc_user_session_attr.'
376 if k and k.startswith(pref):
377 k = k[len(pref):]
378 session_attrs[k] = v
379
380 context.user_session_attrs = session_attrs
381
360 # JS template context
382 # JS template context
361 context.template_context = {
383 context.template_context = {
362 'repo_name': None,
384 'repo_name': None,
@@ -367,6 +389,7 b' def attach_context_attributes(context, r'
367 'email': None,
389 'email': None,
368 'notification_status': False
390 'notification_status': False
369 },
391 },
392 'session_attrs': session_attrs,
370 'visual': {
393 'visual': {
371 'default_renderer': None
394 'default_renderer': None
372 },
395 },
@@ -385,18 +408,6 b' def attach_context_attributes(context, r'
385 }
408 }
386 # END CONFIG VARS
409 # END CONFIG VARS
387
410
388 diffmode = 'sideside'
389 if request.GET.get('diffmode'):
390 if request.GET['diffmode'] == 'unified':
391 diffmode = 'unified'
392 elif request.session.get('diffmode'):
393 diffmode = request.session['diffmode']
394
395 context.diffmode = diffmode
396
397 if request.session.get('diffmode') != diffmode:
398 request.session['diffmode'] = diffmode
399
400 context.csrf_token = auth.get_csrf_token(session=request.session)
411 context.csrf_token = auth.get_csrf_token(session=request.session)
401 context.backends = rhodecode.BACKENDS.keys()
412 context.backends = rhodecode.BACKENDS.keys()
402 context.backends.sort()
413 context.backends.sort()
@@ -150,6 +150,7 b' function registerRCRoutes() {'
150 pyroutes.register('repo_list_data', '/_repos', []);
150 pyroutes.register('repo_list_data', '/_repos', []);
151 pyroutes.register('goto_switcher_data', '/_goto_data', []);
151 pyroutes.register('goto_switcher_data', '/_goto_data', []);
152 pyroutes.register('markup_preview', '/_markup_preview', []);
152 pyroutes.register('markup_preview', '/_markup_preview', []);
153 pyroutes.register('store_user_session_value', '/_store_session_attr', []);
153 pyroutes.register('journal', '/_admin/journal', []);
154 pyroutes.register('journal', '/_admin/journal', []);
154 pyroutes.register('journal_rss', '/_admin/journal/rss', []);
155 pyroutes.register('journal_rss', '/_admin/journal/rss', []);
155 pyroutes.register('journal_atom', '/_admin/journal/atom', []);
156 pyroutes.register('journal_atom', '/_admin/journal/atom', []);
@@ -553,3 +553,20 b' var feedLifetimeOptions = function(query'
553
553
554 query.callback(data);
554 query.callback(data);
555 };
555 };
556
557
558 var storeUserSessionAttr = function (key, val) {
559
560 var postData = {
561 'key': key,
562 'val': val,
563 'csrf_token': CSRF_TOKEN
564 };
565
566 var success = function(o) {
567 return true
568 };
569
570 ajaxPOST(pyroutes.url('store_user_session_value'), postData, success);
571 return false;
572 };
@@ -83,7 +83,7 b" return '%s_%s_%i' % (h.safeid(filename),"
83 collapse_all = len(diffset.files) > collapse_when_files_over
83 collapse_all = len(diffset.files) > collapse_when_files_over
84 %>
84 %>
85
85
86 %if c.diffmode == 'sideside':
86 %if c.user_session_attrs["diffmode"] == 'sideside':
87 <style>
87 <style>
88 .wrapper {
88 .wrapper {
89 max-width: 1600px !important;
89 max-width: 1600px !important;
@@ -162,24 +162,24 b' collapse_all = len(diffset.files) > coll'
162 ${diff_ops(filediff)}
162 ${diff_ops(filediff)}
163 </label>
163 </label>
164 ${diff_menu(filediff, use_comments=use_comments)}
164 ${diff_menu(filediff, use_comments=use_comments)}
165 <table class="cb cb-diff-${c.diffmode} code-highlight ${(over_lines_changed_limit and 'cb-collapsed' or '')}">
165 <table class="cb cb-diff-${c.user_session_attrs["diffmode"]} code-highlight ${(over_lines_changed_limit and 'cb-collapsed' or '')}">
166
166
167 ## new/deleted/empty content case
167 ## new/deleted/empty content case
168 % if not filediff.hunks:
168 % if not filediff.hunks:
169 ## Comment container, on "fakes" hunk that contains all data to render comments
169 ## Comment container, on "fakes" hunk that contains all data to render comments
170 ${render_hunk_lines(c.diffmode, filediff.hunk_ops, use_comments=use_comments, inline_comments=inline_comments)}
170 ${render_hunk_lines(c.user_session_attrs["diffmode"], filediff.hunk_ops, use_comments=use_comments, inline_comments=inline_comments)}
171 % endif
171 % endif
172
172
173 %if filediff.limited_diff:
173 %if filediff.limited_diff:
174 <tr class="cb-warning cb-collapser">
174 <tr class="cb-warning cb-collapser">
175 <td class="cb-text" ${(c.diffmode == 'unified' and 'colspan=4' or 'colspan=6')}>
175 <td class="cb-text" ${(c.user_session_attrs["diffmode"] == 'unified' and 'colspan=4' or 'colspan=6')}>
176 ${_('The requested commit is too big and content was truncated.')} <a href="${h.current_route_path(request, fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
176 ${_('The requested commit is too big and content was truncated.')} <a href="${h.current_route_path(request, fulldiff=1)}" onclick="return confirm('${_("Showing a big diff might take some time and resources, continue?")}')">${_('Show full diff')}</a>
177 </td>
177 </td>
178 </tr>
178 </tr>
179 %else:
179 %else:
180 %if over_lines_changed_limit:
180 %if over_lines_changed_limit:
181 <tr class="cb-warning cb-collapser">
181 <tr class="cb-warning cb-collapser">
182 <td class="cb-text" ${(c.diffmode == 'unified' and 'colspan=4' or 'colspan=6')}>
182 <td class="cb-text" ${(c.user_session_attrs["diffmode"] == 'unified' and 'colspan=4' or 'colspan=6')}>
183 ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
183 ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
184 <a href="#" class="cb-expand"
184 <a href="#" class="cb-expand"
185 onclick="$(this).closest('table').removeClass('cb-collapsed'); return false;">${_('Show them')}
185 onclick="$(this).closest('table').removeClass('cb-collapsed'); return false;">${_('Show them')}
@@ -194,20 +194,20 b' collapse_all = len(diffset.files) > coll'
194
194
195 % for hunk in filediff.hunks:
195 % for hunk in filediff.hunks:
196 <tr class="cb-hunk">
196 <tr class="cb-hunk">
197 <td ${(c.diffmode == 'unified' and 'colspan=3' or '')}>
197 <td ${(c.user_session_attrs["diffmode"] == 'unified' and 'colspan=3' or '')}>
198 ## TODO: dan: add ajax loading of more context here
198 ## TODO: dan: add ajax loading of more context here
199 ## <a href="#">
199 ## <a href="#">
200 <i class="icon-more"></i>
200 <i class="icon-more"></i>
201 ## </a>
201 ## </a>
202 </td>
202 </td>
203 <td ${(c.diffmode == 'sideside' and 'colspan=5' or '')}>
203 <td ${(c.user_session_attrs["diffmode"] == 'sideside' and 'colspan=5' or '')}>
204 @@
204 @@
205 -${hunk.source_start},${hunk.source_length}
205 -${hunk.source_start},${hunk.source_length}
206 +${hunk.target_start},${hunk.target_length}
206 +${hunk.target_start},${hunk.target_length}
207 ${hunk.section_header}
207 ${hunk.section_header}
208 </td>
208 </td>
209 </tr>
209 </tr>
210 ${render_hunk_lines(c.diffmode, hunk, use_comments=use_comments, inline_comments=inline_comments)}
210 ${render_hunk_lines(c.user_session_attrs["diffmode"], hunk, use_comments=use_comments, inline_comments=inline_comments)}
211 % endfor
211 % endfor
212
212
213 <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %>
213 <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %>
@@ -215,7 +215,7 b' collapse_all = len(diffset.files) > coll'
215 ## outdated comments that do not fit into currently displayed lines
215 ## outdated comments that do not fit into currently displayed lines
216 % for lineno, comments in unmatched_comments.items():
216 % for lineno, comments in unmatched_comments.items():
217
217
218 %if c.diffmode == 'unified':
218 %if c.user_session_attrs["diffmode"] == 'unified':
219 % if loop.index == 0:
219 % if loop.index == 0:
220 <tr class="cb-hunk">
220 <tr class="cb-hunk">
221 <td colspan="3"></td>
221 <td colspan="3"></td>
@@ -234,7 +234,7 b' collapse_all = len(diffset.files) > coll'
234 ${inline_comments_container(comments, inline_comments)}
234 ${inline_comments_container(comments, inline_comments)}
235 </td>
235 </td>
236 </tr>
236 </tr>
237 %elif c.diffmode == 'sideside':
237 %elif c.user_session_attrs["diffmode"] == 'sideside':
238 % if loop.index == 0:
238 % if loop.index == 0:
239 <tr class="cb-comment-info">
239 <tr class="cb-comment-info">
240 <td colspan="2"></td>
240 <td colspan="2"></td>
@@ -303,18 +303,18 b' collapse_all = len(diffset.files) > coll'
303 </span>
303 </span>
304 </label>
304 </label>
305
305
306 <table class="cb cb-diff-${c.diffmode} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}">
306 <table class="cb cb-diff-${c.user_session_attrs["diffmode"]} code-highlight ${over_lines_changed_limit and 'cb-collapsed' or ''}">
307 <tr>
307 <tr>
308 % if c.diffmode == 'unified':
308 % if c.user_session_attrs["diffmode"] == 'unified':
309 <td></td>
309 <td></td>
310 %endif
310 %endif
311
311
312 <td></td>
312 <td></td>
313 <td class="cb-text cb-${op_class(BIN_FILENODE)}" ${c.diffmode == 'unified' and 'colspan=4' or 'colspan=5'}>
313 <td class="cb-text cb-${op_class(BIN_FILENODE)}" ${(c.user_session_attrs["diffmode"] == 'unified' and 'colspan=4' or 'colspan=5')}>
314 ${_('File was deleted in this version. There are still outdated/unresolved comments attached to it.')}
314 ${_('File was deleted in this version. There are still outdated/unresolved comments attached to it.')}
315 </td>
315 </td>
316 </tr>
316 </tr>
317 %if c.diffmode == 'unified':
317 %if c.user_session_attrs["diffmode"] == 'unified':
318 <tr class="cb-line">
318 <tr class="cb-line">
319 <td class="cb-data cb-context"></td>
319 <td class="cb-data cb-context"></td>
320 <td class="cb-lineno cb-context"></td>
320 <td class="cb-lineno cb-context"></td>
@@ -323,7 +323,7 b' collapse_all = len(diffset.files) > coll'
323 ${inline_comments_container(comments_dict['comments'], inline_comments)}
323 ${inline_comments_container(comments_dict['comments'], inline_comments)}
324 </td>
324 </td>
325 </tr>
325 </tr>
326 %elif c.diffmode == 'sideside':
326 %elif c.user_session_attrs["diffmode"] == 'sideside':
327 <tr class="cb-line">
327 <tr class="cb-line">
328 <td class="cb-data cb-context"></td>
328 <td class="cb-data cb-context"></td>
329 <td class="cb-lineno cb-context"></td>
329 <td class="cb-lineno cb-context"></td>
@@ -734,13 +734,13 b' def get_comments_for(diff_type, comments'
734 <div class="btn-group">
734 <div class="btn-group">
735
735
736 <a
736 <a
737 class="btn ${c.diffmode == 'sideside' and 'btn-primary'} tooltip"
737 class="btn ${(c.user_session_attrs["diffmode"] == 'sideside' and 'btn-primary')} tooltip"
738 title="${h.tooltip(_('View side by side'))}"
738 title="${h.tooltip(_('View side by side'))}"
739 href="${h.current_route_path(request, diffmode='sideside')}">
739 href="${h.current_route_path(request, diffmode='sideside')}">
740 <span>${_('Side by Side')}</span>
740 <span>${_('Side by Side')}</span>
741 </a>
741 </a>
742 <a
742 <a
743 class="btn ${c.diffmode == 'unified' and 'btn-primary'} tooltip"
743 class="btn ${(c.user_session_attrs["diffmode"] == 'unified' and 'btn-primary')} tooltip"
744 title="${h.tooltip(_('View unified'))}" href="${h.current_route_path(request, diffmode='unified')}">
744 title="${h.tooltip(_('View unified'))}" href="${h.current_route_path(request, diffmode='unified')}">
745 <span>${_('Unified')}</span>
745 <span>${_('Unified')}</span>
746 </a>
746 </a>
@@ -60,15 +60,25 b''
60
60
61 <script type="text/javascript">
61 <script type="text/javascript">
62 $(document).ready(function(){
62 $(document).ready(function(){
63 $('#clone_option').on('change', function(e) {
63
64 var selected = $(this).val();
64 var showCloneField = function(clone_url_format){
65 $.each(['http', 'http_id', 'ssh'], function (idx, val) {
65 $.each(['http', 'http_id', 'ssh'], function (idx, val) {
66 if(val === selected){
66 if(val === clone_url_format){
67 $('#clone_option_' + val).show();
67 $('#clone_option_' + val).show();
68 $('#clone_option').val(val)
68 } else {
69 } else {
69 $('#clone_option_' + val).hide();
70 $('#clone_option_' + val).hide();
70 }
71 }
71 });
72 });
73 };
74 // default taken from session
75 showCloneField(templateContext.session_attrs.clone_url_format);
76
77 $('#clone_option').on('change', function(e) {
78 var selected = $(this).val();
79
80 storeUserSessionAttr('rc_user_session_attr.clone_url_format', selected);
81 showCloneField(selected)
72 });
82 });
73
83
74 var initialCommitData = {
84 var initialCommitData = {
General Comments 0
You need to be logged in to leave comments. Login now