[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
This commit is contained in:
Olivier Lamy 2012-03-06 18:32:06 +00:00
parent 024b2290c7
commit 526a11efce
4 changed files with 196 additions and 28 deletions

View File

@ -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() );

View File

@ -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();
}
});

View File

@ -37,7 +37,7 @@
</table>
<div id="legacy-artifact-pathsPagination"></div>
</div>
<div id="network-proxies-edit" class="tab-pane" data-bind='template: {name:"legacy-artifact-paths-edit-tmpl"}'></div>
<div id="legacy-artifact-paths-edit" class="tab-pane" data-bind='template: {name:"legacy-artifact-paths-edit-tmpl"}'></div>
</div>
</div>
</script>
@ -86,3 +86,63 @@
</script>
<script id="legacy-artifact-paths-edit-tmpl" type="text/html">
<form id="legacy-artifact-paths-edit-form" class="well form-horizontal">
<fieldset id="legacy-artifact-paths-edit-fieldset">
<div class="control-group">
<label class="control-label" for="groupId">${$.i18n.prop('legacy-artifact-paths.groupId')}</label>
<div class="controls">
<input type="text" class="xlarge required" id="groupId" name="groupId" size="8"
data-bind="value: legacyArtifactPath.groupId"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="artifactId">${$.i18n.prop('legacy-artifact-paths.artifactId')}</label>
<div class="controls">
<input type="text" class="xlarge required" id="artifactId" name="artifactId" size="8"
data-bind="value: legacyArtifactPath.artifactId"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="version">${$.i18n.prop('legacy-artifact-paths.version')}</label>
<div class="controls">
<input type="text" class="xlarge required" id="version" name="version" size="8"
data-bind="value: legacyArtifactPath.version"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="classifier">${$.i18n.prop('legacy-artifact-paths.classifier')}</label>
<div class="controls">
<input type="text" class="xlarge" id="classifier" name="classifier" size="8"
data-bind="value: legacyArtifactPath.classifier"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="type">${$.i18n.prop('legacy-artifact-paths.type')}</label>
<div class="controls">
<input type="text" class="xlarge required" id="type" name="type" size="8"
data-bind="value: legacyArtifactPath.type"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="path">${$.i18n.prop('legacy-artifact-paths.path')}</label>
<div class="controls">
<input type="text" class="xlarge required" id="path" name="path" size="8"
data-bind="value: legacyArtifactPath.path"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="artifact">${$.i18n.prop('legacy-artifact-paths.artifact')}</label>
<div class="controls">
<span title="calculated from values" class="uneditable-input"
id="artifact" data-bind="text: legacyArtifactPath.artifact"></span>
</div>
</div>
</fieldset>
<button id="network-proxy-btn-save" data-bind="click: save" class="btn">${$.i18n.prop('save')}</button>
<button id="network-proxy-btn-cancel" data-bind="click: displayGrid" class="btn">${$.i18n.prop('cancel')}</button>
<button id="network-proxy-btn-calculate-path" data-bind="click: calculatePath" class="btn btn-success">${$.i18n.prop('legacy-artifact-paths.calculatePath')}</button>
</form>
</script>

View File

@ -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<obj.redbackRestError.errorMessages.length; i++ ) {
if(obj.redbackRestError.errorMessages[i].errorKey) {
for(var i=0; i<obj.errorMessages.length; i++ ) {
if(obj.errorMessages[i].errorKey) {
$.log("displayRedbackError with array loop");
displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages[i].errorKey, obj.redbackRestError.errorMessages[i].args ),idToAppend);
displayErrorMessage($.i18n.prop( obj.errorMessages[i].errorKey, obj.errorMessages[i].args ),idToAppend);
}
}
} else {
$.log("displayRedbackError no array");
displayErrorMessage($.i18n.prop( obj.redbackRestError.errorMessages.errorKey, obj.redbackRestError.errorMessages.args ),idToAppend);
displayErrorMessage($.i18n.prop( obj.errorMessages.errorKey, obj.errorMessages.args ),idToAppend);
}
}
@ -249,29 +249,30 @@ displayRestError=function(data,idToAppend){
displayRedbackError(archivaRestError,idToAppend)
}
// if we have the fieldName display error on it
if (data.archivaRestError && data.archivaRestError.fieldName){
if ($("#main-content #"+data.archivaRestError.fieldName)){
if (data && data.fieldName){
var mainContent=$("#main-content");
if (mainContent.find("#"+data.fieldName)){
var message=null;
if (data.archivaRestError.errorKey) {
message=$.i18n.prop('data.archivaRestError.errorKey');
if (data.errorKey) {
message=$.i18n.prop('data.errorKey');
} else {
message=data.archivaRestError.errorMessage;
message=data.errorMessage;
}
$( "#main-content div.clearfix" ).removeClass( "error" );
$( "#main-content span.help-inline" ).remove();
$("#main-content #"+data.archivaRestError.fieldName).parents( "div.clearfix" ).addClass( "error" );
$("#main-content #"+data.archivaRestError.fieldName).parent().append( "<span class=\"help-inline\">" + message + "</span>" );
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( "<span class=\"help-inline\">" + message + "</span>" );
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);
}
}