##// END OF EJS Templates
files: don't format 0 revision in select pickers
marcink -
r3707:da37aa49 new-ui
parent child Browse files
Show More
@@ -1,463 +1,467 b''
1 1 <%inherit file="/base/base.mako"/>
2 2
3 3 <%def name="title(*args)">
4 4 ${_('{} Files').format(c.repo_name)}
5 5 %if hasattr(c,'file'):
6 6 &middot; ${(h.safe_unicode(c.file.path) or '\\')}
7 7 %endif
8 8
9 9 %if c.rhodecode_name:
10 10 &middot; ${h.branding(c.rhodecode_name)}
11 11 %endif
12 12 </%def>
13 13
14 14 <%def name="breadcrumbs_links()">
15 15 ${_('Files')}
16 16 %if c.file:
17 17 @ ${h.show_id(c.commit)}
18 18 %endif
19 19 </%def>
20 20
21 21 <%def name="menu_bar_nav()">
22 22 ${self.menu_items(active='repositories')}
23 23 </%def>
24 24
25 25 <%def name="menu_bar_subnav()">
26 26 ${self.repo_menu(active='files')}
27 27 </%def>
28 28
29 29 <%def name="main()">
30 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 36
37 37 var metadataRequest = null;
38 38 var fileSourcePage = ${c.file_source_page};
39 39 var atRef = '${request.GET.get('at', '')}';
40 40
41 41 var getState = function(context) {
42 42 var url = $(location).attr('href');
43 43 var _base_url = '${h.route_path("repo_files",repo_name=c.repo_name,commit_id='',f_path='')}';
44 44 var _annotate_url = '${h.route_path("repo_files:annotated",repo_name=c.repo_name,commit_id='',f_path='')}';
45 45 _base_url = _base_url.replace('//', '/');
46 46 _annotate_url = _annotate_url.replace('//', '/');
47 47
48 48 //extract f_path from url.
49 49 var parts = url.split(_base_url);
50 50 if (parts.length != 2) {
51 51 parts = url.split(_annotate_url);
52 52 if (parts.length != 2) {
53 53 var rev = "tip";
54 54 var f_path = "";
55 55 } else {
56 56 var parts2 = parts[1].split('/');
57 57 var rev = parts2.shift(); // pop the first element which is the revision
58 58 var f_path = parts2.join('/');
59 59 }
60 60
61 61 } else {
62 62 var parts2 = parts[1].split('/');
63 63 var rev = parts2.shift(); // pop the first element which is the revision
64 64 var f_path = parts2.join('/');
65 65 }
66 66
67 67 var url_params = {
68 68 repo_name: templateContext.repo_name,
69 69 commit_id: rev,
70 70 f_path:'__FPATH__'
71 71 };
72 72 if (atRef !== '') {
73 73 url_params['at'] = atRef
74 74 }
75 75
76 76 var _url_base = pyroutes.url('repo_files', url_params);
77 77 var _node_list_url = pyroutes.url('repo_files_nodelist',
78 78 {repo_name: templateContext.repo_name,
79 79 commit_id: rev, f_path: f_path});
80 80
81 81 return {
82 82 url: url,
83 83 f_path: f_path,
84 84 rev: rev,
85 85 commit_id: "${c.commit.raw_id}",
86 86 node_list_url: _node_list_url,
87 87 url_base: _url_base
88 88 };
89 89 };
90 90
91 91 var getFilesMetadata = function() {
92 92 if (metadataRequest && metadataRequest.readyState != 4) {
93 93 metadataRequest.abort();
94 94 }
95 95 if (fileSourcePage) {
96 96 return false;
97 97 }
98 98
99 99 if ($('#file-tree-wrapper').hasClass('full-load')) {
100 100 // in case our HTML wrapper has full-load class we don't
101 101 // trigger the async load of metadata
102 102 return false;
103 103 }
104 104
105 105 var state = getState('metadata');
106 106 var url_data = {
107 107 'repo_name': templateContext.repo_name,
108 108 'commit_id': state.commit_id,
109 109 'f_path': state.f_path
110 110 };
111 111
112 112 var url = pyroutes.url('repo_nodetree_full', url_data);
113 113
114 114 metadataRequest = $.ajax({url: url});
115 115
116 116 metadataRequest.done(function(data) {
117 117 $('#file-tree').html(data);
118 118 timeagoActivate();
119 119 });
120 120 metadataRequest.fail(function (data, textStatus, errorThrown) {
121 121 if (data.status != 0) {
122 122 alert("Error while fetching metadata.\nError code {0} ({1}).Please consider reloading the page".format(data.status,data.statusText));
123 123 }
124 124 });
125 125 };
126 126
127 127 var initFileJS = function () {
128 128 var state = getState('callbacks');
129 129
130 130 // select code link event
131 131 $("#hlcode").mouseup(getSelectionLink);
132 132
133 133 // file history select2 used for history of file, and switch to
134 134 var initialCommitData = {
135 135 at_ref: atRef,
136 136 id: null,
137 137 text: '${c.commit.raw_id}',
138 138 type: 'sha',
139 139 raw_id: '${c.commit.raw_id}',
140 140 idx: ${c.commit.idx},
141 141 files_url: null,
142 142 };
143 143
144 144 // check if we have ref info.
145 145 var selectedRef = fileTreeRefs[atRef];
146 146 if (selectedRef !== undefined) {
147 147 $.extend(initialCommitData, selectedRef)
148 148 }
149 149
150 150 var loadUrl = pyroutes.url('repo_file_history', {'repo_name': templateContext.repo_name, 'commit_id': state.rev,'f_path': state.f_path});
151 151 var cacheKey = '__SINGLE_FILE_REFS__';
152 152 var cachedDataSource = {};
153 153
154 154 var loadRefsData = function (query) {
155 155 $.ajax({
156 156 url: loadUrl,
157 157 data: {},
158 158 dataType: 'json',
159 159 type: 'GET',
160 160 success: function (data) {
161 161 cachedDataSource[cacheKey] = data;
162 162 query.callback({results: data.results});
163 163 }
164 164 });
165 165 };
166 166
167 167 var feedRefsData = function (query, cachedData) {
168 168 var data = {results: []};
169 169 //filter results
170 170 $.each(cachedData.results, function () {
171 171 var section = this.text;
172 172 var children = [];
173 173 $.each(this.children, function () {
174 174 if (query.term.length === 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0) {
175 175 children.push(this)
176 176 }
177 177 });
178 178 data.results.push({
179 179 'text': section,
180 180 'children': children
181 181 })
182 182 });
183 183
184 184 query.callback(data);
185 185 };
186 186
187 187 var select2FileHistorySwitcher = function (targetElement, loadUrl, initialData) {
188 188 var formatResult = function (result, container, query) {
189 189 return formatSelect2SelectionRefs(result);
190 190 };
191 191
192 192 var formatSelection = function (data, container) {
193 193 var commit_ref = data;
194 194
195 195 var tmpl = '';
196 196 if (commit_ref.type === 'sha') {
197 197 tmpl = (commit_ref.raw_id || "").substr(0,8);
198 198 } else if (commit_ref.type === 'branch') {
199 199 tmpl = tmpl.concat('<i class="icon-branch"></i> ');
200 200 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
201 201 } else if (commit_ref.type === 'tag') {
202 202 tmpl = tmpl.concat('<i class="icon-tag"></i> ');
203 203 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
204 204 } else if (commit_ref.type === 'book') {
205 205 tmpl = tmpl.concat('<i class="icon-bookmark"></i> ');
206 206 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
207 207 }
208 208 var idx = commit_ref.idx || 0;
209 if (idx !== 0) {
209 210 tmpl = tmpl.concat('<span class="select-index-number">r{0}</span>'.format(idx));
211 }
210 212 return tmpl
211 213 };
212 214
213 215 $(targetElement).select2({
214 216 dropdownAutoWidth: true,
215 217 width: "resolve",
216 218 containerCssClass: "drop-menu",
217 219 dropdownCssClass: "drop-menu-dropdown",
218 220 query: function(query) {
219 221 var cachedData = cachedDataSource[cacheKey];
220 222 if (cachedData) {
221 223 feedRefsData(query, cachedData)
222 224 } else {
223 225 loadRefsData(query)
224 226 }
225 227 },
226 228 initSelection: function(element, callback) {
227 229 callback(initialData);
228 230 },
229 231 formatResult: formatResult,
230 232 formatSelection: formatSelection
231 233 });
232 234
233 235 };
234 236
235 237 select2FileHistorySwitcher('#file_refs_filter', loadUrl, initialCommitData);
236 238
237 239 $('#file_refs_filter').on('change', function(e) {
238 240 var data = $('#file_refs_filter').select2('data');
239 241 var commit_id = data.id;
240 242
241 243 if ("${c.annotate}" === "True") {
242 244 var url = pyroutes.url('repo_files:annotated',
243 245 {'repo_name': templateContext.repo_name,
244 246 'commit_id': commit_id, 'f_path': state.f_path});
245 247 } else {
246 248 var url = pyroutes.url('repo_files',
247 249 {'repo_name': templateContext.repo_name,
248 250 'commit_id': commit_id, 'f_path': state.f_path});
249 251 }
250 252 window.location = url;
251 253
252 254 });
253 255
254 256 // show more authors
255 257 $('#show_authors').on('click', function(e) {
256 258 e.preventDefault();
257 259 var url = pyroutes.url('repo_file_authors',
258 260 {'repo_name': templateContext.repo_name,
259 261 'commit_id': state.rev, 'f_path': state.f_path});
260 262
261 263 $.pjax({
262 264 url: url,
263 265 data: 'annotate=${("1" if c.annotate else "0")}',
264 266 container: '#file_authors',
265 267 push: false,
266 268 timeout: 5000
267 269 }).complete(function(){
268 270 $('#show_authors').hide();
269 271 $('#file_authors_title').html(_gettext('All Authors'))
270 272 })
271 273 });
272 274
273 275 // load file short history
274 276 $('#file_history_overview').on('click', function(e) {
275 277 e.preventDefault();
276 278 path = state.f_path;
277 279 if (path.indexOf("#") >= 0) {
278 280 path = path.slice(0, path.indexOf("#"));
279 281 }
280 282 var url = pyroutes.url('repo_changelog_file',
281 283 {'repo_name': templateContext.repo_name,
282 284 'commit_id': state.rev, 'f_path': path, 'limit': 6});
283 285 $('#file_history_container').show();
284 286 $('#file_history_container').html('<div class="file-history-inner">{0}</div>'.format(_gettext('Loading ...')));
285 287
286 288 $.pjax({
287 289 url: url,
288 290 container: '#file_history_container',
289 291 push: false,
290 292 timeout: 5000
291 293 });
292 294 });
293 295
294 296
295 297 };
296 298
297 299 var initTreeJS = function () {
298 300 var state = getState('callbacks');
299 301 getFilesMetadata();
300 302
301 303 // fuzzy file filter
302 304 fileBrowserListeners(state.node_list_url, state.url_base);
303 305
304 306 // switch to widget
305 307 var initialCommitData = {
306 308 at_ref: atRef,
307 309 id: null,
308 310 text: '${c.commit.raw_id}',
309 311 type: 'sha',
310 312 raw_id: '${c.commit.raw_id}',
311 313 idx: ${c.commit.idx},
312 314 files_url: null,
313 315 };
314 316
315 317 // check if we have ref info.
316 318 var selectedRef = fileTreeRefs[atRef];
317 319 if (selectedRef !== undefined) {
318 320 $.extend(initialCommitData, selectedRef)
319 321 }
320 322
321 323 var loadUrl = pyroutes.url('repo_refs_data', {'repo_name': templateContext.repo_name});
322 324 var cacheKey = '__ALL_FILE_REFS__';
323 325 var cachedDataSource = {};
324 326
325 327 var loadRefsData = function (query) {
326 328 $.ajax({
327 329 url: loadUrl,
328 330 data: {},
329 331 dataType: 'json',
330 332 type: 'GET',
331 333 success: function (data) {
332 334 cachedDataSource[cacheKey] = data;
333 335 query.callback({results: data.results});
334 336 }
335 337 });
336 338 };
337 339
338 340 var feedRefsData = function (query, cachedData) {
339 341 var data = {results: []};
340 342 //filter results
341 343 $.each(cachedData.results, function () {
342 344 var section = this.text;
343 345 var children = [];
344 346 $.each(this.children, function () {
345 347 if (query.term.length === 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0) {
346 348 children.push(this)
347 349 }
348 350 });
349 351 data.results.push({
350 352 'text': section,
351 353 'children': children
352 354 })
353 355 });
354 356
355 357 //push the typed in commit idx
356 358 if (!isNaN(query.term)) {
357 359 var files_url = pyroutes.url('repo_files',
358 360 {'repo_name': templateContext.repo_name,
359 361 'commit_id': query.term, 'f_path': state.f_path});
360 362
361 363 data.results.push({
362 364 'text': _gettext('go to numeric commit'),
363 365 'children': [{
364 366 at_ref: null,
365 367 id: null,
366 368 text: 'r{0}'.format(query.term),
367 369 type: 'sha',
368 370 raw_id: query.term,
369 371 idx: query.term,
370 372 files_url: files_url,
371 373 }]
372 374 });
373 375 }
374 376 query.callback(data);
375 377 };
376 378
377 379 var select2RefFileSwitcher = function (targetElement, loadUrl, initialData) {
378 380 var formatResult = function (result, container, query) {
379 381 return formatSelect2SelectionRefs(result);
380 382 };
381 383
382 384 var formatSelection = function (data, container) {
383 385 var commit_ref = data;
384 386
385 387 var tmpl = '';
386 388 if (commit_ref.type === 'sha') {
387 389 tmpl = (commit_ref.raw_id || "").substr(0,8);
388 390 } else if (commit_ref.type === 'branch') {
389 391 tmpl = tmpl.concat('<i class="icon-branch"></i> ');
390 392 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
391 393 } else if (commit_ref.type === 'tag') {
392 394 tmpl = tmpl.concat('<i class="icon-tag"></i> ');
393 395 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
394 396 } else if (commit_ref.type === 'book') {
395 397 tmpl = tmpl.concat('<i class="icon-bookmark"></i> ');
396 398 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
397 399 }
398 400
399 401 var idx = commit_ref.idx || 0;
402 if (idx !== 0) {
400 403 tmpl = tmpl.concat('<span class="select-index-number">r{0}</span>'.format(idx));
404 }
401 405 return tmpl
402 406 };
403 407
404 408 $(targetElement).select2({
405 409 dropdownAutoWidth: true,
406 410 width: "resolve",
407 411 containerCssClass: "drop-menu",
408 412 dropdownCssClass: "drop-menu-dropdown",
409 413 query: function(query) {
410 414
411 415 var cachedData = cachedDataSource[cacheKey];
412 416 if (cachedData) {
413 417 feedRefsData(query, cachedData)
414 418 } else {
415 419 loadRefsData(query)
416 420 }
417 421 },
418 422 initSelection: function(element, callback) {
419 423 callback(initialData);
420 424 },
421 425 formatResult: formatResult,
422 426 formatSelection: formatSelection
423 427 });
424 428
425 429 };
426 430
427 431 select2RefFileSwitcher('#refs_filter', loadUrl, initialCommitData);
428 432
429 433 $('#refs_filter').on('change', function(e) {
430 434 var data = $('#refs_filter').select2('data');
431 435 window.location = data.files_url
432 436 });
433 437
434 438 };
435 439
436 440 $(document).ready(function() {
437 441 timeagoActivate();
438 442
439 443 if ($('#trimmed_message_box').height() < 50) {
440 444 $('#message_expand').hide();
441 445 }
442 446
443 447 $('#message_expand').on('click', function(e) {
444 448 $('#trimmed_message_box').css('max-height', 'none');
445 449 $(this).hide();
446 450 });
447 451
448 452 if (fileSourcePage) {
449 453 initFileJS()
450 454 } else {
451 455 initTreeJS()
452 456 }
453 457
454 458 var search_GET = "${request.GET.get('search','')}";
455 459 if (search_GET === "1") {
456 460 NodeFilter.initFilter();
457 461 NodeFilter.focus();
458 462 }
459 463 });
460 464
461 465 </script>
462 466
463 467 </%def> No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now