]> source.dussan.org Git - archiva.git/commitdiff
fix search query
authorOlivier Lamy <olamy@apache.org>
Tue, 28 Feb 2012 00:03:26 +0000 (00:03 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 28 Feb 2012 00:03:26 +0000 (00:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1294405 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/SearchService.java
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/search.js
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/search.html

index bc71f2495b915f6e91a361d3f5e79c160b5885ad..2ae210ace0cbdadf7f7e908953d729b47ed6eb7e 100644 (file)
@@ -56,7 +56,7 @@ public interface SearchService
     List<Artifact> quickSearch( @QueryParam( "queryString" ) String queryString )
         throws ArchivaRestServiceException;
 
-    @Path( "quickSearch" )
+    @Path( "quickSearchWithRepositories" )
     @POST
     @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } )
     @RedbackAuthorization( noPermission = true, noRestriction = true )
index fa5ab42cdacbdac1f5fe832b2b3e3201cd78d97d..2fb7b181c67ca8ef64fc63de707d3a1d81e3a1fe 100644 (file)
@@ -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<String> repositories = new ArrayList<String>();
-    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);
+          }
+        }
+      );
+
 
     }
 
index 44719b627ec742c7d121ffdc638ba2bf40e7b19d..338c0f4bd6e720b206ad9ffbe3b236d86c308bc9 100644 (file)
                   <label class="control-label" for="search-terms"></label>
                   <div class="controls">
                     <input type="text" class="input-medium search-query" id="search-terms" name="search-terms" size="50"
-                           data-bind="value: searchParameters().basicQueryString" placeholder="${$.i18n.prop('search.artifact.search.form.query.terms')}"/>
+                           data-bind="value: searchRequest().queryTerms" placeholder="${$.i18n.prop('search.artifact.search.form.query.terms')}"/>
                   </div>
                 </div>
                 <button type="submit" class="btn" data-bind="click: basicSearch">Search</button>
                       <label class="control-label" for="groupId">${$.i18n.prop('search.artifact.search.form.query.groupId')}</label>
                       <div class="controls">
                         <input type="text" class="input-medium search-query" id="groupId" name="groupId" size="50"
-                               data-bind="value: searchParameters().searchRequest().groupId"/>
+                               data-bind="value: searchRequest().groupId"/>
                       </div>
                     </div>
                     <div class="control-group">
                       <label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.artifactId')}</label>
                       <div class="controls">
                         <input type="text" class="input-medium search-query" id="artifactId" name="artifactId" size="50"
-                               data-bind="value: searchParameters().searchRequest().artifactId"/>
+                               data-bind="value: searchRequest().artifactId"/>
                       </div>
                     </div>
                     <div class="control-group">
                       <label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.version')}</label>
                       <div class="controls">
                         <input type="text" class="input-medium search-query" id="version" name="version" size="50"
-                               data-bind="value: searchParameters().searchRequest().version"/>
+                               data-bind="value: searchRequest().version"/>
                       </div>
                     </div>
                     <div class="control-group">
                       <label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.packaging')}</label>
                       <div class="controls">
                         <input type="text" class="input-medium search-query" id="packaging" name="packaging" size="50"
-                               data-bind="value: searchParameters().searchRequest().packaging"/>
+                               data-bind="value: searchRequest().packaging"/>
                       </div>
                     </div>
                     <div class="control-group">
                       <label class="control-label" for="artifactId">${$.i18n.prop('search.artifact.search.form.query.className')}</label>
                       <div class="controls">
                         <input type="text" class="input-medium search-query" id="className" name="className" size="50"
-                               data-bind="value: searchParameters().searchRequest().className"/>
+                               data-bind="value: searchRequest().className"/>
                       </div>
                     </div>
                   </fieldset>
     </div>
   </div>
 
-</script>
\ No newline at end of file
+</script>
+
+<script id="search-results-view-tmpl" type="text/html">
+  {{if artifacts.length==0}}
+    no results
+  {{else}}
+    results
+  {{/if}}
+</script>