From 526a11efced8a9b8fe308f427f5815a8dc79cedc Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Tue, 6 Mar 2012 18:32:06 +0000 Subject: [PATCH] [MRM-1577] rewrite legacy path admin page add ok. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1297639 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultArchivaAdministrationService.java | 2 +- .../main/webapp/js/archiva/general-admin.js | 121 +++++++++++++++++- .../js/archiva/templates/general-admin.html | 62 ++++++++- .../src/main/webapp/js/archiva/utils.js | 39 +++--- 4 files changed, 196 insertions(+), 28 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java index 495be22a8..0d5a82172 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultArchivaAdministrationService.java @@ -72,7 +72,7 @@ public class DefaultArchivaAdministrationService throws ArchivaRestServiceException { - // Check the proposed Artifact macthes the path + // Check the proposed Artifact matches the path ArtifactReference artifact = new ArtifactReference(); artifact.setGroupId( legacyArtifactPath.getGroupId() ); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js index 53907404c..b74afdf94 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/general-admin.js @@ -22,7 +22,7 @@ $(function() { // legacy path part //------------------------- - LegacyArtifactPath=function(path,groupId,artifactId,version,classifier,type){ + LegacyArtifactPath=function(path,groupId,artifactId,version,classifier,type,update){ //private String path; this.path=ko.observable(path); @@ -32,7 +32,7 @@ $(function() { */ //private String artifact; //this.artifact=ko.observable(artifact); - + this.update=update; //private String groupId; this.groupId=ko.observable(groupId); @@ -84,7 +84,97 @@ $(function() { return data?new LegacyArtifactPath(data.path,data.groupId,data.artifactId,data.version,data.classifier,data.type):null; } - LegacyPathViewModel=function(){ + activateLegacyArtifactPathFormValidation=function(){ + var theForm=$("#main-content #legacy-artifact-paths-edit-form"); + var validator = theForm.validate({ + showErrors: function(validator, errorMap, errorList) { + customShowError("#main-content #legacy-artifact-paths-edit-form",validator,errorMap,errorMap); + } + }); + } + + LegacyArtifactPathViewModel=function(legacyArtifactPath,update,legacyArtifactPathsViewModel){ + var self=this; + this.update=update; + this.legacyArtifactPath=legacyArtifactPath; + this.legacyArtifactPathsViewModel=legacyArtifactPathsViewModel; + + this.display=function(){ + var mainContent=$("#main-content"); + ko.applyBindings(self,mainContent.find("#legacy-artifact-paths-edit" ).get(0)); + mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("edit")); + activateLegacyArtifactPathFormValidation(); + activateLegacyArtifactPathsEditTab(); + } + + displayGrid=function(){ + activateLegacyArtifactPathsGridTab(); + } + + calculatePath=function(){ + var path=""; + if (self.legacyArtifactPath.groupId()){ + path+=self.legacyArtifactPath.groupId()+"/jars/"; + } + if (self.legacyArtifactPath.artifactId()){ + path+=self.legacyArtifactPath.artifactId(); + } + if (self.legacyArtifactPath.version()){ + path+="-"+self.legacyArtifactPath.version(); + } + if (self.legacyArtifactPath.classifier()){ + path+="-"+self.legacyArtifactPath.classifier(); + } + if (self.legacyArtifactPath.type()){ + path+="."+self.legacyArtifactPath.type(); + } + self.legacyArtifactPath.path(path); + } + + this.save=function(){ + var theForm=$("#main-content #legacy-artifact-paths-edit-form"); + if (!theForm.valid()){ + return; + } + // do that on server side + /*if (theForm.find("#artifact" ).val() + !=theForm.find("#path" ).val()){ + var errorList=[{ + message: $.i18n.prop("path must match artifact"), + element: theForm.find("#path" ).get(0) + }]; + customShowError("#main-content #legacy-artifact-paths-edit-form", null, null, errorList); + return; + }*/ + // TODO call id exists if add ? + clearUserMessages(); + $.log("save ok"); + if (self.update){ + $.log("update"); + }else { + $.ajax("restServices/archivaServices/archivaAdministrationService/addLegacyArtifactPath", + { + type: "POST", + contentType: 'application/json', + data: ko.toJSON(self.legacyArtifactPath), + dataType: 'json', + success: function(data) { + self.legacyArtifactPath.modified(false); + self.legacyArtifactPathsViewModel.legacyArtifactPaths.push(self.legacyArtifactPath); + displaySuccessMessage($.i18n.prop('legacy-artifact-path.added',self.legacyArtifactPath.path())); + activateLegacyArtifactPathsGridTab(); + }, + error: function(data) { + var res = $.parseJSON(data.responseText); + displayRestError(res); + } + } + ); + } + } + } + + LegacyArtifactPathsViewModel=function(){ var self=this; this.legacyArtifactPaths=ko.observableArray([]); @@ -108,7 +198,8 @@ $(function() { editLegacyArtifactPath=function(legacyArtifactPath){ - + var legacyArtifactPathViewModel=new LegacyArtifactPathViewModel(legacyArtifactPath,true); + legacyArtifactPathViewModel.display(); } removeLegacyArtifactPath=function(legacyArtifactPath){ @@ -131,11 +222,27 @@ $(function() { type: "GET", dataType: 'json', success: function(data){ - var legacyPathViewModel=new LegacyPathViewModel(); + var legacyArtifactPathsViewModel=new LegacyArtifactPathsViewModel(); var legacyPaths=mapLegacyArtifactPaths(data); $.log("legacyPaths:"+legacyPaths.length); - legacyPathViewModel.legacyArtifactPaths(legacyPaths); - ko.applyBindings(legacyPathViewModel,mainContent.find("#legacy-artifact-paths-view" ).get(0)); + legacyArtifactPathsViewModel.legacyArtifactPaths(legacyPaths); + ko.applyBindings(legacyArtifactPathsViewModel,mainContent.find("#legacy-artifact-paths-view" ).get(0)); + + mainContent.find("#legacy-artifact-paths-view-tabs").on('show', function (e) { + if ($(e.target).attr("href")=="#legacy-artifact-paths-edit") { + var viewModel = new LegacyArtifactPathViewModel(new LegacyArtifactPath(),false,legacyArtifactPathsViewModel); + viewModel.display(); + activateLegacyArtifactPathFormValidation(); + clearUserMessages(); + } + if ($(e.target).attr("href")=="#legacy-artifact-paths-view") { + mainContent.find("#legacy-artifact-paths-view-tabs-li-edit a").html($.i18n.prop("add")); + clearUserMessages(); + } + + }); + + activateLegacyArtifactPathsGridTab(); } }); diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html index 9ebecb04e..9a39acc8d 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/templates/general-admin.html @@ -37,7 +37,7 @@
-
+
@@ -86,3 +86,63 @@ + + diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js index 242654a9c..08ec9fd9b 100644 --- a/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/main/webapp/js/archiva/utils.js @@ -224,17 +224,17 @@ mapStringArray=function(data){ * @param idToAppend */ displayRedbackError=function(obj,idToAppend) { - if ($.isArray(obj.redbackRestError.errorMessages)) { + if ($.isArray(obj.errorMessages)) { $.log("displayRedbackError with array"); - for(var i=0; i" + message + "" ); + mainContent.find("div.clearfix" ).removeClass( "error" ); + mainContent.find("span.help-inline" ).remove(); + mainContent.find("#"+data.fieldName).parents( "div.clearfix" ).addClass( "error" ); + mainContent.find("#"+data.fieldName).parent().append( "" + message + "" ); return; } // we don't have any id with this fieldName so continue } - if (data.archivaRestError && data.archivaRestError.errorKey && data.archivaRestError.errorKey.length>0){ - $.log("with errorKey:"+dataarchivaRestError.errorKey); - displayErrorMessage($.i18n.prop( data.archivaRestError.errorKey ),idToAppend); + if (data.errorKey && data.errorKey.length>0){ + displayErrorMessage($.i18n.prop( data.errorKey ),idToAppend); } else { - $.log("data.errorMessage:"+data.archivaRestError.errorMessage); - displayErrorMessage(data.archivaRestError.errorMessage,idToAppend); + $.log("data.errorMessage:"+data.errorMessage); + displayErrorMessage(data.errorMessage,idToAppend); } } -- 2.39.5