@iobroker/adapter-react-v5 4.6.12 → 4.7.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/Components/FileViewer.js +1 -1
- package/Components/FileViewer.js.map +1 -1
- package/Components/JsonConfigComponent/ConfigColor.d.ts +2 -1
- package/Components/JsonConfigComponent/ConfigFile.js +1 -1
- package/Components/JsonConfigComponent/ConfigFile.js.map +1 -1
- package/Components/JsonConfigComponent/ConfigFileSelector.js +4 -4
- package/Components/JsonConfigComponent/ConfigFileSelector.js.map +1 -1
- package/Components/JsonConfigComponent/ConfigGeneric.d.ts +68 -67
- package/Components/JsonConfigComponent/ConfigGeneric.js +600 -665
- package/Components/JsonConfigComponent/ConfigInterface.d.ts +14 -0
- package/Components/JsonConfigComponent/ConfigInterface.js +146 -0
- package/Components/JsonConfigComponent/ConfigInterface.js.map +1 -0
- package/Components/JsonConfigComponent/ConfigJsonEditor.d.ts +0 -1
- package/Components/JsonConfigComponent/ConfigJsonEditor.js +6 -11
- package/Components/JsonConfigComponent/ConfigJsonEditor.js.map +1 -1
- package/Components/JsonConfigComponent/ConfigLicense.d.ts +2 -1
- package/Components/JsonConfigComponent/ConfigNumber.d.ts +16 -2
- package/Components/JsonConfigComponent/ConfigNumber.js +105 -201
- package/Components/JsonConfigComponent/ConfigPattern.d.ts +2 -1
- package/Components/JsonConfigComponent/ConfigPort.d.ts +1 -1
- package/Components/JsonConfigComponent/ConfigPort.js +159 -210
- package/Components/JsonConfigComponent/ConfigUUID.d.ts +2 -1
- package/Components/JsonConfigComponent/wrapper/AdminConnection.d.ts +2 -0
- package/Components/JsonConfigComponent/wrapper/AdminConnection.js +7 -0
- package/Components/MDUtils.js +3 -3
- package/Components/MDUtils.js.map +1 -1
- package/Components/SimpleCron/cron2text.js +31 -36
- package/Components/SimpleCron/cron2text.js.map +1 -1
- package/Components/SimpleCron/index.js +10 -10
- package/Components/SimpleCron/index.js.map +1 -1
- package/LegacyConnection.js.map +1 -1
- package/README.md +1 -1
- package/package.json +1 -1
- package/Components/JsonConfigComponent/ConfigGeneric.js.map +0 -1
- package/Components/JsonConfigComponent/ConfigNumber.js.map +0 -1
- package/Components/JsonConfigComponent/ConfigPort.js.map +0 -1
|
@@ -1,702 +1,637 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
7
17
|
});
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
function
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.isObject = void 0;
|
|
30
|
+
const react_1 = __importStar(require("react"));
|
|
31
|
+
const material_1 = require("@mui/material");
|
|
32
|
+
const icons_material_1 = require("@mui/icons-material");
|
|
33
|
+
const i18n_1 = __importDefault(require("./wrapper/i18n"));
|
|
34
|
+
const Utils_1 = __importDefault(require("./wrapper/Components/Utils"));
|
|
35
|
+
const Confirm_1 = __importDefault(require("./wrapper/Dialogs/Confirm"));
|
|
36
|
+
const Icon_1 = __importDefault(require("./wrapper/Components/Icon"));
|
|
37
|
+
// because this class is used in adapter-react-v5, do not include here any foreign files like from '../../helpers/utils.ts'
|
|
38
|
+
function isObject(it) {
|
|
39
|
+
// This is necessary because:
|
|
40
|
+
// typeof null === 'object'
|
|
41
|
+
// typeof [] === 'object'
|
|
42
|
+
// [] instanceof Object === true
|
|
43
|
+
return Object.prototype.toString.call(it) === '[object Object]'; // this code is 25% faster than below one
|
|
44
|
+
// return it && typeof it === 'object' && !(it instanceof Array);
|
|
45
|
+
}
|
|
46
|
+
exports.isObject = isObject;
|
|
47
|
+
class ConfigGeneric extends react_1.Component {
|
|
48
|
+
constructor(props) {
|
|
49
|
+
super(props);
|
|
50
|
+
this.onUpdate = (data) => {
|
|
51
|
+
const value = ConfigGeneric.getValue(data || this.props.data, this.props.attr) || '';
|
|
52
|
+
if (this.state.value !== value) {
|
|
53
|
+
this.setState({ value });
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
this.forceUpdate();
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
// @ts-expect-error of course, as we just
|
|
60
|
+
this.state = {
|
|
61
|
+
confirmDialog: false,
|
|
62
|
+
confirmNewValue: null,
|
|
63
|
+
confirmAttr: null,
|
|
64
|
+
confirmData: null,
|
|
65
|
+
};
|
|
66
|
+
this.isError = {};
|
|
67
|
+
if (props.schema) {
|
|
68
|
+
if (props.custom) {
|
|
69
|
+
this.defaultValue = props.schema.defaultFunc
|
|
70
|
+
? this.executeCustom(props.schema.defaultFunc, props.schema.default, props.data, props.instanceObj, props.arrayIndex, props.globalData)
|
|
71
|
+
: props.schema.default;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
this.defaultValue = props.schema.defaultFunc
|
|
75
|
+
? this.execute(props.schema.defaultFunc, props.schema.default, props.data, props.arrayIndex, props.globalData)
|
|
76
|
+
: props.schema.default;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
this.lang = i18n_1.default.getLanguage();
|
|
64
80
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return setTimeout(function () {
|
|
82
|
-
return _this2.props.forceUpdate([_this2.props.attr], _this2.props.data);
|
|
81
|
+
componentDidMount() {
|
|
82
|
+
this.props.registerOnForceUpdate && this.props.registerOnForceUpdate(this.props.attr, this.onUpdate);
|
|
83
|
+
const LIKE_SELECT = ['select', 'autocomplete', 'autocompleteSendTo'];
|
|
84
|
+
// init default value
|
|
85
|
+
if (this.defaultValue !== undefined) {
|
|
86
|
+
const value = ConfigGeneric.getValue(this.props.data, this.props.attr);
|
|
87
|
+
if (value === undefined ||
|
|
88
|
+
(LIKE_SELECT.includes(this.props.schema.type) && (value === '' || value === null))) {
|
|
89
|
+
setTimeout(() => {
|
|
90
|
+
if (this.props.custom) {
|
|
91
|
+
this.props.onChange(this.props.attr, this.defaultValue, () => setTimeout(() => this.props.forceUpdate([this.props.attr], this.props.data), 100));
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
ConfigGeneric.setValue(this.props.data, this.props.attr, this.defaultValue);
|
|
95
|
+
this.props.onChange(this.props.data, undefined, () => this.props.forceUpdate([this.props.attr], this.props.data));
|
|
96
|
+
}
|
|
83
97
|
}, 100);
|
|
84
|
-
});
|
|
85
|
-
// this.onChange(this.props.attr, this.defaultValue);
|
|
86
|
-
} else {
|
|
87
|
-
ConfigGeneric.setValue(_this2.props.data, _this2.props.attr, _this2.defaultValue);
|
|
88
|
-
_this2.props.onChange(_this2.props.data, undefined, function () {
|
|
89
|
-
return _this2.props.forceUpdate([_this2.props.attr], _this2.props.data);
|
|
90
|
-
});
|
|
91
98
|
}
|
|
92
|
-
}, 100);
|
|
93
99
|
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
100
|
+
else if (this.props.schema.defaultSendTo) {
|
|
101
|
+
this.sendTo();
|
|
102
|
+
}
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
console.error("Cannot parse json data: ".concat(data));
|
|
111
|
-
}
|
|
112
|
-
} else {
|
|
113
|
-
data = {
|
|
114
|
-
attr: this.props.attr,
|
|
115
|
-
value: ConfigGeneric.getValue(this.props.data, this.props.attr)
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
if (data === undefined) {
|
|
119
|
-
data = null;
|
|
120
|
-
}
|
|
121
|
-
this.props.socket.sendTo("".concat(this.props.adapterName, ".").concat(this.props.instance), this.props.schema.defaultSendTo, data).then(function (value) {
|
|
122
|
-
if (value !== null && value !== undefined) {
|
|
123
|
-
if (_this3.props.custom) {
|
|
124
|
-
_this3.props.onChange(_this3.props.attr, value, function () {
|
|
125
|
-
return _this3.props.forceUpdate([_this3.props.attr], _this3.props.data);
|
|
126
|
-
});
|
|
127
|
-
// this.onChange(this.props.attr, this.defaultValue);
|
|
128
|
-
} else {
|
|
129
|
-
ConfigGeneric.setValue(_this3.props.data, _this3.props.attr, value);
|
|
130
|
-
_this3.props.onChange(_this3.props.data, undefined, function () {
|
|
131
|
-
return _this3.props.forceUpdate([_this3.props.attr], _this3.props.data);
|
|
132
|
-
});
|
|
104
|
+
sendTo() {
|
|
105
|
+
if (this.props.alive) {
|
|
106
|
+
this.defaultSendToDone = true;
|
|
107
|
+
let data = this.props.schema.data;
|
|
108
|
+
if (data === undefined && this.props.schema.jsonData) {
|
|
109
|
+
data = this.getPattern(this.props.schema.jsonData);
|
|
110
|
+
try {
|
|
111
|
+
data = JSON.parse(data);
|
|
112
|
+
}
|
|
113
|
+
catch (e) {
|
|
114
|
+
console.error(`Cannot parse json data: ${data}`);
|
|
115
|
+
}
|
|
133
116
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
117
|
+
else {
|
|
118
|
+
data = {
|
|
119
|
+
attr: this.props.attr,
|
|
120
|
+
value: ConfigGeneric.getValue(this.props.data, this.props.attr),
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (data === undefined) {
|
|
124
|
+
data = null;
|
|
125
|
+
}
|
|
126
|
+
this.props.socket
|
|
127
|
+
.sendTo(`${this.props.adapterName}.${this.props.instance}`, this.props.schema.defaultSendTo, data)
|
|
128
|
+
.then((value) => {
|
|
129
|
+
if (value !== null && value !== undefined) {
|
|
130
|
+
if (this.props.custom) {
|
|
131
|
+
this.props.onChange(this.props.attr, value, () => this.props.forceUpdate([this.props.attr], this.props.data));
|
|
132
|
+
// this.onChange(this.props.attr, this.defaultValue);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
ConfigGeneric.setValue(this.props.data, this.props.attr, value);
|
|
136
|
+
this.props.onChange(this.props.data, undefined, () => this.props.forceUpdate([this.props.attr], this.props.data));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
this.defaultSendToDone = false;
|
|
143
|
+
// show error, that instance does not started
|
|
144
|
+
this.onError(this.props.attr, i18n_1.default.t('ra_Instance %s is not alive', this.props.instance.toString()));
|
|
145
|
+
}
|
|
150
146
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (typeof text === 'string') {
|
|
158
|
-
text = noTranslation ? text : _i18n["default"].t(text);
|
|
159
|
-
if (text.includes('${')) {
|
|
160
|
-
return this.getPattern(text);
|
|
161
|
-
}
|
|
162
|
-
return text;
|
|
163
|
-
}
|
|
164
|
-
if (text && (0, _typeof2["default"])(text) === 'object') {
|
|
165
|
-
if (text.func) {
|
|
166
|
-
// calculate pattern
|
|
167
|
-
if ((0, _typeof2["default"])(text.func) === 'object') {
|
|
168
|
-
return this.getPattern(text.func[this.lang] || text.func.en || '');
|
|
169
|
-
}
|
|
170
|
-
return this.getPattern(text.func);
|
|
171
|
-
}
|
|
172
|
-
return text[this.lang] || text.en || '';
|
|
173
|
-
}
|
|
174
|
-
return text.toString();
|
|
147
|
+
componentWillUnmount() {
|
|
148
|
+
this.props.registerOnForceUpdate && this.props.registerOnForceUpdate(this.props.attr);
|
|
149
|
+
if (this.sendToTimeout) {
|
|
150
|
+
clearTimeout(this.sendToTimeout);
|
|
151
|
+
this.sendToTimeout = null;
|
|
152
|
+
}
|
|
175
153
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
154
|
+
/**
|
|
155
|
+
* Extract attribute out of data
|
|
156
|
+
*
|
|
157
|
+
* @param data
|
|
158
|
+
* @param attr
|
|
159
|
+
*/
|
|
160
|
+
static getValue(data, attr) {
|
|
161
|
+
if (typeof attr === 'string') {
|
|
162
|
+
return ConfigGeneric.getValue(data, attr.split('.'));
|
|
163
|
+
}
|
|
164
|
+
if (attr.length === 1) {
|
|
165
|
+
return data[attr[0]];
|
|
166
|
+
}
|
|
167
|
+
const part = attr.shift();
|
|
168
|
+
if (typeof part === 'string' && typeof data[part] === 'object') {
|
|
169
|
+
return ConfigGeneric.getValue(data[part], attr);
|
|
170
|
+
}
|
|
181
171
|
return null;
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
172
|
+
}
|
|
173
|
+
static setValue(data, attr, value) {
|
|
174
|
+
if (typeof attr === 'string') {
|
|
175
|
+
ConfigGeneric.setValue(data, attr.split('.'), value);
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if (attr.length === 1) {
|
|
179
|
+
if (value === null) {
|
|
180
|
+
delete data[attr[0]];
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
data[attr[0]] = value;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const part = attr.shift();
|
|
188
|
+
if (typeof part !== 'string') {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (!data[part] || typeof data[part] === 'object') {
|
|
192
|
+
data[part] = data[part] || {};
|
|
193
|
+
}
|
|
194
|
+
ConfigGeneric.setValue(data[part], attr, value);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
getText(text, noTranslation) {
|
|
198
|
+
if (!text) {
|
|
199
|
+
return '';
|
|
200
|
+
}
|
|
201
|
+
if (typeof text === 'string') {
|
|
202
|
+
const strText = noTranslation ? text : i18n_1.default.t(text);
|
|
203
|
+
if (strText.includes('${')) {
|
|
204
|
+
return this.getPattern(strText);
|
|
205
|
+
}
|
|
206
|
+
return strText;
|
|
207
|
+
}
|
|
208
|
+
if (isObject(text)) {
|
|
209
|
+
if (text.func) {
|
|
210
|
+
// calculate pattern
|
|
211
|
+
if (typeof text.func === 'object') {
|
|
212
|
+
return this.getPattern(text.func[this.lang] || text.func.en || '');
|
|
213
|
+
}
|
|
214
|
+
return this.getPattern(text.func);
|
|
215
|
+
}
|
|
216
|
+
return text[this.lang] || text.en || '';
|
|
217
|
+
}
|
|
218
|
+
return text.toString();
|
|
219
|
+
}
|
|
220
|
+
renderConfirmDialog() {
|
|
221
|
+
if (!this.state.confirmDialog) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
const confirm = this.state.confirmData || this.props.schema.confirm;
|
|
225
|
+
let icon = null;
|
|
226
|
+
if (confirm.type === 'warning') {
|
|
227
|
+
icon = react_1.default.createElement(icons_material_1.Warning, null);
|
|
228
|
+
}
|
|
229
|
+
else if (confirm.type === 'error') {
|
|
230
|
+
icon = react_1.default.createElement(icons_material_1.Error, null);
|
|
231
|
+
}
|
|
232
|
+
else if (confirm.type === 'info') {
|
|
233
|
+
icon = react_1.default.createElement(icons_material_1.Info, null);
|
|
234
|
+
}
|
|
235
|
+
return (react_1.default.createElement(Confirm_1.default, { title: this.getText(confirm.title) || i18n_1.default.t('ra_Please confirm'), text: this.getText(confirm.text), ok: this.getText(confirm.ok) || i18n_1.default.t('ra_Ok'), cancel: this.getText(confirm.cancel) || i18n_1.default.t('ra_Cancel'), icon: icon, onClose: isOk => this.setState({ confirmDialog: false }, () => {
|
|
236
|
+
if (isOk) {
|
|
237
|
+
const data = JSON.parse(JSON.stringify(this.props.data));
|
|
238
|
+
if (this.state.confirmDepAttr) {
|
|
239
|
+
ConfigGeneric.setValue(data, this.state.confirmDepAttr, this.state.confirmDepNewValue);
|
|
240
|
+
}
|
|
241
|
+
ConfigGeneric.setValue(data, this.state.confirmAttr, this.state.confirmNewValue);
|
|
242
|
+
this.setState({
|
|
243
|
+
confirmDialog: false,
|
|
244
|
+
confirmDepAttr: null,
|
|
245
|
+
confirmDepNewValue: null,
|
|
246
|
+
confirmNewValue: null,
|
|
247
|
+
confirmAttr: null,
|
|
248
|
+
confirmData: null,
|
|
249
|
+
}, () => this.props.onChange(data));
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
this.setState({
|
|
253
|
+
confirmDialog: false,
|
|
254
|
+
confirmDepAttr: null,
|
|
255
|
+
confirmDepNewValue: null,
|
|
256
|
+
confirmNewValue: null,
|
|
257
|
+
confirmAttr: null,
|
|
258
|
+
confirmData: null,
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
}) }));
|
|
262
|
+
}
|
|
263
|
+
// eslint-disable-next-line react/no-unused-class-component-methods
|
|
264
|
+
getIcon(iconSettings) {
|
|
265
|
+
iconSettings = iconSettings || this.props.schema.icon;
|
|
266
|
+
let icon = null;
|
|
267
|
+
if (iconSettings === 'auth') {
|
|
268
|
+
icon = react_1.default.createElement(icons_material_1.Key, null);
|
|
269
|
+
}
|
|
270
|
+
else if (iconSettings === 'send') {
|
|
271
|
+
icon = react_1.default.createElement(icons_material_1.Send, null);
|
|
272
|
+
}
|
|
273
|
+
else if (iconSettings === 'web') {
|
|
274
|
+
icon = react_1.default.createElement(icons_material_1.Public, null);
|
|
275
|
+
}
|
|
276
|
+
else if (iconSettings === 'warning') {
|
|
277
|
+
icon = react_1.default.createElement(icons_material_1.Warning, null);
|
|
278
|
+
}
|
|
279
|
+
else if (iconSettings === 'error') {
|
|
280
|
+
icon = react_1.default.createElement(icons_material_1.Error, null);
|
|
281
|
+
}
|
|
282
|
+
else if (iconSettings === 'info') {
|
|
283
|
+
icon = react_1.default.createElement(icons_material_1.Info, null);
|
|
284
|
+
}
|
|
285
|
+
else if (iconSettings === 'search') {
|
|
286
|
+
icon = react_1.default.createElement(icons_material_1.Search, null);
|
|
287
|
+
}
|
|
288
|
+
else if (iconSettings === 'book') {
|
|
289
|
+
icon = react_1.default.createElement(icons_material_1.MenuBook, null);
|
|
290
|
+
}
|
|
291
|
+
else if (iconSettings === 'help') {
|
|
292
|
+
icon = react_1.default.createElement(icons_material_1.Help, null);
|
|
293
|
+
}
|
|
294
|
+
else if (iconSettings === 'upload') {
|
|
295
|
+
icon = react_1.default.createElement(icons_material_1.UploadFile, null);
|
|
296
|
+
}
|
|
297
|
+
else if (iconSettings) {
|
|
298
|
+
if (iconSettings.endsWith('.png') || iconSettings.endsWith('.svg') || iconSettings.endsWith('.jpg')) {
|
|
299
|
+
// this path is relative to ./adapter/NAME
|
|
300
|
+
if (!iconSettings.startsWith('http://') && !iconSettings.startsWith('https://')) {
|
|
301
|
+
iconSettings = `./adapter/${this.props.adapterName}/${iconSettings}`;
|
|
302
|
+
}
|
|
231
303
|
}
|
|
232
|
-
|
|
304
|
+
icon = react_1.default.createElement(Icon_1.default, { src: iconSettings, style: { width: 22, height: 22 } });
|
|
233
305
|
}
|
|
234
|
-
|
|
306
|
+
return icon;
|
|
235
307
|
}
|
|
236
|
-
|
|
237
308
|
/**
|
|
238
309
|
* Trigger onChange, to activate save button on change
|
|
239
310
|
*
|
|
240
311
|
* @param attr the changed attribute
|
|
241
312
|
* @param newValue new value of the attribute
|
|
242
|
-
* @param
|
|
243
|
-
* @return {Promise<void>}
|
|
313
|
+
* @param cb optional callback function, else returns a Promise
|
|
244
314
|
*/
|
|
245
315
|
// eslint-disable-next-line react/no-unused-class-component-methods
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}, function () {
|
|
260
|
-
if (typeof cb === 'function') {
|
|
261
|
-
cb();
|
|
262
|
-
} else {
|
|
263
|
-
resolve();
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
// find any inputs with confirmation
|
|
269
|
-
if (this.props.schema.confirmDependsOn) {
|
|
270
|
-
var _loop = function _loop() {
|
|
271
|
-
var dep = _this5.props.schema.confirmDependsOn[z];
|
|
272
|
-
if (dep.confirm) {
|
|
273
|
-
var val = ConfigGeneric.getValue(data, dep.attr);
|
|
274
|
-
if (_this5.execute(dep.confirm.condition, false, data, _this5.props.arrayIndex, _this5.props.globalData)) {
|
|
275
|
-
return {
|
|
276
|
-
v: new Promise(function (resolve) {
|
|
277
|
-
_this5.setState({
|
|
278
|
-
confirmDialog: true,
|
|
279
|
-
confirmNewValue: newValue,
|
|
280
|
-
confirmAttr: attr,
|
|
281
|
-
confirmDepNewValue: val,
|
|
282
|
-
confirmDepAttr: dep.attr,
|
|
283
|
-
confirmData: dep.confirm
|
|
284
|
-
}, function () {
|
|
285
|
-
if (typeof cb === 'function') {
|
|
316
|
+
onChange(attr, newValue, cb) {
|
|
317
|
+
const data = JSON.parse(JSON.stringify(this.props.data));
|
|
318
|
+
ConfigGeneric.setValue(data, attr, newValue);
|
|
319
|
+
if (this.props.schema.confirm &&
|
|
320
|
+
this.execute(this.props.schema.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
|
|
321
|
+
return new Promise(resolve => {
|
|
322
|
+
this.setState({
|
|
323
|
+
confirmDialog: true,
|
|
324
|
+
confirmNewValue: newValue,
|
|
325
|
+
confirmAttr: attr,
|
|
326
|
+
confirmData: null,
|
|
327
|
+
}, () => {
|
|
328
|
+
if (typeof cb === 'function') {
|
|
286
329
|
cb();
|
|
287
|
-
|
|
330
|
+
}
|
|
331
|
+
else {
|
|
288
332
|
resolve();
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
// find any inputs with confirmation
|
|
338
|
+
if (this.props.schema.confirmDependsOn) {
|
|
339
|
+
for (let z = 0; z < this.props.schema.confirmDependsOn.length; z++) {
|
|
340
|
+
const dep = this.props.schema.confirmDependsOn[z];
|
|
341
|
+
if (dep.confirm) {
|
|
342
|
+
const val = ConfigGeneric.getValue(data, dep.attr);
|
|
343
|
+
if (this.execute(dep.confirm.condition, false, data, this.props.arrayIndex, this.props.globalData)) {
|
|
344
|
+
return new Promise(resolve => {
|
|
345
|
+
this.setState({
|
|
346
|
+
confirmDialog: true,
|
|
347
|
+
confirmNewValue: newValue,
|
|
348
|
+
confirmAttr: attr,
|
|
349
|
+
confirmDepNewValue: val,
|
|
350
|
+
confirmDepAttr: dep.attr,
|
|
351
|
+
confirmData: dep.confirm,
|
|
352
|
+
}, () => {
|
|
353
|
+
if (typeof cb === 'function') {
|
|
354
|
+
cb();
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
resolve();
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
}
|
|
294
363
|
}
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
364
|
+
}
|
|
365
|
+
const changed = [];
|
|
366
|
+
if (this.props.schema.onChangeDependsOn) {
|
|
367
|
+
for (let z = 0; z < this.props.schema.onChangeDependsOn.length; z++) {
|
|
368
|
+
const dep = this.props.schema.onChangeDependsOn[z];
|
|
369
|
+
if (dep.onChange) {
|
|
370
|
+
const val = ConfigGeneric.getValue(data, dep.attr);
|
|
371
|
+
let _newValue;
|
|
372
|
+
if (this.props.custom) {
|
|
373
|
+
_newValue = this.executeCustom(dep.onChange.calculateFunc, data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData);
|
|
374
|
+
}
|
|
375
|
+
else {
|
|
376
|
+
_newValue = this.execute(dep.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
|
|
377
|
+
}
|
|
378
|
+
if (_newValue !== val) {
|
|
379
|
+
ConfigGeneric.setValue(data, dep.attr, _newValue);
|
|
380
|
+
changed.push(dep.attr);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
313
383
|
}
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
384
|
+
}
|
|
385
|
+
if (this.props.schema.hiddenDependsOn) {
|
|
386
|
+
for (let z = 0; z < this.props.schema.hiddenDependsOn.length; z++) {
|
|
387
|
+
const dep = this.props.schema.hiddenDependsOn[z];
|
|
388
|
+
dep.hidden && changed.push(dep.attr);
|
|
317
389
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
}, i * 50);
|
|
354
|
-
});
|
|
355
|
-
} else {
|
|
356
|
-
this.props.onChange(data, undefined, function () {
|
|
357
|
-
changed.length && _this5.props.forceUpdate(changed, data);
|
|
358
|
-
cb && cb();
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
return Promise.resolve();
|
|
390
|
+
}
|
|
391
|
+
if (this.props.schema.labelDependsOn) {
|
|
392
|
+
for (let z = 0; z < this.props.schema.labelDependsOn.length; z++) {
|
|
393
|
+
const dep = this.props.schema.labelDependsOn[z];
|
|
394
|
+
dep.hidden && changed.push(dep.attr);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (this.props.schema.helpDependsOn) {
|
|
398
|
+
for (let z = 0; z < this.props.schema.helpDependsOn.length; z++) {
|
|
399
|
+
const dep = this.props.schema.helpDependsOn[z];
|
|
400
|
+
dep.hidden && changed.push(dep.attr);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (this.props.schema.onChange && !this.props.schema.onChange.ignoreOwnChanges) {
|
|
404
|
+
const val = ConfigGeneric.getValue(data, this.props.attr);
|
|
405
|
+
const newValue_ = this.props.custom
|
|
406
|
+
? this.executeCustom(this.props.schema.onChange.calculateFunc, data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
407
|
+
: this.execute(this.props.schema.onChange.calculateFunc, val, data, this.props.arrayIndex, this.props.globalData);
|
|
408
|
+
if (newValue_ !== val) {
|
|
409
|
+
ConfigGeneric.setValue(data, this.props.attr, newValue_);
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (this.props.custom) {
|
|
413
|
+
this.props.onChange(attr, newValue, () => cb && cb());
|
|
414
|
+
changed &&
|
|
415
|
+
changed.length &&
|
|
416
|
+
changed.forEach((_attr, i) => setTimeout(() => this.props.onChange(_attr, ConfigGeneric.getValue(data, _attr)), i * 50));
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
this.props.onChange(data, undefined, () => {
|
|
420
|
+
changed.length && this.props.forceUpdate(changed, data);
|
|
421
|
+
cb && cb();
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
return Promise.resolve();
|
|
362
425
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
426
|
+
execute(func, defaultValue, data, arrayIndex, globalData) {
|
|
427
|
+
let fun;
|
|
428
|
+
if (isObject(func)) {
|
|
429
|
+
fun = func.func;
|
|
430
|
+
}
|
|
431
|
+
else {
|
|
432
|
+
fun = func;
|
|
433
|
+
}
|
|
434
|
+
if (!fun) {
|
|
435
|
+
return defaultValue;
|
|
436
|
+
}
|
|
437
|
+
try {
|
|
438
|
+
// eslint-disable-next-line no-new-func
|
|
439
|
+
const f = new Function('data', 'originalData', '_system', '_alive', '_common', '_socket', '_instance', 'arrayIndex', 'globalData', '_changed', fun.includes('return') ? fun : `return ${fun}`);
|
|
440
|
+
return f(data || this.props.data, this.props.originalData, this.props.systemConfig, this.props.alive, this.props.common, this.props.socket, this.props.instance, arrayIndex, globalData, this.props.changed);
|
|
441
|
+
}
|
|
442
|
+
catch (e) {
|
|
443
|
+
console.error(`Cannot execute ${func}: ${e}`);
|
|
444
|
+
return defaultValue;
|
|
445
|
+
}
|
|
380
446
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
447
|
+
executeCustom(func, data, customObj, instanceObj, arrayIndex, globalData) {
|
|
448
|
+
let fun;
|
|
449
|
+
if (isObject(func)) {
|
|
450
|
+
fun = func.func;
|
|
451
|
+
}
|
|
452
|
+
else {
|
|
453
|
+
fun = func;
|
|
454
|
+
}
|
|
455
|
+
if (!fun) {
|
|
456
|
+
return null;
|
|
457
|
+
}
|
|
458
|
+
try {
|
|
459
|
+
// eslint-disable-next-line no-new-func
|
|
460
|
+
const f = new Function('data', 'originalData', '_system', 'instanceObj', 'customObj', '_socket', 'arrayIndex', 'globalData', '_changed', fun.includes('return') ? fun : `return ${fun}`);
|
|
461
|
+
return f(data || this.props.data, this.props.originalData, this.props.systemConfig, instanceObj, customObj, this.props.socket, arrayIndex, globalData, this.props.changed);
|
|
462
|
+
}
|
|
463
|
+
catch (e) {
|
|
464
|
+
console.error(`Cannot execute ${fun}: ${e}`);
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
398
467
|
}
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
468
|
+
calculate(schema) {
|
|
469
|
+
let error;
|
|
470
|
+
let disabled;
|
|
471
|
+
let hidden;
|
|
472
|
+
let defaultValue;
|
|
473
|
+
if (this.props.custom) {
|
|
474
|
+
error = schema.validator
|
|
475
|
+
? !this.executeCustom(schema.validator, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
476
|
+
: false;
|
|
477
|
+
disabled = schema.disabled
|
|
478
|
+
? this.executeCustom(schema.disabled, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
479
|
+
: false;
|
|
480
|
+
hidden = schema.hidden
|
|
481
|
+
? this.executeCustom(schema.hidden, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
482
|
+
: false;
|
|
483
|
+
defaultValue = schema.defaultFunc
|
|
484
|
+
? this.executeCustom(schema.defaultFunc, this.props.data, this.props.customObj, this.props.instanceObj, this.props.arrayIndex, this.props.globalData)
|
|
485
|
+
: schema.default;
|
|
486
|
+
}
|
|
487
|
+
else {
|
|
488
|
+
error = schema.validator
|
|
489
|
+
? !this.execute(schema.validator, false, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
490
|
+
: false;
|
|
491
|
+
disabled = schema.disabled
|
|
492
|
+
? this.execute(schema.disabled, false, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
493
|
+
: false;
|
|
494
|
+
hidden = schema.hidden
|
|
495
|
+
? this.execute(schema.hidden, false, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
496
|
+
: false;
|
|
497
|
+
defaultValue = schema.defaultFunc
|
|
498
|
+
? this.execute(schema.defaultFunc, schema.default, this.props.data, this.props.arrayIndex, this.props.globalData)
|
|
499
|
+
: schema.default;
|
|
500
|
+
}
|
|
501
|
+
return {
|
|
502
|
+
error, disabled, hidden, defaultValue,
|
|
503
|
+
};
|
|
423
504
|
}
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
this.props.onError && this.props.onError(attr, error);
|
|
505
|
+
onError(attr, error) {
|
|
506
|
+
if (!error) {
|
|
507
|
+
delete this.isError[attr];
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
this.isError[attr] = error;
|
|
511
|
+
}
|
|
512
|
+
this.props.onError && this.props.onError(attr, error);
|
|
433
513
|
}
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
) {
|
|
438
|
-
return this.getText(this.props.schema.label) || this.getText(this.props.schema.text);
|
|
514
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
515
|
+
renderItem(_error, _disabled, _defaultValue) {
|
|
516
|
+
return this.getText(this.props.schema.label) || this.getText(this.props.schema.text);
|
|
439
517
|
}
|
|
440
|
-
|
|
441
518
|
// eslint-disable-next-line react/no-unused-class-component-methods
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
return text;
|
|
451
|
-
}
|
|
452
|
-
return /*#__PURE__*/_react["default"].createElement("a", {
|
|
453
|
-
href: link,
|
|
454
|
-
target: "_blank",
|
|
455
|
-
rel: "noreferrer",
|
|
456
|
-
style: {
|
|
457
|
-
color: this.props.themeType === 'dark' ? '#a147ff' : '#5b238f',
|
|
458
|
-
textDecoration: 'underline'
|
|
459
|
-
}
|
|
460
|
-
}, this.getText(text, noTranslation));
|
|
461
|
-
}
|
|
462
|
-
}, {
|
|
463
|
-
key: "getPattern",
|
|
464
|
-
value: function getPattern(pattern, data) {
|
|
465
|
-
data = data || this.props.data;
|
|
466
|
-
if (!pattern) {
|
|
467
|
-
return '';
|
|
468
|
-
}
|
|
469
|
-
if ((0, _typeof2["default"])(pattern) === 'object') {
|
|
470
|
-
if (pattern.func) {
|
|
471
|
-
pattern = pattern.func;
|
|
472
|
-
} else {
|
|
473
|
-
console.log("Object must be stringified: ".concat(JSON.stringify(pattern)));
|
|
474
|
-
pattern = JSON.stringify(pattern);
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
try {
|
|
478
|
-
if (this.props.custom) {
|
|
479
|
-
// eslint-disable-next-line no-new-func
|
|
480
|
-
var _f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', 'instanceObj', 'customObj', '_socket', '_changed', "return `".concat(pattern.replace(/`/g, '\\`'), "`"));
|
|
481
|
-
return _f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.systemConfig, this.props.instanceObj, this.props.customObj, this.props.socket, this.props.changed);
|
|
482
|
-
}
|
|
483
|
-
// eslint-disable-next-line no-new-func
|
|
484
|
-
var f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', '_alive', '_common', '_socket', '_changed', "return `".concat(pattern.replace(/`/g, '\\`'), "`"));
|
|
485
|
-
return f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.systemConfig, this.props.alive, this.props.common, this.props.socket, this.props.changed);
|
|
486
|
-
} catch (e) {
|
|
487
|
-
console.error("Cannot execute ".concat(pattern, ": ").concat(e));
|
|
488
|
-
return pattern;
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
}, {
|
|
492
|
-
key: "render",
|
|
493
|
-
value: function render() {
|
|
494
|
-
var _this6 = this;
|
|
495
|
-
var schema = this.props.schema;
|
|
496
|
-
if (!schema) {
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
499
|
-
if (this.props.alive && this.defaultSendToDone === false) {
|
|
500
|
-
this.sendToTimeout = setTimeout(function () {
|
|
501
|
-
_this6.sendToTimeout = null;
|
|
502
|
-
_this6.sendTo();
|
|
503
|
-
}, 200);
|
|
504
|
-
}
|
|
505
|
-
var _this$calculate = this.calculate(schema),
|
|
506
|
-
error = _this$calculate.error,
|
|
507
|
-
disabled = _this$calculate.disabled,
|
|
508
|
-
hidden = _this$calculate.hidden,
|
|
509
|
-
defaultValue = _this$calculate.defaultValue;
|
|
510
|
-
if (hidden) {
|
|
511
|
-
// Remove all errors if element is hidden
|
|
512
|
-
if (Object.keys(this.isError).length) {
|
|
513
|
-
setTimeout(function (isError) {
|
|
514
|
-
return Object.keys(isError).forEach(function (attr) {
|
|
515
|
-
return _this6.props.onError(attr);
|
|
516
|
-
});
|
|
517
|
-
}, 100, JSON.parse(JSON.stringify(this.isError)));
|
|
518
|
-
this.isError = {};
|
|
519
|
-
}
|
|
520
|
-
if (schema.hideOnlyControl) {
|
|
521
|
-
var _item = /*#__PURE__*/_react["default"].createElement(_material.Grid, {
|
|
522
|
-
item: true,
|
|
523
|
-
xs: schema.xs || undefined,
|
|
524
|
-
lg: schema.lg || undefined,
|
|
525
|
-
md: schema.md || undefined,
|
|
526
|
-
sm: schema.sm || undefined,
|
|
527
|
-
style: _objectSpread(_objectSpread({
|
|
528
|
-
marginBottom: 0,
|
|
529
|
-
/* marginRight: 8, */
|
|
530
|
-
textAlign: 'left'
|
|
531
|
-
}, schema.style), this.props.themeType === 'dark' ? schema.darkStyle : {})
|
|
532
|
-
});
|
|
533
|
-
if (schema.newLine) {
|
|
534
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
|
|
535
|
-
style: {
|
|
536
|
-
flexBasis: '100%',
|
|
537
|
-
height: 0
|
|
538
|
-
}
|
|
539
|
-
}), _item);
|
|
540
|
-
}
|
|
541
|
-
return _item;
|
|
519
|
+
renderHelp(text, link, noTranslation) {
|
|
520
|
+
if (!link) {
|
|
521
|
+
text = this.getText(text, noTranslation) || '';
|
|
522
|
+
if (text &&
|
|
523
|
+
(text.includes('<a ') || text.includes('<br') || text.includes('<b>') || text.includes('<i>'))) {
|
|
524
|
+
return Utils_1.default.renderTextWithA(text);
|
|
525
|
+
}
|
|
526
|
+
return text;
|
|
542
527
|
}
|
|
543
|
-
return
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
if (error && !Object.keys(this.isError).length) {
|
|
548
|
-
this.isError = (0, _defineProperty2["default"])({}, this.props.attr, schema.validatorErrorText ? _i18n["default"].t(schema.validatorErrorText) : true);
|
|
549
|
-
setTimeout(function (isError) {
|
|
550
|
-
return Object.keys(isError).forEach(function (attr) {
|
|
551
|
-
return _this6.props.onError(attr, isError[attr]);
|
|
552
|
-
});
|
|
553
|
-
}, 100, JSON.parse(JSON.stringify(this.isError)));
|
|
554
|
-
} else if (!error && Object.keys(this.isError).length) {
|
|
555
|
-
setTimeout(function (isError) {
|
|
556
|
-
return Object.keys(isError).forEach(function (attr) {
|
|
557
|
-
return _this6.props.onError(attr);
|
|
558
|
-
});
|
|
559
|
-
}, 100, JSON.parse(JSON.stringify(this.isError)));
|
|
560
|
-
this.isError = {};
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
var renderedItem = this.renderItem(error, disabled || this.props.commandRunning || this.props.disabled, defaultValue);
|
|
564
|
-
if (this.noPlaceRequired) {
|
|
565
|
-
return renderedItem;
|
|
566
|
-
}
|
|
567
|
-
var item = /*#__PURE__*/_react["default"].createElement(_material.Grid, {
|
|
568
|
-
item: true,
|
|
569
|
-
title: this.getText(schema.tooltip),
|
|
570
|
-
xs: schema.xs || undefined,
|
|
571
|
-
lg: schema.lg || undefined,
|
|
572
|
-
md: schema.md || undefined,
|
|
573
|
-
sm: schema.sm || undefined,
|
|
574
|
-
style: _objectSpread(_objectSpread({
|
|
575
|
-
marginBottom: 0,
|
|
576
|
-
// marginRight: 8,
|
|
577
|
-
textAlign: 'left',
|
|
578
|
-
width: schema.type === 'divider' || schema.type === 'header' ? schema.width || '100%' : undefined
|
|
579
|
-
}, schema.style), this.props.themeType === 'dark' ? schema.darkStyle : {})
|
|
580
|
-
}, this.props.schema.defaultSendTo && this.props.schema.button ? /*#__PURE__*/_react["default"].createElement(_material.Grid, {
|
|
581
|
-
container: true,
|
|
582
|
-
style: {
|
|
583
|
-
width: '100%'
|
|
584
|
-
}
|
|
585
|
-
}, /*#__PURE__*/_react["default"].createElement(_material.Grid, {
|
|
586
|
-
item: true,
|
|
587
|
-
flex: 1
|
|
588
|
-
}, renderedItem), /*#__PURE__*/_react["default"].createElement(_material.Grid, {
|
|
589
|
-
item: true
|
|
590
|
-
}, /*#__PURE__*/_react["default"].createElement(_material.Button, {
|
|
591
|
-
variant: "outlined",
|
|
592
|
-
onClick: function onClick() {
|
|
593
|
-
return _this6.sendTo();
|
|
594
|
-
},
|
|
595
|
-
title: this.props.schema.buttonTooltip ? this.getText(this.props.schema.buttonTooltip, this.props.schema.buttonTooltipNoTranslation) : _i18n["default"].t('ra_Request data by instance')
|
|
596
|
-
}, this.getText(this.props.schema.button)))) : renderedItem);
|
|
597
|
-
if (schema.newLine) {
|
|
598
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement("div", {
|
|
599
|
-
style: {
|
|
600
|
-
flexBasis: '100%',
|
|
601
|
-
height: 0
|
|
602
|
-
}
|
|
603
|
-
}), this.renderConfirmDialog(), item);
|
|
604
|
-
}
|
|
605
|
-
if (this.state.confirmDialog) {
|
|
606
|
-
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, this.renderConfirmDialog(), item);
|
|
607
|
-
}
|
|
608
|
-
return item;
|
|
609
|
-
}
|
|
610
|
-
}], [{
|
|
611
|
-
key: "getValue",
|
|
612
|
-
value:
|
|
613
|
-
/**
|
|
614
|
-
* Extract attribute out of data
|
|
615
|
-
*
|
|
616
|
-
* @param {Record<string, any>} data
|
|
617
|
-
* @param {string|string[]} attr
|
|
618
|
-
* @return {*|null}
|
|
619
|
-
*/
|
|
620
|
-
function getValue(data, attr) {
|
|
621
|
-
if (typeof attr === 'string') {
|
|
622
|
-
return ConfigGeneric.getValue(data, attr.split('.'));
|
|
623
|
-
}
|
|
624
|
-
if (attr.length === 1) {
|
|
625
|
-
return data[attr[0]];
|
|
626
|
-
}
|
|
627
|
-
var part = attr.shift();
|
|
628
|
-
if ((0, _typeof2["default"])(data[part]) === 'object') {
|
|
629
|
-
return ConfigGeneric.getValue(data[part], attr);
|
|
630
|
-
}
|
|
631
|
-
return null;
|
|
528
|
+
return react_1.default.createElement("a", { href: link, target: "_blank", rel: "noreferrer", style: {
|
|
529
|
+
color: this.props.themeType === 'dark' ? '#a147ff' : '#5b238f',
|
|
530
|
+
textDecoration: 'underline',
|
|
531
|
+
} }, this.getText(text, noTranslation));
|
|
632
532
|
}
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
533
|
+
getPattern(pattern, data) {
|
|
534
|
+
data = data || this.props.data;
|
|
535
|
+
if (!pattern) {
|
|
536
|
+
return '';
|
|
537
|
+
}
|
|
538
|
+
if (typeof pattern === 'object') {
|
|
539
|
+
if (pattern.func) {
|
|
540
|
+
pattern = pattern.func;
|
|
541
|
+
}
|
|
542
|
+
else {
|
|
543
|
+
console.log(`Object must be stringified: ${JSON.stringify(pattern)}`);
|
|
544
|
+
pattern = JSON.stringify(pattern);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
try {
|
|
548
|
+
if (this.props.custom) {
|
|
549
|
+
// eslint-disable-next-line no-new-func
|
|
550
|
+
const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', 'instanceObj', 'customObj', '_socket', '_changed', `return \`${pattern.replace(/`/g, '\\`')}\``);
|
|
551
|
+
return f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.systemConfig, this.props.instanceObj, this.props.customObj, this.props.socket, this.props.changed);
|
|
552
|
+
}
|
|
553
|
+
// eslint-disable-next-line no-new-func
|
|
554
|
+
const f = new Function('data', 'originalData', 'arrayIndex', 'globalData', '_system', '_alive', '_common', '_socket', '_changed', `return \`${pattern.replace(/`/g, '\\`')}\``);
|
|
555
|
+
return f(data, this.props.originalData, this.props.arrayIndex, this.props.globalData, this.props.systemConfig, this.props.alive, this.props.common, this.props.socket, this.props.changed);
|
|
556
|
+
}
|
|
557
|
+
catch (e) {
|
|
558
|
+
console.error(`Cannot execute ${pattern}: ${e}`);
|
|
559
|
+
return pattern;
|
|
560
|
+
}
|
|
653
561
|
}
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
(
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
562
|
+
render() {
|
|
563
|
+
const schema = this.props.schema;
|
|
564
|
+
if (!schema) {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
if (this.props.alive && this.defaultSendToDone === false) {
|
|
568
|
+
this.sendToTimeout = setTimeout(() => {
|
|
569
|
+
this.sendToTimeout = null;
|
|
570
|
+
this.sendTo();
|
|
571
|
+
}, 200);
|
|
572
|
+
}
|
|
573
|
+
const { error, disabled, hidden, defaultValue, } = this.calculate(schema);
|
|
574
|
+
if (hidden) {
|
|
575
|
+
// Remove all errors if element is hidden
|
|
576
|
+
if (Object.keys(this.isError).length) {
|
|
577
|
+
setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr)), 100, JSON.parse(JSON.stringify(this.isError)));
|
|
578
|
+
this.isError = {};
|
|
579
|
+
}
|
|
580
|
+
if (schema.hideOnlyControl) {
|
|
581
|
+
const item = react_1.default.createElement(material_1.Grid, { item: true, xs: schema.xs || undefined, lg: schema.lg || undefined, md: schema.md || undefined, sm: schema.sm || undefined, style: (Object.assign(Object.assign({ marginBottom: 0, textAlign: 'left' }, schema.style), (this.props.themeType === 'dark' ? schema.darkStyle : {}))) });
|
|
582
|
+
if (schema.newLine) {
|
|
583
|
+
return react_1.default.createElement(react_1.default.Fragment, null,
|
|
584
|
+
react_1.default.createElement("div", { style: { flexBasis: '100%', height: 0 } }),
|
|
585
|
+
item);
|
|
586
|
+
}
|
|
587
|
+
return item;
|
|
588
|
+
}
|
|
589
|
+
return null;
|
|
590
|
+
}
|
|
591
|
+
// Add error
|
|
592
|
+
if (schema.validatorNoSaveOnError) {
|
|
593
|
+
if (error && !Object.keys(this.isError).length) {
|
|
594
|
+
this.isError = {
|
|
595
|
+
[this.props.attr]: schema.validatorErrorText ? i18n_1.default.t(schema.validatorErrorText) : true,
|
|
596
|
+
};
|
|
597
|
+
setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr, isError[attr])), 100, JSON.parse(JSON.stringify(this.isError)));
|
|
598
|
+
}
|
|
599
|
+
else if (!error && Object.keys(this.isError).length) {
|
|
600
|
+
setTimeout(isError => Object.keys(isError).forEach(attr => this.props.onError(attr)), 100, JSON.parse(JSON.stringify(this.isError)));
|
|
601
|
+
this.isError = {};
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
const renderedItem = this.renderItem(error, disabled || this.props.commandRunning || this.props.disabled, defaultValue);
|
|
605
|
+
if (this.noPlaceRequired) {
|
|
606
|
+
return renderedItem;
|
|
607
|
+
}
|
|
608
|
+
const item = react_1.default.createElement(material_1.Grid, { item: true, title: this.getText(schema.tooltip), xs: schema.xs || undefined, lg: schema.lg || undefined, md: schema.md || undefined, sm: schema.sm || undefined, style: (Object.assign(Object.assign({ marginBottom: 0,
|
|
609
|
+
// marginRight: 8,
|
|
610
|
+
textAlign: 'left', width: schema.type === 'divider' || schema.type === 'header'
|
|
611
|
+
? schema.width || '100%'
|
|
612
|
+
: undefined }, schema.style), (this.props.themeType === 'dark' ? schema.darkStyle : {}))) }, this.props.schema.defaultSendTo && this.props.schema.button ?
|
|
613
|
+
react_1.default.createElement(material_1.Grid, { container: true, style: { width: '100%' } },
|
|
614
|
+
react_1.default.createElement(material_1.Grid, { item: true, flex: 1 }, renderedItem),
|
|
615
|
+
react_1.default.createElement(material_1.Grid, { item: true },
|
|
616
|
+
react_1.default.createElement(material_1.Button, { variant: "outlined", onClick: () => this.sendTo(), title: this.props.schema.buttonTooltip
|
|
617
|
+
? this.getText(this.props.schema.buttonTooltip, this.props.schema.buttonTooltipNoTranslation)
|
|
618
|
+
: i18n_1.default.t('ra_Request data by instance') }, this.getText(this.props.schema.button)))) : renderedItem);
|
|
619
|
+
if (schema.newLine) {
|
|
620
|
+
return react_1.default.createElement(react_1.default.Fragment, null,
|
|
621
|
+
react_1.default.createElement("div", { style: { flexBasis: '100%', height: 0 } }),
|
|
622
|
+
this.renderConfirmDialog(),
|
|
623
|
+
item);
|
|
624
|
+
}
|
|
625
|
+
if (this.state.confirmDialog) {
|
|
626
|
+
return react_1.default.createElement(react_1.default.Fragment, null,
|
|
627
|
+
this.renderConfirmDialog(),
|
|
628
|
+
item);
|
|
629
|
+
}
|
|
630
|
+
return item;
|
|
667
631
|
}
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
ConfigGeneric.
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
schema: _propTypes["default"].object,
|
|
675
|
-
attr: _propTypes["default"].string,
|
|
676
|
-
// eslint-disable-next-line react/no-unused-prop-types
|
|
677
|
-
value: _propTypes["default"].any,
|
|
678
|
-
// eslint-disable-next-line react/no-unused-prop-types
|
|
679
|
-
themeName: _propTypes["default"].string,
|
|
680
|
-
style: _propTypes["default"].object,
|
|
681
|
-
onError: _propTypes["default"].func,
|
|
682
|
-
onChange: _propTypes["default"].func,
|
|
683
|
-
// eslint-disable-next-line react/no-unused-prop-types
|
|
684
|
-
customs: _propTypes["default"].object,
|
|
685
|
-
forceUpdate: _propTypes["default"].func.isRequired,
|
|
686
|
-
disabled: _propTypes["default"].bool,
|
|
687
|
-
systemConfig: _propTypes["default"].object,
|
|
688
|
-
alive: _propTypes["default"].bool,
|
|
689
|
-
changed: _propTypes["default"].bool,
|
|
690
|
-
common: _propTypes["default"].object,
|
|
691
|
-
adapterName: _propTypes["default"].string,
|
|
692
|
-
instance: _propTypes["default"].number,
|
|
693
|
-
// eslint-disable-next-line react/no-unused-prop-types
|
|
694
|
-
dateFormat: _propTypes["default"].string,
|
|
695
|
-
// eslint-disable-next-line react/no-unused-prop-types
|
|
696
|
-
isFloatComma: _propTypes["default"].bool,
|
|
697
|
-
customObj: _propTypes["default"].object,
|
|
698
|
-
instanceObj: _propTypes["default"].object,
|
|
699
|
-
custom: _propTypes["default"].bool
|
|
700
|
-
};
|
|
701
|
-
var _default = exports["default"] = ConfigGeneric;
|
|
702
|
-
//# sourceMappingURL=ConfigGeneric.js.map
|
|
632
|
+
}
|
|
633
|
+
ConfigGeneric.DIFFERENT_VALUE = '__different__';
|
|
634
|
+
ConfigGeneric.DIFFERENT_LABEL = 'ra___different__';
|
|
635
|
+
ConfigGeneric.NONE_VALUE = '';
|
|
636
|
+
ConfigGeneric.NONE_LABEL = 'ra_none';
|
|
637
|
+
exports.default = ConfigGeneric;
|