##// END OF EJS Templates
ui: new file tree switcher...
marcink -
r3655:6431a1ec new-ui
parent child Browse files
Show More
@@ -225,8 +225,7 b' class RepoFilesView(RepoAppView):'
225 225
226 226 return branch_name, sha_commit_id, is_head
227 227
228 def _get_tree_at_commit(
229 self, c, commit_id, f_path, full_load=False):
228 def _get_tree_at_commit(self, c, commit_id, f_path, full_load=False):
230 229
231 230 repo_id = self.db_repo.repo_id
232 231 force_recache = self.get_recache_flag()
@@ -632,8 +631,7 b' class RepoFilesView(RepoAppView):'
632 631 c.authors = []
633 632 # this loads a simple tree without metadata to speed things up
634 633 # later via ajax we call repo_nodetree_full and fetch whole
635 c.file_tree = self._get_tree_at_commit(
636 c, c.commit.raw_id, f_path)
634 c.file_tree = self._get_tree_at_commit(c, c.commit.raw_id, f_path)
637 635
638 636 except RepositoryError as e:
639 637 h.flash(safe_str(h.escape(e)), category='error')
@@ -367,8 +367,7 b' class RepoSummaryView(RepoAppView):'
367 367 })
368 368 return result
369 369
370 def _create_reference_items(self, repo, full_repo_name, refs, ref_type,
371 format_ref_id):
370 def _create_reference_items(self, repo, full_repo_name, refs, ref_type, format_ref_id):
372 371 result = []
373 372 is_svn = h.is_svn(repo)
374 373 for ref_name, raw_id in refs.iteritems():
@@ -380,6 +379,7 b' class RepoSummaryView(RepoAppView):'
380 379 'raw_id': raw_id,
381 380 'type': ref_type,
382 381 'files_url': files_url,
382 'idx': 0,
383 383 })
384 384 return result
385 385
@@ -217,9 +217,10 b' class _ToolTip(object):'
217 217 tooltip = _ToolTip()
218 218
219 219
220 def files_breadcrumbs(repo_name, commit_id, file_path):
220 def files_breadcrumbs(repo_name, commit_id, file_path, at_ref=None):
221 221 if isinstance(file_path, str):
222 222 file_path = safe_unicode(file_path)
223 route_qry = {'at': at_ref} if at_ref else None
223 224
224 225 # TODO: johbo: Is this always a url like path, or is this operating
225 226 # system dependent?
@@ -236,8 +237,9 b' def files_breadcrumbs(repo_name, commit_'
236 237 'repo_files',
237 238 repo_name=repo_name,
238 239 commit_id=commit_id,
239 f_path=''),
240 class_='pjax-link')]
240 f_path='',
241 _query=route_qry),
242 )]
241 243
242 244 last_cnt = len(path_segments) - 1
243 245 for cnt, segment in enumerate(path_segments):
@@ -253,8 +255,9 b' def files_breadcrumbs(repo_name, commit_'
253 255 'repo_files',
254 256 repo_name=repo_name,
255 257 commit_id=commit_id,
256 f_path='/'.join(path_segments[:cnt + 1])),
257 class_='pjax-link'))
258 f_path='/'.join(path_segments[:cnt + 1]),
259 _query=route_qry),
260 ))
258 261 else:
259 262 url_segments.append(segment_html)
260 263
@@ -142,7 +142,7 b' var fileBrowserListeners = function(node'
142 142 };
143 143
144 144 var typeIcon = '<i class="{0}"></i>'.format(typeObj[t]);
145 match.push('<tr class="browser-result"><td><a class="pjax-link" href="{0}">{1}{2}</a></td><td colspan="5"></td></tr>'.format(new_url,typeIcon, n_hl));
145 match.push('<tr class="browser-result"><td><a class="match-link" href="{0}">{1}{2}</a></td><td colspan="5"></td></tr>'.format(new_url,typeIcon, n_hl));
146 146 }
147 147 }
148 148 if(results.length > limit){
@@ -231,8 +231,8 b' var fileBrowserListeners = function(node'
231 231 }
232 232 if (e.keyCode === 13){ // Enter
233 233 if ($('.browser-highlight').length !== 0){
234 var url = $('.browser-highlight').find('.pjax-link').attr('href');
235 $.pjax({url: url, container: '#pjax-container', timeout: pjaxTimeout});
234 var url = $('.browser-highlight').find('.match-link').attr('href');
235 window.location = url;
236 236 }
237 237 }
238 238 if (e.keyCode === 27){ // Esc
@@ -18,7 +18,7 b''
18 18 <a href="${h.route_path('repo_files:default_path',repo_name=c.repo_name,commit_id=commit.raw_id,_query=dict(at=book))}"><i class="icon-bookmark"></i>${h.shorter(book)}</a>
19 19 </span>
20 20 <script>
21 fileTreeRefs["${book}"] = {raw_id: "${commit.raw_id}", type:"book"};
21 fileTreeRefs["${book}"] = {raw_id: "${commit.raw_id}", type:"book", text: "${book}"};
22 22 </script>
23 23 %endfor
24 24 %endif
@@ -28,7 +28,7 b''
28 28 <a href="${h.route_path('repo_files:default_path',repo_name=c.repo_name,commit_id=commit.raw_id,_query=dict(at=tag))}"><i class="icon-tag"></i>${tag}</a>
29 29 </span>
30 30 <script>
31 fileTreeRefs["${tag}"] = {raw_id: "${commit.raw_id}", type:"tag"};
31 fileTreeRefs["${tag}"] = {raw_id: "${commit.raw_id}", type:"tag", text: "${tag}"};
32 32 </script>
33 33 %endfor
34 34
@@ -37,7 +37,7 b''
37 37 <a href="${h.route_path('repo_files:default_path',repo_name=c.repo_name,commit_id=commit.raw_id,_query=dict(at=commit.branch))}"><i class="icon-code-fork"></i>${h.shorter(commit.branch)}</a>
38 38 </span>
39 39 <script>
40 fileTreeRefs["${commit.branch}"] = {raw_id: "${commit.raw_id}", type:"branch"};
40 fileTreeRefs["${commit.branch}"] = {raw_id: "${commit.raw_id}", type:"branch", text: "${commit.branch}"};
41 41 </script>
42 42 %endif
43 43
@@ -1,9 +1,9 b''
1 1 <%inherit file="/base/base.mako"/>
2 2
3 3 <%def name="title(*args)">
4 ${_('%s Files') % c.repo_name}
4 ${_('{} Files').format(c.repo_name)}
5 5 %if hasattr(c,'file'):
6 &middot; ${h.safe_unicode(c.file.path) or '\\'}
6 &middot; ${(h.safe_unicode(c.file.path) or '\\')}
7 7 %endif
8 8
9 9 %if c.rhodecode_name:
@@ -27,17 +27,16 b''
27 27 </%def>
28 28
29 29 <%def name="main()">
30 <div id="pjax-container">
30 <div>
31 31 <div id="files_data">
32 32 <%include file='files_pjax.mako'/>
33 33 </div>
34 34 </div>
35 35 <script>
36 var pjaxTimeout = 5000;
37 36
38 var curState = {
39 commit_id: "${c.commit.raw_id}"
40 };
37 var metadataRequest = null;
38 var fileSourcePage = ${c.file_source_page};
39 var atRef = '${request.GET.get('at', '')}';
41 40
42 41 var getState = function(context) {
43 42 var url = $(location).attr('href');
@@ -65,23 +64,30 b''
65 64 var f_path = parts2.join('/');
66 65 }
67 66
67 var url_params = {
68 repo_name: templateContext.repo_name,
69 commit_id: rev,
70 f_path:'__FPATH__'
71 };
72 if (atRef !== '') {
73 url_params['at'] = atRef
74 }
75
76 var _url_base = pyroutes.url('repo_files', url_params);
68 77 var _node_list_url = pyroutes.url('repo_files_nodelist',
69 78 {repo_name: templateContext.repo_name,
70 79 commit_id: rev, f_path: f_path});
71 var _url_base = pyroutes.url('repo_files',
72 {repo_name: templateContext.repo_name,
73 commit_id: rev, f_path:'__FPATH__'});
80
74 81 return {
75 82 url: url,
76 83 f_path: f_path,
77 84 rev: rev,
78 commit_id: curState.commit_id,
85 commit_id: "${c.commit.raw_id}",
79 86 node_list_url: _node_list_url,
80 87 url_base: _url_base
81 88 };
82 89 };
83 90
84 var metadataRequest = null;
85 91 var getFilesMetadata = function() {
86 92 if (metadataRequest && metadataRequest.readyState != 4) {
87 93 metadataRequest.abort();
@@ -120,7 +126,6 b''
120 126 };
121 127
122 128 var callbacks = function() {
123 var state = getState('callbacks');
124 129 timeagoActivate();
125 130
126 131 if ($('#trimmed_message_box').height() < 50) {
@@ -132,6 +137,8 b''
132 137 $(this).hide();
133 138 });
134 139
140 var state = getState('callbacks');
141
135 142 // VIEW FOR FILE SOURCE
136 143 if (fileSourcePage) {
137 144 // variants for with source code, not tree view
@@ -147,6 +154,7 b''
147 154 raw_id: null,
148 155 files_url: null
149 156 };
157
150 158 select2FileHistorySwitcher('#diff1', initialCommitData, state);
151 159
152 160 // show at, diff to actions handlers
@@ -200,7 +208,7 b''
200 208
201 209 $.pjax({
202 210 url: url,
203 data: 'annotate=${"1" if c.annotate else "0"}',
211 data: 'annotate=${("1" if c.annotate else "0")}',
204 212 container: '#file_authors',
205 213 push: false,
206 214 timeout: pjaxTimeout
@@ -240,9 +248,8 b''
240 248 fileBrowserListeners(state.node_list_url, state.url_base);
241 249
242 250 // switch to widget
243 console.log(state)
244 251 var initialCommitData = {
245 at_ref: '${request.GET.get('at')}',
252 at_ref: atRef,
246 253 id: null,
247 254 text: '${c.commit.raw_id}',
248 255 type: 'sha',
@@ -251,6 +258,12 b''
251 258 files_url: null,
252 259 };
253 260
261 // check if we have ref info.
262 var selectedRef = fileTreeRefs[atRef];
263 if (selectedRef !== undefined) {
264 $.extend(initialCommitData, selectedRef)
265 }
266
254 267 var loadUrl = pyroutes.url('repo_refs_data', {'repo_name': templateContext.repo_name});
255 268
256 269 var select2RefFileSwitcher = function (targetElement, loadUrl, initialData) {
@@ -260,7 +273,6 b''
260 273
261 274 var formatSelection = function (data, container) {
262 275 var commit_ref = data;
263 console.log(data)
264 276
265 277 var tmpl = '';
266 278 if (commit_ref.type === 'sha') {
@@ -319,60 +331,12 b''
319 331
320 332 $('#refs_filter').on('change', function(e) {
321 333 var data = $('#refs_filter').select2('data');
322 curState.commit_id = data.raw_id;
323 $.pjax({url: data.files_url, container: '#pjax-container', timeout: pjaxTimeout});
324 });
325
326 $("#prev_commit_link").on('click', function(e) {
327 var data = $(this).data();
328 curState.commit_id = data.commitId;
329 });
330
331 $("#next_commit_link").on('click', function(e) {
332 var data = $(this).data();
333 curState.commit_id = data.commitId;
334 window.location = data.files_url
334 335 });
335 336
336 337 }
337 338 };
338 339
339 $(document).pjax(".pjax-link", "#pjax-container", {
340 "fragment": "#pjax-content",
341 "maxCacheLength": 1000,
342 "timeout": pjaxTimeout
343 });
344
345 // define global back/forward states
346 var isPjaxPopState = false;
347 $(document).on('pjax:popstate', function() {
348 isPjaxPopState = true;
349 });
350
351 $(document).on('pjax:end', function(xhr, options) {
352 if (isPjaxPopState) {
353 isPjaxPopState = false;
354 callbacks();
355 _NODEFILTER.resetFilter();
356 }
357
358 // run callback for tracking if defined for google analytics etc.
359 // this is used to trigger tracking on pjax
360 if (typeof window.rhodecode_statechange_callback !== 'undefined') {
361 var state = getState('statechange');
362 rhodecode_statechange_callback(state.url, null)
363 }
364 });
365
366 $(document).on('pjax:success', function(event, xhr, options) {
367 if (event.target.id == "file_history_container") {
368 $('#file_history_overview').hide();
369 $('#file_history_overview_full').show();
370 timeagoActivate();
371 } else {
372 callbacks();
373 }
374 });
375
376 340 $(document).ready(function() {
377 341 callbacks();
378 342 var search_GET = "${request.GET.get('search','')}";
@@ -383,4 +347,4 b''
383 347
384 348 </script>
385 349
386 </%def>
350 </%def> No newline at end of file
@@ -33,7 +33,7 b''
33 33 </div>
34 34 <div class="right-content">
35 35 <div id="specify-custom-path-container">
36 <span id="path-breadcrumbs">${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.f_path)}</span>
36 <span id="path-breadcrumbs">${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.f_path, request.GET.get('at'))}</span>
37 37 <a class="custom-path-link" id="specify-custom-path" href="#">${_('Specify Custom Path')}</a>
38 38 </div>
39 39 <div id="remove-custom-path-container" style="display: none;">
@@ -6,13 +6,13 b''
6 6 <div class="info_box">
7 7
8 8 <div class="info_box_elem previous">
9 <a id="prev_commit_link" data-commit-id="${c.prev_commit.raw_id}" class="pjax-link ${'disabled' if c.url_prev == '#' else ''}" href="${c.url_prev}" title="${_('Previous commit')}"><i class="icon-left"></i></a>
9 <a id="prev_commit_link" data-commit-id="${c.prev_commit.raw_id}" class=" ${'disabled' if c.url_prev == '#' else ''}" href="${c.url_prev}" title="${_('Previous commit')}"><i class="icon-left"></i></a>
10 10 </div>
11 11
12 12 ${h.hidden('refs_filter')}
13 13
14 14 <div class="info_box_elem next">
15 <a id="next_commit_link" data-commit-id="${c.next_commit.raw_id}" class="pjax-link ${'disabled' if c.url_next == '#' else ''}" href="${c.url_next}" title="${_('Next commit')}"><i class="icon-right"></i></a>
15 <a id="next_commit_link" data-commit-id="${c.next_commit.raw_id}" class=" ${'disabled' if c.url_next == '#' else ''}" href="${c.url_next}" title="${_('Next commit')}"><i class="icon-right"></i></a>
16 16 </div>
17 17 </div>
18 18
@@ -1,4 +1,10 b''
1 <div id="file-tree-wrapper" class="browser-body ${'full-load' if c.full_load else ''}">
1 <%
2 if request.GET.get('at'):
3 query={'at': request.GET.get('at')}
4 else:
5 query=None
6 %>
7 <div id="file-tree-wrapper" class="browser-body ${('full-load' if c.full_load else '')}">
2 8 <table class="code-browser rctable repo_summary">
3 9 <thead>
4 10 <tr>
@@ -14,7 +20,7 b''
14 20 %if c.file.parent:
15 21 <tr class="parity0">
16 22 <td class="td-componentname">
17 <a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.file.parent.path)}" class="pjax-link">
23 <a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=c.file.parent.path, _query=query)}">
18 24 <i class="icon-directory"></i>..
19 25 </a>
20 26 </td>
@@ -38,8 +44,9 b''
38 44 % endif
39 45 </span>
40 46 % else:
41 <a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=h.safe_unicode(node.path))}" class="pjax-link">
42 <i class="${'icon-file-text browser-file' if node.is_file() else 'icon-directory browser-dir'}"></i>${node.name}
47
48 <a href="${h.route_path('repo_files',repo_name=c.repo_name,commit_id=c.commit.raw_id,f_path=h.safe_unicode(node.path), _query=query)}">
49 <i class="${('icon-file-text browser-file' if node.is_file() else 'icon-directory browser-dir')}"></i>${node.name}
43 50 </a>
44 51 % endif
45 52 </td>
@@ -31,7 +31,7 b''
31 31 ${_('Path')}:
32 32 </div>
33 33 <div class="right-content">
34 <span id="path-breadcrumbs">${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.f_path)}</span>
34 <span id="path-breadcrumbs">${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.f_path, request.GET.get('at'))}</span>
35 35 </div>
36 36 </div>
37 37 </div>
@@ -32,7 +32,7 b''
32 32 </div>
33 33 <div class="right-content">
34 34 <div id="specify-custom-path-container">
35 <span id="path-breadcrumbs">${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.f_path)}</span>
35 <span id="path-breadcrumbs">${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.f_path, request.GET.get('at'))}</span>
36 36 </div>
37 37 </div>
38 38 </div>
@@ -9,17 +9,13 b''
9 9 %endif
10 10 </%def>
11 11
12 <div id="pjax-content" data-title="${self.title()}">
13 <script>
14 // set the pageSource variable
15 var fileSourcePage = ${c.file_source_page};
16 </script>
12 <div>
17 13
18 14 <div class="summary-detail">
19 15 <div class="summary-detail-header">
20 16 <div class="breadcrumbs files_location">
21 17 <h4>
22 ${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.file.path)}
18 ${h.files_breadcrumbs(c.repo_name,c.commit.raw_id,c.file.path, request.GET.get('at'))}
23 19 %if c.annotate:
24 20 - ${_('annotation')}
25 21 %endif
@@ -41,19 +41,19 b' def test_urlify_text(url, expected_url):'
41 41
42 42 @pytest.mark.parametrize('repo_name, commit_id, path, expected_result', [
43 43 ('rX<X', 'cX<X', 'pX<X/aX<X/bX<X',
44 '<a class="pjax-link" href="/rX%3CX/files/cX%3CX/">rX&lt;X</a>/'
45 '<a class="pjax-link" href="/rX%3CX/files/cX%3CX/pX%3CX">pX&lt;X</a>/'
46 '<a class="pjax-link" href="/rX%3CX/files/cX%3CX/pX%3CX/aX%3CX">aX&lt;X'
44 '<a href="/rX%3CX/files/cX%3CX/">rX&lt;X</a>/'
45 '<a href="/rX%3CX/files/cX%3CX/pX%3CX">pX&lt;X</a>/'
46 '<a href="/rX%3CX/files/cX%3CX/pX%3CX/aX%3CX">aX&lt;X'
47 47 '</a>/bX&lt;X'),
48 48 # Path with only one segment
49 49 ('rX<X', 'cX<X', 'pX<X',
50 '<a class="pjax-link" href="/rX%3CX/files/cX%3CX/">rX&lt;X</a>/pX&lt;X'),
50 '<a href="/rX%3CX/files/cX%3CX/">rX&lt;X</a>/pX&lt;X'),
51 51 # Empty path
52 52 ('rX<X', 'cX<X', '', 'rX&lt;X'),
53 53 ('rX"X', 'cX"X', 'pX"X/aX"X/bX"X',
54 '<a class="pjax-link" href="/rX%22X/files/cX%22X/">rX&#34;X</a>/'
55 '<a class="pjax-link" href="/rX%22X/files/cX%22X/pX%22X">pX&#34;X</a>/'
56 '<a class="pjax-link" href="/rX%22X/files/cX%22X/pX%22X/aX%22X">aX&#34;X'
54 '<a href="/rX%22X/files/cX%22X/">rX&#34;X</a>/'
55 '<a href="/rX%22X/files/cX%22X/pX%22X">pX&#34;X</a>/'
56 '<a href="/rX%22X/files/cX%22X/pX%22X/aX%22X">aX&#34;X'
57 57 '</a>/bX&#34;X'),
58 58 ], ids=['simple', 'one_segment', 'empty_path', 'simple_quote'])
59 59 def test_files_breadcrumbs_xss(
General Comments 0
You need to be logged in to leave comments. Login now