From 0113a7a12e7a73f37d1d27318c1032faf40ef007 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 2 Oct 2012 15:13:38 +0000 Subject: [PATCH] [MRM-1681] addProxy Connectors Rules screen screen implementation. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1392956 13f79535-47bb-0310-9956-ffa450edef68 --- .../services/ProxyConnectorRuleService.java | 2 +- .../js/archiva/proxy-connectors-rules.js | 104 ++++++++++++++++-- .../js/templates/archiva/repositories.html | 53 +++++++-- .../src/test/tomcat/log4j2-test.xml | 8 +- 4 files changed, 142 insertions(+), 25 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorRuleService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorRuleService.java index d57fed33a..d2cacba57 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorRuleService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/ProxyConnectorRuleService.java @@ -48,7 +48,7 @@ public interface ProxyConnectorRuleService throws ArchivaRestServiceException; @Path ( "proxyConnectorRule" ) - @PUT + @POST @Consumes ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @Produces ( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) @RedbackAuthorization ( permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION ) diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js index f28d81b20..9df238a8f 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/proxy-connectors-rules.js @@ -23,9 +23,13 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra ProxyConnectorRulesViewModel=function(proxyConnectorRules,proxyConnectors){ var self=this; - this.proxyConnectorRules=ko.observableArray(proxyConnectorRules?proxyConnectorRules:[]); + this.proxyConnectorRules=ko.observableArray(proxyConnectorRules); this.proxyConnectors=proxyConnectors; + // FIXME get that from a REST service + // FIXME i18n + this.ruleTypes=[new RuleType("WHITE_LIST"," white list"),new RuleType("BLACK_LIST"," black list")]; + this.displayGrid=function(){ var mainContent = $("#main-content"); @@ -33,15 +37,14 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra data: self.proxyConnectorRules, pageSize: 5, gridUpdateCallBack: function(){ - $("#main-content" ).find("#proxy-connectors-rules-view-tabsTable" ).find("[title]").tooltip(); + //$("#main-content" ).find("#proxy-connectors-rules-view-tabsTable" ).find("[title]").tooltip(); } }); - ko.applyBindings(self,mainContent.find("#proxy-connectors-rules-view-tabs-view").get(0)); + ko.applyBindings(self,mainContent.find("#proxy-connector-rules-view").get(0)); removeSmallSpinnerImg(); - mainContent.find("#proxy-connectors-rules-view-tabs").on('show', function (e) { $.log("on show:"+$(e.target).attr("href")); if ($(e.target).attr("href")=="#proxy-connector-rules-edit") { @@ -49,10 +52,79 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra ko.applyBindings(proxyConnectorRuleViewModel,mainContent.find("#proxy-connector-rules-edit" ).get(0)); activateProxyConnectorRulesEditTab(); } + }); + } + addProxyConnectorRule=function(proxyConnectorRule){ + $.log("addProxyConnectorRule"); + self.saveProxyConnectorRule(proxyConnectorRule,"restServices/archivaServices/proxyConnectorRuleService/proxyConnectorRule"); + } + + this.saveProxyConnectorRule=function(proxyConnectorRule,url){ + $.log("saveProxyConnectorRule:"+url); + $("#user-messages" ).html(mediumSpinnerImg()); + $.ajax(url, + { + type: "POST", + contentType: 'application/json', + data: ko.toJSON(proxyConnectorRule), + dataType: 'json', + success: function(data) { + $.log("save proxyConnectorRule pattern:"+proxyConnectorRule.pattern()); + var message=$.i18n.prop(self.update?'proxy-connector-rule.updated':'proxy-connector-rule.added',proxyConnectorRule.pattern()); + displaySuccessMessage(message); + proxyConnectorRule.modified(false); + self.proxyConnectorRules.push(proxyConnectorRule); + activateProxyConnectorRulesGridTab(); + }, + error: function(data) { + var res = $.parseJSON(data.responseText); + displayRestError(res); + }, + complete:function(data){ + removeMediumSpinnerImg("#user-messages"); + } + } + ); + } + updateProxyConnectorRule=function(proxyConnectorRule){ + $.log("updateProxyConnectorRule"); + self.saveProxyConnectorRule(proxyConnectorRule,"restServices/archivaServices/proxyConnectorRuleService/updateProxyConnectorRule"); + } + + removeProxyConnectorRule=function(proxyConnectorRule){ + + //FIXME modal dialog to confirm + + $("#user-messages" ).html(mediumSpinnerImg()); + $.ajax("restServices/archivaServices/proxyConnectorRuleService/deleteProxyConnectorRule", + { + type:"POST", + contentType: 'application/json', + data: ko.toJSON(proxyConnectorRule), + dataType: 'json', + success:function(data){ + var message=$.i18n.prop('proxy-connector-rule.deleted',proxyConnectorRule.pattern()); + displaySuccessMessage(message); + }, + error: function(data) { + var res = $.parseJSON(data.responseText); + displayRestError(res); + }, + complete:function(data){ + removeMediumSpinnerImg("#user-messages"); + } + } + ); + } + + editProxyConnectorRule=function(proxyConnectorRule){ + var proxyConnectorRuleViewModel=new ProxyConnectorRuleViewModel(proxyConnectorRule,self,true); + ko.applyBindings(proxyConnectorRuleViewModel,$("#main-content").find("#proxy-connector-rules-edit" ).get(0)); + activateProxyConnectorRulesEditTab(); - }); } + } ProxyConnectorRuleViewModel=function(proxyConnectorRule,proxyConnectorRulesViewModel,update){ @@ -63,7 +135,14 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra this.update=update; proxyConnectorMoved=function(arg){ + $.log("repositoryMoved:"+arg.sourceIndex+" to " + arg.targetIndex); + } + saveProxyConnectorRule=function(){ + $.log("pattern:"+self.proxyConnectorRule.pattern()); + $.log("proxyConnectorRuleType:"+proxyConnectorRule.proxyConnectorRuleType()); + $.log("proxyConnectors:"+proxyConnectorRule.proxyConnectors().length); + self.proxyConnectorRulesViewModel.saveProxyConnectorRule(self.proxyConnectorRule) } } @@ -74,7 +153,7 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra screenChange(); var mainContent = $("#main-content"); mainContent.html($("#proxyConnectorsRulesMain").tmpl()); - mainContent.append(smallSpinnerImg()); + $("#user-messages").html(mediumSpinnerImg()); loadAllProxyConnectors(function(data){ var proxyConnectors = mapProxyConnectors(data); @@ -86,6 +165,9 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra var proxyConnectorRulesViewModel = new ProxyConnectorRulesViewModel(proxyConnectorRules,proxyConnectors); proxyConnectorRulesViewModel.displayGrid(); activateProxyConnectorRulesGridTab(); + }, + complete: function(data){ + removeMediumSpinnerImg("#user-messages"); } }); @@ -123,7 +205,7 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra if (data==null){ return null; } - return new ProxyConnector(data.pattern, data.proxyConnectorRuleType, mapProxyConnectors(data.proxyConnectors)); + return new ProxyConnectorRule(data.pattern, data.proxyConnectorRuleType, mapProxyConnectors(data.proxyConnectors)); } mapProxyConnectorRules=function(data){ @@ -137,9 +219,9 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra activateProxyConnectorRulesGridTab=function(){ var mainContent = $("#main-content"); mainContent.find("#proxy-connectors-rules-view-tabs-content div[class*='tab-pane']").removeClass("active"); - mainContent.find("#proxy-connectors-rules-view-tabs > li").removeClass("active"); + mainContent.find("#proxy-connectors-rules-view-tabs li").removeClass("active"); - mainContent.find("#repository-groups-view").addClass("active"); + mainContent.find("#proxy-connector-rules-view").addClass("active"); mainContent.find("#proxy-connectors-rules-view-tabs-li-grid").addClass("active"); mainContent.find("#proxy-connectors-rules-view-tabs-a-edit").html($.i18n.prop("add")); @@ -155,5 +237,9 @@ define("archiva.proxy-connectors-rules",["jquery","i18n","jquery.tmpl","bootstra mainContent.find("#proxy-connectors-rules-view-tabs-edit").addClass("active"); } + RuleType=function(type,label){ + this.type=type; + this.label=label; + } }); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html index ec153d777..01e489669 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/templates/archiva/repositories.html @@ -1229,14 +1229,14 @@
-
+
@@ -1285,14 +1285,36 @@ {{each(i, row) itemsOnCurrentPage()}} - - - - - - - - + + + + + + + + {{/each}} @@ -1307,6 +1329,8 @@
${proxyConnectorRule.pattern()} +
+ ${proxyConnectorRule.proxyConnectorRuleType()}
{{else}} @@ -1320,13 +1344,20 @@ data-bind="value:proxyConnectorRule.pattern,css:{'uneditable-input': update},readonly:update"/> +
+ +
+
${row.pattern()}${row.proxyConnectorRuleType()}connectoreditdeletesave
${row.pattern()}${row.proxyConnectorRuleType()} +
    + {{each(j,proxyConnector) row.proxyConnectors()}} +
  • ${proxyConnector.sourceRepoId()} <-> ${proxyConnector.targetRepoId()}
  • + {{/each}} +
+
+ + + + + + + + + + + + + {{if row.modified()}} + ${$.i18n.prop('save')} + {{/if}} +