mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add v2 /flows api and deploy-overwrite protection
This commit is contained in:
@@ -35,6 +35,7 @@ RED.deploy = (function() {
|
||||
$("#btn-deploy img").attr("src",deploymentTypes[type].img);
|
||||
}
|
||||
|
||||
var currentDiff = null;
|
||||
|
||||
/**
|
||||
* options:
|
||||
@@ -76,7 +77,7 @@ RED.deploy = (function() {
|
||||
$('#btn-deploy').click(function() { save(); });
|
||||
|
||||
$( "#node-dialog-confirm-deploy" ).dialog({
|
||||
title: "Confirm deploy",
|
||||
title: RED._('deploy.confirm.button.confirm'),
|
||||
modal: true,
|
||||
autoOpen: false,
|
||||
width: 550,
|
||||
@@ -88,6 +89,15 @@ RED.deploy = (function() {
|
||||
$( this ).dialog( "close" );
|
||||
}
|
||||
},
|
||||
// {
|
||||
// id: "node-dialog-confirm-deploy-review",
|
||||
// text: RED._("deploy.confirm.button.review"),
|
||||
// class: "primary",
|
||||
// click: function() {
|
||||
// showDiff();
|
||||
// $( this ).dialog( "close" );
|
||||
// }
|
||||
// },
|
||||
{
|
||||
text: RED._("deploy.confirm.button.confirm"),
|
||||
class: "primary",
|
||||
@@ -97,7 +107,7 @@ RED.deploy = (function() {
|
||||
if (ignoreChecked) {
|
||||
ignoreDeployWarnings[$( "#node-dialog-confirm-deploy-type" ).val()] = true;
|
||||
}
|
||||
save(true);
|
||||
save(true,$( "#node-dialog-confirm-deploy-type" ).val() === "conflict");
|
||||
$( this ).dialog( "close" );
|
||||
}
|
||||
}
|
||||
@@ -109,6 +119,15 @@ RED.deploy = (function() {
|
||||
'<label style="display:inline;" for="node-dialog-confirm-deploy-hide"> do not warn about this again</label>'+
|
||||
'<input type="hidden" id="node-dialog-confirm-deploy-type">'+
|
||||
'</div>');
|
||||
},
|
||||
open: function() {
|
||||
if ($( "#node-dialog-confirm-deploy-type" ).val() === "conflict") {
|
||||
// $("#node-dialog-confirm-deploy-review").show();
|
||||
$("#node-dialog-confirm-deploy-hide").parent().hide();
|
||||
} else {
|
||||
// $("#node-dialog-confirm-deploy-review").hide();
|
||||
$("#node-dialog-confirm-deploy-hide").parent().show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -123,6 +142,199 @@ RED.deploy = (function() {
|
||||
$("#btn-deploy").addClass("disabled");
|
||||
}
|
||||
});
|
||||
|
||||
// $("#node-dialog-view-diff").dialog({
|
||||
// title: RED._('deploy.confirm.button.review'),
|
||||
// modal: true,
|
||||
// autoOpen: false,
|
||||
// buttons: [
|
||||
// {
|
||||
// text: RED._("deploy.confirm.button.cancel"),
|
||||
// click: function() {
|
||||
// $( this ).dialog( "close" );
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// text: RED._("deploy.confirm.button.merge"),
|
||||
// class: "primary",
|
||||
// click: function() {
|
||||
// $( this ).dialog( "close" );
|
||||
// }
|
||||
// }
|
||||
// ],
|
||||
// open: function() {
|
||||
// $(this).dialog({width:Math.min($(window).width(),900),height:Math.min($(window).height(),600)});
|
||||
// }
|
||||
// });
|
||||
|
||||
// $("#node-dialog-view-diff-diff").editableList({
|
||||
// addButton: false,
|
||||
// scrollOnAdd: false,
|
||||
// addItem: function(container,i,object) {
|
||||
// var tab = object.tab.n;
|
||||
// var tabDiv = $('<div>',{class:"node-diff-tab collapsed"}).appendTo(container);
|
||||
//
|
||||
// var titleRow = $('<div>',{class:"node-diff-tab-title"}).appendTo(tabDiv);
|
||||
// titleRow.click(function(evt) {
|
||||
// evt.preventDefault();
|
||||
// titleRow.parent().toggleClass('collapsed');
|
||||
// })
|
||||
// var chevron = $('<i class="fa fa-angle-down node-diff-chevron ">').appendTo(titleRow);
|
||||
// var title = $('<span>').html(tab.label||tab.id).appendTo(titleRow);
|
||||
//
|
||||
// var stats = $('<span>',{class:"node-diff-tab-stats"}).appendTo(titleRow);
|
||||
//
|
||||
// var addedCount = 0;
|
||||
// var deletedCount = 0;
|
||||
// var changedCount = 0;
|
||||
// var conflictedCount = 0;
|
||||
//
|
||||
// object.tab.nodes.forEach(function(node) {
|
||||
// var realNode = RED.nodes.node(node.id);
|
||||
// var hasChanges = false;
|
||||
// if (currentDiff.added[node.id]) {
|
||||
// addedCount++;
|
||||
// hasChanges = true;
|
||||
// }
|
||||
// if (currentDiff.deleted[node.id]) {
|
||||
// deletedCount++;
|
||||
// hasChanges = true;
|
||||
// }
|
||||
// if (currentDiff.changed[node.id]) {
|
||||
// changedCount++;
|
||||
// hasChanges = true;
|
||||
// }
|
||||
// if (currentDiff.conflicted[node.id]) {
|
||||
// conflictedCount++;
|
||||
// hasChanges = true;
|
||||
// }
|
||||
//
|
||||
// if (hasChanges) {
|
||||
// var def = RED.nodes.getType(node.type)||{};
|
||||
// var div = $("<div>",{class:"node-diff-node-entry collapsed"}).appendTo(tabDiv);
|
||||
// var nodeTitleDiv = $("<div>",{class:"node-diff-node-entry-title"}).appendTo(div);
|
||||
// nodeTitleDiv.click(function(evt) {
|
||||
// evt.preventDefault();
|
||||
// $(this).parent().toggleClass('collapsed');
|
||||
// })
|
||||
// var newNode = currentDiff.newConfig.all[node.id];
|
||||
// var nodePropertiesDiv = $("<div>",{class:"node-diff-node-entry-properties"}).appendTo(div);
|
||||
//
|
||||
// var nodePropertiesTable = $("<table>").appendTo(nodePropertiesDiv);
|
||||
//
|
||||
// if (node.hasOwnProperty('x')) {
|
||||
// if (newNode.x !== node.x || newNode.y !== node.y) {
|
||||
// var currentPosition = node.x+", "+node.y
|
||||
// var newPosition = newNode.x+", "+newNode.y;
|
||||
// $("<tr><td>position</td><td>"+currentPosition+"</td><td>"+newPosition+"</td></tr>").appendTo(nodePropertiesTable);
|
||||
// }
|
||||
// }
|
||||
// var properties = Object.keys(node).filter(function(p) { return p!='z'&&p!='wires'&&p!=='x'&&p!=='y'&&p!=='id'&&p!=='type'&&(!def.defaults||!def.defaults.hasOwnProperty(p))});
|
||||
// if (def.defaults) {
|
||||
// properties = properties.concat(Object.keys(def.defaults));
|
||||
// }
|
||||
// properties.forEach(function(d) {
|
||||
// var localValue = JSON.stringify(node[d]);
|
||||
// var remoteValue = JSON.stringify(newNode[d]);
|
||||
// var originalValue = realNode._config[d];
|
||||
//
|
||||
// if (remoteValue !== originalValue) {
|
||||
// var formattedProperty = formatNodeProperty(node[d]);
|
||||
// var newFormattedProperty = formatNodeProperty(newNode[d]);
|
||||
// if (localValue === originalValue) {
|
||||
// // no conflict change
|
||||
// } else {
|
||||
// // conflicting change
|
||||
// }
|
||||
// $("<tr><td>"+d+'</td><td class="">'+formattedProperty+'</td><td class="node-diff-property-changed">'+newFormattedProperty+"</td></tr>").appendTo(nodePropertiesTable);
|
||||
// }
|
||||
//
|
||||
// })
|
||||
// var nodeChevron = $('<i class="fa fa-angle-down node-diff-chevron">').appendTo(nodeTitleDiv);
|
||||
//
|
||||
//
|
||||
// // var leftColumn = $('<div>',{class:"node-diff-column"}).appendTo(div);
|
||||
// // var rightColumn = $('<div>',{class:"node-diff-column"}).appendTo(div);
|
||||
// // rightColumn.html(" ");
|
||||
//
|
||||
//
|
||||
//
|
||||
// var nodeDiv = $("<div>",{class:"node-diff-node-entry-node"}).appendTo(nodeTitleDiv);
|
||||
// var colour = def.color;
|
||||
// var icon_url = "arrow-in.png";
|
||||
// if (node.type === 'tab') {
|
||||
// colour = "#C0DEED";
|
||||
// icon_url = "subflow.png";
|
||||
// } else if (def.category === 'config') {
|
||||
// icon_url = "cog.png";
|
||||
// } else if (node.type === 'unknown') {
|
||||
// icon_url = "alert.png";
|
||||
// } else {
|
||||
// icon_url = def.icon;
|
||||
// }
|
||||
// nodeDiv.css('backgroundColor',colour);
|
||||
//
|
||||
// var iconContainer = $('<div/>',{class:"palette_icon_container"}).appendTo(nodeDiv);
|
||||
// $('<div/>',{class:"palette_icon",style:"background-image: url(icons/"+icon_url+")"}).appendTo(iconContainer);
|
||||
//
|
||||
//
|
||||
//
|
||||
// var contentDiv = $('<div>',{class:"node-diff-node-description"}).appendTo(nodeTitleDiv);
|
||||
//
|
||||
// $('<span>',{class:"node-diff-node-label"}).html(node.label || node.name || node.id).appendTo(contentDiv);
|
||||
// //$('<div>',{class:"red-ui-search-result-node-type"}).html(node.type).appendTo(contentDiv);
|
||||
// //$('<div>',{class:"red-ui-search-result-node-id"}).html(node.id).appendTo(contentDiv);
|
||||
// }
|
||||
//
|
||||
// });
|
||||
//
|
||||
// var statsInfo = '<span class="node-diff-count">'+object.tab.nodes.length+" nodes"+
|
||||
// (addedCount+deletedCount+changedCount+conflictedCount > 0 ? " : ":"")+
|
||||
// "</span> "+
|
||||
// ((addedCount > 0)?'<span class="node-diff-added">'+addedCount+' added</span> ':'')+
|
||||
// ((deletedCount > 0)?'<span class="node-diff-deleted">'+deletedCount+' deleted</span> ':'')+
|
||||
// ((changedCount > 0)?'<span class="node-diff-changed">'+changedCount+' changed</span> ':'')+
|
||||
// ((conflictedCount > 0)?'<span class="node-diff-conflicted">'+conflictedCount+' conflicts</span>':'');
|
||||
// stats.html(statsInfo);
|
||||
//
|
||||
//
|
||||
//
|
||||
// //
|
||||
// //
|
||||
// //
|
||||
// // var node = object.node;
|
||||
// // var realNode = RED.nodes.node(node.id);
|
||||
// // var def = RED.nodes.getType(object.node.type)||{};
|
||||
// // var l = "";
|
||||
// // if (def && def.label && realNode) {
|
||||
// // l = def.label;
|
||||
// // try {
|
||||
// // l = (typeof l === "function" ? l.call(realNode) : l);
|
||||
// // } catch(err) {
|
||||
// // console.log("Definition error: "+node.type+".label",err);
|
||||
// // }
|
||||
// // }
|
||||
// // l = l||node.label||node.name||node.id||"";
|
||||
// // console.log(node);
|
||||
// // var div = $('<div>').appendTo(container);
|
||||
// // div.html(l);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
function formatNodeProperty(prop) {
|
||||
var formattedProperty = prop;
|
||||
if (formattedProperty === null) {
|
||||
formattedProperty = 'null';
|
||||
} else if (formattedProperty === undefined) {
|
||||
formattedProperty = 'undefined';
|
||||
} else if (typeof formattedProperty === 'object') {
|
||||
formattedProperty = JSON.stringify(formattedProperty);
|
||||
}
|
||||
if (/\n/.test(formattedProperty)) {
|
||||
formattedProperty = "<pre>"+formattedProperty+"</pre>"
|
||||
}
|
||||
return formattedProperty;
|
||||
}
|
||||
|
||||
function getNodeInfo(node) {
|
||||
@@ -160,11 +372,157 @@ RED.deploy = (function() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
function save(force) {
|
||||
function resolveConflict(currentNodes) {
|
||||
$( "#node-dialog-confirm-deploy-config" ).hide();
|
||||
$( "#node-dialog-confirm-deploy-unknown" ).hide();
|
||||
$( "#node-dialog-confirm-deploy-unused" ).hide();
|
||||
$( "#node-dialog-confirm-deploy-conflict" ).show();
|
||||
$( "#node-dialog-confirm-deploy-type" ).val("conflict");
|
||||
$( "#node-dialog-confirm-deploy" ).dialog( "open" );
|
||||
|
||||
// $("#node-dialog-confirm-deploy-review").append($('<img src="red/images/spin.svg" style="background: rgba(255,255,255,0.8); margin-top: -16px; margin-left: -8px; height:16px; position: absolute; "/>'));
|
||||
// $("#node-dialog-confirm-deploy-review .ui-button-text").css("opacity",0.4);
|
||||
// $("#node-dialog-confirm-deploy-review").attr("disabled",true).addClass("disabled");
|
||||
// $.ajax({
|
||||
// headers: {
|
||||
// "Accept":"application/json",
|
||||
// },
|
||||
// cache: false,
|
||||
// url: 'flows',
|
||||
// success: function(nodes) {
|
||||
// var newNodes = nodes.flows;
|
||||
// var newRevision = nodes.rev;
|
||||
// generateDiff(currentNodes,newNodes);
|
||||
// $("#node-dialog-confirm-deploy-review").attr("disabled",false).removeClass("disabled");
|
||||
// $("#node-dialog-confirm-deploy-review img").remove();
|
||||
// $("#node-dialog-confirm-deploy-review .ui-button-text").css("opacity",1);
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
// function parseNodes(nodeList) {
|
||||
// var tabOrder = [];
|
||||
// var tabs = {};
|
||||
// var subflows = {};
|
||||
// var globals = [];
|
||||
// var all = {};
|
||||
//
|
||||
// nodeList.forEach(function(node) {
|
||||
// all[node.id] = node;
|
||||
// if (node.type === 'tab') {
|
||||
// tabOrder.push(node.id);
|
||||
// tabs[node.id] = {n:node,nodes:[]};
|
||||
// } else if (node.type === 'subflow') {
|
||||
// subflows[node.id] = {n:node,nodes:[]};
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// nodeList.forEach(function(node) {
|
||||
// if (node.type !== 'tab' && node.type !== 'subflow') {
|
||||
// if (tabs[node.z]) {
|
||||
// tabs[node.z].nodes.push(node);
|
||||
// } else if (subflows[node.z]) {
|
||||
// subflows[node.z].nodes.push(node);
|
||||
// } else {
|
||||
// globals.push(node);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// return {
|
||||
// all: all,
|
||||
// tabOrder: tabOrder,
|
||||
// tabs: tabs,
|
||||
// subflows: subflows,
|
||||
// globals: globals
|
||||
// }
|
||||
// }
|
||||
|
||||
// function generateDiff(currentNodes,newNodes) {
|
||||
// var currentConfig = parseNodes(currentNodes);
|
||||
// var newConfig = parseNodes(newNodes);
|
||||
// var pending = RED.nodes.pending();
|
||||
// var added = {};
|
||||
// var deleted = {};
|
||||
// var changed = {};
|
||||
// var conflicted = {};
|
||||
//
|
||||
//
|
||||
// Object.keys(currentConfig.all).forEach(function(id) {
|
||||
// var node = RED.nodes.workspace(id)||RED.nodes.subflow(id)||RED.nodes.node(id);
|
||||
// if (!newConfig.all.hasOwnProperty(id)) {
|
||||
// if (!pending.added.hasOwnProperty(id)) {
|
||||
// deleted[id] = true;
|
||||
// conflicted[id] = node.changed;
|
||||
// }
|
||||
// } else if (JSON.stringify(currentConfig.all[id]) !== JSON.stringify(newConfig.all[id])) {
|
||||
// changed[id] = true;
|
||||
// conflicted[id] = node.changed;
|
||||
// }
|
||||
// });
|
||||
// Object.keys(newConfig.all).forEach(function(id) {
|
||||
// if (!currentConfig.all.hasOwnProperty(id) && !pending.deleted.hasOwnProperty(id)) {
|
||||
// added[id] = true;
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// // console.log("Added",added);
|
||||
// // console.log("Deleted",deleted);
|
||||
// // console.log("Changed",changed);
|
||||
// // console.log("Conflicted",conflicted);
|
||||
//
|
||||
// var formatString = function(id) {
|
||||
// return conflicted[id]?"!":(added[id]?"+":(deleted[id]?"-":(changed[id]?"~":" ")));
|
||||
// }
|
||||
// newConfig.tabOrder.forEach(function(tabId) {
|
||||
// var tab = newConfig.tabs[tabId];
|
||||
// console.log(formatString(tabId),"Flow:",tab.n.label, "("+tab.n.id+")");
|
||||
// tab.nodes.forEach(function(node) {
|
||||
// console.log(" ",formatString(node.id),node.type,node.name || node.id);
|
||||
// })
|
||||
// if (currentConfig.tabs[tabId]) {
|
||||
// currentConfig.tabs[tabId].nodes.forEach(function(node) {
|
||||
// if (deleted[node.id]) {
|
||||
// console.log(" ",formatString(node.id),node.type,node.name || node.id);
|
||||
// }
|
||||
// })
|
||||
// }
|
||||
// });
|
||||
// currentConfig.tabOrder.forEach(function(tabId) {
|
||||
// if (deleted[tabId]) {
|
||||
// console.log(formatString(tabId),"Flow:",tab.n.label, "("+tab.n.id+")");
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// currentDiff = {
|
||||
// currentConfig: currentConfig,
|
||||
// newConfig: newConfig,
|
||||
// added: added,
|
||||
// deleted: deleted,
|
||||
// changed: changed,
|
||||
// conflicted: conflicted
|
||||
// }
|
||||
// }
|
||||
|
||||
// function showDiff() {
|
||||
// if (currentDiff) {
|
||||
// var list = $("#node-dialog-view-diff-diff");
|
||||
// list.editableList('empty');
|
||||
// var currentConfig = currentDiff.currentConfig;
|
||||
// currentConfig.tabOrder.forEach(function(tabId) {
|
||||
// var tab = currentConfig.tabs[tabId];
|
||||
// list.editableList('addItem',{tab:tab})
|
||||
// });
|
||||
// }
|
||||
// $("#node-dialog-view-diff").dialog("open");
|
||||
// }
|
||||
|
||||
|
||||
function save(skipValidation,force) {
|
||||
if (RED.nodes.dirty()) {
|
||||
//$("#debug-tab-clear").click(); // uncomment this to auto clear debug on deploy
|
||||
|
||||
if (!force) {
|
||||
if (!skipValidation) {
|
||||
var hasUnknown = false;
|
||||
var hasInvalid = false;
|
||||
var hasUnusedConfig = false;
|
||||
@@ -196,6 +554,7 @@ RED.deploy = (function() {
|
||||
$( "#node-dialog-confirm-deploy-config" ).hide();
|
||||
$( "#node-dialog-confirm-deploy-unknown" ).hide();
|
||||
$( "#node-dialog-confirm-deploy-unused" ).hide();
|
||||
$( "#node-dialog-confirm-deploy-conflict" ).hide();
|
||||
|
||||
var showWarning = false;
|
||||
|
||||
@@ -229,24 +588,28 @@ RED.deploy = (function() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
var nns = RED.nodes.createCompleteNodeSet();
|
||||
|
||||
$("#btn-deploy-icon").removeClass('fa-download');
|
||||
$("#btn-deploy-icon").addClass('spinner');
|
||||
RED.nodes.dirty(false);
|
||||
|
||||
var data = {flows:nns};
|
||||
|
||||
if (!force) {
|
||||
data.rev = RED.nodes.version();
|
||||
}
|
||||
|
||||
$.ajax({
|
||||
url:"flows",
|
||||
type: "POST",
|
||||
data: JSON.stringify(nns),
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json; charset=utf-8",
|
||||
headers: {
|
||||
"Node-RED-Deployment-Type":deploymentType
|
||||
}
|
||||
}).done(function(data,textStatus,xhr) {
|
||||
RED.nodes.dirty(false);
|
||||
RED.nodes.version(data.rev);
|
||||
if (hasUnusedConfig) {
|
||||
RED.notify(
|
||||
'<p>'+RED._("deploy.successfulDeploy")+'</p>'+
|
||||
@@ -264,10 +627,14 @@ RED.deploy = (function() {
|
||||
}
|
||||
});
|
||||
RED.nodes.eachConfig(function (confNode) {
|
||||
confNode.changed = false;
|
||||
if (confNode.credentials) {
|
||||
delete confNode.credentials;
|
||||
}
|
||||
});
|
||||
RED.nodes.eachWorkspace(function(ws) {
|
||||
ws.changed = false;
|
||||
})
|
||||
// Once deployed, cannot undo back to a clean state
|
||||
RED.history.markAllDirty();
|
||||
RED.view.redraw();
|
||||
@@ -276,6 +643,8 @@ RED.deploy = (function() {
|
||||
RED.nodes.dirty(true);
|
||||
if (xhr.status === 401) {
|
||||
RED.notify(RED._("deploy.deployFailed",{message:RED._("user.notAuthorized")}),"error");
|
||||
} else if (xhr.status === 409) {
|
||||
resolveConflict(nns);
|
||||
} else if (xhr.responseText) {
|
||||
RED.notify(RED._("deploy.deployFailed",{message:xhr.responseText}),"error");
|
||||
} else {
|
||||
@@ -287,7 +656,6 @@ RED.deploy = (function() {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
init: init
|
||||
}
|
||||
|
@@ -93,6 +93,7 @@ RED.workspaces = (function() {
|
||||
node: workspace,
|
||||
dirty: RED.nodes.dirty()
|
||||
}
|
||||
workspace.changed = true;
|
||||
RED.history.push(historyEvent);
|
||||
workspace_tabs.renameTab(workspace.id,label);
|
||||
RED.nodes.dirty(true);
|
||||
|
Reference in New Issue
Block a user