better handling of repositoryId in url while browsing to make it work with history

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1366908 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-07-29 19:21:55 +00:00
parent e75ddd592e
commit 0985ccf02a
2 changed files with 67 additions and 43 deletions

View File

@ -220,9 +220,9 @@ function() {
var repositoryId = this.params.repositoryId; var repositoryId = this.params.repositoryId;
$.log("repositoryId:"+repositoryId); $.log("repositoryId:"+repositoryId);
if (groupId){ if (groupId){
displayBrowseGroupId(groupId); displayBrowseGroupId(groupId,repositoryId);
} else { } else {
displayBrowse(true); displayBrowse(true,repositoryId);
} }
}); });
this.get('#browse~:repositoryId',function(context){ this.get('#browse~:repositoryId',function(context){

View File

@ -23,14 +23,20 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
// browse part // browse part
//----------------------------------------- //-----------------------------------------
BrowseViewModel=function(browseResultEntries,parentBrowseViewModel,groupId){ BrowseViewModel=function(browseResultEntries,parentBrowseViewModel,groupId,repositoryId){
var self=this; var self=this;
this.browseResultEntries=browseResultEntries; this.browseResultEntries=browseResultEntries;
this.parentBrowseViewModel=parentBrowseViewModel; this.parentBrowseViewModel=parentBrowseViewModel;
this.groupId=groupId; this.groupId=groupId;
this.repositoryId=repositoryId;
displayGroupId=function(groupId){ displayGroupId=function(groupId){
$.log("BrowseViewModel#displayGroupId,self.repositoryId:"+self.repositoryId);
if(self.repositoryId){
window.sammyArchivaApplication.setLocation("#browse~"+self.repositoryId+"/"+groupId);
} else {
window.sammyArchivaApplication.setLocation("#browse/"+groupId); window.sammyArchivaApplication.setLocation("#browse/"+groupId);
} }
}
displayParentGroupId=function(){ displayParentGroupId=function(){
$.log("called displayParentGroupId groupId:"+self.parentBrowseViewModel.groupId); $.log("called displayParentGroupId groupId:"+self.parentBrowseViewModel.groupId);
// if null parent is root level // if null parent is root level
@ -86,7 +92,7 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
return breadCrumbEntries; return breadCrumbEntries;
} }
displayGroupDetail=function(groupId,parentBrowseViewModel,restUrl){ displayGroupDetail=function(groupId,parentBrowseViewModel,restUrl,repositoryId){
var mainContent = $("#main-content"); var mainContent = $("#main-content");
mainContent.find("#browse_artifact_detail").hide(); mainContent.find("#browse_artifact_detail").hide();
var browseResult=mainContent.find("#browse_result"); var browseResult=mainContent.find("#browse_result");
@ -114,7 +120,7 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
var browseResultEntries = mapBrowseResultEntries(data); var browseResultEntries = mapBrowseResultEntries(data);
var browseViewModel = new BrowseViewModel(browseResultEntries,parentBrowseViewModel,groupId); var browseViewModel = new BrowseViewModel(browseResultEntries,parentBrowseViewModel,groupId,repositoryId);
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); enableAutocompleBrowse(groupId);
@ -661,10 +667,9 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
mainContent.find("#browse_artifact" ).hide(); mainContent.find("#browse_artifact" ).hide();
mainContent.find("#browse_result").html(mediumSpinnerImg()); mainContent.find("#browse_result").html(mediumSpinnerImg());
$.ajax("restServices/archivaServices/browseService/userRepositories", {
type: "GET", userRepositoriesCall(
dataType: 'json', function(data) {
success: function(data) {
mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data,selected:repositoryId})); mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data,selected:repositoryId}));
var url="restServices/archivaServices/browseService/rootGroups"; var url="restServices/archivaServices/browseService/rootGroups";
if(repositoryId){ if(repositoryId){
@ -676,21 +681,19 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
success: function(data) { success: function(data) {
var browseResultEntries = mapBrowseResultEntries(data); var browseResultEntries = mapBrowseResultEntries(data);
$.log("size:"+browseResultEntries.length); $.log("size:"+browseResultEntries.length);
var browseViewModel = new BrowseViewModel(browseResultEntries,null,null); var browseViewModel = new BrowseViewModel(browseResultEntries,null,null,repositoryId);
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();
} }
}); });
} }
}); )
} }
changeBrowseRepository=function(){ changeBrowseRepository=function(){
var selectedRepository=getSelectedBrowsingRepository(); var selectedRepository=getSelectedBrowsingRepository();
//$.log("changeBrowseRepository:"+selectedRepository);
//displayGroupDetail(null,null,"restServices/archivaServices/browseService/rootGroups?repositoryId="+encodeURIComponent(selectedRepository));
window.sammyArchivaApplication.setLocation("#browse~"+selectedRepository); window.sammyArchivaApplication.setLocation("#browse~"+selectedRepository);
} }
@ -827,20 +830,31 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
* called if browser url contains queryParam browse=groupId * called if browser url contains queryParam browse=groupId
* @param groupId * @param groupId
*/ */
displayBrowseGroupId=function(groupId){ displayBrowseGroupId=function(groupId,repositoryId){
clearUserMessages(); clearUserMessages();
$.log("displayBrowseGroupId:"+groupId); $.log("displayBrowseGroupId:"+groupId+":"+repositoryId);
userRepositoriesCall(
function(data){
var mainContent = $("#main-content"); var mainContent = $("#main-content");
mainContent.html($("#browse-tmpl" ).tmpl()); mainContent.html($("#browse-tmpl" ).tmpl());
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,repositoryId);
displayGroupDetail(groupId,parentBrowseViewModel,null); var url="restServices/archivaServices/browseService/browseGroupId/"+encodeURIComponent(groupId);
if (repositoryId){
url+="?repositoryId="+repositoryId;
mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data,selected:repositoryId}));
}else{
mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data,selected:""}));
}
displayGroupDetail(groupId,parentBrowseViewModel,url,repositoryId);
}
);
} }
displayBrowseArtifactDetail=function(groupId, artifactId){ displayBrowseArtifactDetail=function(groupId, artifactId){
$.log("displayBrowseArtifactDetail"); $.log("displayBrowseArtifactDetail");
window.sammyArchivaApplication.setLocation("#artifact/"+groupId+"/"+artifactId); window.sammyArchivaApplication.setLocation("#artifact/"+groupId+"/"+artifactId);
//displayArtifactDetail(groupId,artifactId,null,null);
} }
goToBrowseArtifactDetail=function(groupId, artifactId){ goToBrowseArtifactDetail=function(groupId, artifactId){
@ -1353,13 +1367,23 @@ define("archiva.search",["jquery","i18n","jquery.tmpl","choosen","knockout","kno
mainContent.find("#browse_artifact_detail").html(mediumSpinnerImg()); mainContent.find("#browse_artifact_detail").html(mediumSpinnerImg());
mainContent.find("#browse_breadcrumb" ).show(); mainContent.find("#browse_breadcrumb" ).show();
mainContent.find("#browse_breadcrumb" ).html(mediumSpinnerImg()); mainContent.find("#browse_breadcrumb" ).html(mediumSpinnerImg());
userRepositoriesCall(
function(data) {
mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data,selected:repositoryId}));
var artifactVersionDetailViewModel=new ArtifactVersionDetailViewModel(groupId,artifactId,version,repositoryId);
artifactVersionDetailViewModel.display();
}
);
}
userRepositoriesCall=function(successCallbackFn){
$.ajax("restServices/archivaServices/browseService/userRepositories", { $.ajax("restServices/archivaServices/browseService/userRepositories", {
type: "GET", type: "GET",
dataType: 'json', dataType: 'json',
success: function(data) { success: function(data) {
mainContent.find("#selected_repository" ).html($("#selected_repository_tmpl" ).tmpl({repositories:data,selected:repositoryId})); successCallbackFn(data);
var artifactVersionDetailViewModel=new ArtifactVersionDetailViewModel(groupId,artifactId,version,repositoryId);
artifactVersionDetailViewModel.display();
} }
}); });
} }