1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Merge pull request #3202 from node-red/tour-guide-fix

Fixes from 2.1.0-beta.2
This commit is contained in:
Nick O'Leary 2021-10-19 10:20:24 +01:00 committed by GitHub
commit 8d79deffb5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 146 additions and 133 deletions

View File

@ -345,6 +345,47 @@
} }
} }
}; };
// For a type with options, check value is a valid selection
// If !opt.multiple, returns the valid option object
// if opt.multiple, returns an array of valid option objects
// If not valid, returns null;
function isOptionValueValid(opt, currentVal) {
if (!opt.multiple) {
for (var i=0;i<opt.options.length;i++) {
op = opt.options[i];
if (typeof op === "string" && op === currentVal) {
return {value:currentVal}
} else if (op.value === currentVal) {
return op;
}
}
} else {
// Check to see if value is a valid csv of
// options.
var currentValues = {};
var selected = [];
currentVal.split(",").forEach(function(v) {
if (v) {
currentValues[v] = true;
}
});
for (var i=0;i<opt.options.length;i++) {
op = opt.options[i];
var val = typeof op === "string" ? op : op.value;
if (currentValues.hasOwnProperty(val)) {
delete currentValues[val];
selected.push(typeof op === "string" ? {value:op} : op.value)
}
}
if (!$.isEmptyObject(currentValues)) {
return null;
}
return selected
}
}
var nlsd = false; var nlsd = false;
$.widget( "nodered.typedInput", { $.widget( "nodered.typedInput", {
@ -408,6 +449,8 @@
}); });
this.defaultInputType = this.input.attr('type'); this.defaultInputType = this.input.attr('type');
// Used to remember selections per-type to restore them when switching between types
this.oldValues = {};
this.uiSelect.addClass("red-ui-typedInput-container"); this.uiSelect.addClass("red-ui-typedInput-container");
@ -512,9 +555,6 @@
this.optionExpandButton = $('<button tabindex="0" class="red-ui-typedInput-option-expand" style="display:inline-block"></button>').appendTo(this.uiSelect); this.optionExpandButton = $('<button tabindex="0" class="red-ui-typedInput-option-expand" style="display:inline-block"></button>').appendTo(this.uiSelect);
this.optionExpandButtonIcon = $('<i class="red-ui-typedInput-icon fa fa-ellipsis-h"></i>').appendTo(this.optionExpandButton); this.optionExpandButtonIcon = $('<i class="red-ui-typedInput-icon fa fa-ellipsis-h"></i>').appendTo(this.optionExpandButton);
// Used to remember selections per-type to restore them when switching between types
this.oldValues = {};
this.type(this.options.default||this.typeList[0].value); this.type(this.options.default||this.typeList[0].value);
}catch(err) { }catch(err) {
console.log(err.stack); console.log(err.stack);
@ -859,22 +899,44 @@
return this.propertyType; return this.propertyType;
} else { } else {
var that = this; var that = this;
var previousValue = null;
var opt = this.typeMap[type]; var opt = this.typeMap[type];
if (opt && this.propertyType !== type) { if (opt && this.propertyType !== type) {
// If previousType is !null, then this is a change of the type, rather than the initialisation // If previousType is !null, then this is a change of the type, rather than the initialisation
var previousType = this.typeMap[this.propertyType]; var previousType = this.typeMap[this.propertyType];
var typeChanged = !!previousType; var typeChanged = !!previousType;
previousValue = this.input.val();
if (typeChanged) { if (typeChanged) {
if (previousType.options && opt.hasValue !== true) { if (previousType.options && opt.hasValue !== true) {
this.oldValues[previousType.value] = this.input.val(); this.oldValues[previousType.value] = previousValue;
} else if (previousType.hasValue === false) { } else if (previousType.hasValue === false) {
this.oldValues[previousType.value] = this.input.val(); this.oldValues[previousType.value] = previousValue;
} else { } else {
this.oldValues["_"] = this.input.val(); this.oldValues["_"] = previousValue;
} }
if ((opt.options && opt.hasValue !== true) || opt.hasValue === false) { if ((opt.options && opt.hasValue !== true) || opt.hasValue === false) {
this.input.val(this.oldValues.hasOwnProperty(opt.value)?this.oldValues[opt.value]:(opt.default||[]).join(",")) if (this.oldValues.hasOwnProperty(opt.value)) {
this.input.val(this.oldValues[opt.value]);
} else {
// No old value for the option type.
// It is possible code has called 'value' then 'type'
// to set the selected option. This is what the Inject/Switch/Change
// nodes did before 2.1.
// So we need to be careful to not reset the value if it is a valid option.
var validOptions = isOptionValueValid(opt,previousValue);
if (previousValue && validOptions) {
this.input.val(previousValue);
} else {
if (typeof opt.default === "string") {
this.input.val(opt.default);
} else if (Array.isArray(opt.default)) {
this.input.val(opt.default.join(","))
} else {
this.input.val("");
}
}
}
} else { } else {
this.input.val(this.oldValues.hasOwnProperty("_")?this.oldValues["_"]:(opt.default||"")) this.input.val(this.oldValues.hasOwnProperty("_")?this.oldValues["_"]:(opt.default||""))
} }
@ -951,22 +1013,12 @@
var op; var op;
if (!opt.hasValue) { if (!opt.hasValue) {
var validValue = false; // Check the value is valid for the available options
var currentVal = this.input.val(); var validValues = isOptionValueValid(opt,this.input.val());
if (!opt.multiple) { if (!opt.multiple) {
for (var i=0;i<opt.options.length;i++) { if (validValues) {
op = opt.options[i]; that._updateOptionSelectLabel(validValues)
if (typeof op === "string" && op === currentVal) { } else {
that._updateOptionSelectLabel({value:currentVal});
validValue = true;
break;
} else if (op.value === currentVal) {
that._updateOptionSelectLabel(op);
validValue = true;
break;
}
}
if (!validValue) {
op = opt.options[0]; op = opt.options[0];
if (typeof op === "string") { if (typeof op === "string") {
this.value(op); this.value(op);
@ -977,26 +1029,13 @@
} }
} }
} else { } else {
// Check to see if value is a valid csv of if (!validValues) {
// options. validValues = (opt.default || []).map(function(v) {
var currentValues = {}; return typeof v === "string"?v:v.value
var selected = []; });
currentVal.split(",").forEach(function(v) { this.value(validValues.join(","));
if (v) {
selected.push(v);
currentValues[v] = true;
}
});
for (var i=0;i<opt.options.length;i++) {
op = opt.options[i];
delete currentValues[op.value||op];
} }
if (!$.isEmptyObject(currentValues)) { that._updateOptionSelectLabel(validValues);
selected = opt.default || [];
// Invalid, set to default/empty
this.value(selected.join(","));
}
that._updateOptionSelectLabel(selected);
} }
} else { } else {
var selectedOption = this.optionValue||opt.options[0]; var selectedOption = this.optionValue||opt.options[0];

View File

@ -93,6 +93,8 @@ export default {
{ {
title: {"en-US":"Link Call node added"}, title: {"en-US":"Link Call node added"},
prepare(done) { prepare(done) {
this.paletteWasClosed = $("#red-ui-main-container").hasClass("red-ui-palette-closed");
RED.actions.invoke("core:toggle-palette",true)
$('[data-palette-type="link call"]')[0].scrollIntoView({block:"center"}) $('[data-palette-type="link call"]')[0].scrollIntoView({block:"center"})
setTimeout(done,100); setTimeout(done,100);
}, },
@ -100,13 +102,27 @@ export default {
direction: "right", direction: "right",
description: { "en-US": '<p>The <code>Link Call</code> node lets you call another flow that begins with a <code>Link In</code> node and get the result back when the message reaches a <code>Link Out</code> node.</p>' }, description: { "en-US": '<p>The <code>Link Call</code> node lets you call another flow that begins with a <code>Link In</code> node and get the result back when the message reaches a <code>Link Out</code> node.</p>' },
}, },
{
title: {"en-US":"MQTT nodes support dynamic connections"},
prepare(done) {
$('[data-palette-type="mqtt out"]')[0].scrollIntoView({block:"center"})
setTimeout(done,100);
},
element: '[data-palette-type="mqtt out"]',
direction: "right",
description: { "en-US": '<p>The <code>MQTT</code> nodes now support creating their connections and subscriptions dynamically.</p>' },
},
{ {
title: {"en-US":"File nodes renamed"}, title: {"en-US":"File nodes renamed"},
prepare(done) { prepare(done) {
$('[data-palette-type="file"]')[0].scrollIntoView({block:"center"}) $('[data-palette-type="file"]')[0].scrollIntoView({block:"center"})
setTimeout(done,100); setTimeout(done,100);
}, },
complete() {
if (this.paletteWasClosed) {
RED.actions.invoke("core:toggle-palette",false)
}
},
element: '[data-palette-type="file"]', element: '[data-palette-type="file"]',
direction: "right", direction: "right",
description: { "en-US": '<p>The file nodes have been renamed to make it clearer which node does what.</p>' }, description: { "en-US": '<p>The file nodes have been renamed to make it clearer which node does what.</p>' },

View File

@ -539,12 +539,10 @@
var propertyValue = $('<input/>',{class:"node-input-prop-property-value",type:"text"}) var propertyValue = $('<input/>',{class:"node-input-prop-property-value",type:"text"})
.css("width","calc(70% - 30px)") .css("width","calc(70% - 30px)")
.appendTo(row) .appendTo(row)
.typedInput({default:'str',types:['flow','global','str','num','bool','json','bin','date','jsonata','env','msg']}); .typedInput({default:prop.vt,types:['flow','global','str','num','bool','json','bin','date','jsonata','env','msg']});
propertyName.typedInput('value',prop.p); propertyName.typedInput('value',prop.p);
propertyValue.typedInput('value',prop.v); propertyValue.typedInput('value',prop.v);
propertyValue.typedInput('type',prop.vt);
}, },
removable: true, removable: true,
sortable: true sortable: true

View File

@ -117,30 +117,35 @@
return r; return r;
} }
function createValueField(row){ function createValueField(row, defaultType){
return $('<input/>',{class:"node-input-rule-value",type:"text",style:"width: 100%;"}).appendTo(row).typedInput({default:'str',types:['msg','flow','global','str','num','jsonata','env',previousValueType]}); return $('<input/>',{class:"node-input-rule-value",type:"text",style:"width: 100%;"}).appendTo(row)
.typedInput({default:defaultType||'str',types:['msg','flow','global','str','num','jsonata','env',previousValueType]});
} }
function createNumValueField(row){ function createNumValueField(row, defaultType){
return $('<input/>',{class:"node-input-rule-num-value",type:"text",style:"width: 100%;"}).appendTo(row).typedInput({default:'num',types:['flow','global','num','jsonata','env']}); return $('<input/>',{class:"node-input-rule-num-value",type:"text",style:"width: 100%;"}).appendTo(row)
.typedInput({default:defaultType||'num',types:['flow','global','num','jsonata','env']});
} }
function createExpValueField(row){ function createExpValueField(row){
return $('<input/>',{class:"node-input-rule-exp-value",type:"text",style:"width: 100%;"}).appendTo(row).typedInput({default:'jsonata',types:['jsonata']}); return $('<input/>',{class:"node-input-rule-exp-value",type:"text",style:"width: 100%;"}).appendTo(row)
.typedInput({default:'jsonata',types:['jsonata']});
} }
function createBtwnValueField(row){ function createBtwnValueField(row, defaultType){
return $('<input/>',{class:"node-input-rule-btwn-value",type:"text",style:"width: 100%;"}).appendTo(row).typedInput({default:'num',types:['msg','flow','global','str','num','jsonata','env',previousValueType]}); return $('<input/>',{class:"node-input-rule-btwn-value",type:"text",style:"width: 100%;"}).appendTo(row)
.typedInput({default:defaultType||'num',types:['msg','flow','global','str','num','jsonata','env',previousValueType]});
} }
function createBtwnValue2Field(row3, andLabel){ function createBtwnValue2Field(row3, andLabel, defaultType){
$('<div/>',{class:"node-input-rule-btwn-label", style:"width: 120px; text-align: right;"}).text(" "+andLabel+" ").appendTo(row3); $('<div/>',{class:"node-input-rule-btwn-label", style:"width: 120px; text-align: right;"}).text(" "+andLabel+" ").appendTo(row3);
var row3InputCell = $('<div/>',{style:"flex-grow:1; margin-left: 5px;"}).appendTo(row3); var row3InputCell = $('<div/>',{style:"flex-grow:1; margin-left: 5px;"}).appendTo(row3);
return $('<input/>',{class:"node-input-rule-btwn-value2",type:"text",style:"width: 100%"}).appendTo(row3InputCell).typedInput({default:'num',types:['msg','flow','global','str','num','jsonata','env',previousValueType]}); return $('<input/>',{class:"node-input-rule-btwn-value2",type:"text",style:"width: 100%"}).appendTo(row3InputCell)
.typedInput({default:defaultType||'num',types:['msg','flow','global','str','num','jsonata','env',previousValueType]});
} }
function createTypeValueField(){ function createTypeValueField(row, defaultType){
return $('<input/>',{class:"node-input-rule-type-value",type:"text",style:"width: 100%;"}).appendTo(row).typedInput({default:'string',types:[ return $('<input/>',{class:"node-input-rule-type-value",type:"text",style:"width: 100%;"}).appendTo(row).typedInput({default:defaultType || 'string',types:[
{value:"string",label:RED._("common.type.string"),hasValue:false,icon:"red/images/typedInput/az.png"}, {value:"string",label:RED._("common.type.string"),hasValue:false,icon:"red/images/typedInput/az.png"},
{value:"number",label:RED._("common.type.number"),hasValue:false,icon:"red/images/typedInput/09.png"}, {value:"number",label:RED._("common.type.number"),hasValue:false,icon:"red/images/typedInput/09.png"},
{value:"boolean",label:RED._("common.type.boolean"),hasValue:false,icon:"red/images/typedInput/bool.png"}, {value:"boolean",label:RED._("common.type.boolean"),hasValue:false,icon:"red/images/typedInput/bool.png"},
@ -279,24 +284,12 @@
selectField.on("change", function() { selectField.on("change", function() {
var fieldToFocus; var fieldToFocus;
var type = selectField.val(); var type = selectField.val();
if (valueField){ if (valueField) { valueField.typedInput('hide'); }
valueField.typedInput('hide'); if (expValueField) { expValueField.typedInput('hide'); }
} if (numValueField) { numValueField.typedInput('hide'); }
if (expValueField){ if (typeValueField) { typeValueField.typedInput('hide'); }
expValueField.typedInput('hide'); if (btwnValueField) { btwnValueField.typedInput('hide'); }
} if (btwnValue2Field) { btwnValue2Field.typedInput('hide'); }
if (numValueField){
numValueField.typedInput('hide');
}
if (typeValueField){
typeValueField.typedInput('hide');
}
if (btwnValueField){
btwnValueField.typedInput('hide');
}
if (btwnValue2Field){
btwnValue2Field.typedInput('hide');
}
if ((type === "btwn") || (type === "index")) { if ((type === "btwn") || (type === "index")) {
if (!btwnValueField){ if (!btwnValueField){
@ -319,7 +312,7 @@
} else if (type === "istype") { } else if (type === "istype") {
if (!typeValueField){ if (!typeValueField){
typeValueField = createTypeValueField(); typeValueField = createTypeValueField(rowInputCell);
} }
typeValueField.typedInput('show'); typeValueField.typedInput('show');
fieldToFocus = typeValueField; fieldToFocus = typeValueField;
@ -362,48 +355,26 @@
// } // }
}); });
selectField.val(rule.t); selectField.val(rule.t);
if ((rule.t == "btwn") || (rule.t == "index")) {
if (!btwnValueField){
btwnValueField = createBtwnValueField(rowInputCell);
}
btwnValueField.typedInput('value',rule.v);
btwnValueField.typedInput('type',rule.vt||'num');
if (!btwnValue2Field){ if ((rule.t == "btwn") || (rule.t == "index")) {
btwnValue2Field = createBtwnValue2Field(row3, andLabel); btwnValueField = createBtwnValueField(rowInputCell,rule.vt||'num');
} btwnValueField.typedInput('value',rule.v);
btwnValue2Field = createBtwnValue2Field(row3, andLabel,rule.v2t||'num');
btwnValue2Field.typedInput('value',rule.v2); btwnValue2Field.typedInput('value',rule.v2);
btwnValue2Field.typedInput('type',rule.v2t||'num');
} else if ((rule.t === "head") || (rule.t === "tail")) { } else if ((rule.t === "head") || (rule.t === "tail")) {
if (!numValueField){ numValueField = createNumValueField(rowInputCell,rule.vt||'num');
numValueField = createNumValueField(row);
}
numValueField.typedInput('value',rule.v); numValueField.typedInput('value',rule.v);
numValueField.typedInput('type',rule.vt||'num');
} else if (rule.t === "istype") { } else if (rule.t === "istype") {
if (!typeValueField){ typeValueField = createTypeValueField(rowInputCell,rule.vt);
typeValueField =createTypeValueField();
}
typeValueField.typedInput('value',rule.vt); typeValueField.typedInput('value',rule.vt);
typeValueField.typedInput('type',rule.vt);
} else if (rule.t === "jsonata_exp") { } else if (rule.t === "jsonata_exp") {
if (!expValueField){ expValueField = createExpValueField(rowInputCell,rule.vt||'jsonata');
expValueField = createExpValueField(row);
}
expValueField.typedInput('value',rule.v); expValueField.typedInput('value',rule.v);
expValueField.typedInput('type',rule.vt||'jsonata');
} else if (typeof rule.v != "undefined") { } else if (typeof rule.v != "undefined") {
if (!valueField){ valueField = createValueField(rowInputCell,rule.vt||'str');
valueField = createValueField(rowInputCell);
}
valueField.typedInput('value',rule.v); valueField.typedInput('value',rule.v);
valueField.typedInput('type',rule.vt||'str');
}
if (rule.case) {
caseSensitive.prop('checked',true);
} else {
caseSensitive.prop('checked',false);
} }
caseSensitive.prop('checked',!!rule.case);
selectField.change(); selectField.change();
var currentOutputs = JSON.parse(outputCount.val()||"{}"); var currentOutputs = JSON.parse(outputCount.val()||"{}");

View File

@ -115,12 +115,12 @@
var regex = this._("change.label.regex"); var regex = this._("change.label.regex");
var deepCopyLabel = this._("change.label.deepCopy"); var deepCopyLabel = this._("change.label.deepCopy");
function createPropertyValue(row2_1,row2_2) { function createPropertyValue(row2_1, row2_2, defaultType) {
var propValInput = $('<input/>',{class:"node-input-rule-property-value",type:"text"}) var propValInput = $('<input/>',{class:"node-input-rule-property-value",type:"text"})
.appendTo(row2_1) .appendTo(row2_1)
.typedInput({default:'str',types:['msg','flow','global','str','num','bool','json','bin','date','jsonata','env']}); .typedInput({default:defaultType||'str',types:['msg','flow','global','str','num','bool','json','bin','date','jsonata','env']});
var dcLabel = $('<label style="padding-left: 130px; display: flex; align-items: center "></label>').appendTo(row2_2); var dcLabel = $('<label style="padding-left: 130px;"></label>').appendTo(row2_2);
var deepCopy = $('<input type="checkbox" class="node-input-rule-property-deepCopy" style="width: auto; margin: 0 6px 0 0">').appendTo(dcLabel) var deepCopy = $('<input type="checkbox" class="node-input-rule-property-deepCopy" style="width: auto; margin: 0 6px 0 0">').appendTo(dcLabel)
$('<span>').text(deepCopyLabel).appendTo(dcLabel) $('<span>').text(deepCopyLabel).appendTo(dcLabel)
@ -129,20 +129,20 @@
}) })
return [propValInput, deepCopy]; return [propValInput, deepCopy];
} }
function createFromValue(row3_1) { function createFromValue(row3_1, defaultType) {
return $('<input/>',{class:"node-input-rule-property-search-value",type:"text"}) return $('<input/>',{class:"node-input-rule-property-search-value",type:"text"})
.appendTo(row3_1) .appendTo(row3_1)
.typedInput({default:'str',types:['msg','flow','global','str','re','num','bool','env']}); .typedInput({default:defaultType||'str',types:['msg','flow','global','str','re','num','bool','env']});
} }
function createToValue(row3_2) { function createToValue(row3_2, defaultType) {
return $('<input/>',{class:"node-input-rule-property-replace-value",type:"text"}) return $('<input/>',{class:"node-input-rule-property-replace-value",type:"text"})
.appendTo(row3_2) .appendTo(row3_2)
.typedInput({default:'str',types:['msg','flow','global','str','num','bool','json','bin','env']}); .typedInput({default:defaultType||'str',types:['msg','flow','global','str','num','bool','json','bin','env']});
} }
function createMoveValue(row4) { function createMoveValue(row4, defaultType) {
return $('<input/>',{class:"node-input-rule-property-move-value",type:"text"}) return $('<input/>',{class:"node-input-rule-property-move-value",type:"text"})
.appendTo(row4) .appendTo(row4)
.typedInput({default:'msg',types:['msg','flow','global']}); .typedInput({default:defaultType||'msg',types:['msg','flow','global']});
} }
$('#node-input-rule-container').css('min-height','150px').css('min-width','450px').editableList({ $('#node-input-rule-container').css('min-height','150px').css('min-width','450px').editableList({
@ -268,33 +268,22 @@
propertyName.typedInput('value',rule.p); propertyName.typedInput('value',rule.p);
propertyName.typedInput('type',rule.pt); propertyName.typedInput('type',rule.pt);
if (rule.t == "set") { if (rule.t == "set") {
if(!propertyValue) { var parts = createPropertyValue(row2_1, row2_2, rule.tot);
var parts = createPropertyValue(row2_1, row2_2); propertyValue = parts[0];
propertyValue = parts[0]; deepCopy = parts[1];
deepCopy = parts[1];
}
propertyValue.typedInput('value',rule.to); propertyValue.typedInput('value',rule.to);
propertyValue.typedInput('type',rule.tot);
deepCopy.prop("checked", !!rule.dc); deepCopy.prop("checked", !!rule.dc);
} }
if (rule.t == "move") { if (rule.t == "move") {
if(!moveValue) { moveValue = createMoveValue(row4,rule.tot);
moveValue = createMoveValue(row4);
}
moveValue.typedInput('value',rule.to); moveValue.typedInput('value',rule.to);
moveValue.typedInput('type',rule.tot);
} }
if (rule.t == "change") { if (rule.t == "change") {
if(!fromValue) { fromValue = createFromValue(row3_1, rule.fromt);
fromValue = createFromValue(row3_1);
}
fromValue.typedInput('value',rule.from); fromValue.typedInput('value',rule.from);
fromValue.typedInput('type',rule.fromt);
if (!toValue) { toValue = createToValue(row3_2,rule.tot);
toValue = createToValue(row3_2);
}
toValue.typedInput('value',rule.to); toValue.typedInput('value',rule.to);
toValue.typedInput('type',rule.tot);
} }
selectField.change(); selectField.change();
container[0].appendChild(fragment); container[0].appendChild(fragment);