From c6946043df45f87faaa268e0918213910561b0ce Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 28 Feb 2012 00:03:47 +0000 Subject: start displaying search results in a grid git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1294406 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/archiva/i18n/default.properties | 4 ++ .../src/main/webapp/js/archiva/search.js | 49 ++++++++++++++++++---- .../main/webapp/js/archiva/templates/search.html | 27 ++++++++---- .../src/main/webapp/js/knockout.simpleGrid.js | 8 +--- 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties index f0c7bd8a4..b9c2abe0d 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/resources/org/apache/archiva/i18n/default.properties @@ -217,3 +217,7 @@ search.artifact.search.form.advanced=Advanced Parameters search.artifact.search.form.query.artifactId=Artifact ID search.artifact.search.form.repositories.all=All search.artifact.search.form.terms.empty=You must enter some search terms. +search.artifact.noresults=No results found. +search.artifact.results.groupId=Group ID +search.artifact.results.artifactId=Artifact ID +search.artifact.results.version=Version 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 2fb7b181c..7885cc422 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 @@ -639,15 +639,38 @@ $(function() { } ResultViewModel=function(artifacts){ - this.artifacts=artifacts; + var self=this; + this.artifacts=ko.observableArray(artifacts); + this.gridViewModel = new ko.simpleGrid.viewModel({ + data: self.artifacts, + columns: [ + { + headerText: $.i18n.prop('search.artifact.results.groupId'), + rowText: "groupId" + }, + { + headerText: $.i18n.prop('search.artifact.results.artifactId'), + rowText: "artifactId" + }, + { + headerText: $.i18n.prop('search.artifact.results.version'), + rowText: "version" + } + ], + pageSize: 10, + gridUpdateCallBack: function(){ + + } + }); } SearchViewModel=function(){ + var self=this; this.searchRequest=ko.observable(new SearchRequest()); this.observableRepoIds=ko.observableArray([]); this.selectedRepoIds=[]; - + this.resultViewModel=new ResultViewModel([]); basicSearch=function(){ //$.log("query:"+this.searchParameters().basicQueryString()); //$.log("repoIds:"+this.selectedRepoIds); @@ -664,8 +687,8 @@ $(function() { // cleanup previours error message customShowError("#main-content #search-basic-form", null, null, []); } - var searchResults=$("#main-content #search-results" ); - searchResults.html(mediumSpinnerImg()); + var searchResultsGrid=$("#main-content #search-results #search-results-grid" ); + $("#main-content #user-messages").html(mediumSpinnerImg()); this.searchRequest().repositories=this.selectedRepoIds; $.ajax("restServices/archivaServices/searchService/quickSearchWithRepositories", { @@ -674,10 +697,20 @@ $(function() { contentType: 'application/json', dataType: 'json', success: function(data) { - var resultViewModel=new ResultViewModel(mapArtifacts(data)); - searchResults.attr("data-bind","template:{name:'search-results-view-tmpl'}"); - ko.applyBindings(resultViewModel,searchResults.get(0)); - activateSearchResultsTab(); + clearUserMessages(); + var artifacts=mapArtifacts(data); + if (artifacts.length<1){ + displayWarningMessage( $.i18n.prop("search.artifact.noresults")); + return; + } else { + self.resultViewModel.artifacts(artifacts); + if (!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)); + } + activateSearchResultsTab(); + } }, error: function(data) { var res = $.parseJSON(data.responseText); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html index 338c0f4bd..ae212d7c6 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html @@ -255,7 +255,9 @@
- No Results yet. Try a search ! + +
+
@@ -264,10 +266,21 @@ - diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js index 4c2ca96ee..68f7cfa30 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js @@ -64,12 +64,8 @@ // Render the page links var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0); - if (viewModel.pageLinksUpdateCallBack){ - ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode") - .subscribe(viewModel.pageLinksUpdateCallBack); - } else { - ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode"); - } + ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode") + .subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){}); if (viewModel.pageLinksUpdateCallBack) viewModel.pageLinksUpdateCallBack(); } }; -- cgit v1.2.3