mirror of https://github.com/apache/archiva.git
start autocomplete box on browsing
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1294333 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
9c88535d0c
commit
11b1451053
|
@ -156,19 +156,6 @@ $(function() {
|
|||
});
|
||||
}
|
||||
|
||||
// handle url with registration link
|
||||
$(document).ready(function() {
|
||||
var validateMeId = $.urlParam('validateMe');
|
||||
if (validateMeId) {
|
||||
validateKey(validateMeId);
|
||||
}
|
||||
|
||||
var browse = $.urlParam('browse');
|
||||
if (browse){
|
||||
displayBrowseGroupId(browse);
|
||||
}
|
||||
});
|
||||
|
||||
startArchivaApplication = function(){
|
||||
$.log("startArchivaApplication");
|
||||
$('#topbar-menu-container').html($("#topbar-menu"));
|
||||
|
@ -206,11 +193,28 @@ $(function() {
|
|||
|
||||
}
|
||||
});
|
||||
// by default display search screen
|
||||
displaySearch();
|
||||
|
||||
|
||||
}
|
||||
startArchivaApplication();
|
||||
|
||||
|
||||
// handle url with registration link
|
||||
$(document).ready(function() {
|
||||
var validateMeId = $.urlParam('validateMe');
|
||||
if (validateMeId) {
|
||||
validateKey(validateMeId);
|
||||
return;
|
||||
}
|
||||
|
||||
var browse = $.urlParam('browse');
|
||||
if (browse){
|
||||
displayBrowseGroupId(browse);
|
||||
return;
|
||||
}
|
||||
// by default display search screen
|
||||
displaySearch();
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
|
|
@ -180,6 +180,101 @@ $(function() {
|
|||
ko.applyBindings(browseViewModel,mainContent.find("#browse_result").get(0));
|
||||
}
|
||||
});
|
||||
enableAutocompleBrowse();
|
||||
}
|
||||
|
||||
enableAutocompleBrowse=function(){
|
||||
// browse-autocomplete
|
||||
$( "#main-content #browse-autocomplete" ).autocomplete({
|
||||
minLength: 3,
|
||||
source: function(request, response){
|
||||
var query = "";
|
||||
if (request.term.indexOf('.')<0){
|
||||
// try with rootGroups then filtered
|
||||
$.get("restServices/archivaServices/browseService/rootGroups",
|
||||
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]);
|
||||
}
|
||||
}
|
||||
response(filetered);
|
||||
|
||||
}
|
||||
);
|
||||
return;
|
||||
}
|
||||
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);
|
||||
} else {
|
||||
// substring before last
|
||||
query=request.term.substringBeforeLast(".");
|
||||
}
|
||||
} else {
|
||||
query=request.term;
|
||||
}
|
||||
$.get("restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(query),
|
||||
function(data) {
|
||||
var browseResultEntries = mapbrowseResultEntries(data);
|
||||
if (dotEnd){
|
||||
response(browseResultEntries);
|
||||
} else {
|
||||
var filetered = [];
|
||||
for(var i=0;i<browseResultEntries.length;i++){
|
||||
if (browseResultEntries[i].name.startsWith(request.term)){
|
||||
filetered.push(browseResultEntries[i]);
|
||||
}
|
||||
}
|
||||
response(filetered);
|
||||
}
|
||||
}
|
||||
);
|
||||
},
|
||||
select: function( event, ui ) {
|
||||
$.log("ui.item.label:"+ui.item.name);
|
||||
if (ui.item.project=='true'){
|
||||
// value org.apache.maven/maven-archiver
|
||||
// split this org.apache.maven and maven-archiver
|
||||
var id=ui.item.name;
|
||||
var values = id.split(".");
|
||||
var groupId="";
|
||||
for (var i = 0;i<values.length-1;i++){
|
||||
groupId+=values[i];
|
||||
if (i<values.length-2)groupId+=".";
|
||||
}
|
||||
var artifactId=values[values.length-1];
|
||||
displayArtifactDetail(groupId,artifactId,self);
|
||||
} else {
|
||||
displayBrowseGroupIdFromAutoComplete(ui.item.name);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}).data( "autocomplete" )._renderItem = function( ul, item ) {
|
||||
return $( "<li></li>" )
|
||||
.data( "item.autocomplete", item )
|
||||
.append( "<a>" + item.name + "</a>" )
|
||||
.appendTo( ul );
|
||||
};;
|
||||
}
|
||||
|
||||
/**
|
||||
* called if browser url contains queryParam browse=groupId
|
||||
* @param groupId
|
||||
*/
|
||||
displayBrowseGroupIdFromAutoComplete=function(groupId){
|
||||
clearUserMessages();
|
||||
var mainContent = $("#main-content");
|
||||
//mainContent.html($("#browse-tmpl" ).tmpl());
|
||||
mainContent.find("#browse_result").html(mediumSpinnerImg());
|
||||
var parentBrowseViewModel=new BrowseViewModel(null,null,null);
|
||||
displayGroupDetail(groupId,parentBrowseViewModel,null);
|
||||
enableAutocompleBrowse();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -192,7 +287,8 @@ $(function() {
|
|||
mainContent.html($("#browse-tmpl" ).tmpl());
|
||||
mainContent.find("#browse_result").html(mediumSpinnerImg());
|
||||
var parentBrowseViewModel=new BrowseViewModel(null,null,null);
|
||||
displayGroupDetail(groupId,parentBrowseViewModel,null)
|
||||
displayGroupDetail(groupId,parentBrowseViewModel,null);
|
||||
enableAutocompleBrowse();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
</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>
|
||||
|
|
|
@ -329,6 +329,19 @@ mapStringList=function(data){
|
|||
return [];
|
||||
}
|
||||
|
||||
// utils
|
||||
String.prototype.endsWith = function(str) {
|
||||
return (this.match(str+"$")==str)
|
||||
}
|
||||
|
||||
String.prototype.startsWith = function(str) {
|
||||
return (this.match("^"+str)==str)
|
||||
}
|
||||
|
||||
String.prototype.substringBeforeLast = function(str) {
|
||||
return this.substring(0,this.lastIndexOf(str));
|
||||
}
|
||||
|
||||
// extends jquery tmpl to support var def
|
||||
$.extend($.tmpl.tag, {
|
||||
"var": {
|
||||
|
|
Loading…
Reference in New Issue