diff --git a/bitbake/lib/toaster/toastergui/static/js/importlayer.js b/bitbake/lib/toaster/toastergui/static/js/importlayer.js index 9d54286f4a..d14a8abcaf 100644 --- a/bitbake/lib/toaster/toastergui/static/js/importlayer.js +++ b/bitbake/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. */ diff --git a/bitbake/lib/toaster/toastergui/templates/importlayer.html b/bitbake/lib/toaster/toastergui/templates/importlayer.html index 6b2111a1f4..5ef8a5786c 100644 --- a/bitbake/lib/toaster/toastergui/templates/importlayer.html +++ b/bitbake/lib/toaster/toastergui/templates/importlayer.html @@ -51,26 +51,51 @@
    - +
    + + + @@ -83,13 +108,16 @@ + + +
    Layer dependencies (optional) - + @@ -105,6 +133,7 @@ To import a layer, you need to enter a repository URL, a branch, tag or commit and a layer name + {% endblock %} diff --git a/bitbake/lib/toaster/toastergui/views.py b/bitbake/lib/toaster/toastergui/views.py index 14029813e8..8034cfceaf 100755 --- a/bitbake/lib/toaster/toastergui/views.py +++ b/bitbake/lib/toaster/toastergui/views.py @@ -2279,9 +2279,14 @@ if toastermain.settings.MANAGED: def _lv_to_dict(x): - return {"id": x.pk, "name": x.layer.name, "tooltip": x.layer.vcs_url+" | "+x.commit, - "detail": "(" + x.layer.vcs_url + (")" if x.up_branch == None else " | "+x.up_branch.name+")"), - "giturl": x.layer.vcs_url, "layerdetailurl" : reverse('layerdetails', args=(x.pk,))} + return {"id": x.pk, + "name": x.layer.name, + "tooltip": x.layer.vcs_url+" | "+x.get_vcs_reference(), + "detail": "(" + x.layer.vcs_url + (")" if x.up_branch == None else " | "+x.get_vcs_reference()+")"), + "giturl": x.layer.vcs_url, + "layerdetailurl" : reverse('layerdetails', args=(x.pk,)), + "revision" : x.get_vcs_reference(), + } # returns layers for current project release that are not in the project set, matching the name