autocomplete in browse is now from the current groupId

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1296966 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-03-05 08:45:33 +00:00
parent 0a8d820602
commit c21bb53a98
3 changed files with 49 additions and 22 deletions

View File

@ -767,7 +767,9 @@
<configuration> <configuration>
<tasks> <tasks>
<copy overwrite="true" file="${basedir}/src/test/tomcat/auto-admin-creation.properties" <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> </tasks>
</configuration> </configuration>
</execution> </execution>

View File

@ -100,6 +100,7 @@ $(function() {
var browseViewModel = new BrowseViewModel(browseResultEntries,parentBrowseViewModel,groupId); var browseViewModel = new BrowseViewModel(browseResultEntries,parentBrowseViewModel,groupId);
ko.applyBindings(browseViewModel,browseBreadCrumb.get(0)); ko.applyBindings(browseViewModel,browseBreadCrumb.get(0));
ko.applyBindings(browseViewModel,browseResult.get(0)); ko.applyBindings(browseViewModel,browseResult.get(0));
enableAutocompleBrowse(groupId);
} }
}); });
} }
@ -178,27 +179,41 @@ $(function() {
var browseViewModel = new BrowseViewModel(browseResultEntries,null,null); var browseViewModel = new BrowseViewModel(browseResultEntries,null,null);
ko.applyBindings(browseViewModel,mainContent.find("#browse_breadcrumb").get(0)); ko.applyBindings(browseViewModel,mainContent.find("#browse_breadcrumb").get(0));
ko.applyBindings(browseViewModel,mainContent.find("#browse_result").get(0)); ko.applyBindings(browseViewModel,mainContent.find("#browse_result").get(0));
}
});
enableAutocompleBrowse(); enableAutocompleBrowse();
} }
});
enableAutocompleBrowse=function(){ }
enableAutocompleBrowse=function(groupId){
// browse-autocomplete // browse-autocomplete
var url="restServices/archivaServices/browseService/rootGroups";
if (groupId){
url="restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(groupId);
}
$( "#main-content #browse-autocomplete" ).autocomplete({ $( "#main-content #browse-autocomplete" ).autocomplete({
minLength: 3, minLength: 2,
source: function(request, response){ source: function(request, response){
var query = ""; var query = "";
if (request.term.indexOf('.')<0){ if (request.term.indexOf('.')<0&&!groupId){
// try with rootGroups then filtered // try with rootGroups then filtered
$.get("restServices/archivaServices/browseService/rootGroups", $.get(url,
function(data) { function(data) {
var browseResultEntries = mapbrowseResultEntries(data); var browseResultEntries = mapbrowseResultEntries(data);
var filetered = []; var filetered = [];
for(var i=0;i<browseResultEntries.length;i++){ for(var i=0;i<browseResultEntries.length;i++){
if (browseResultEntries[i].name.startsWith(request.term)){ if (browseResultEntries[i].name.startsWith(request.term)){
if (groupId){
$.log("groupId:"+groupId+",browseResultEntry.name:"+browseResultEntries[i].name);
if (browseResultEntries[i].name.startsWith(groupId)) {
filetered.push(browseResultEntries[i]); filetered.push(browseResultEntries[i]);
} }
} else {
filetered.push(browseResultEntries[i]);
}
}
} }
response(filetered); response(filetered);
@ -211,13 +226,13 @@ $(function() {
// org.apa request with org before last dot and filter response with startsWith // org.apa request with org before last dot and filter response with startsWith
if (request.term.indexOf(".")>=0){ if (request.term.indexOf(".")>=0){
if (dotEnd){ if (dotEnd){
query= request.term.substring(0, request.term.length-1); query= groupId?groupId+'.'+request.term.substring(0, request.term.length-1):request.term.substring(0, request.term.length-1);
} else { } else {
// substring before last // substring before last
query=request.term.substringBeforeLast("."); query=groupId?groupId+'.'+request.term.substringBeforeLast("."):request.term.substringBeforeLast(".");
} }
} else { } else {
query=request.term; query=groupId?groupId:request.term;
} }
$.get("restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(query), $.get("restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(query),
function(data) { function(data) {
@ -227,10 +242,16 @@ $(function() {
} else { } else {
var filetered = []; var filetered = [];
for(var i=0;i<browseResultEntries.length;i++){ for(var i=0;i<browseResultEntries.length;i++){
if (groupId){
if (browseResultEntries[i].name.startsWith(groupId+'.'+request.term)){
filetered.push(browseResultEntries[i]);
}
} else {
if (browseResultEntries[i].name.startsWith(request.term)){ if (browseResultEntries[i].name.startsWith(request.term)){
filetered.push(browseResultEntries[i]); filetered.push(browseResultEntries[i]);
} }
} }
}
response(filetered); response(filetered);
} }
} }
@ -258,13 +279,13 @@ $(function() {
}).data( "autocomplete" )._renderItem = function( ul, item ) { }).data( "autocomplete" )._renderItem = function( ul, item ) {
return $( "<li></li>" ) return $( "<li></li>" )
.data( "item.autocomplete", item ) .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 ); .appendTo( ul );
}; };
} }
/** /**
* called if browser url contains queryParam browse=groupId *
* @param groupId * @param groupId
*/ */
displayBrowseGroupIdFromAutoComplete=function(groupId){ displayBrowseGroupIdFromAutoComplete=function(groupId){
@ -274,7 +295,6 @@ $(function() {
mainContent.find("#browse_result").html(mediumSpinnerImg()); mainContent.find("#browse_result").html(mediumSpinnerImg());
var parentBrowseViewModel=new BrowseViewModel(null,null,null); var parentBrowseViewModel=new BrowseViewModel(null,null,null);
displayGroupDetail(groupId,parentBrowseViewModel,null); displayGroupDetail(groupId,parentBrowseViewModel,null);
enableAutocompleBrowse();
} }
/** /**
@ -289,7 +309,6 @@ $(function() {
mainContent.find("#browse_result").html(mediumSpinnerImg()); mainContent.find("#browse_result").html(mediumSpinnerImg());
var parentBrowseViewModel=new BrowseViewModel(null,null,null); var parentBrowseViewModel=new BrowseViewModel(null,null,null);
displayGroupDetail(groupId,parentBrowseViewModel,null); displayGroupDetail(groupId,parentBrowseViewModel,null);
enableAutocompleBrowse();
} }

View File

@ -24,7 +24,6 @@
</div> </div>
</div> </div>
<div id="main_browse_result"> <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="main_browse_result_content" class="well">
<div id="browse_breadcrumb" data-bind='template:{name:"browse-breadcrumb-tmpl"}'></div> <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> <div id="browse_result" class="well" data-bind='template:{name:"browse-groups-tmpl"}'></div>
@ -82,7 +81,14 @@
{{/if}} {{/if}}
</li> </li>
{{/each}} {{/each}}
<li>
{{if number>0}}
<span class="divider">/</span>
{{/if}}
<input type="text" class="form-search span6" size="50" id="browse-autocomplete"/>
</li>
</ul> </ul>
</script> </script>
<script id="browse-artifact-tmpl" type="text/html"> <script id="browse-artifact-tmpl" type="text/html">