##// 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 63 name='markup_preview',
64 64 pattern='/_markup_preview')
65 65
66 config.add_route(
67 name='store_user_session_value',
68 pattern='/_store_session_attr')
69
66 70 # register our static links via redirection mechanism
67 71 routing_links.connect_redirection_links(config)
68 72
@@ -444,3 +444,18 b' class HomeView(BaseAppView):'
444 444 if text:
445 445 return h.render(text, renderer=renderer, mentions=True)
446 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 357 'appenlight.api_public_key', '')
358 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 382 # JS template context
361 383 context.template_context = {
362 384 'repo_name': None,
@@ -367,6 +389,7 b' def attach_context_attributes(context, r'
367 389 'email': None,
368 390 'notification_status': False
369 391 },
392 'session_attrs': session_attrs,
370 393 'visual': {
371 394 'default_renderer': None
372 395 },
@@ -385,18 +408,6 b' def attach_context_attributes(context, r'
385 408 }
386 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 411 context.csrf_token = auth.get_csrf_token(session=request.session)
401 412 context.backends = rhodecode.BACKENDS.keys()
402 413 context.backends.sort()
@@ -150,6 +150,7 b' function registerRCRoutes() {'
150 150 pyroutes.register('repo_list_data', '/_repos', []);
151 151 pyroutes.register('goto_switcher_data', '/_goto_data', []);
152 152 pyroutes.register('markup_preview', '/_markup_preview', []);
153 pyroutes.register('store_user_session_value', '/_store_session_attr', []);
153 154 pyroutes.register('journal', '/_admin/journal', []);
154 155 pyroutes.register('journal_rss', '/_admin/journal/rss', []);
155 156 pyroutes.register('journal_atom', '/_admin/journal/atom', []);
@@ -553,3 +553,20 b' var feedLifetimeOptions = function(query'
553 553
554 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 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 87 <style>
88 88 .wrapper {
89 89 max-width: 1600px !important;
@@ -162,24 +162,24 b' collapse_all = len(diffset.files) > coll'
162 162 ${diff_ops(filediff)}
163 163 </label>
164 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 167 ## new/deleted/empty content case
168 168 % if not filediff.hunks:
169 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 171 % endif
172 172
173 173 %if filediff.limited_diff:
174 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 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 177 </td>
178 178 </tr>
179 179 %else:
180 180 %if over_lines_changed_limit:
181 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 183 ${_('This diff has been collapsed as it changes many lines, (%i lines changed)' % lines_changed)}
184 184 <a href="#" class="cb-expand"
185 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 195 % for hunk in filediff.hunks:
196 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 198 ## TODO: dan: add ajax loading of more context here
199 199 ## <a href="#">
200 200 <i class="icon-more"></i>
201 201 ## </a>
202 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 205 -${hunk.source_start},${hunk.source_length}
206 206 +${hunk.target_start},${hunk.target_length}
207 207 ${hunk.section_header}
208 208 </td>
209 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 211 % endfor
212 212
213 213 <% unmatched_comments = (inline_comments or {}).get(filediff.patch['filename'], {}) %>
@@ -215,7 +215,7 b' collapse_all = len(diffset.files) > coll'
215 215 ## outdated comments that do not fit into currently displayed lines
216 216 % for lineno, comments in unmatched_comments.items():
217 217
218 %if c.diffmode == 'unified':
218 %if c.user_session_attrs["diffmode"] == 'unified':
219 219 % if loop.index == 0:
220 220 <tr class="cb-hunk">
221 221 <td colspan="3"></td>
@@ -234,7 +234,7 b' collapse_all = len(diffset.files) > coll'
234 234 ${inline_comments_container(comments, inline_comments)}
235 235 </td>
236 236 </tr>
237 %elif c.diffmode == 'sideside':
237 %elif c.user_session_attrs["diffmode"] == 'sideside':
238 238 % if loop.index == 0:
239 239 <tr class="cb-comment-info">
240 240 <td colspan="2"></td>
@@ -303,18 +303,18 b' collapse_all = len(diffset.files) > coll'
303 303 </span>
304 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 307 <tr>
308 % if c.diffmode == 'unified':
308 % if c.user_session_attrs["diffmode"] == 'unified':
309 309 <td></td>
310 310 %endif
311 311
312 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 314 ${_('File was deleted in this version. There are still outdated/unresolved comments attached to it.')}
315 315 </td>
316 316 </tr>
317 %if c.diffmode == 'unified':
317 %if c.user_session_attrs["diffmode"] == 'unified':
318 318 <tr class="cb-line">
319 319 <td class="cb-data cb-context"></td>
320 320 <td class="cb-lineno cb-context"></td>
@@ -323,7 +323,7 b' collapse_all = len(diffset.files) > coll'
323 323 ${inline_comments_container(comments_dict['comments'], inline_comments)}
324 324 </td>
325 325 </tr>
326 %elif c.diffmode == 'sideside':
326 %elif c.user_session_attrs["diffmode"] == 'sideside':
327 327 <tr class="cb-line">
328 328 <td class="cb-data cb-context"></td>
329 329 <td class="cb-lineno cb-context"></td>
@@ -734,13 +734,13 b' def get_comments_for(diff_type, comments'
734 734 <div class="btn-group">
735 735
736 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 738 title="${h.tooltip(_('View side by side'))}"
739 739 href="${h.current_route_path(request, diffmode='sideside')}">
740 740 <span>${_('Side by Side')}</span>
741 741 </a>
742 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 744 title="${h.tooltip(_('View unified'))}" href="${h.current_route_path(request, diffmode='unified')}">
745 745 <span>${_('Unified')}</span>
746 746 </a>
@@ -60,15 +60,25 b''
60 60
61 61 <script type="text/javascript">
62 62 $(document).ready(function(){
63 $('#clone_option').on('change', function(e) {
64 var selected = $(this).val();
63
64 var showCloneField = function(clone_url_format){
65 65 $.each(['http', 'http_id', 'ssh'], function (idx, val) {
66 if(val === selected){
66 if(val === clone_url_format){
67 67 $('#clone_option_' + val).show();
68 $('#clone_option').val(val)
68 69 } else {
69 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 84 var initialCommitData = {
General Comments 0
You need to be logged in to leave comments. Login now