aboutsummaryrefslogtreecommitdiffstats
path: root/lib/toaster/toastergui/static/js/importlayer.js
diff options
context:
space:
mode:
authorMichael Wood <michael.g.wood@intel.com>2015-03-02 15:00:49 +0000
committerAlexandru DAMIAN <alexandru.damian@intel.com>2015-03-09 13:15:21 +0000
commit4590cfcb2d5e26518e04f8abc8e7c2dad973f6d2 (patch)
tree2bb238fbe530b6fe16d45f07982d127b73899ee6 /lib/toaster/toastergui/static/js/importlayer.js
parent507d2a36e53ba2c1f49616d52e4700f6c1bca8fd (diff)
downloadbitbake-contrib-4590cfcb2d5e26518e04f8abc8e7c2dad973f6d2.tar.gz
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 <michael.g.wood@intel.com>
Diffstat (limited to 'lib/toaster/toastergui/static/js/importlayer.js')
-rw-r--r--lib/toaster/toastergui/static/js/importlayer.js94
1 files changed, 40 insertions, 54 deletions
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 <strong>"+layerData.name+"</strong> already exists with this Git repository URL and this revision. You can:");
- optionsList.append("<li>Import <strong>"+layerData.name+"</strong> with a different revision </li>");
- optionsList.append("<li>or <a href=\""+ctx.layerDetailsUrl+error.existing_layer_version+"/\" >change the revision of the existing layer</a></li>");
-
- layerRevisionCtrl.addClass("error");
-
- invalidLayerRevision.html("A layer <strong>"+layerData.name+"</strong> already exists with this revision.<br />You can import <strong>"+layerData.name+"</strong> with a different revision");
- invalidLayerRevision.show();
- break;
-
- case 'hint-layer-exists-with-different-url':
- title.text("This layer already exists");
- body.html("A layer <strong>"+layerData.name+"</strong> already exists with a different Git repository URL:<p style='margin-top:10px;'><strong>"+error.current_url+"</strong></p><p>You can:</p>");
- optionsList.append("<li>Import the layer under a different name</li>");
- optionsList.append("<li>or <a href=\""+ctx.layerDetailsUrl+error.current_id+"/\" >change the Git repository URL of the existing layer</a></li>");
- duplicatedLayerName.html("A layer <strong>"+layerData.name+"</strong> already exists with a different Git repository URL.<br />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 <strong>"+layerData.name+"</strong> already exists. You can:");
- optionsList.append("<li>Import the layer under a different name</li>");
- 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.
*/