@iobroker/json-config 8.3.13 → 8.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/build/JsonConfigComponent/ConfigAccordion.d.ts +2 -2
- package/build/JsonConfigComponent/ConfigAccordion.js +21 -19
- package/build/JsonConfigComponent/ConfigAccordion.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAlive.d.ts +3 -1
- package/build/JsonConfigComponent/ConfigAlive.js +22 -10
- package/build/JsonConfigComponent/ConfigAlive.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAutocomplete.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigAutocomplete.js +2 -2
- package/build/JsonConfigComponent/ConfigAutocomplete.js.map +1 -1
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js +3 -3
- package/build/JsonConfigComponent/ConfigAutocompleteSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCRON.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigCRON.js +2 -2
- package/build/JsonConfigComponent/ConfigCRON.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCertCollection.js +2 -2
- package/build/JsonConfigComponent/ConfigCertCollection.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCertificateSelect.js +1 -1
- package/build/JsonConfigComponent/ConfigCertificateSelect.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCertificates.js +2 -2
- package/build/JsonConfigComponent/ConfigCertificates.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCheckDocker.js +1 -1
- package/build/JsonConfigComponent/ConfigCheckDocker.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCheckLicense.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigCheckLicense.js +7 -7
- package/build/JsonConfigComponent/ConfigCheckLicense.js.map +1 -1
- package/build/JsonConfigComponent/ConfigChip.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigChip.js +2 -2
- package/build/JsonConfigComponent/ConfigChip.js.map +1 -1
- package/build/JsonConfigComponent/ConfigCoordinates.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigCoordinates.js +3 -3
- package/build/JsonConfigComponent/ConfigCoordinates.js.map +1 -1
- package/build/JsonConfigComponent/ConfigDatePicker.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigDatePicker.js +2 -2
- package/build/JsonConfigComponent/ConfigDatePicker.js.map +1 -1
- package/build/JsonConfigComponent/ConfigFile.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigFile.js +2 -2
- package/build/JsonConfigComponent/ConfigFile.js.map +1 -1
- package/build/JsonConfigComponent/ConfigFileSelector.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigFileSelector.js +2 -2
- package/build/JsonConfigComponent/ConfigFileSelector.js.map +1 -1
- package/build/JsonConfigComponent/ConfigFunc.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigFunc.js +2 -2
- package/build/JsonConfigComponent/ConfigFunc.js.map +1 -1
- package/build/JsonConfigComponent/ConfigGeneric.d.ts +22 -7
- package/build/JsonConfigComponent/ConfigGeneric.js +165 -51
- package/build/JsonConfigComponent/ConfigGeneric.js.map +1 -1
- package/build/JsonConfigComponent/ConfigIFrame.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigIFrame.js +2 -2
- package/build/JsonConfigComponent/ConfigIFrame.js.map +1 -1
- package/build/JsonConfigComponent/ConfigIFrameSendTo.d.ts +2 -2
- package/build/JsonConfigComponent/ConfigIFrameSendTo.js +6 -6
- package/build/JsonConfigComponent/ConfigIFrameSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigIP.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigIP.js +2 -2
- package/build/JsonConfigComponent/ConfigIP.js.map +1 -1
- package/build/JsonConfigComponent/ConfigImageSendTo.d.ts +2 -2
- package/build/JsonConfigComponent/ConfigImageSendTo.js +6 -6
- package/build/JsonConfigComponent/ConfigImageSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigImageUpload.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigImageUpload.js +2 -2
- package/build/JsonConfigComponent/ConfigImageUpload.js.map +1 -1
- package/build/JsonConfigComponent/ConfigInstanceSelect.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigInstanceSelect.js +2 -2
- package/build/JsonConfigComponent/ConfigInstanceSelect.js.map +1 -1
- package/build/JsonConfigComponent/ConfigInterface.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigInterface.js +5 -5
- package/build/JsonConfigComponent/ConfigInterface.js.map +1 -1
- package/build/JsonConfigComponent/ConfigJsonEditor.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigJsonEditor.js +2 -2
- package/build/JsonConfigComponent/ConfigJsonEditor.js.map +1 -1
- package/build/JsonConfigComponent/ConfigLanguage.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigLanguage.js +2 -2
- package/build/JsonConfigComponent/ConfigLanguage.js.map +1 -1
- package/build/JsonConfigComponent/ConfigLicense.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigLicense.js +2 -2
- package/build/JsonConfigComponent/ConfigLicense.js.map +1 -1
- package/build/JsonConfigComponent/ConfigNumber.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigNumber.js +2 -2
- package/build/JsonConfigComponent/ConfigNumber.js.map +1 -1
- package/build/JsonConfigComponent/ConfigOAuth2.js +1 -1
- package/build/JsonConfigComponent/ConfigOAuth2.js.map +1 -1
- package/build/JsonConfigComponent/ConfigObjectId.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigObjectId.js +3 -3
- package/build/JsonConfigComponent/ConfigObjectId.js.map +1 -1
- package/build/JsonConfigComponent/ConfigPanel.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigPanel.js +11 -8
- package/build/JsonConfigComponent/ConfigPanel.js.map +1 -1
- package/build/JsonConfigComponent/ConfigPassword.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigPassword.js +2 -2
- package/build/JsonConfigComponent/ConfigPassword.js.map +1 -1
- package/build/JsonConfigComponent/ConfigPattern.d.ts +8 -1
- package/build/JsonConfigComponent/ConfigPattern.js +29 -3
- package/build/JsonConfigComponent/ConfigPattern.js.map +1 -1
- package/build/JsonConfigComponent/ConfigPort.js +2 -2
- package/build/JsonConfigComponent/ConfigPort.js.map +1 -1
- package/build/JsonConfigComponent/ConfigQrCode.js +1 -1
- package/build/JsonConfigComponent/ConfigQrCode.js.map +1 -1
- package/build/JsonConfigComponent/ConfigQrCodeSendTo.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigQrCodeSendTo.js +5 -5
- package/build/JsonConfigComponent/ConfigQrCodeSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigRoom.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigRoom.js +2 -2
- package/build/JsonConfigComponent/ConfigRoom.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSelect.d.ts +13 -11
- package/build/JsonConfigComponent/ConfigSelect.js +35 -29
- package/build/JsonConfigComponent/ConfigSelect.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSelectSendTo.d.ts +16 -11
- package/build/JsonConfigComponent/ConfigSelectSendTo.js +26 -23
- package/build/JsonConfigComponent/ConfigSelectSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSendto.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigSendto.js +8 -8
- package/build/JsonConfigComponent/ConfigSendto.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSetState.js +2 -2
- package/build/JsonConfigComponent/ConfigSetState.js.map +1 -1
- package/build/JsonConfigComponent/ConfigSlider.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigSlider.js +2 -2
- package/build/JsonConfigComponent/ConfigSlider.js.map +1 -1
- package/build/JsonConfigComponent/ConfigState.d.ts +2 -1
- package/build/JsonConfigComponent/ConfigState.js +32 -26
- package/build/JsonConfigComponent/ConfigState.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTable.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigTable.js +21 -19
- package/build/JsonConfigComponent/ConfigTable.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTabs.d.ts +6 -0
- package/build/JsonConfigComponent/ConfigTabs.js +57 -21
- package/build/JsonConfigComponent/ConfigTabs.js.map +1 -1
- package/build/JsonConfigComponent/ConfigText.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigText.js +2 -2
- package/build/JsonConfigComponent/ConfigText.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTextSendTo.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigTextSendTo.js +3 -3
- package/build/JsonConfigComponent/ConfigTextSendTo.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTimePicker.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigTimePicker.js +2 -2
- package/build/JsonConfigComponent/ConfigTimePicker.js.map +1 -1
- package/build/JsonConfigComponent/ConfigTopic.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigTopic.js +2 -2
- package/build/JsonConfigComponent/ConfigTopic.js.map +1 -1
- package/build/JsonConfigComponent/ConfigUUID.js +2 -2
- package/build/JsonConfigComponent/ConfigUUID.js.map +1 -1
- package/build/JsonConfigComponent/ConfigUser.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigUser.js +2 -2
- package/build/JsonConfigComponent/ConfigUser.js.map +1 -1
- package/build/JsonConfigComponent/ConfigYamlEditor.d.ts +1 -1
- package/build/JsonConfigComponent/ConfigYamlEditor.js +2 -2
- package/build/JsonConfigComponent/ConfigYamlEditor.js.map +1 -1
- package/build/JsonConfigComponent/index.d.ts +2 -0
- package/build/JsonConfigComponent/index.js +16 -1
- package/build/JsonConfigComponent/index.js.map +1 -1
- package/build/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -24,6 +24,7 @@ export default class ConfigGeneric extends Component {
|
|
|
24
24
|
sendToTimeout;
|
|
25
25
|
noPlaceRequired;
|
|
26
26
|
reportedHidden = false;
|
|
27
|
+
calculateTimeout = null;
|
|
27
28
|
constructor(props) {
|
|
28
29
|
super(props);
|
|
29
30
|
// @ts-expect-error of course, as we just
|
|
@@ -35,24 +36,30 @@ export default class ConfigGeneric extends Component {
|
|
|
35
36
|
confirmCallback: null,
|
|
36
37
|
};
|
|
37
38
|
this.isError = {};
|
|
39
|
+
this.lang = I18n.getLanguage();
|
|
40
|
+
// Initialize literal defaults synchronously so the first render has them.
|
|
41
|
+
// defaultFunc is evaluated asynchronously in componentDidMount.
|
|
38
42
|
if (props.schema) {
|
|
39
43
|
if (props.custom) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
if (!props.schema.defaultFunc) {
|
|
45
|
+
this.defaultValue = props.schema.default;
|
|
46
|
+
}
|
|
43
47
|
}
|
|
44
|
-
else if (props.schema.type !== 'state') {
|
|
45
|
-
this.defaultValue = props.schema.
|
|
46
|
-
? this.execute(props.schema.defaultFunc, props.schema.default, props.data, props.arrayIndex, props.globalData)
|
|
47
|
-
: props.schema.default;
|
|
48
|
+
else if (props.schema.type !== 'state' && !props.schema.defaultFunc) {
|
|
49
|
+
this.defaultValue = props.schema.default;
|
|
48
50
|
}
|
|
49
51
|
}
|
|
50
|
-
this.lang = I18n.getLanguage();
|
|
51
52
|
}
|
|
52
|
-
componentDidMount() {
|
|
53
|
-
if (this.props.
|
|
54
|
-
|
|
53
|
+
async componentDidMount() {
|
|
54
|
+
if (this.props.schema?.defaultFunc) {
|
|
55
|
+
if (this.props.custom) {
|
|
56
|
+
this.defaultValue = await this.executeCustom(this.props.schema.defaultFunc, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData);
|
|
57
|
+
}
|
|
58
|
+
else if (this.props.schema.type !== 'state') {
|
|
59
|
+
this.defaultValue = await this.execute(this.props.schema.defaultFunc, this.props.schema.default, this.props.data, this.props.arrayIndex, this.props.globalData);
|
|
60
|
+
}
|
|
55
61
|
}
|
|
62
|
+
this.props.oContext.registerOnForceUpdate?.(this.props.attr, this.onUpdate);
|
|
56
63
|
const LIKE_SELECT = ['select', 'autocomplete', 'autocompleteSendTo'];
|
|
57
64
|
// init default value
|
|
58
65
|
if (this.defaultValue !== undefined) {
|
|
@@ -71,15 +78,15 @@ export default class ConfigGeneric extends Component {
|
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
else if (this.props.schema.defaultSendTo) {
|
|
74
|
-
this.sendTo();
|
|
81
|
+
this.sendTo().catch(e => console.error(e));
|
|
75
82
|
}
|
|
76
83
|
}
|
|
77
|
-
sendTo() {
|
|
84
|
+
async sendTo() {
|
|
78
85
|
if (this.props.alive) {
|
|
79
86
|
this.defaultSendToDone = true;
|
|
80
87
|
let data = this.props.schema.data;
|
|
81
88
|
if (data === undefined && this.props.schema.jsonData) {
|
|
82
|
-
const dataStr = this.
|
|
89
|
+
const dataStr = await this.getPatternAsync(this.props.schema.jsonData, null, true);
|
|
83
90
|
try {
|
|
84
91
|
data = JSON.parse(dataStr);
|
|
85
92
|
}
|
|
@@ -126,6 +133,10 @@ export default class ConfigGeneric extends Component {
|
|
|
126
133
|
clearTimeout(this.sendToTimeout);
|
|
127
134
|
this.sendToTimeout = null;
|
|
128
135
|
}
|
|
136
|
+
if (this.calculateTimeout) {
|
|
137
|
+
clearTimeout(this.calculateTimeout);
|
|
138
|
+
this.calculateTimeout = null;
|
|
139
|
+
}
|
|
129
140
|
}
|
|
130
141
|
onUpdate = (data) => {
|
|
131
142
|
const value = ConfigGeneric.getValue(data || this.props.data, this.props.attr) || '';
|
|
@@ -351,12 +362,12 @@ export default class ConfigGeneric extends Component {
|
|
|
351
362
|
* @param newValue new value of the attribute
|
|
352
363
|
* @param cb optional callback function, else returns a Promise
|
|
353
364
|
*/
|
|
354
|
-
onChange(attr, newValue, cb) {
|
|
365
|
+
async onChange(attr, newValue, cb) {
|
|
355
366
|
// Do not use here deep copy, as it is not JsonConfig
|
|
356
367
|
const data = JSON.parse(JSON.stringify(this.props.data));
|
|
357
368
|
ConfigGeneric.setValue(data, attr, newValue);
|
|
358
369
|
if (this.props.schema.confirm &&
|
|
359
|
-
this.execute(this.props.schema.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
|
|
370
|
+
(await this.execute(this.props.schema.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData))) {
|
|
360
371
|
return new Promise(resolve => {
|
|
361
372
|
this.setState({
|
|
362
373
|
confirmDialog: true,
|
|
@@ -379,7 +390,7 @@ export default class ConfigGeneric extends Component {
|
|
|
379
390
|
const dep = this.props.schema.confirmDependsOn[z];
|
|
380
391
|
if (dep.confirm) {
|
|
381
392
|
const val = ConfigGeneric.getValue(data, dep.attr);
|
|
382
|
-
if (this.execute(dep.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
|
|
393
|
+
if (await this.execute(dep.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
|
|
383
394
|
return new Promise(resolve => {
|
|
384
395
|
this.setState({
|
|
385
396
|
confirmDialog: true,
|
|
@@ -409,10 +420,10 @@ export default class ConfigGeneric extends Component {
|
|
|
409
420
|
const val = ConfigGeneric.getValue(data, dep.attr);
|
|
410
421
|
let _newValue;
|
|
411
422
|
if (this.props.custom) {
|
|
412
|
-
_newValue = this.executeCustom(dep.onChange.calculateFunc, data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData);
|
|
423
|
+
_newValue = await this.executeCustom(dep.onChange.calculateFunc, data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData);
|
|
413
424
|
}
|
|
414
425
|
else {
|
|
415
|
-
_newValue = this.execute(dep.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
|
|
426
|
+
_newValue = await this.execute(dep.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
|
|
416
427
|
}
|
|
417
428
|
if (_newValue !== val) {
|
|
418
429
|
ConfigGeneric.setValue(data, dep.attr, _newValue);
|
|
@@ -448,8 +459,8 @@ export default class ConfigGeneric extends Component {
|
|
|
448
459
|
if (this.props.schema.onChange && !this.props.schema.onChange.ignoreOwnChanges) {
|
|
449
460
|
const val = ConfigGeneric.getValue(data, this.props.attr);
|
|
450
461
|
const newValue_ = this.props.custom
|
|
451
|
-
? this.executeCustom(this.props.schema.onChange.calculateFunc, data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
452
|
-
: this.execute(this.props.schema.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
|
|
462
|
+
? await this.executeCustom(this.props.schema.onChange.calculateFunc, data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
463
|
+
: await this.execute(this.props.schema.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
|
|
453
464
|
if (newValue_ !== val) {
|
|
454
465
|
ConfigGeneric.setValue(data, this.props.attr, newValue_);
|
|
455
466
|
}
|
|
@@ -465,14 +476,22 @@ export default class ConfigGeneric extends Component {
|
|
|
465
476
|
if (changed.length) {
|
|
466
477
|
this.props.oContext.forceUpdate(changed, data);
|
|
467
478
|
}
|
|
468
|
-
|
|
469
|
-
cb();
|
|
470
|
-
}
|
|
479
|
+
cb?.();
|
|
471
480
|
});
|
|
472
481
|
}
|
|
473
482
|
return Promise.resolve();
|
|
474
483
|
}
|
|
475
|
-
|
|
484
|
+
/** Ensure that every bare getObject( call is preceded by "await". */
|
|
485
|
+
static ensureAwaitGetObject(code) {
|
|
486
|
+
return code.replace(/(?<![\w$.])getObject\(/g, (match, offset) => {
|
|
487
|
+
const before = code.slice(Math.max(0, offset - 10), offset);
|
|
488
|
+
if (/await\s+$/.test(before)) {
|
|
489
|
+
return match;
|
|
490
|
+
}
|
|
491
|
+
return `await ${match}`;
|
|
492
|
+
});
|
|
493
|
+
}
|
|
494
|
+
async execute(func, defaultValue, data, arrayIndex, globalData) {
|
|
476
495
|
let fun;
|
|
477
496
|
if (isObject(func)) {
|
|
478
497
|
fun = func.func;
|
|
@@ -486,16 +505,20 @@ export default class ConfigGeneric extends Component {
|
|
|
486
505
|
if (!fun) {
|
|
487
506
|
return defaultValue;
|
|
488
507
|
}
|
|
508
|
+
if (fun.includes('getObject(')) {
|
|
509
|
+
// ensure, that await is placed in front of getObject
|
|
510
|
+
fun = ConfigGeneric.ensureAwaitGetObject(fun);
|
|
511
|
+
}
|
|
489
512
|
try {
|
|
490
|
-
const f = new Function('data', 'originalData', '_system', '_alive', '_common', '_socket', '_instance', 'arrayIndex', 'globalData', '_changed', fun.includes('return') ? fun : `return ${fun}`);
|
|
491
|
-
return f(data || this.props.data, this.props.originalData, this.props.oContext.systemConfig, this.props.alive, this.props.common, this.props.oContext.socket, this.props.oContext.instance, arrayIndex, globalData, this.props.changed);
|
|
513
|
+
const f = new Function('data', 'originalData', '_system', '_alive', '_common', '_socket', '_instance', 'arrayIndex', 'globalData', '_changed', '_href', 'getObject', fun.includes('return') ? fun : `return ${fun}`);
|
|
514
|
+
return await f(data || this.props.data, this.props.originalData, this.props.oContext.systemConfig, this.props.alive, this.props.common, this.props.oContext.socket, this.props.oContext.instance, arrayIndex, globalData, this.props.changed, window.location.href, this.getObject);
|
|
492
515
|
}
|
|
493
516
|
catch (e) {
|
|
494
517
|
console.error(`Cannot execute ${JSON.stringify(func)}: ${e}`);
|
|
495
518
|
return defaultValue;
|
|
496
519
|
}
|
|
497
520
|
}
|
|
498
|
-
executeCustom(func, data, customObj, instanceObj, arrayIndex, globalData) {
|
|
521
|
+
async executeCustom(func, data, customObj, instanceObj, arrayIndex, globalData) {
|
|
499
522
|
let fun;
|
|
500
523
|
if (isObject(func)) {
|
|
501
524
|
fun = func.func;
|
|
@@ -509,30 +532,34 @@ export default class ConfigGeneric extends Component {
|
|
|
509
532
|
if (!fun) {
|
|
510
533
|
return null;
|
|
511
534
|
}
|
|
535
|
+
if (fun.includes('getObject(')) {
|
|
536
|
+
// ensure, that await is placed in front of getObject
|
|
537
|
+
fun = ConfigGeneric.ensureAwaitGetObject(fun);
|
|
538
|
+
}
|
|
512
539
|
try {
|
|
513
|
-
const f = new Function('data', 'originalData', '_system', 'instanceObj', 'customObj', '_socket', 'arrayIndex', 'globalData', '_changed', fun.includes('return') ? fun : `return ${fun}`);
|
|
514
|
-
return f(data || this.props.data, this.props.originalData, this.props.oContext.systemConfig, instanceObj, customObj, this.props.oContext.socket, arrayIndex, globalData, this.props.changed);
|
|
540
|
+
const f = new Function('data', 'originalData', '_system', 'instanceObj', 'customObj', '_socket', 'arrayIndex', 'globalData', '_changed', '_href', 'getObject', fun.includes('return') ? fun : `return ${fun}`);
|
|
541
|
+
return await f(data || this.props.data, this.props.originalData, this.props.oContext.systemConfig, instanceObj, customObj, this.props.oContext.socket, arrayIndex, globalData, this.props.changed, window.location.href, this.getObject);
|
|
515
542
|
}
|
|
516
543
|
catch (e) {
|
|
517
544
|
console.error(`Cannot execute ${fun}: ${e}`);
|
|
518
545
|
return null;
|
|
519
546
|
}
|
|
520
547
|
}
|
|
521
|
-
calculate(schema) {
|
|
548
|
+
async calculate(schema) {
|
|
522
549
|
let error;
|
|
523
550
|
let disabled;
|
|
524
551
|
let hidden;
|
|
525
552
|
let defaultValue;
|
|
526
553
|
if (this.props.custom) {
|
|
527
554
|
error = schema.validator
|
|
528
|
-
? !this.executeCustom(schema.validator, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
555
|
+
? !(await this.executeCustom(schema.validator, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData))
|
|
529
556
|
: false;
|
|
530
557
|
if (schema.disabled === true) {
|
|
531
558
|
disabled = true;
|
|
532
559
|
}
|
|
533
560
|
else {
|
|
534
561
|
disabled = schema.disabled
|
|
535
|
-
? this.executeCustom(schema.disabled, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
562
|
+
? (await this.executeCustom(schema.disabled, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData))
|
|
536
563
|
: false;
|
|
537
564
|
}
|
|
538
565
|
if (schema.hidden === true) {
|
|
@@ -540,23 +567,23 @@ export default class ConfigGeneric extends Component {
|
|
|
540
567
|
}
|
|
541
568
|
else {
|
|
542
569
|
hidden = schema.hidden
|
|
543
|
-
? this.executeCustom(schema.hidden, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
570
|
+
? (await this.executeCustom(schema.hidden, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData))
|
|
544
571
|
: false;
|
|
545
572
|
}
|
|
546
573
|
defaultValue = schema.defaultFunc
|
|
547
|
-
? this.executeCustom(schema.defaultFunc, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
574
|
+
? await this.executeCustom(schema.defaultFunc, this.props.data, this.props.customObj, this.props.oContext.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
548
575
|
: schema.default;
|
|
549
576
|
}
|
|
550
577
|
else {
|
|
551
578
|
error = schema.validator
|
|
552
|
-
? !this.execute(schema.validator, false, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
579
|
+
? !(await this.execute(schema.validator, false, this.props.data, this.props.arrayIndex, this.props.globalData))
|
|
553
580
|
: false;
|
|
554
581
|
if (schema.disabled === true) {
|
|
555
582
|
disabled = true;
|
|
556
583
|
}
|
|
557
584
|
else {
|
|
558
585
|
disabled = schema.disabled
|
|
559
|
-
? this.execute(schema.disabled, false, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
586
|
+
? (await this.execute(schema.disabled, false, this.props.data, this.props.arrayIndex, this.props.globalData))
|
|
560
587
|
: false;
|
|
561
588
|
}
|
|
562
589
|
if (schema.hidden === true) {
|
|
@@ -564,11 +591,11 @@ export default class ConfigGeneric extends Component {
|
|
|
564
591
|
}
|
|
565
592
|
else {
|
|
566
593
|
hidden = schema.hidden
|
|
567
|
-
? this.execute(schema.hidden, false, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
594
|
+
? (await this.execute(schema.hidden, false, this.props.data, this.props.arrayIndex, this.props.globalData))
|
|
568
595
|
: false;
|
|
569
596
|
}
|
|
570
597
|
defaultValue = schema.defaultFunc
|
|
571
|
-
? this.execute(schema.defaultFunc, schema.default, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
598
|
+
? await this.execute(schema.defaultFunc, schema.default, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
572
599
|
: schema.default;
|
|
573
600
|
}
|
|
574
601
|
return {
|
|
@@ -629,6 +656,60 @@ export default class ConfigGeneric extends Component {
|
|
|
629
656
|
});
|
|
630
657
|
return str;
|
|
631
658
|
}
|
|
659
|
+
/** This function is used in pattern */
|
|
660
|
+
getObject = async (id) => {
|
|
661
|
+
try {
|
|
662
|
+
const obj = await this.props.oContext.getCachedObject(id);
|
|
663
|
+
return obj || null;
|
|
664
|
+
}
|
|
665
|
+
catch (e) {
|
|
666
|
+
console.error(e);
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
async getPatternAsync(pattern, data, noTranslation) {
|
|
671
|
+
data ||= this.props.data;
|
|
672
|
+
if (!pattern) {
|
|
673
|
+
return '';
|
|
674
|
+
}
|
|
675
|
+
let patternStr;
|
|
676
|
+
if (typeof pattern === 'object') {
|
|
677
|
+
if (pattern.func) {
|
|
678
|
+
patternStr = pattern.func;
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
console.log(`Object must be stringified: ${JSON.stringify(pattern)}`);
|
|
682
|
+
patternStr = JSON.stringify(pattern);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
patternStr = pattern;
|
|
687
|
+
}
|
|
688
|
+
if (patternStr.includes('getObject(')) {
|
|
689
|
+
// ensure, that await is placed in front of getObject
|
|
690
|
+
patternStr = ConfigGeneric.ensureAwaitGetObject(patternStr);
|
|
691
|
+
}
|
|
692
|
+
try {
|
|
693
|
+
if (this.props.custom) {
|
|
694
|
+
const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', 'instanceObj', 'customObj', '_socket', '_changed', '_href', 'getObject', `return \`${ConfigGeneric.escapeString(patternStr, data)}\``);
|
|
695
|
+
const text = await f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.oContext.systemConfig, this.props.oContext.instanceObj, this.props.customObj, this.props.oContext.socket, this.props.changed, window.location.href, this.getObject);
|
|
696
|
+
if (noTranslation) {
|
|
697
|
+
return text;
|
|
698
|
+
}
|
|
699
|
+
return I18n.t(text);
|
|
700
|
+
}
|
|
701
|
+
const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', '_alive', '_common', '_socket', '_changed', '_href', 'getObject', `return \`${ConfigGeneric.escapeString(patternStr, data)}\``);
|
|
702
|
+
const text = await f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.oContext.systemConfig, this.props.alive, this.props.common, this.props.oContext.socket, this.props.changed, window.location.href, this.getObject);
|
|
703
|
+
if (noTranslation) {
|
|
704
|
+
return text;
|
|
705
|
+
}
|
|
706
|
+
return I18n.t(text);
|
|
707
|
+
}
|
|
708
|
+
catch (e) {
|
|
709
|
+
console.error(`Cannot execute ${patternStr}: ${e}`);
|
|
710
|
+
return patternStr;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
632
713
|
getPattern(pattern, data, noTranslation) {
|
|
633
714
|
data ||= this.props.data;
|
|
634
715
|
if (!pattern) {
|
|
@@ -647,13 +728,21 @@ export default class ConfigGeneric extends Component {
|
|
|
647
728
|
else {
|
|
648
729
|
patternStr = pattern;
|
|
649
730
|
}
|
|
731
|
+
if (patternStr.includes('getObject(')) {
|
|
732
|
+
// ensure, that await is placed in front of getObject
|
|
733
|
+
console.log(`It is not possible to use getObject function in text patterns: ${patternStr}`);
|
|
734
|
+
}
|
|
650
735
|
try {
|
|
651
736
|
if (this.props.custom) {
|
|
652
|
-
const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', 'instanceObj', 'customObj', '_socket', '_changed', '_href', `return \`${ConfigGeneric.escapeString(patternStr, data)}\``);
|
|
653
|
-
|
|
737
|
+
const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', 'instanceObj', 'customObj', '_socket', '_changed', '_href', 'getObject', `return \`${ConfigGeneric.escapeString(patternStr, data)}\``);
|
|
738
|
+
const text = f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.oContext.systemConfig, this.props.oContext.instanceObj, this.props.customObj, this.props.oContext.socket, this.props.changed, window.location.href, this.getObject);
|
|
739
|
+
if (noTranslation) {
|
|
740
|
+
return text;
|
|
741
|
+
}
|
|
742
|
+
return I18n.t(text);
|
|
654
743
|
}
|
|
655
|
-
const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', '_alive', '_common', '_socket', '_changed', '_href', `return \`${ConfigGeneric.escapeString(patternStr, data)}\``);
|
|
656
|
-
const text = f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.oContext.systemConfig, this.props.alive, this.props.common, this.props.oContext.socket, this.props.changed, window.location.href);
|
|
744
|
+
const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', '_alive', '_common', '_socket', '_changed', '_href', 'getObject', `return \`${ConfigGeneric.escapeString(patternStr, data)}\``);
|
|
745
|
+
const text = f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.oContext.systemConfig, this.props.alive, this.props.common, this.props.oContext.socket, this.props.changed, window.location.href, this.getObject);
|
|
657
746
|
if (noTranslation) {
|
|
658
747
|
return text;
|
|
659
748
|
}
|
|
@@ -664,6 +753,28 @@ export default class ConfigGeneric extends Component {
|
|
|
664
753
|
return patternStr;
|
|
665
754
|
}
|
|
666
755
|
}
|
|
756
|
+
updateCalculatedValues() {
|
|
757
|
+
if (this.calculateTimeout) {
|
|
758
|
+
clearTimeout(this.calculateTimeout);
|
|
759
|
+
}
|
|
760
|
+
this.calculateTimeout = setTimeout(async () => {
|
|
761
|
+
this.calculateTimeout = null;
|
|
762
|
+
const schema = this.props.schema;
|
|
763
|
+
if (!schema) {
|
|
764
|
+
return null;
|
|
765
|
+
}
|
|
766
|
+
const { error, disabled, hidden, defaultValue } = await this.calculate(schema);
|
|
767
|
+
if (!this.state.calculatedValues ||
|
|
768
|
+
this.state.calculatedValues.error !== error ||
|
|
769
|
+
this.state.calculatedValues.disabled !== disabled ||
|
|
770
|
+
this.state.calculatedValues.hidden !== hidden ||
|
|
771
|
+
this.state.calculatedValues.defaultValue !== defaultValue) {
|
|
772
|
+
this.setState({
|
|
773
|
+
calculatedValues: { error, disabled, hidden, defaultValue },
|
|
774
|
+
});
|
|
775
|
+
}
|
|
776
|
+
}, 50);
|
|
777
|
+
}
|
|
667
778
|
render() {
|
|
668
779
|
const schema = this.props.schema;
|
|
669
780
|
if (!schema) {
|
|
@@ -674,13 +785,16 @@ export default class ConfigGeneric extends Component {
|
|
|
674
785
|
return null;
|
|
675
786
|
}
|
|
676
787
|
if (this.props.alive && this.defaultSendToDone === false) {
|
|
677
|
-
this.sendToTimeout = setTimeout(() => {
|
|
788
|
+
this.sendToTimeout = setTimeout(async () => {
|
|
678
789
|
this.sendToTimeout = null;
|
|
679
|
-
this.sendTo();
|
|
790
|
+
await this.sendTo();
|
|
680
791
|
}, 200);
|
|
681
792
|
}
|
|
682
|
-
|
|
683
|
-
if (
|
|
793
|
+
this.updateCalculatedValues();
|
|
794
|
+
if (!this.state.calculatedValues) {
|
|
795
|
+
return null;
|
|
796
|
+
}
|
|
797
|
+
if (this.state.calculatedValues.hidden) {
|
|
684
798
|
// Remove all errors if an element is hidden
|
|
685
799
|
if (Object.keys(this.isError).length) {
|
|
686
800
|
setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr)), 100, JSON.parse(JSON.stringify(this.isError)));
|
|
@@ -719,18 +833,18 @@ export default class ConfigGeneric extends Component {
|
|
|
719
833
|
}
|
|
720
834
|
// Add error
|
|
721
835
|
if (schema.validatorNoSaveOnError) {
|
|
722
|
-
if (error && !Object.keys(this.isError).length) {
|
|
836
|
+
if (this.state.calculatedValues.error && !Object.keys(this.isError).length) {
|
|
723
837
|
this.isError = {
|
|
724
838
|
[this.props.attr]: schema.validatorErrorText ? I18n.t(schema.validatorErrorText) : true,
|
|
725
839
|
};
|
|
726
840
|
setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr, isError[attr])), 100, JSON.parse(JSON.stringify(this.isError)));
|
|
727
841
|
}
|
|
728
|
-
else if (!error && Object.keys(this.isError).length) {
|
|
842
|
+
else if (!this.state.calculatedValues.error && Object.keys(this.isError).length) {
|
|
729
843
|
setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr)), 100, JSON.parse(JSON.stringify(this.isError)));
|
|
730
844
|
this.isError = {};
|
|
731
845
|
}
|
|
732
846
|
}
|
|
733
|
-
const renderedItem = this.renderItem(error, disabled || this.props.commandRunning || this.props.disabled, defaultValue);
|
|
847
|
+
const renderedItem = this.renderItem(this.state.calculatedValues.error, this.state.calculatedValues.disabled || this.props.commandRunning || this.props.disabled, this.state.calculatedValues.defaultValue);
|
|
734
848
|
if (this.noPlaceRequired) {
|
|
735
849
|
return renderedItem;
|
|
736
850
|
}
|
|
@@ -749,7 +863,7 @@ export default class ConfigGeneric extends Component {
|
|
|
749
863
|
} }, this.props.schema.defaultSendTo && this.props.schema.button ? (React.createElement(Grid2, { container: true, style: { width: '100%' } },
|
|
750
864
|
React.createElement(Grid2, { flex: 1 }, renderedItem),
|
|
751
865
|
React.createElement(Grid2, null,
|
|
752
|
-
React.createElement(Button, { disabled: disabled, variant: "outlined", onClick: () => this.sendTo(), title: this.props.schema.buttonTooltip
|
|
866
|
+
React.createElement(Button, { disabled: this.state.calculatedValues.disabled, variant: "outlined", onClick: () => this.sendTo(), title: this.props.schema.buttonTooltip
|
|
753
867
|
? this.getText(this.props.schema.buttonTooltip, this.props.schema.buttonTooltipNoTranslation)
|
|
754
868
|
: I18n.t('ra_Request data by instance') }, this.getText(this.props.schema.button))))) : (renderedItem)));
|
|
755
869
|
if (schema.newLine) {
|