]> source.dussan.org Git - archiva.git/commitdiff
add autocomplete to apply filtering on search results
authorOlivier Lamy <olamy@apache.org>
Wed, 29 Feb 2012 18:51:23 +0000 (18:51 +0000)
committerOlivier Lamy <olamy@apache.org>
Wed, 29 Feb 2012 18:51:23 +0000 (18:51 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1295209 13f79535-47bb-0310-9956-ffa450edef68

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
archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js
archiva-modules/archiva-web/pom.xml

index 51295b07e0661aa1adaf94e3bd7286da0de1b911..a8de514c6cfa89e63d4e8f01d170c2c51db93ad9 100644 (file)
@@ -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<self.resultViewModel.artifacts().length;i++){
index db333ab90b35383511129496fde571396902824f..4c1b98637991fb90672596711818f2e3eba95ad8 100644 (file)
                   <button type="submit" id="btn-advanced-search" class="btn btn-primary"
                           data-bind="click: advancedSearch">${$.i18n.prop('search.artifact.search.form.btn.search')}</button>
 
-                  <button type="submit" id="btn-advanced-search-filter" class="btn btn-success hide"
-                          data-bind="click: filterResults">${$.i18n.prop('search.artifact.search.form.btn.search.filter')}</button>
-
                 </form>
             </div>
             <div class="pill-pane" id="search-osgi-form-pane">
         </tr>
         <tr>
           {{each(i, columnDefinition) columns}}
-            <th title="${ columnDefinition.title }" id="search-filter-auto-${ columnDefinition.id }"><input type="text" place-holder="filter"/></th>
+            <th title="${ columnDefinition.title }">
+              <input type="text" class="form-search" id="search-filter-auto-${ columnDefinition.id }" place-holder="filtering"/>
+            </th>
           {{/each}}
         </tr>
     </thead>
index c0ac9f7e308c9ae49d8d3a2056f5826a10eb1493..6c31107c03e1196a59822fb03ec9fd6db604c163 100644 (file)
@@ -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)
index 0dfdaa403001176daf3f99752f6e44e0d62dc247..174ad67776061a592d440d1061f95b3559afb9fb 100644 (file)
       </modules>
     </profile>
   </profiles>
+
 </project>