From 128af35a7ec7768322af12997760eb53dcf3950a Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 9 Feb 2012 23:08:09 +0000 Subject: [PATCH] [MRM-1576] rewrite proxies connector page refactor to ease edit mode. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1242596 13f79535-47bb-0310-9956-ffa450edef68 --- .../webapp/js/archiva/proxy-connectors.js | 65 +++++++++++-------- .../archiva/templates/proxy-connectors.html | 20 +++--- .../src/main/webapp/js/knockout.simpleGrid.js | 6 +- 3 files changed, 52 insertions(+), 39 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js index 36e322689..348529324 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors.js @@ -241,11 +241,11 @@ $(function() { $.log("editProxyConnector"); } - removeProxyConnector=function(managedRepositoryConnectorView,targetRepoId){ - $.log("removeProxyConnector:"+managedRepositoryConnectorView.source()+","+targetRepoId); - var url="restServices/archivaServices/proxyConnectorService/removeProxyConnector?"; - url += "sourceRepoId="+encodeURIComponent(managedRepositoryConnectorView.source()); - url += "&targetRepoId="+encodeURIComponent(targetRepoId); + removeProxyConnector=function(sourceRepoId,targetRepoId){ + proxyConnector=getProxyConnector(sourceRepoId, targetRepoId); + /*var url="restServices/archivaServices/proxyConnectorService/removeProxyConnector?"; + url += "sourceRepoId="+encodeURIComponent(proxyConnector.sourceRepoId()); + url += "&targetRepoId="+encodeURIComponent(proxyConnector.targetRepoId()); $.ajax(url, { type: "GET", @@ -261,33 +261,22 @@ $(function() { displayRestError(res); } } - ); + );*/ + self.proxyConnectors.remove(proxyConnector); + self.displayGrid(); } this.findUniqueManagedRepos=function(){ - var sourcesRepos=[]; + var managedRepositoriesIds=[]; //sourceRepoId for(i=0;i0){ - sourceRepo[0].targetRepos.push(curTarget); - } else { - sourcesRepos.push(new ManagedRepositoryConnectorView(curSrcRepoId,getManagedRepository(curSrcRepoId).name(),[curTarget])); + var curSrcRepoId=self.proxyConnectors()[i].sourceRepoId(); + if ($.inArray(curSrcRepoId,managedRepositoriesIds)<0){ + managedRepositoriesIds.push(curSrcRepoId) } } - return sourcesRepos; + $.log("managedRepositoriesIds:"+managedRepositoriesIds); + return managedRepositoriesIds; } getManagedRepository=function(id){ @@ -305,24 +294,44 @@ $(function() { return repo.id()==id; } ); + $.log("getRemoteRepository:"+id+":"+remoteRepository); return ($.isArray(remoteRepository) && remoteRepository.length>0) ? remoteRepository[0]:new RemoteRepository(); } - this.getProxyConnector=function(sourceRepoId,targetRepoId){ + // return remote repositories proxied for a managed repository + getRemoteRepositories=function(id){ + $.log("getRemoteRepositories:"+id); + var remoteRepositoryIds=$.grep(self.proxyConnectors(), + function(repo,idx){ + return repo.sourceRepoId()==id; + } + ); + $.log("remoteRepositoryIds.length:"+remoteRepositoryIds.length); + var remoteRepositories=[]; + for (i=0;i0) ? proxyConnector[0]:new ProxyConnector(); + var res = ($.isArray(proxyConnector) && proxyConnector.length>0) ? proxyConnector[0]:new ProxyConnector(); + $.log("getProxyConnector res:"+res); + return res; } showSettings=function(sourceRepoId,targetRepoId){ var targetContent = $("#proxy-connectors-grid-remoterepo-settings-content-"+sourceRepoId+"-"+targetRepoId); targetContent.html(""); targetContent.append($("#proxy-connectors-remote-settings-popover-tmpl") - .tmpl(self.getProxyConnector(sourceRepoId,targetRepoId))); + .tmpl(getProxyConnector(sourceRepoId,targetRepoId))); var targetImg = $("#proxy-connectors-grid-remoterepo-settings-edit-"+sourceRepoId+"-"+targetRepoId); targetImg.attr("data-content",targetContent.html()); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html index 667d742ce..69f2557ef 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/proxy-connectors.html @@ -54,33 +54,33 @@ {{each(i, row) itemsOnCurrentPage()}} - {{var sourceId = row.source()}} - +
-

${row.source()}

-

${row.sourceName()}

+

${getManagedRepository(row).id()}

+

${getManagedRepository(row).name()}

+ - {{each(j, targetRepo) row.targetRepos()}} - {{var targetRepoId = targetRepo.targetRepoId()}} + {{each(j, targetRepo) getRemoteRepositories(row)}} + {{var targetRepoId = targetRepo.id()}}

${targetRepoId}

${getRemoteRepository(targetRepoId).name()}

${getRemoteRepository(targetRepoId).url()}

+ data-bind="event: { mouseover: function(){ showSettings(row,targetRepoId)},},click: function(){ editProxyConnector(row)}" + id="proxy-connectors-grid-remoterepo-settings-edit-${row}-${targetRepoId}" href="#"> ${$.i18n.prop('edit')} - +

- {{/each}} + {{/each}} {{/each}} diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js index cc56f592b..1f38f0743 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/knockout.simpleGrid.js @@ -64,8 +64,12 @@ // Render the page links var pageLinksContainer = $("#"+allBindings.pageLinksId).get(0); - ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode") + if (viewModel.pageLinksUpdateCallBack){ + ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode") .subscribe(viewModel.pageLinksUpdateCallBack?viewModel.pageLinksUpdateCallBack:function(){}); + } else { + ko.renderTemplate(pageLinksTemplateName, viewModel, { templateEngine: templateEngine }, pageLinksContainer, "replaceNode"); + } if (viewModel.pageLinksUpdateCallBack) viewModel.pageLinksUpdateCallBack(); } }; -- 2.39.5