diff options
author | Olivier Lamy <olamy@apache.org> | 2012-07-09 07:29:07 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-07-09 07:29:07 +0000 |
commit | dda044ce85b9d05cd1fdf395d8be936ddba0d253 (patch) | |
tree | b35358b1bca90b65d2713bc5ca9b8279ddd01bfc /archiva-modules/archiva-web | |
parent | 21957c06c7ded958f9ed59861a368800540555d6 (diff) | |
download | archiva-dda044ce85b9d05cd1fdf395d8be936ddba0d253.tar.gz archiva-dda044ce85b9d05cd1fdf395d8be936ddba0d253.zip |
fix search results filtering when coming from autocomplete box
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1358945 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules/archiva-web')
3 files changed, 34 insertions, 12 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js index 716ced64b..a13f3e055 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/main.js @@ -330,13 +330,13 @@ function() { select: function( event, ui ) { $.log("select artifactId:"+ui.item.artifactId); // user can be in a non search view so init the search view first + var searchViewModel = new SearchViewModel(); + var searchRequest = new SearchRequest(); + searchRequest.artifactId(ui.item.artifactId); + searchViewModel.searchRequest(searchRequest); displaySearch(function(){ - var searchViewModel = new SearchViewModel(); - var searchRequest = new SearchRequest(); - searchRequest.artifactId(ui.item.artifactId); - searchViewModel.searchRequest(searchRequest); searchViewModel.externalAdvancedSearch(); - }); + },searchViewModel); } }).data( "autocomplete" )._renderItem = function( ul, item ) { return $( "<li></li>" ) 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 58557c5b3..af5d75819 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 @@ -1272,6 +1272,10 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock }); } + /** + * search results view model: display a grid with autocomplete filtering on grid headers + * @param artifacts + */ ResultViewModel=function(artifacts){ var self=this; this.originalArtifacts=artifacts; @@ -1339,6 +1343,9 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock }); } + /** + * View model used for search response and filtering + */ SearchViewModel=function(){ var self=this; this.searchRequest=ko.observable(new SearchRequest()); @@ -1371,6 +1378,7 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock self.search("restServices/archivaServices/searchService/searchArtifacts"); } removeFilter=function(){ + $.log("removeFilter:"+self.resultViewModel.originalArtifacts.length); self.resultViewModel.artifacts(self.resultViewModel.originalArtifacts); } this.search=function(url){ @@ -1382,7 +1390,6 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock mainContent.find("#btn-advanced-search" ).button("loading"); $("#user-messages").html(mediumSpinnerImg()); - self.selectedRepoIds=[]; mainContent.find("#search-basic-repositories" ) .find(".chzn-choices li span").each(function(i,span){ @@ -1400,19 +1407,21 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock success: function(data) { clearUserMessages(); var artifacts=mapArtifacts(data); + $.log("search#ajax call success:artifacts.length:"+artifacts.length); if (artifacts.length<1){ displayWarningMessage( $.i18n.prop("search.artifact.noresults")); return; } else { self.resultViewModel.originalArtifacts=artifacts; + $.log("search#ajax call success:self.resultViewModel.originalArtifacts:"+self.resultViewModel.originalArtifacts.length); self.resultViewModel.artifacts(artifacts); if (!searchResultsGrid.attr("data-bind")){ + $.log('!searchResultsGrid.attr("data-bind")'); searchResultsGrid.attr("data-bind", "simpleGrid: gridViewModel,simpleGridTemplate:'search-results-view-grid-tmpl',pageLinksId:'search-results-view-grid-pagination'"); ko.applyBindings(self.resultViewModel,searchResultsGrid.get(0)); ko.applyBindings(self,mainContent.find("#remove-filter-id" ).get(0)); - mainContent.find("#search-result-number-div").attr("data-bind", - "template:{name:'search-result-number-div-tmpl'}"); + mainContent.find("#search-result-number-div").attr("data-bind","template:{name:'search-result-number-div-tmpl'}"); ko.applyBindings(self,mainContent.find("#search-result-number-div" ).get(0)); } @@ -1444,7 +1453,13 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock } - displaySearch=function(successCallbackFn){ + /** + * display a search result (collection of Artifacts) in a grid + * see template with id #search-artifacts-div-tmpl + * @param successCallbackFn can be a callback function called on success getting observable repositories. + * @param searchViewModelCurrent model to reuse if not null whereas a new one is created. + */ + displaySearch=function(successCallbackFn,searchViewModelCurrent){ clearUserMessages(); var mainContent=$("#main-content"); mainContent.html(mediumSpinnerImg()); @@ -1453,7 +1468,14 @@ define("search",["jquery","i18n","jquery.tmpl","choosen","order!knockout","knock dataType: 'json', success: function(data) { mainContent.html($("#search-artifacts-div-tmpl" ).tmpl()); - var searchViewModel=new SearchViewModel(); + var searchViewModel; + if (searchViewModelCurrent){ + $.log("searchViewModelCurrent not null"); + searchViewModel=searchViewModelCurrent + }else { + $.log("searchViewModelCurrent null"); + searchViewModel=new SearchViewModel(); + } var repos=mapStringList(data); $.log("repos:"+repos); searchViewModel.observableRepoIds(repos); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/search.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/search.html index a6608f599..b58a88216 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/search.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/search.html @@ -170,8 +170,7 @@ </div> </script> <script id="search-artifacts-div-tmpl" type="text/html"> - <div id="search-artifacts-div" data-bind='template:{name:"search-artifacts-form-tmpl"}'> - </div> + <div id="search-artifacts-div" data-bind='template:{name:"search-artifacts-form-tmpl"}'></div> </script> <script id="search-artifacts-form-tmpl" type="text/html"> @@ -349,6 +348,7 @@ <table class="table table-striped table-bordered" id="search-results-grid"> </table> <div id="search-results-view-grid-pagination"></div> + </div> </div> |