]> source.dussan.org Git - archiva.git/commitdiff
autocomplete in browse is now from the current groupId
authorOlivier Lamy <olamy@apache.org>
Mon, 5 Mar 2012 08:45:33 +0000 (08:45 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 5 Mar 2012 08:45:33 +0000 (08:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1296966 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp-js/pom.xml
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 8d0f2ec066862377e2ea265b6c83dd6d3fe5fab7..6a187e35eb92f486adec0003ec0a7d36068d7735 100644 (file)
                 <configuration>
                   <tasks>
                     <copy overwrite="true" file="${basedir}/src/test/tomcat/auto-admin-creation.properties"
-                          todir="${basedir}/target/"/>
+                          todir="${project.build.directory}/target/"/>
+                    <copy overwrite="true" file="${basedir}/src/test/tomcat/log4j.xml"
+                          todir="${project.build.outputDirectory}"/>
                   </tasks>
                 </configuration>
               </execution>
index 130b05ffb04c045d2c28f85673c705b4cde18fe5..17e7057a74f50c1e0b2a6dc32bdc068cd1bf6167 100644 (file)
@@ -100,6 +100,7 @@ $(function() {
               var browseViewModel = new BrowseViewModel(browseResultEntries,parentBrowseViewModel,groupId);
               ko.applyBindings(browseViewModel,browseBreadCrumb.get(0));
               ko.applyBindings(browseViewModel,browseResult.get(0));
+              enableAutocompleBrowse(groupId);
             }
          });
         }
@@ -178,26 +179,40 @@ $(function() {
           var browseViewModel = new BrowseViewModel(browseResultEntries,null,null);
           ko.applyBindings(browseViewModel,mainContent.find("#browse_breadcrumb").get(0));
           ko.applyBindings(browseViewModel,mainContent.find("#browse_result").get(0));
+          enableAutocompleBrowse();
         }
     });
-    enableAutocompleBrowse();
+
   }
 
-  enableAutocompleBrowse=function(){
+  enableAutocompleBrowse=function(groupId){
     // browse-autocomplete
+    var url="restServices/archivaServices/browseService/rootGroups";
+    if (groupId){
+      url="restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(groupId);
+    }
     $( "#main-content #browse-autocomplete" ).autocomplete({
-      minLength: 3,
+      minLength: 2,
                        source: function(request, response){
         var query = "";
-        if (request.term.indexOf('.')<0){
+        if (request.term.indexOf('.')<0&&!groupId){
           // try with rootGroups then filtered
-          $.get("restServices/archivaServices/browseService/rootGroups",
+          $.get(url,
              function(data) {
                var browseResultEntries = mapbrowseResultEntries(data);
+
                var filetered = [];
                for(var i=0;i<browseResultEntries.length;i++){
                  if (browseResultEntries[i].name.startsWith(request.term)){
-                   filetered.push(browseResultEntries[i]);
+                   if (groupId){
+                     $.log("groupId:"+groupId+",browseResultEntry.name:"+browseResultEntries[i].name);
+                     if (browseResultEntries[i].name.startsWith(groupId)) {
+                       filetered.push(browseResultEntries[i]);
+                     }
+
+                   } else {
+                     filetered.push(browseResultEntries[i]);
+                   }
                  }
                }
                response(filetered);
@@ -209,16 +224,16 @@ $(function() {
         var dotEnd=request.term.endsWith(".");
         // org.apache. requets with org.apache
         // org.apa request with org before last dot and filter response with startsWith
-        if (request.term.indexOf(".")>=0){
-          if (dotEnd){
-            query= request.term.substring(0, request.term.length-1);
+          if (request.term.indexOf(".")>=0){
+            if (dotEnd){
+              query= groupId?groupId+'.'+request.term.substring(0, request.term.length-1):request.term.substring(0, request.term.length-1);
+            } else {
+              // substring before last
+              query=groupId?groupId+'.'+request.term.substringBeforeLast("."):request.term.substringBeforeLast(".");
+            }
           } else {
-            // substring before last
-            query=request.term.substringBeforeLast(".");
+            query=groupId?groupId:request.term;
           }
-        } else {
-          query=request.term;
-        }
         $.get("restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(query),
            function(data) {
              var browseResultEntries = mapbrowseResultEntries(data);
@@ -227,8 +242,14 @@ $(function() {
              } else {
                var filetered = [];
                for(var i=0;i<browseResultEntries.length;i++){
-                 if (browseResultEntries[i].name.startsWith(request.term)){
-                   filetered.push(browseResultEntries[i]);
+                 if (groupId){
+                   if (browseResultEntries[i].name.startsWith(groupId+'.'+request.term)){
+                     filetered.push(browseResultEntries[i]);
+                   }
+                 } else {
+                   if (browseResultEntries[i].name.startsWith(request.term)){
+                     filetered.push(browseResultEntries[i]);
+                   }
                  }
                }
                response(filetered);
@@ -258,13 +279,13 @@ $(function() {
                }).data( "autocomplete" )._renderItem = function( ul, item ) {
                                        return $( "<li></li>" )
                                                .data( "item.autocomplete", item )
-                                               .append( "<a>" + item.name + "</a>" )
+                                               .append( groupId ? "<a>" +  item.name.substring(groupId.length+1, item.name.length) + "</a>": "<a>" + item.name + "</a>" )
                                                .appendTo( ul );
                                };
   }
 
   /**
-   * called if browser url contains queryParam browse=groupId
+   *
    * @param groupId
    */
   displayBrowseGroupIdFromAutoComplete=function(groupId){
@@ -274,7 +295,6 @@ $(function() {
     mainContent.find("#browse_result").html(mediumSpinnerImg());
     var parentBrowseViewModel=new BrowseViewModel(null,null,null);
     displayGroupDetail(groupId,parentBrowseViewModel,null);
-    enableAutocompleBrowse();
   }
 
   /**
@@ -289,7 +309,6 @@ $(function() {
     mainContent.find("#browse_result").html(mediumSpinnerImg());
     var parentBrowseViewModel=new BrowseViewModel(null,null,null);
     displayGroupDetail(groupId,parentBrowseViewModel,null);
-    enableAutocompleBrowse();
   }
 
 
index c55651366305a894f45f543c55890dfe9d99356a..3ca8e4711ee122ddc756c84758314896c4299605 100644 (file)
@@ -24,7 +24,6 @@
     </div>
   </div>
   <div id="main_browse_result">
-    <input type="text" class="form-search span6" size="50" id="browse-autocomplete"/>
     <div id="main_browse_result_content" class="well">
       <div id="browse_breadcrumb" data-bind='template:{name:"browse-breadcrumb-tmpl"}'></div>
       <div id="browse_result" class="well" data-bind='template:{name:"browse-groups-tmpl"}'></div>
         {{/if}}
       </li>
     {{/each}}
+    <li>
+      {{if number>0}}
+        <span class="divider">/</span>
+      {{/if}}
+      <input type="text" class="form-search span6" size="50" id="browse-autocomplete"/>
+    </li>
   </ul>
+
 </script>
 
 <script id="browse-artifact-tmpl" type="text/html">