Show context store name on TypedInput flow/global types

Fixes #2793
This commit is contained in:
Nick O'Leary 2021-03-10 17:51:20 +00:00
parent c37ea90206
commit f7a6a333e1
No known key found for this signature in database
GPG Key ID: 4F2157149161A6C9
1 changed files with 49 additions and 22 deletions

View File

@ -32,6 +32,21 @@
return v; return v;
} }
} }
var contextLabel = function(container,value) {
var that = this;
container.css("pointer-events","none");
container.css("flex-grow",0);
container.css("position",'relative');
container.css("overflow",'visible');
$('<div></div>').text(value).css({
position: "absolute",
bottom:"-2px",
right: "5px",
"font-size": "0.7em",
opacity: 0.3
}).appendTo(container);
this.elementDiv.show();
}
var mapDeprecatedIcon = function(icon) { var mapDeprecatedIcon = function(icon) {
if (/^red\/images\/typedInput\/.+\.png$/.test(icon)) { if (/^red\/images\/typedInput\/.+\.png$/.test(icon)) {
icon = icon.replace(/.png$/,".svg"); icon = icon.replace(/.png$/,".svg");
@ -44,13 +59,15 @@
options:[], options:[],
validate:RED.utils.validatePropertyExpression, validate:RED.utils.validatePropertyExpression,
parse: contextParse, parse: contextParse,
export: contextExport export: contextExport,
valueLabel: contextLabel
}, },
global: {value:"global",label:"global.",hasValue:true, global: {value:"global",label:"global.",hasValue:true,
options:[], options:[],
validate:RED.utils.validatePropertyExpression, validate:RED.utils.validatePropertyExpression,
parse: contextParse, parse: contextParse,
export: contextExport export: contextExport,
valueLabel: contextLabel
}, },
str: {value:"str",label:"string",icon:"red/images/typedInput/az.svg"}, str: {value:"str",label:"string",icon:"red/images/typedInput/az.svg"},
num: {value:"num",label:"number",icon:"red/images/typedInput/09.svg",validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/}, num: {value:"num",label:"number",icon:"red/images/typedInput/09.svg",validate:/^[+-]?[0-9]*\.?[0-9]*([eE][-+]?[0-9]+)?$/},
@ -592,34 +609,43 @@
_updateOptionSelectLabel: function(o) { _updateOptionSelectLabel: function(o) {
var opt = this.typeMap[this.propertyType]; var opt = this.typeMap[this.propertyType];
this.optionSelectLabel.empty(); this.optionSelectLabel.empty();
if (opt.hasValue) {
this.valueLabelContainer.empty();
this.valueLabelContainer.show();
} else {
this.valueLabelContainer.hide();
}
if (this.typeMap[this.propertyType].valueLabel) { if (this.typeMap[this.propertyType].valueLabel) {
if (opt.multiple) { if (opt.multiple) {
this.typeMap[this.propertyType].valueLabel.call(this,this.optionSelectLabel,o); this.typeMap[this.propertyType].valueLabel.call(this,opt.hasValue?this.valueLabelContainer:this.optionSelectLabel,o);
} else { } else {
this.typeMap[this.propertyType].valueLabel.call(this,this.optionSelectLabel,o.value); this.typeMap[this.propertyType].valueLabel.call(this,opt.hasValue?this.valueLabelContainer:this.optionSelectLabel,o.value);
} }
} else if (!opt.multiple) { }
if (o.icon) { if (!this.typeMap[this.propertyType].valueLabel || opt.hasValue) {
if (o.icon.indexOf("<") === 0) { if (!opt.multiple) {
$(o.icon).prependTo(this.optionSelectLabel); if (o.icon) {
} else if (o.icon.indexOf("/") !== -1) { if (o.icon.indexOf("<") === 0) {
// url $(o.icon).prependTo(this.optionSelectLabel);
$('<img>',{src:mapDeprecatedIcon(o.icon),style:"height: 18px;"}).prependTo(this.optionSelectLabel); } else if (o.icon.indexOf("/") !== -1) {
// url
$('<img>',{src:mapDeprecatedIcon(o.icon),style:"height: 18px;"}).prependTo(this.optionSelectLabel);
} else {
// icon class
$('<i>',{class:"red-ui-typedInput-icon "+o.icon}).prependTo(this.optionSelectLabel);
}
} else if (o.label) {
this.optionSelectLabel.text(o.label);
} else { } else {
// icon class this.optionSelectLabel.text(o.value);
$('<i>',{class:"red-ui-typedInput-icon "+o.icon}).prependTo(this.optionSelectLabel); }
if (opt.hasValue) {
this.optionValue = o.value;
this.input.trigger('change',[this.propertyType,this.value()]);
} }
} else if (o.label) {
this.optionSelectLabel.text(o.label);
} else { } else {
this.optionSelectLabel.text(o.value); this.optionSelectLabel.text(o.length+" selected");
} }
if (opt.hasValue) {
this.optionValue = o.value;
this.input.trigger('change',[this.propertyType,this.value()]);
}
} else {
this.optionSelectLabel.text(o.length+" selected");
} }
}, },
_destroy: function() { _destroy: function() {
@ -893,6 +919,7 @@
// Reset any CSS the custom label may have set // Reset any CSS the custom label may have set
this.valueLabelContainer.css("pointer-events",""); this.valueLabelContainer.css("pointer-events","");
this.valueLabelContainer.css("flex-grow",1); this.valueLabelContainer.css("flex-grow",1);
this.valueLabelContainer.css("overflow","hidden");
this.valueLabelContainer.show(); this.valueLabelContainer.show();
this.valueLabelContainer.empty(); this.valueLabelContainer.empty();
this.elementDiv.hide(); this.elementDiv.hide();