From 4590cfcb2d5e26518e04f8abc8e7c2dad973f6d2 Mon Sep 17 00:00:00 2001 From: Michael Wood Date: Mon, 2 Mar 2015 15:00:49 +0000 Subject: toaster: Enforce unique layer names We had some clever functionality to manage duplicate layer names by using layer versions and new revisions, unfortunately this was too opaque to the user. [YOCTO #7337] Signed-off-by: Michael Wood --- lib/toaster/toastergui/static/js/importlayer.js | 94 +++++++++++-------------- 1 file changed, 40 insertions(+), 54 deletions(-) (limited to 'lib/toaster/toastergui/static/js/importlayer.js') diff --git a/lib/toaster/toastergui/static/js/importlayer.js b/lib/toaster/toastergui/static/js/importlayer.js index 9d54286f4..d14a8abca 100644 --- a/lib/toaster/toastergui/static/js/importlayer.js +++ b/lib/toaster/toastergui/static/js/importlayer.js @@ -148,7 +148,6 @@ function importLayerPageInit (ctx) { headers: { 'X-CSRFToken' : $.cookie('csrftoken')}, success: function (data) { if (data.error != "ok") { - show_error_message(data, layerData); console.log(data.error); } else { /* Success layer import now go to the project page */ @@ -164,59 +163,7 @@ function importLayerPageInit (ctx) { } }); - function show_error_message(error, layerData) { - - var errorMsg = $("#import-error").fadeIn(); - var errorType = error.error; - var body = errorMsg.children("p"); - var title = errorMsg.children("h3"); - var optionsList = errorMsg.children("ul"); - var invalidLayerRevision = $("#invalid-layer-revision-hint"); - var layerRevisionCtrl = $("#layer-revision-ctrl"); - - /* remove any existing items */ - optionsList.children().each(function(){ $(this).remove(); }); - body.text(""); - title.text(""); - invalidLayerRevision.hide(); - layerNameCtrl.removeClass("error"); - layerRevisionCtrl.removeClass("error"); - - switch (errorType){ - case 'hint-layer-version-exists': - title.text("This layer already exists"); - body.html("A layer "+layerData.name+" already exists with this Git repository URL and this revision. You can:"); - optionsList.append("
  • Import "+layerData.name+" with a different revision
  • "); - optionsList.append("
  • or change the revision of the existing layer
  • "); - - layerRevisionCtrl.addClass("error"); - - invalidLayerRevision.html("A layer "+layerData.name+" already exists with this revision.
    You can import "+layerData.name+" with a different revision"); - invalidLayerRevision.show(); - break; - - case 'hint-layer-exists-with-different-url': - title.text("This layer already exists"); - body.html("A layer "+layerData.name+" already exists with a different Git repository URL:

    "+error.current_url+"

    You can:

    "); - optionsList.append("
  • Import the layer under a different name
  • "); - optionsList.append("
  • or change the Git repository URL of the existing layer
  • "); - duplicatedLayerName.html("A layer "+layerData.name+" already exists with a different Git repository URL.
    To import this layer give it a different name."); - duplicatedLayerName.show(); - layerNameCtrl.addClass("error"); - break; - - case 'hint-layer-exists': - title.text("This layer already exists"); - body.html("A layer "+layerData.name+" already exists. You can:"); - optionsList.append("
  • Import the layer under a different name
  • "); - break; - default: - title.text("Error") - body.text(data.error); - } - } - - function enable_import_btn (enabled) { + function enable_import_btn(enabled) { var importAndAddHint = $("#import-and-add-hint"); if (enabled) { @@ -244,6 +191,38 @@ function importLayerPageInit (ctx) { enable_import_btn(true); } + function layerExistsError(layer){ + var dupLayerInfo = $("#duplicate-layer-info"); + dupLayerInfo.find(".dup-layer-name").text(layer.name); + dupLayerInfo.find(".dup-layer-link").attr("href", layer.layerdetailurl); + dupLayerInfo.find("#dup-layer-vcs-url").text(layer.giturl); + dupLayerInfo.find("#dup-layer-revision").text(layer.revision); + + $(".fields-apart-from-layer-name").fadeOut(function(){ + + dupLayerInfo.fadeIn(); + }); + } + + layerNameInput.on('blur', function() { + if (!$(this).val()){ + return; + } + var name = $(this).val(); + + /* Check if the layer name exists */ + $.getJSON(ctx.xhrDataTypeaheadUrl, { type : "layers", project_id: ctx.projectId, include_added: "true" , value: name }, function(layer) { + if (layer.list.length > 0) { + for (var i in layer.list){ + if (layer.list[i].name == name) { + console.log(layer.list[i]) + layerExistsError(layer.list[i]); + } + } + } + }); + }); + vcsURLInput.on('input', function() { check_form(); }); @@ -260,6 +239,13 @@ function importLayerPageInit (ctx) { return; } + if ($("#duplicate-layer-info").css("display") != "None"){ + $("#duplicate-layer-info").fadeOut(function(){ + $(".fields-apart-from-layer-name").show(); + }); + + } + /* Don't remove the error class if we're displaying the error for another * reason. */ -- cgit 1.2.3-korg