From 7c71fde835415e5f2c928136b18a8302d0ba661b Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 28 Feb 2012 00:03:26 +0000 Subject: [PATCH] fix search query git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1294405 13f79535-47bb-0310-9956-ffa450edef68 --- .../rest/api/services/SearchService.java | 2 +- .../src/main/webapp/js/archiva/search.js | 40 ++++++++++++++----- .../webapp/js/archiva/templates/search.html | 22 ++++++---- 3 files changed, 47 insertions(+), 17 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java index bc71f2495..2ae210ace 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java @@ -56,7 +56,7 @@ public interface SearchService List quickSearch( @QueryParam( "queryString" ) String queryString ) throws ArchivaRestServiceException; - @Path( "quickSearch" ) + @Path( "quickSearchWithRepositories" ) @POST @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @RedbackAuthorization( noPermission = true, noRestriction = true ) 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 fa5ab42cd..2fb7b181c 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 @@ -598,6 +598,9 @@ $(function() { } SearchRequest=function(){ + + this.queryTerms=ko.observable(); + //private String groupId; this.groupId=ko.observable(); @@ -614,7 +617,7 @@ $(function() { this.className=ko.observable(); //private List repositories = new ArrayList(); - this.repositories=ko.observableArray(); + this.repositories=ko.observableArray([]); //private String bundleVersion; this.bundleVersion=ko.observable(); @@ -635,21 +638,20 @@ $(function() { this.includePomArtifacts=ko.observable(false); } - - SearchParameters=function(){ - this.basicQueryString=ko.observable(); - this.searchRequest=ko.observable(new SearchRequest()); + ResultViewModel=function(artifacts){ + this.artifacts=artifacts; } + SearchViewModel=function(){ - this.searchParameters=ko.observable(new SearchParameters()); + this.searchRequest=ko.observable(new SearchRequest()); this.observableRepoIds=ko.observableArray([]); this.selectedRepoIds=[]; basicSearch=function(){ //$.log("query:"+this.searchParameters().basicQueryString()); //$.log("repoIds:"+this.selectedRepoIds); - var queryTerm=this.searchParameters().basicQueryString(); + var queryTerm=this.searchRequest().queryTerms(); if (!queryTerm || $.trim(queryTerm).length<1){ $.log("empty"); var errorList=[{ @@ -662,8 +664,28 @@ $(function() { // cleanup previours error message customShowError("#main-content #search-basic-form", null, null, []); } - $("#main-content #search-results" ).html(mediumSpinnerImg()); - activateSearchResultsTab(); + var searchResults=$("#main-content #search-results" ); + searchResults.html(mediumSpinnerImg()); + this.searchRequest().repositories=this.selectedRepoIds; + $.ajax("restServices/archivaServices/searchService/quickSearchWithRepositories", + { + type: "POST", + data: "{\"searchRequest\": " + ko.toJSON(this.searchRequest)+"}", + 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(); + }, + error: function(data) { + var res = $.parseJSON(data.responseText); + displayRestError(res); + } + } + ); + } 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 44719b627..338c0f4bd 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 @@ -198,7 +198,7 @@
+ data-bind="value: searchRequest().queryTerms" placeholder="${$.i18n.prop('search.artifact.search.form.query.terms')}"/>
@@ -211,35 +211,35 @@
+ data-bind="value: searchRequest().groupId"/>
+ data-bind="value: searchRequest().artifactId"/>
+ data-bind="value: searchRequest().version"/>
+ data-bind="value: searchRequest().packaging"/>
+ data-bind="value: searchRequest().className"/>
@@ -262,4 +262,12 @@ - \ No newline at end of file + + + -- 2.39.5