mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Add deploy warning for unused config nodes
This commit is contained in:
parent
bb1fe8daef
commit
eae4e3d983
@ -22,6 +22,12 @@ RED.deploy = (function() {
|
|||||||
"flows":{img:"red/images/deploy-flows-o.png"}
|
"flows":{img:"red/images/deploy-flows-o.png"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ignoreDeployWarnings = {
|
||||||
|
unknown: false,
|
||||||
|
unusedConfig: false,
|
||||||
|
invalid: false
|
||||||
|
}
|
||||||
|
|
||||||
var deploymentType = "full";
|
var deploymentType = "full";
|
||||||
|
|
||||||
function changeDeploymentType(type) {
|
function changeDeploymentType(type) {
|
||||||
@ -73,12 +79,17 @@ RED.deploy = (function() {
|
|||||||
title: "Confirm deploy",
|
title: "Confirm deploy",
|
||||||
modal: true,
|
modal: true,
|
||||||
autoOpen: false,
|
autoOpen: false,
|
||||||
width: 530,
|
width: 550,
|
||||||
height: 230,
|
height: "auto",
|
||||||
buttons: [
|
buttons: [
|
||||||
{
|
{
|
||||||
text: "Confirm deploy",
|
text: "Confirm deploy",
|
||||||
click: function() {
|
click: function() {
|
||||||
|
|
||||||
|
var ignoreChecked = $( "#node-dialog-confirm-deploy-hide" ).prop("checked");
|
||||||
|
if (ignoreChecked) {
|
||||||
|
ignoreDeployWarnings[$( "#node-dialog-confirm-deploy-type" ).val()] = true;
|
||||||
|
}
|
||||||
save(true);
|
save(true);
|
||||||
$( this ).dialog( "close" );
|
$( this ).dialog( "close" );
|
||||||
}
|
}
|
||||||
@ -89,7 +100,15 @@ RED.deploy = (function() {
|
|||||||
$( this ).dialog( "close" );
|
$( this ).dialog( "close" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
],
|
||||||
|
create: function() {
|
||||||
|
$("#node-dialog-confirm-deploy").parent().find("div.ui-dialog-buttonpane")
|
||||||
|
.append('<div style="height:0; vertical-align: middle; display:inline-block;">'+
|
||||||
|
'<input style="vertical-align:top;" type="checkbox" id="node-dialog-confirm-deploy-hide">'+
|
||||||
|
'<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>');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.nodes.on('change',function(state) {
|
RED.nodes.on('change',function(state) {
|
||||||
@ -110,31 +129,77 @@ RED.deploy = (function() {
|
|||||||
//$("#debug-tab-clear").click(); // uncomment this to auto clear debug on deploy
|
//$("#debug-tab-clear").click(); // uncomment this to auto clear debug on deploy
|
||||||
|
|
||||||
if (!force) {
|
if (!force) {
|
||||||
var invalid = false;
|
var hasUnknown = false;
|
||||||
|
var hasInvalid = false;
|
||||||
|
var hasUnusedConfig = false;
|
||||||
|
|
||||||
var unknownNodes = [];
|
var unknownNodes = [];
|
||||||
RED.nodes.eachNode(function(node) {
|
RED.nodes.eachNode(function(node) {
|
||||||
invalid = invalid || !node.valid;
|
hasInvalid = hasInvalid || !node.valid;
|
||||||
if (node.type === "unknown") {
|
if (node.type === "unknown") {
|
||||||
if (unknownNodes.indexOf(node.name) == -1) {
|
if (unknownNodes.indexOf(node.name) == -1) {
|
||||||
unknownNodes.push(node.name);
|
unknownNodes.push(node.name);
|
||||||
}
|
}
|
||||||
invalid = true;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (invalid) {
|
hasUnknown = unknownNodes.length > 0;
|
||||||
if (unknownNodes.length > 0) {
|
|
||||||
$( "#node-dialog-confirm-deploy-config" ).hide();
|
var unusedConfigNodes = {};
|
||||||
$( "#node-dialog-confirm-deploy-unknown" ).show();
|
RED.nodes.eachConfig(function(node) {
|
||||||
var list = "<li>"+unknownNodes.join("</li><li>")+"</li>";
|
if (node.users.length === 0) {
|
||||||
$( "#node-dialog-confirm-deploy-unknown-list" ).html(list);
|
var label = "";
|
||||||
} else {
|
if (typeof node._def.label == "function") {
|
||||||
$( "#node-dialog-confirm-deploy-config" ).show();
|
label = node._def.label.call(node);
|
||||||
$( "#node-dialog-confirm-deploy-unknown" ).hide();
|
} else {
|
||||||
|
label = node._def.label;
|
||||||
|
}
|
||||||
|
label = label || node.id;
|
||||||
|
unusedConfigNodes[node.type] = unusedConfigNodes[node.type] || [];
|
||||||
|
unusedConfigNodes[node.type].push(label);
|
||||||
|
hasUnusedConfig = true;
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$( "#node-dialog-confirm-deploy-config" ).hide();
|
||||||
|
$( "#node-dialog-confirm-deploy-unknown" ).hide();
|
||||||
|
$( "#node-dialog-confirm-deploy-unused" ).hide();
|
||||||
|
|
||||||
|
var showWarning = false;
|
||||||
|
|
||||||
|
if (hasUnknown && !ignoreDeployWarnings.unknown) {
|
||||||
|
showWarning = true;
|
||||||
|
$( "#node-dialog-confirm-deploy-type" ).val("unknown");
|
||||||
|
$( "#node-dialog-confirm-deploy-unknown" ).show();
|
||||||
|
$( "#node-dialog-confirm-deploy-unknown-list" )
|
||||||
|
.html("<li>"+unknownNodes.join("</li><li>")+"</li>");
|
||||||
|
} else if (hasInvalid && !ignoreDeployWarnings.invalid) {
|
||||||
|
showWarning = true;
|
||||||
|
$( "#node-dialog-confirm-deploy-type" ).val("invalid");
|
||||||
|
$( "#node-dialog-confirm-deploy-config" ).show();
|
||||||
|
} else if (hasUnusedConfig && !ignoreDeployWarnings.unusedConfig) {
|
||||||
|
showWarning = true;
|
||||||
|
$( "#node-dialog-confirm-deploy-type" ).val("unusedConfig");
|
||||||
|
$( "#node-dialog-confirm-deploy-unused" ).show();
|
||||||
|
var unusedNodeLabels = [];
|
||||||
|
var unusedTypes = Object.keys(unusedConfigNodes).sort();
|
||||||
|
unusedTypes.forEach(function(type) {
|
||||||
|
unusedConfigNodes[type].forEach(function(label) {
|
||||||
|
unusedNodeLabels.push(type+": "+label);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$( "#node-dialog-confirm-deploy-unused-list" )
|
||||||
|
.html("<li>"+unusedNodeLabels.join("</li><li>")+"</li>");
|
||||||
|
}
|
||||||
|
if (showWarning) {
|
||||||
|
$( "#node-dialog-confirm-deploy-hide" ).prop("checked",false);
|
||||||
$( "#node-dialog-confirm-deploy" ).dialog( "open" );
|
$( "#node-dialog-confirm-deploy" ).dialog( "open" );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var nns = RED.nodes.createCompleteNodeSet();
|
var nns = RED.nodes.createCompleteNodeSet();
|
||||||
|
|
||||||
$("#btn-deploy-icon").removeClass('fa-download');
|
$("#btn-deploy-icon").removeClass('fa-download');
|
||||||
|
@ -95,12 +95,17 @@
|
|||||||
|
|
||||||
<div id="node-dialog-confirm-deploy" class="hide">
|
<div id="node-dialog-confirm-deploy" class="hide">
|
||||||
<form class="form-horizontal">
|
<form class="form-horizontal">
|
||||||
<div id="node-dialog-confirm-deploy-config" style="text-align: center; padding-top: 30px;">
|
<div id="node-dialog-confirm-deploy-config" style="text-align: left; padding-top: 30px;">
|
||||||
Some of the nodes are not properly configured. Are you sure you want to deploy?
|
Some of the nodes are not properly configured. Are you sure you want to deploy?
|
||||||
</div>
|
</div>
|
||||||
<div id="node-dialog-confirm-deploy-unknown" style="text-align: center; padding-top: 10px;">
|
<div id="node-dialog-confirm-deploy-unknown" style="text-align: left; padding-top: 10px;">
|
||||||
The workspace contains some unknown node types:
|
The workspace contains some unknown node types:
|
||||||
<ul style="width: 300px; margin: auto; text-align: left;" id="node-dialog-confirm-deploy-unknown-list"></ul>
|
<ul style="font-size: 0.9em; width: 400px; margin: 10px auto; text-align: left;" id="node-dialog-confirm-deploy-unknown-list"></ul>
|
||||||
|
Are you sure you want to deploy?
|
||||||
|
</div>
|
||||||
|
<div id="node-dialog-confirm-deploy-unused" style="text-align: left; padding-top: 10px;">
|
||||||
|
The workspace contains some unused configuration nodes:
|
||||||
|
<ul style="font-size: 0.9em; width: 400px; margin: 10px auto; text-align: left;" id="node-dialog-confirm-deploy-unused-list"></ul>
|
||||||
Are you sure you want to deploy?
|
Are you sure you want to deploy?
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
Loading…
Reference in New Issue
Block a user