##// END OF EJS Templates
files: bring back ability to specify numeric commit number in files selector
marcink -
r3667:a0a98ffc new-ui
parent child Browse files
Show More
@@ -319,8 +319,7 b' class RepoSummaryView(RepoAppView):'
319 319 (_("Tag"), repo.tags, 'tag'),
320 320 (_("Bookmark"), repo.bookmarks, 'book'),
321 321 ]
322 res = self._create_reference_data(
323 repo, self.db_repo_name, refs_to_create)
322 res = self._create_reference_data(repo, self.db_repo_name, refs_to_create)
324 323 data = {
325 324 'more': False,
326 325 'results': res
@@ -265,6 +265,60 b''
265 265 }
266 266
267 267 var loadUrl = pyroutes.url('repo_refs_data', {'repo_name': templateContext.repo_name});
268 var cacheKey = '__ALL_FILE_REFS__';
269 var cachedDataSource = {};
270
271 var loadRefsData = function (query) {
272 $.ajax({
273 url: loadUrl,
274 data: {},
275 dataType: 'json',
276 type: 'GET',
277 success: function (data) {
278 cachedDataSource[cacheKey] = data;
279 query.callback({results: data.results});
280 }
281 });
282 };
283
284 var feedRefsData = function (query, cachedData) {
285 var data = {results: []};
286 //filter results
287 $.each(cachedData.results, function () {
288 var section = this.text;
289 var children = [];
290 $.each(this.children, function () {
291 if (query.term.length === 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0) {
292 children.push(this)
293 }
294 });
295 data.results.push({
296 'text': section,
297 'children': children
298 })
299 });
300
301 //push the typed in commit idx
302 if (!isNaN(query.term)) {
303 var files_url = pyroutes.url('repo_files',
304 {'repo_name': templateContext.repo_name,
305 'commit_id': query.term, 'f_path': state.f_path});
306
307 data.results.push({
308 'text': _gettext('go to numeric commit'),
309 'children': [{
310 at_ref: null,
311 id: null,
312 text: 'r{0}'.format(query.term),
313 type: 'sha',
314 raw_id: query.term,
315 idx: query.term,
316 files_url: files_url,
317 }]
318 });
319 }
320 query.callback(data);
321 };
268 322
269 323 var select2RefFileSwitcher = function (targetElement, loadUrl, initialData) {
270 324 var formatResult = function (result, container, query) {
@@ -288,34 +342,22 b''
288 342 tmpl = tmpl.concat(escapeHtml(commit_ref.text));
289 343 }
290 344
291 tmpl = tmpl.concat('<span class="select-index-number">{0}</span>'.format(commit_ref.idx));
345 tmpl = tmpl.concat('<span class="select-index-number">r{0}</span>'.format(commit_ref.idx));
292 346 return tmpl
293 347 };
294 348
295 349 $(targetElement).select2({
296 cachedDataSource: {},
297 350 dropdownAutoWidth: true,
298 351 width: "resolve",
299 352 containerCssClass: "drop-menu",
300 353 dropdownCssClass: "drop-menu-dropdown",
301 354 query: function(query) {
302 var self = this;
303 var cacheKey = '__ALL_FILE_REFS__';
304 var cachedData = self.cachedDataSource[cacheKey];
355
356 var cachedData = cachedDataSource[cacheKey];
305 357 if (cachedData) {
306 var data = select2RefFilterResults(query.term, cachedData);
307 query.callback({results: data.results});
358 feedRefsData(query, cachedData)
308 359 } else {
309 $.ajax({
310 url: loadUrl,
311 data: {},
312 dataType: 'json',
313 type: 'GET',
314 success: function(data) {
315 self.cachedDataSource[cacheKey] = data;
316 query.callback({results: data.results});
317 }
318 });
360 loadRefsData(query)
319 361 }
320 362 },
321 363 initSelection: function(element, callback) {
General Comments 0
You need to be logged in to leave comments. Login now