Merge branch '0.18' into projects

This commit is contained in:
Nick O'Leary
2018-01-16 11:21:54 +00:00
146 changed files with 6584 additions and 1498 deletions

View File

@@ -99,7 +99,7 @@
this.uiSelect = this.elementDiv.wrap( "<div>" ).parent();
var attrStyle = this.element.attr('style');
var m;
if ((m = /width\s*:\s*(\d+(%|px))/i.exec(attrStyle)) !== null) {
if ((m = /width\s*:\s*(calc\s*\(.*\)|\d+(%|px))/i.exec(attrStyle)) !== null) {
this.element.css('width','100%');
this.uiSelect.width(m[1]);
this.uiWidth = null;
@@ -354,10 +354,27 @@
return this.element.val();
} else {
if (this.typeMap[this.propertyType].options) {
if (this.typeMap[this.propertyType].options.indexOf(value) === -1) {
value = "";
var validValue = false;
var label;
for (var i=0;i<this.typeMap[this.propertyType].options.length;i++) {
var op = this.typeMap[this.propertyType].options[i];
if (typeof op === "string") {
if (op === value) {
label = value;
validValue = true;
break;
}
} else if (op.value === value) {
label = op.label||op.value;
validValue = true;
break;
}
}
this.optionSelectLabel.text(value);
if (!validValue) {
value = "";
label = "";
}
this.optionSelectLabel.text(label);
}
this.element.val(value);
this.element.trigger('change',this.type(),value);
@@ -394,11 +411,31 @@
that.value(v);
});
var currentVal = this.element.val();
if (opt.options.indexOf(currentVal) !== -1) {
this.optionSelectLabel.text(currentVal);
} else {
this.value(opt.options[0]);
var validValue = false;
var op;
for (var i=0;i<opt.options.length;i++) {
op = opt.options[i];
if (typeof op === "string") {
if (op === currentVal) {
this.optionSelectLabel.text(currentVal);
validValue = true;
break;
}
} else if (op.value === currentVal) {
this.optionSelectLabel.text(op.label||op.value);
validValue = true;
break;
}
}
if (!validValue) {
op = opt.options[0];
if (typeof op === "string") {
this.value(op);
} else {
this.value(op.value);
}
}
console.log(validValue);
}
} else {
if (this.optionMenu) {

View File

@@ -108,6 +108,17 @@ RED.editor = (function() {
}
}
}
if (node.icon) {
var iconPath = RED.utils.separateIconPath(node.icon);
if (!iconPath.module) {
return isValid;
}
var iconSets = RED.nodes.getIconSets();
var iconFileList = iconSets[iconPath.module];
if (!iconFileList || iconFileList.indexOf(iconPath.file) === -1) {
isValid = false;
}
}
return isValid;
}
@@ -159,6 +170,23 @@ RED.editor = (function() {
}
}
}
if (!node._def.defaults.hasOwnProperty("icon") && node.icon) {
var iconPath = RED.utils.separateIconPath(node.icon);
var iconSets = RED.nodes.getIconSets();
var iconFileList = iconSets[iconPath.module];
var iconModule = $("#node-settings-icon-module");
var iconFile = $("#node-settings-icon-file");
if (!iconFileList) {
iconModule.addClass("input-error");
iconFile.removeClass("input-error");
} else if (iconFileList.indexOf(iconPath.file) === -1) {
iconModule.removeClass("input-error");
iconFile.addClass("input-error");
} else {
iconModule.removeClass("input-error");
iconFile.removeClass("input-error");
}
}
}
function validateNodeEditorProperty(node,defaults,property,prefix) {
var input = $("#"+prefix+"-"+property);
@@ -713,10 +741,78 @@ RED.editor = (function() {
} else {
buildLabelRow().appendTo(outputsDiv);
}
if (!node._def.defaults.hasOwnProperty("icon")) {
$('<div class="form-row"><div id="node-settings-icon"></div></div>').appendTo(dialogForm);
var iconDiv = $("#node-settings-icon");
$('<label data-i18n="editor.settingIcon">').appendTo(iconDiv);
var iconForm = $('<div>',{class:"node-label-form-row"});
iconForm.appendTo(iconDiv);
$('<label>').appendTo(iconForm);
var selectIconModule = $('<select id="node-settings-icon-module"><option value=""></option></select>').appendTo(iconForm);
var iconPath;
if (node.icon) {
iconPath = RED.utils.separateIconPath(node.icon);
} else {
iconPath = RED.utils.getDefaultNodeIcon(node._def, node);
}
var iconSets = RED.nodes.getIconSets();
Object.keys(iconSets).forEach(function(moduleName) {
selectIconModule.append($("<option></option>").val(moduleName).text(moduleName));
});
if (iconPath.module && !iconSets[iconPath.module]) {
selectIconModule.append($("<option disabled></option>").val(iconPath.module).text(iconPath.module));
}
selectIconModule.val(iconPath.module);
var iconModuleHidden = $('<input type="hidden" id="node-settings-icon-module-hidden"></input>').appendTo(iconForm);
iconModuleHidden.val(iconPath.module);
var selectIconFile = $('<select id="node-settings-icon-file"><option value=""></option></select>').appendTo(iconForm);
selectIconModule.change(function() {
moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, true);
});
var iconFileHidden = $('<input type="hidden" id="node-settings-icon-file-hidden"></input>').appendTo(iconForm);
iconFileHidden.val(iconPath.file);
selectIconFile.change(function() {
selectIconFile.removeClass("input-error");
var fileName = selectIconFile.val();
iconFileHidden.val(fileName);
});
moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, false);
var iconFileList = iconSets[selectIconModule.val()];
if (!iconFileList || iconFileList.indexOf(iconPath.file) === -1) {
selectIconFile.append($("<option disabled></option>").val(iconPath.file).text(iconPath.file));
}
selectIconFile.val(iconPath.file);
}
}
function moduleChange(selectIconModule, selectIconFile, iconModuleHidden, iconFileHidden, iconSets, updateIconFile) {
selectIconFile.children().remove();
var moduleName = selectIconModule.val();
if (moduleName !== null) {
iconModuleHidden.val(moduleName);
}
var iconFileList = iconSets[moduleName];
if (iconFileList) {
iconFileList.forEach(function(fileName) {
if (updateIconFile) {
updateIconFile = false;
iconFileHidden.val(fileName);
}
selectIconFile.append($("<option></option>").val(fileName).text(fileName));
});
}
selectIconFile.prop("disabled", !iconFileList);
selectIconModule.removeClass("input-error");
}
function showEditDialog(node) {
var editing_node = node;
var isDefaultIcon;
var defaultIcon;
editStack.push(node);
RED.view.state(RED.state.EDITING);
var type = node.type;
@@ -885,6 +981,8 @@ RED.editor = (function() {
if (outputsChanged) {
changed = true;
}
} else {
newValue = parseInt(newValue);
}
}
if (editing_node[d] != newValue) {
@@ -963,6 +1061,33 @@ RED.editor = (function() {
changed = true;
}
if (!editing_node._def.defaults.hasOwnProperty("icon")) {
var iconModule = $("#node-settings-icon-module-hidden").val();
var iconFile = $("#node-settings-icon-file-hidden").val();
var icon = (iconModule && iconFile) ? iconModule+"/"+iconFile : "";
if (!isDefaultIcon) {
if (icon !== editing_node.icon) {
changes.icon = editing_node.icon;
editing_node.icon = icon;
changed = true;
}
} else {
if (icon !== defaultIcon) {
changes.icon = editing_node.icon;
editing_node.icon = icon;
changed = true;
} else {
var iconPath = RED.utils.getDefaultNodeIcon(editing_node._def, editing_node);
var currentDefaultIcon = iconPath.module+"/"+iconPath.file;
if (defaultIcon !== currentDefaultIcon) {
changes.icon = editing_node.icon;
editing_node.icon = currentDefaultIcon;
changed = true;
}
}
}
}
if (changed) {
var wasChanged = editing_node.changed;
editing_node.changed = true;
@@ -1054,6 +1179,13 @@ RED.editor = (function() {
} else {
ns = node._def.set.id;
}
var iconPath = RED.utils.getDefaultNodeIcon(node._def,node);
defaultIcon = iconPath.module+"/"+iconPath.file;
if (node.icon && node.icon !== defaultIcon) {
isDefaultIcon = false;
} else {
isDefaultIcon = true;
}
buildEditForm(nodeProperties.content,"dialog-form",type,ns);
buildLabelForm(portLabels.content,node);
@@ -1841,12 +1973,12 @@ RED.editor = (function() {
tabs.addTab({
id: 'expression-help',
label: 'Function reference',
label: RED._('expressionEditor.functionReference'),
content: $("#node-input-expression-tab-help")
});
tabs.addTab({
id: 'expression-tests',
label: 'Test',
label: RED._('expressionEditor.test'),
content: $("#node-input-expression-tab-test")
});
testDataEditor = RED.editor.createEditor({

View File

@@ -14,6 +14,31 @@
* limitations under the License.
**/
RED.notify = (function() {
/*
// Example usage for a modal dialog with buttons
var myNotification = RED.notify("This is the message to display",{
modal: true,
fixed: true,
type: 'warning',
buttons: [
{
text: "cancel",
click: function(e) {
myNotification.close();
}
},
{
text: "okay",
class:"primary",
click: function(e) {
myNotification.close();
}
}
]
});
*/
var currentNotifications = [];
var c = 0;
return function(msg,type,fixed,timeout) {

View File

@@ -21,7 +21,7 @@ RED.palette = (function() {
var categoryContainers = {};
function createCategoryContainer(category, label){
function createCategoryContainer(category, label) {
label = (label || category).replace(/_/g, " ");
var catDiv = $('<div id="palette-container-'+category+'" class="palette-category palette-close hide">'+
'<div id="palette-header-'+category+'" class="palette-header"><i class="expanded fa fa-angle-down"></i><span>'+label+'</span></div>'+
@@ -325,14 +325,26 @@ RED.palette = (function() {
}
}
}
function hideNodeType(nt) {
var nodeTypeId = escapeNodeType(nt);
$("#palette_node_"+nodeTypeId).hide();
var paletteNode = $("#palette_node_"+nodeTypeId);
paletteNode.hide();
var categoryNode = paletteNode.closest(".palette-category");
var cl = categoryNode.find(".palette_node");
var c = 0;
for (var i = 0; i < cl.length; i++) {
if ($(cl[i]).css('display') === 'none') { c += 1; }
}
if (c === cl.length) { categoryNode.hide(); }
}
function showNodeType(nt) {
var nodeTypeId = escapeNodeType(nt);
$("#palette_node_"+nodeTypeId).show();
var paletteNode = $("#palette_node_"+nodeTypeId);
var categoryNode = paletteNode.closest(".palette-category");
categoryNode.show();
paletteNode.show();
}
function refreshNodeTypes() {
@@ -396,7 +408,6 @@ RED.palette = (function() {
RED.events.on('registry:node-type-removed', function(nodeType) {
removeNodeType(nodeType);
});
RED.events.on('registry:node-set-enabled', function(nodeSet) {
for (var j=0;j<nodeSet.types.length;j++) {
showNodeType(nodeSet.types[j]);
@@ -427,7 +438,6 @@ RED.palette = (function() {
}
});
$("#palette > .palette-spinner").show();
$("#palette-search input").searchBox({

View File

@@ -12,6 +12,7 @@ RED.typeSearch = (function() {
var activeFilter = "";
var addCallback;
var cancelCallback;
var typesUsed = {};
@@ -155,11 +156,19 @@ RED.typeSearch = (function() {
t = t.parent();
}
hide(true);
if (cancelCallback) {
cancelCallback();
}
}
}
function show(opts) {
if (!visible) {
RED.keyboard.add("*","escape",function(){hide()});
RED.keyboard.add("*","escape",function(){
hide();
if (cancelCallback) {
cancelCallback();
}
});
if (dialog === null) {
createDialog();
}
@@ -175,6 +184,7 @@ RED.typeSearch = (function() {
}
refreshTypeList();
addCallback = opts.add;
closeCallback = opts.close;
RED.events.emit("type-search:open");
//shade.show();
dialog.css({left:opts.x+"px",top:opts.y+"px"}).show();
@@ -255,16 +265,19 @@ RED.typeSearch = (function() {
var commonCount = 0;
var item;
for(i=0;i<common.length;i++) {
item = {
type: common[i],
common: true,
def: RED.nodes.getType(common[i])
};
item.label = getTypeLabel(item.type,item.def);
if (i === common.length-1) {
item.separator = true;
var itemDef = RED.nodes.getType(common[i]);
if (itemDef) {
item = {
type: common[i],
common: true,
def: itemDef
};
item.label = getTypeLabel(item.type,item.def);
if (i === common.length-1) {
item.separator = true;
}
searchResults.editableList('addItem', item);
}
searchResults.editableList('addItem', item);
}
for(i=0;i<Math.min(5,recentlyUsed.length);i++) {
item = {

View File

@@ -171,7 +171,7 @@ RED.utils = (function() {
}
function formatNumber(element,obj,sourceId,path,cycle,initialFormat) {
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path]) || initialFormat || "dec";
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path] && formattedPaths[sourceId][path]['number']) || initialFormat || "dec";
if (cycle) {
if (format === 'dec') {
if ((obj.toString().length===13) && (obj<=2147483647000)) {
@@ -187,10 +187,12 @@ RED.utils = (function() {
format = 'dec';
}
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
formattedPaths[sourceId][path] = format;
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
formattedPaths[sourceId][path]['number'] = format;
} else if (initialFormat !== undefined){
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
formattedPaths[sourceId][path] = format;
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
formattedPaths[sourceId][path]['number'] = format;
}
if (format === 'dec') {
element.text(""+obj);
@@ -204,7 +206,7 @@ RED.utils = (function() {
}
function formatBuffer(element,button,sourceId,path,cycle) {
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path]) || "raw";
var format = (formattedPaths[sourceId] && formattedPaths[sourceId][path] && formattedPaths[sourceId][path]['buffer']) || "raw";
if (cycle) {
if (format === 'raw') {
format = 'string';
@@ -212,7 +214,8 @@ RED.utils = (function() {
format = 'raw';
}
formattedPaths[sourceId] = formattedPaths[sourceId]||{};
formattedPaths[sourceId][path] = format;
formattedPaths[sourceId][path] = formattedPaths[sourceId][path]||{};
formattedPaths[sourceId][path]['buffer'] = format;
}
if (format === 'raw') {
button.text('raw');
@@ -689,16 +692,21 @@ RED.utils = (function() {
return result;
}
function getNodeIcon(def,node) {
if (def.category === 'config') {
return "icons/node-red/cog.png"
} else if (node && node.type === 'tab') {
return "icons/node-red/subflow.png"
} else if (node && node.type === 'unknown') {
return "icons/node-red/alert.png"
} else if (node && node.type === 'subflow') {
return "icons/node-red/subflow.png"
function separateIconPath(icon) {
var result = {module: "", file: ""};
if (icon) {
var index = icon.indexOf('/');
if (index !== -1) {
result.module = icon.slice(0, index);
result.file = icon.slice(index + 1);
} else {
result.file = icon;
}
}
return result;
}
function getDefaultNodeIcon(def,node) {
var icon_url;
if (typeof def.icon === "function") {
try {
@@ -710,7 +718,34 @@ RED.utils = (function() {
} else {
icon_url = def.icon;
}
return "icons/"+def.set.module+"/"+icon_url;
var iconPath = separateIconPath(icon_url);
if (!iconPath.module) {
iconPath.module = def.set.module;
}
return iconPath;
}
function getNodeIcon(def,node) {
if (def.category === 'config') {
return "icons/node-red/cog.png"
} else if (node && node.type === 'tab') {
return "icons/node-red/subflow.png"
} else if (node && node.type === 'unknown') {
return "icons/node-red/alert.png"
} else if (node && node.type === 'subflow') {
return "icons/node-red/subflow.png"
} else if (node && node.icon) {
var iconPath = separateIconPath(node.icon);
var iconSets = RED.nodes.getIconSets();
var iconFileList = iconSets[iconPath.module];
if (iconFileList && iconFileList.indexOf(iconPath.file) !== -1) {
return "icons/" + node.icon;
}
}
var iconPath = getDefaultNodeIcon(def, node);
return "icons/"+iconPath.module+"/"+iconPath.file;
}
function getNodeLabel(node,defaultLabel) {
@@ -735,6 +770,8 @@ RED.utils = (function() {
getMessageProperty: getMessageProperty,
normalisePropertyExpression: normalisePropertyExpression,
validatePropertyExpression: validatePropertyExpression,
separateIconPath: separateIconPath,
getDefaultNodeIcon: getDefaultNodeIcon,
getNodeIcon: getNodeIcon,
getNodeLabel: getNodeLabel,
}

View File

@@ -546,6 +546,9 @@ RED.view = (function() {
RED.typeSearch.show({
x:d3.event.clientX-mainPos.left-node_width/2,
y:d3.event.clientY-mainPos.top-node_height/2,
cancel: function() {
resetMouseVars();
},
add: function(type) {
var result = addNode(type);
if (!result) {
@@ -683,7 +686,7 @@ RED.view = (function() {
var mousePos;
if (mouse_mode == RED.state.JOINING || mouse_mode === RED.state.QUICK_JOINING) {
// update drag line
if (drag_lines.length === 0) {
if (drag_lines.length === 0 && mousedown_port_type !== null) {
if (d3.event.shiftKey) {
// Get all the wires we need to detach.
var links = [];
@@ -1347,7 +1350,7 @@ RED.view = (function() {
mouseup_node = null;
mousedown_link = null;
mouse_mode = 0;
mousedown_port_type = PORT_TYPE_OUTPUT;
mousedown_port_type = null;
activeSpliceLink = null;
spliceActive = false;
d3.select(".link_splice").classed("link_splice",false);