Mercurial > kallithea
changeset 6156:d9757113c013
files: improve select2 performance with many branches
Do to this select2 what was done to compare_diff and others in cc18e56220a2 and
elsewhere.
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 06 Sep 2016 00:51:18 +0200 |
parents | 9b80c2a64781 |
children | 470fac079543 |
files | kallithea/templates/files/files.html |
diffstat | 1 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/templates/files/files.html Tue Sep 06 00:51:18 2016 +0200 +++ b/kallithea/templates/files/files.html Tue Sep 06 00:51:18 2016 +0200 @@ -149,22 +149,30 @@ $("#diff1").select2({ placeholder: _TM['Select changeset'], dropdownAutoWidth: true, + maxResults: 50, query: function(query){ var key = 'cache'; var cached = cache[key] ; if(cached) { var data = {results: []}; + var queryLower = query.term.toLowerCase(); //filter results $.each(cached.results, function(){ var section = this.text; var children = []; $.each(this.children, function(){ - if(query.term.length == 0 || this.text.toUpperCase().indexOf(query.term.toUpperCase()) >= 0 ){ - children.push({'id': this.id, 'text': this.text}); + if(children.length < 50 ? + ((queryLower.length == 0) || (this.text.toLowerCase().indexOf(queryLower) >= 0)) : + ((queryLower.length != 0) && (this.text.toLowerCase().indexOf(queryLower) == 0))) { + children.push(this); } }); + children = branchSort(children, undefined, query) data.results.push({'text': section, 'children': children}); }); + //push the typed in changeset + data.results.push({'text':_TM['Specify changeset'], + 'children': [{'id': query.term, 'text': query.term, 'type': 'rev'}]}); query.callback(data); }else{ $.ajax({ @@ -174,7 +182,7 @@ type: 'GET', success: function(data) { cache[key] = data; - query.callback({results: data.results}); + query.callback(data); } }); }