From a624792de0c6e500564777564ce72bc2b5844b73 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 7 Feb 2012 18:24:05 +0000 Subject: [PATCH] refactor proxy connectors grid loadind, start edition too git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1241542 13f79535-47bb-0310-9956-ffa450edef68 --- .../main/webapp/js/archiva/network-proxies.js | 20 +- .../webapp/js/archiva/proxy-connectors.js | 97 ++++++---- .../main/webapp/js/archiva/repositories.js | 180 +++++++++--------- .../archiva/templates/proxy-connectors.html | 53 +++++- 4 files changed, 221 insertions(+), 129 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js index 10fec2348..f8b78d1c9 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/network-proxies.js @@ -118,7 +118,7 @@ $(function() { } NetworkProxiesViewModel=function(){ - this.networkProxies=ko.observableArray([]);//.subscribe(function(val){$.log('subscribe')}); + this.networkProxies=ko.observableArray([]); var self=this; @@ -220,12 +220,8 @@ $(function() { - $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", { - type: "GET", - dataType: 'json', - success: function(data) { + loadNetworkProxies( function(data) { networkProxiesViewModel.networkProxies(mapNetworkProxies(data)); - //networkProxiesViewModel.networkProxies.subscribe(function(){$.log("change in networkProxies")}); networkProxiesViewModel.gridViewModel = new ko.simpleGrid.viewModel({ data: networkProxiesViewModel.networkProxies, columns: [ @@ -257,8 +253,16 @@ $(function() { }); ko.applyBindings(networkProxiesViewModel,$("#main-content #network-proxies-view").get(0)); } - } - ); + ) + } + + loadNetworkProxies=function(successCallbackFn, errorCallbackFn){ + $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", { + type: "GET", + dataType: 'json', + success: successCallbackFn, + error: errorCallbackFn + }); } activateNetworkProxyFormValidation=function(){ 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 6358f0a92..011db78b7 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 @@ -92,6 +92,13 @@ $(function() { this.targetRepos=ko.observableArray(targetRepos); } + ProxyConnectorViewModel=function(proxyConnector,update,proxyConnectorsViewModel){ + var self=this; + this.proxyConnector=ko.observable(); + this.proxyConnectorsViewModel=proxyConnectorsViewModel; + //mappe policies avec policyInformations pour avoir object + plus complexe + } + ProxyConnectorsViewModel=function(){ var self=this; this.proxyConnectors=ko.observableArray([]); @@ -99,6 +106,8 @@ $(function() { this.policyInformations=ko.observableArray([]); this.managedRepositories=ko.observableArray([]); this.remoteRepositories=ko.observableArray([]); + this.networkProxies=ko.observableArray([]); + editProxyConnector=function(proxyConnector){ } @@ -186,16 +195,29 @@ $(function() { $("#main-content #proxyConnectorsTable [title]").tooltip(); } }); + var mainContent = $("#main-content"); this.gridViewModel.getManagedRepository=getManagedRepository; - ko.applyBindings(this,$("#main-content #proxyConnectorsTable").get(0)); + ko.applyBindings(this,mainContent.find("#proxyConnectorsTable").get(0)); removeSmallSpinnerImg("#main-content"); - $("#main-content #proxy-connectors-view-tabs a:first").tab('show'); + this,mainContent.find("#proxy-connectors-view-tabs #proxy-connectors-view-tabs-a-network-proxies-grid").tab('show'); + + mainContent.find("#proxy-connectors-view-tabs").on('show', function (e) { + + if ($(e.target).attr("href")=="#proxy-connectors-edit") { + var proxyConnectorViewModel=new ProxyConnectorViewModel(new ProxyConnector(),false,self); + ko.applyBindings(proxyConnectorViewModel,mainContent.find("#proxy-connectors-edit").get(0)); + + } + if ($(e.target).attr("href")=="#proxy-connectors-view") { + $("#proxy-connectors-view-tabs-a-network-proxies-grid").html($.i18n.prop("add")); + + } + + }); } } - // FIXME use various callback to prevent async false !! - displayProxyConnectors=function(){ var mainContent = $("#main-content"); mainContent.html($("#proxyConnectorsMain").tmpl()); @@ -204,44 +226,50 @@ $(function() { this.proxyConnectorsViewModel = new ProxyConnectorsViewModel(); var self=this; - $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", { - type: "GET", - dataType: 'json', - async: false, - success: function(data) { - self.proxyConnectorsViewModel.managedRepositories(mapManagedRepositories(data)); - } - }); + loadManagedRepositories(function(data) { + self.proxyConnectorsViewModel.managedRepositories(mapManagedRepositories(data)); + + loadRemoteRepositories(function(data) { + self.proxyConnectorsViewModel.remoteRepositories(mapRemoteRepositories(data)); + + loadNetworkProxies(function(data) { + self.proxyConnectorsViewModel.networkProxies(mapNetworkProxies(data)); + + loadAllPolicies( function(data) { + self.proxyConnectorsViewModel.policyInformations(mapPolicyInformations(data)); + + loadAllProxyConnectors( function(data) { + self.proxyConnectorsViewModel.proxyConnectors(mapProxyConnectors(data)); + self.proxyConnectorsViewModel.displayGrid(); + }); + + }); + + }); + + }); - $.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", { - type: "GET", - dataType: 'json', - async: false, - success: function(data) { - self.proxyConnectorsViewModel.remoteRepositories(mapRemoteRepositories(data)); - } }); + } + + loadAllPolicies=function(successCallBackFn,errorCallBackFn){ $.ajax("restServices/archivaServices/proxyConnectorService/allPolicies", { type: "GET", dataType: 'json', - async: false, - success: function(data) { - self.proxyConnectorsViewModel.policyInformations(mapPolicyInformations(data)); - } + success: successCallBackFn, + error: errorCallBackFn } ); + } + loadAllProxyConnectors=function(successCallBackFn,errorCallBackFn){ $.ajax("restServices/archivaServices/proxyConnectorService/getProxyConnectors", { - type: "GET", - dataType: 'json', - success: function(data) { - self.proxyConnectorsViewModel.proxyConnectors(mapProxyConnectors(data)); - self.proxyConnectorsViewModel.displayGrid(); - } - } - ); - + type: "GET", + dataType: 'json', + success: successCallBackFn, + error: errorCallBackFn + }); } mapProxyConnector=function(data){ @@ -251,8 +279,11 @@ $(function() { var policies = data.policies == null ? null: $.each(data.policies,function(item){ return new Entry(item.key, item.value); }); + var properties = data.properties == null ? null: $.each(data.properties,function(item){ + return new Entry(item.key, item.value); + }); return new ProxyConnector(data.sourceRepoId,data.targetRepoId,data.proxyId,mapStringArray(data.blackListPatterns), - mapStringArray(data.whiteListPatterns),policies,data.properties, + mapStringArray(data.whiteListPatterns),policies,properties, data.disabled,data.order); } diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js index d77c543ca..9a3e3559f 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/repositories.js @@ -487,20 +487,22 @@ $(function() { } activateManagedRepositoriesGridTab=function(){ - $("#main-content #managed-repository-edit-li").removeClass("active"); - $("#main-content #managed-repository-edit").removeClass("active"); + var mainContent = $("#main-content"); + mainContent.find("#managed-repository-edit-li").removeClass("active"); + mainContent.find("#managed-repository-edit").removeClass("active"); - $("#main-content #managed-repositories-view-li").addClass("active"); - $("#main-content #managed-repositories-view").addClass("active"); - $("#main-content #managed-repository-edit-li a").html($.i18n.prop("add")); + mainContent.find("#managed-repositories-view-li").addClass("active"); + mainContent.find("#managed-repositories-view").addClass("active"); + mainContent.find("#managed-repository-edit-li a").html($.i18n.prop("add")); } activateManagedRepositoryEditTab=function(){ - $("#main-content #managed-repositories-view-li").removeClass("active"); - $("#main-content #managed-repositories-view").removeClass("active"); + var mainContent = $("#main-content"); + mainContent.find("#managed-repositories-view-li").removeClass("active"); + mainContent.find("#managed-repositories-view").removeClass("active"); - $("#main-content #managed-repository-edit-li").addClass("active"); - $("#main-content #managed-repository-edit").addClass("active"); + mainContent.find("#managed-repository-edit-li").addClass("active"); + mainContent.find("#managed-repository-edit").addClass("active"); } @@ -799,87 +801,77 @@ $(function() { var managedRepositoriesViewModel = new ManagedRepositoriesViewModel(); var remoteRepositoriesViewModel = new RemoteRepositoriesViewModel(); - $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", { - type: "GET", - dataType: 'json', - success: function(data) { - managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data)); - managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({ - data: managedRepositoriesViewModel.managedRepositories, - columns: [ - { - headerText: $.i18n.prop('identifier'), - rowText: "id" - }, - { - headerText: $.i18n.prop('name'), - rowText: "name" - }, - { - headerText: $.i18n.prop('type'), - rowText: "getTypeLabel", - // FIXME i18n - title: "Repository type (default is Maven 2)" - } - ], - pageSize: 5, - gridUpdateCallBack: function(){ - $("#main-content #managed-repositories-table").find("[title]").tooltip(); - } - }); - var mainContent = $("#main-content"); - ko.applyBindings(managedRepositoriesViewModel,mainContent.find("#managed-repositories-view").get(0)); - - mainContent.find("#managed-repositories-pills #managed-repositories-view-a").tab('show'); - removeMediumSpinnerImg("#main-content #managed-repositories-content"); - activateManagedRepositoriesGridTab(); + loadManagedRepositories(function(data) { + managedRepositoriesViewModel.managedRepositories(mapManagedRepositories(data)); + managedRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({ + data: managedRepositoriesViewModel.managedRepositories, + columns: [ + { + headerText: $.i18n.prop('identifier'), + rowText: "id" + }, + { + headerText: $.i18n.prop('name'), + rowText: "name" + }, + { + headerText: $.i18n.prop('type'), + rowText: "getTypeLabel", + // FIXME i18n + title: "Repository type (default is Maven 2)" + } + ], + pageSize: 5, + gridUpdateCallBack: function(){ + $("#main-content #managed-repositories-table").find("[title]").tooltip(); } - } - ); + }); + var mainContent = $("#main-content"); + ko.applyBindings(managedRepositoriesViewModel,mainContent.find("#managed-repositories-view").get(0)); - $.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", { - type: "GET", - dataType: 'json', - success: function(data) { - remoteRepositoriesViewModel.remoteRepositories(mapRemoteRepositories(data)); - remoteRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({ - data: remoteRepositoriesViewModel.remoteRepositories, - columns: [ - { - headerText: $.i18n.prop('identifier'), - rowText: "id" - }, - { - headerText: $.i18n.prop('name'), - rowText: "name" - }, - { - headerText: $.i18n.prop('url'), - rowText: "url" - }, - { - headerText: $.i18n.prop('type'), - rowText: "getTypeLabel", - // FIXME i18n - title: "Repository type (default is Maven 2)" - } - ], - pageSize: 5, - gridUpdateCallBack: function(){ - $("#main-content #remote-repositories-table").find("[title]").tooltip(); - } - }); - var mainContent = $("#main-content"); - ko.applyBindings(remoteRepositoriesViewModel,mainContent.find("#remote-repositories-table").get(0)); - mainContent.find("#remote-repositories-pills #remote-repositories-view-a").tab('show') - removeMediumSpinnerImg("#main-content #remote-repositories-content"); + mainContent.find("#managed-repositories-pills #managed-repositories-view-a").tab('show'); + removeMediumSpinnerImg("#main-content #managed-repositories-content"); + activateManagedRepositoriesGridTab(); + }); + + loadRemoteRepositories(function(data) { + remoteRepositoriesViewModel.remoteRepositories(mapRemoteRepositories(data)); + remoteRepositoriesViewModel.gridViewModel = new ko.simpleGrid.viewModel({ + data: remoteRepositoriesViewModel.remoteRepositories, + columns: [ + { + headerText: $.i18n.prop('identifier'), + rowText: "id" + }, + { + headerText: $.i18n.prop('name'), + rowText: "name" + }, + { + headerText: $.i18n.prop('url'), + rowText: "url" + }, + { + headerText: $.i18n.prop('type'), + rowText: "getTypeLabel", + // FIXME i18n + title: "Repository type (default is Maven 2)" + } + ], + pageSize: 5, + gridUpdateCallBack: function(){ + $("#main-content #remote-repositories-table").find("[title]").tooltip(); } - } - ); + }); + var mainContent = $("#main-content"); + ko.applyBindings(remoteRepositoriesViewModel,mainContent.find("#remote-repositories-table").get(0)); + mainContent.find("#remote-repositories-pills #remote-repositories-view-a").tab('show') + removeMediumSpinnerImg("#main-content #remote-repositories-content"); + }); - $("#main-content #managed-repositories-pills").on('show', function (e) { + mainContent.find("#managed-repositories-pills").on('show', function (e) { var mainContent = $("#main-content"); if ($(e.target).attr("href")=="#managed-repository-edit") { var viewModel = new ManagedRepositoryViewModel(new ManagedRepository(),false,managedRepositoriesViewModel); @@ -892,7 +884,7 @@ $(function() { }); - $("#main-content #remote-repositories-pills").on('show', function (e) { + mainContent.find("#remote-repositories-pills").on('show', function (e) { if ($(e.target).attr("href")=="#remote-repository-edit") { $.ajax("restServices/archivaServices/networkProxyService/getNetworkProxies", { type: "GET", @@ -913,4 +905,22 @@ $(function() { } + loadManagedRepositories=function(successCallBackFn,errorCallBackFn){ + $.ajax("restServices/archivaServices/managedRepositoriesService/getManagedRepositories", { + type: "GET", + dataType: 'json', + success: successCallBackFn, + error: errorCallBackFn + }); + } + + loadRemoteRepositories=function(successCallBackFn,errorCallBackFn){ + $.ajax("restServices/archivaServices/remoteRepositoriesService/getRemoteRepositories", { + type: "GET", + dataType: 'json', + success: successCallBackFn, + error: errorCallBackFn + }); + } + }); \ No newline at end of file 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 d5c764c26..1987c80e3 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 @@ -26,7 +26,7 @@ ${$.i18n.prop('proxy-connectors.grid.tab.title')}
  • - ${$.i18n.prop('add')} + ${$.i18n.prop('add')}
  • @@ -36,7 +36,7 @@
    -
    +
    @@ -92,7 +92,7 @@ {{/if}} - + {{each policies().entry}} @@ -104,4 +104,51 @@
    Policies${$.i18n.prop('proxy-connector.policies')}
    + + + \ No newline at end of file -- 2.39.5