From: Olivier Lamy Date: Wed, 29 Feb 2012 18:51:23 +0000 (+0000) Subject: add autocomplete to apply filtering on search results X-Git-Tag: archiva-1.4-M3~1176 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a15504344b6aeaf9e3415fd5821b455151f690ec;p=archiva.git add autocomplete to apply filtering on search results git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1295209 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js index 51295b07e..a8de514c6 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js @@ -703,6 +703,7 @@ $(function() { var searchResultsGrid=mainContent.find("#search-results #search-results-grid" ); mainContent.find("#btn-basic-search" ).button("loading"); + mainContent.find("#btn-advanced-search" ).button("loading"); $("#user-messages").html(mediumSpinnerImg()); @@ -733,8 +734,50 @@ $(function() { "simpleGrid: gridViewModel,simpleGridTemplate:'search-results-view-grid-tmpl',pageLinksId:'search-results-view-grid-pagination'"); ko.applyBindings(self.resultViewModel,searchResultsGrid.get(0)); } + // FIXME something generic here ! + + $( "#main-content #search-filter-auto-groupId" ).autocomplete({ + minLength: 1, + source: function(request, response){ + var groupIds=[]; + $(self.resultViewModel.artifacts()).each(function(idx,artifact){ + if(artifact.groupId.startsWith(request.term)){ + groupIds.push(artifact.groupId); + } + }); + response(unifyArray(groupIds,true)); + } + }); + + $( "#main-content #search-filter-auto-artifactId" ).autocomplete({ + minLength: 1, + source: function(request, response){ + var artifactIds=[]; + $(self.resultViewModel.artifacts()).each(function(idx,artifact){ + if(artifact.artifactId.startsWith(request.term)){ + artifactIds.push(artifact.artifactId); + } + }); + response(unifyArray(artifactIds,true)); + } + }); + + $( "#main-content #search-filter-auto-version" ).autocomplete({ + minLength: 1, + source: function(request, response){ + var versions=[]; + $(self.resultViewModel.artifacts()).each(function(idx,artifact){ + if(artifact.version.startsWith(request.term)){ + versions.push(artifact.version); + } + }); + response(unifyArray(versions,true)); + } + }); + + + activateSearchResultsTab(); - mainContent.find("#btn-advanced-search-filter" ).show(); } }, error: function(data) { @@ -742,13 +785,15 @@ $(function() { displayRestError(res); }, complete:function() { - $("#main-content #btn-basic-search" ).button("reset"); + mainContent.find("##btn-basic-search" ).button("reset"); + mainContent.find("#btn-advanced-search" ).button("reset"); removeMediumSpinnerImg("#user-messages"); } } ); } + // olamy not used as we cannot filter on className etc... filterResults=function(){ var filtered=[]; for (var i=0;i${$.i18n.prop('search.artifact.search.form.btn.search')} - -
@@ -290,7 +287,9 @@ {{each(i, columnDefinition) columns}} - + + + {{/each}} diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js index c0ac9f7e3..6c31107c0 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js @@ -329,6 +329,21 @@ mapStringList=function(data){ return []; } +/** + * return an array with removing duplicate strings + * @param strArray an array of string + * @param sorted to sort or not + */ +unifyArray=function(strArray,sorted){ + var res = []; + $(strArray).each(function(idx,str){ + if ( $.inArray(str,res)<0){ + res.push(str); + } + }); + return sorted?res.sort():res; +} + // utils String.prototype.endsWith = function(str) { return (this.match(str+"$")==str) diff --git a/archiva-modules/archiva-web/pom.xml b/archiva-modules/archiva-web/pom.xml index 0dfdaa403..174ad6777 100644 --- a/archiva-modules/archiva-web/pom.xml +++ b/archiva-modules/archiva-web/pom.xml @@ -133,4 +133,5 @@ +