@5minds/node-red-dashboard-2-processcube-dynamic-form 1.1.2-develop-3b99b7-m7bxlaek → 1.1.2-develop-231918-m7na5yab

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.
@@ -1,770 +1,769 @@
1
1
  <template>
2
- <!-- Component must be wrapped in a block so props such as className and style can be passed in from parent -->
3
- <div className="ui-dynamic-form-wrapper">
4
- <p v-if="hasFields()">
5
- <v-form ref="form" v-model="form" :class="dynamicClass">
6
- <h3 style="padding: 16px">{{ this.props.name }}</h3>
7
- <div style="padding: 16px; max-height: 550px; overflow-y: auto">
8
- <FormKit type="group" id="form">
9
- <v-row v-for="(field, index) in fields()" :key="field">
10
- <v-col cols="12">
11
- <component
12
- v-if="createComponent(field).innerText"
13
- :is="createComponent(field).type"
14
- v-bind="createComponent(field).props"
15
- v-model="formData[field.id]"
16
- >
17
- {{ createComponent(field).innerText }}
18
- </component>
19
- <div v-else-if="createComponent(field).type == 'v-slider'">
20
- <p class="formkit-label">{{ field.label }}</p>
21
- <component
22
- :is="createComponent(field).type"
23
- v-bind="createComponent(field).props"
24
- v-model="field.defaultValue"
25
- />
26
- <p class="formkit-help">
27
- {{ field.customForm ? JSON.parse(field.customForm).hint : undefined }}
28
- </p>
2
+ <!-- Component must be wrapped in a block so props such as className and style can be passed in from parent -->
3
+ <div className="ui-dynamic-form-wrapper">
4
+ <p v-if="hasFields()">
5
+ <v-form ref="form" v-model="form" :class="dynamicClass">
6
+ <h3 style="padding: 16px">{{ props.name }}</h3>
7
+ <div style="padding: 16px; max-height: 550px; overflow-y: auto">
8
+ <FormKit id="form" type="group">
9
+ <v-row v-for="(field, index) in fields()" :key="field">
10
+ <v-col cols="12">
11
+ <component
12
+ :is="createComponent(field).type"
13
+ v-if="createComponent(field).innerText"
14
+ v-bind="createComponent(field).props"
15
+ v-model="formData[field.id]"
16
+ >
17
+ {{ createComponent(field).innerText }}
18
+ </component>
19
+ <div v-else-if="createComponent(field).type == 'v-slider'">
20
+ <p class="formkit-label">{{ field.label }}</p>
21
+ <component
22
+ :is="createComponent(field).type"
23
+ v-bind="createComponent(field).props"
24
+ v-model="field.defaultValue"
25
+ />
26
+ <p class="formkit-help">
27
+ {{ field.customForm ? JSON.parse(field.customForm).hint : undefined }}
28
+ </p>
29
+ </div>
30
+ <component
31
+ :is="createComponent(field).type"
32
+ v-else
33
+ v-bind="createComponent(field).props"
34
+ v-model="formData[field.id]"
35
+ />
36
+ </v-col>
37
+ </v-row>
38
+ </FormKit>
29
39
  </div>
30
- <component
31
- v-else
32
- :is="createComponent(field).type"
33
- v-bind="createComponent(field).props"
34
- v-model="formData[field.id]"
35
- />
36
- </v-col>
37
- </v-row>
38
- </FormKit>
39
- </div>
40
- <v-row :class="dynamicFooterClass">
41
- <v-row v-if="error" style="padding: 12px">
42
- <v-alert v-if="error" type="error">Error: {{ errorMsg }}</v-alert>
43
- </v-row>
44
- <div style="display: flex; gap: 8px">
45
- <div v-for="(action, index) in actions" :key="index" style="flex-grow: 1">
46
- <v-btn :key="index" style="width: 100% !important; min-height: 36px" @click="actionFn(action)">
47
- {{ action.label }}
48
- </v-btn>
49
- </div>
50
- </div>
51
- </v-row>
52
- </v-form>
53
- </p>
54
- <p v-else>
55
- <v-alert :text="waiting_info" :title="waiting_title" />
56
- </p>
57
- </div>
40
+ <v-row :class="dynamicFooterClass">
41
+ <v-row v-if="error" style="padding: 12px">
42
+ <v-alert v-if="error" type="error">Error: {{ errorMsg }}</v-alert>
43
+ </v-row>
44
+ <div style="display: flex; gap: 8px">
45
+ <div v-for="(action, index) in actions" :key="index" style="flex-grow: 1">
46
+ <v-btn :key="index" style="width: 100% !important; min-height: 36px" @click="actionFn(action)">
47
+ {{ action.label }}
48
+ </v-btn>
49
+ </div>
50
+ </div>
51
+ </v-row>
52
+ </v-form>
53
+ </p>
54
+ <p v-else>
55
+ <v-alert :text="waiting_info" :title="waiting_title" />
56
+ </p>
57
+ </div>
58
58
  </template>
59
59
 
60
60
  <script>
61
- import { markRaw, h, getCurrentInstance } from 'vue';
62
- import { mapState } from 'vuex';
63
- import { plugin, defaultConfig } from '@formkit/vue';
64
- import '@formkit/themes/genesis';
65
- import { FormKit } from '@formkit/vue';
66
- import { getNode } from '@formkit/core';
61
+ import { FormKit, defaultConfig, plugin } from '@formkit/vue'
62
+ import { getCurrentInstance, h, markRaw } from 'vue'
63
+ import { mapState } from 'vuex'
64
+ import '@formkit/themes/genesis'
65
+ import { getNode } from '@formkit/core'
67
66
 
68
67
  export default {
69
- name: 'UIDynamicForm',
70
- inject: ['$socket'],
71
- props: {
68
+ name: 'UIDynamicForm',
69
+ inject: ['$socket'],
70
+ props: {
72
71
  /* do not remove entries from this - Dashboard's Layout Manager's will pass this data to your component */
73
- id: { type: String, required: true },
74
- props: { type: Object, default: () => ({}) },
75
- state: {
76
- type: Object,
77
- default: () => ({ enabled: false, visible: false }),
72
+ id: { type: String, required: true },
73
+ props: { type: Object, default: () => ({}) },
74
+ state: {
75
+ type: Object,
76
+ default: () => ({ enabled: false, visible: false })
77
+ }
78
+ },
79
+ setup (props) {
80
+ console.info('UIDynamicForm setup with:', props)
81
+ console.debug('Vue function loaded correctly', markRaw)
82
+ const instance = getCurrentInstance()
83
+ const app = instance.appContext.app
84
+ const formkitConfig = defaultConfig({
85
+ theme: 'genesis'
86
+ })
87
+ app.use(plugin, formkitConfig)
78
88
  },
79
- },
80
- setup(props) {
81
- console.info('UIDynamicForm setup with:', props);
82
- console.debug('Vue function loaded correctly', markRaw);
83
- const instance = getCurrentInstance();
84
- const app = instance.appContext.app;
85
- const formkitConfig = defaultConfig({
86
- theme: 'genesis',
87
- });
88
- app.use(plugin, formkitConfig);
89
- },
90
- data() {
91
- return {
92
- actions: [],
93
- form: {},
94
- formData: {},
95
- taskInput: {},
96
- theme: '',
97
- error: false,
98
- errorMsg: '',
99
- };
100
- },
101
- created() {
102
- const currentPath = window.location.pathname;
103
- const lastPart = currentPath.substring(currentPath.lastIndexOf('/'));
89
+ data () {
90
+ return {
91
+ actions: [],
92
+ form: {},
93
+ formData: {},
94
+ taskInput: {},
95
+ theme: '',
96
+ error: false,
97
+ errorMsg: ''
98
+ }
99
+ },
100
+ created () {
101
+ const currentPath = window.location.pathname
102
+ const lastPart = currentPath.substring(currentPath.lastIndexOf('/'))
104
103
 
105
- const store = this.$store.state;
104
+ const store = this.$store.state
106
105
 
107
- for (let key in store.ui.pages) {
108
- if (store.ui.pages[key].path === lastPart) {
109
- const theme = store.ui.pages[key].theme;
110
- if (store.ui.themes[theme].name === 'ProcessCube Lightmode') {
111
- this.theme = 'light';
112
- } else if (store.ui.themes[theme].name === 'ProcessCube Darkmode') {
113
- this.theme = 'dark';
114
- } else {
115
- this.theme = 'default';
106
+ for (const key in store.ui.pages) {
107
+ if (store.ui.pages[key].path === lastPart) {
108
+ const theme = store.ui.pages[key].theme
109
+ if (store.ui.themes[theme].name === 'ProcessCube Lightmode') {
110
+ this.theme = 'light'
111
+ } else if (store.ui.themes[theme].name === 'ProcessCube Darkmode') {
112
+ this.theme = 'dark'
113
+ } else {
114
+ this.theme = 'default'
115
+ }
116
+ break
117
+ }
116
118
  }
117
- break;
118
- }
119
- }
120
- },
121
- computed: {
122
- ...mapState('data', ['messages']),
123
- waiting_title() {
124
- return this.props.waiting_title || 'Warten auf den Usertask...';
125
119
  },
126
- waiting_info() {
127
- return (
128
- this.props.waiting_info ||
120
+ computed: {
121
+ ...mapState('data', ['messages']),
122
+ waiting_title () {
123
+ return this.props.waiting_title || 'Warten auf den Usertask...'
124
+ },
125
+ waiting_info () {
126
+ return (
127
+ this.props.waiting_info ||
129
128
  'Der Usertask wird automatisch angezeigt, wenn ein entsprechender Task vorhanden ist.'
130
- );
131
- },
129
+ )
130
+ },
132
131
 
133
- dynamicClass() {
134
- return `ui-dynamic-form-${this.theme}`;
135
- },
132
+ dynamicClass () {
133
+ return `ui-dynamic-form-${this.theme}`
134
+ },
136
135
 
137
- dynamicFooterClass() {
138
- return `ui-dynamic-form-footer-${this.theme}`;
136
+ dynamicFooterClass () {
137
+ return `ui-dynamic-form-footer-${this.theme}`
138
+ }
139
139
  },
140
- },
141
- mounted() {
142
- const elements = document.querySelectorAll('.formkit-input');
140
+ mounted () {
141
+ const elements = document.querySelectorAll('.formkit-input')
143
142
 
144
- elements.forEach((element) => {
145
- element.classList.add('test');
146
- });
143
+ elements.forEach((element) => {
144
+ element.classList.add('test')
145
+ })
147
146
 
148
- this.$socket.on('widget-load:' + this.id, (msg) => {
149
- this.init();
150
- this.$store.commit('data/bind', {
151
- widgetId: this.id,
152
- msg,
153
- });
154
- });
155
- this.$socket.on('msg-input:' + this.id, (msg) => {
156
- // store the latest message in our client-side vuex store when we receive a new message
157
- this.init();
147
+ this.$socket.on('widget-load:' + this.id, (msg) => {
148
+ this.init()
149
+ this.$store.commit('data/bind', {
150
+ widgetId: this.id,
151
+ msg
152
+ })
153
+ })
154
+ this.$socket.on('msg-input:' + this.id, (msg) => {
155
+ // store the latest message in our client-side vuex store when we receive a new message
156
+ this.init()
158
157
 
159
- this.messages[this.id] = msg;
158
+ this.messages[this.id] = msg
160
159
 
161
- const hasTask = msg.payload && msg.payload.userTask;
162
- const defaultValues = msg.payload.userTask.userTaskConfig.formFields;
163
- const initialValues = msg.payload.userTask.startToken;
160
+ const hasTask = msg.payload && msg.payload.userTask
161
+ const defaultValues = msg.payload.userTask.userTaskConfig.formFields
162
+ const initialValues = msg.payload.userTask.startToken
164
163
 
165
- if (hasTask) {
166
- this.taskInput = msg.payload.userTask;
167
- }
164
+ if (hasTask) {
165
+ this.taskInput = msg.payload.userTask
166
+ }
168
167
 
169
- if (hasTask && defaultValues) {
170
- defaultValues.forEach((field) => {
171
- this.formData[field.id] = field.defaultValue;
172
- });
173
- }
168
+ if (hasTask && defaultValues) {
169
+ defaultValues.forEach((field) => {
170
+ this.formData[field.id] = field.defaultValue
171
+ })
172
+ }
174
173
 
175
- if (hasTask && initialValues) {
176
- Object.keys(initialValues).forEach((key) => {
177
- this.formData[key] = initialValues[key];
178
- });
179
- }
174
+ if (hasTask && initialValues) {
175
+ Object.keys(initialValues).forEach((key) => {
176
+ this.formData[key] = initialValues[key]
177
+ })
178
+ }
180
179
 
181
- this.$store.commit('data/bind', {
182
- widgetId: this.id,
183
- msg,
184
- });
185
- });
186
- // tell Node-RED that we're loading a new instance of this widget
187
- this.$socket.emit('widget-load', this.id);
188
- },
189
- unmounted() {
180
+ this.$store.commit('data/bind', {
181
+ widgetId: this.id,
182
+ msg
183
+ })
184
+ })
185
+ // tell Node-RED that we're loading a new instance of this widget
186
+ this.$socket.emit('widget-load', this.id)
187
+ },
188
+ unmounted () {
190
189
  /* Make sure, any events you subscribe to on SocketIO are unsubscribed to here */
191
- this.$socket?.off('widget-load' + this.id);
192
- this.$socket?.off('msg-input:' + this.id);
193
- },
194
- components: {
195
- FormKit,
196
- },
197
- methods: {
198
- createComponent(field) {
199
- const hint = field.customForm ? JSON.parse(field.customForm).hint : undefined;
200
- const placeholder = field.customForm ? JSON.parse(field.customForm).placeholder : undefined;
201
- const validation = field.customForm ? JSON.parse(field.customForm).validation : undefined;
202
- const name = field.id;
203
-
204
- switch (field.type) {
205
- case 'long':
206
- return {
207
- type: 'FormKit',
208
- props: {
209
- type: 'number',
210
- id: field.id,
211
- name: name,
212
- label: field.label,
213
- required: field.required,
214
- value: field.defaultValue,
215
- number: 'integer',
216
- help: hint,
217
- wrapperClass: '$remove:formkit-wrapper',
218
- inputClass: `input-${this.theme}`,
219
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
220
- validation: validation,
221
- validationVisibility: 'live',
222
- },
223
- };
224
- case 'number':
225
- const step = field.customForm ? JSON.parse(field.customForm).step : undefined;
226
- return {
227
- type: 'FormKit',
228
- props: {
229
- type: 'number',
230
- id: field.id,
231
- name: name,
232
- label: field.label,
233
- required: field.required,
234
- value: field.defaultValue,
235
- step: step,
236
- help: hint,
237
- wrapperClass: '$remove:formkit-wrapper',
238
- inputClass: `input-${this.theme}`,
239
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
240
- validation: validation,
241
- validationVisibility: 'live',
242
- },
243
- };
244
- case 'date':
245
- return {
246
- type: 'FormKit',
247
- props: {
248
- type: 'date',
249
- id: field.id,
250
- name: name,
251
- label: field.label,
252
- required: field.required,
253
- value: field.defaultValue,
254
- help: hint,
255
- wrapperClass: '$remove:formkit-wrapper',
256
- inputClass: `input-${this.theme}`,
257
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
258
- validation: validation,
259
- validationVisibility: 'live',
260
- },
261
- };
262
- case 'enum':
263
- const enums = field.enumValues.map((obj) => {
264
- return { value: obj.id, label: obj.name };
265
- });
266
- return {
267
- type: 'FormKit',
268
- props: {
269
- type: 'select', // JSON.parse(field.customForm).displayAs
270
- id: field.id,
271
- name: name,
272
- label: field.label,
273
- required: field.required,
274
- value: field.defaultValue,
275
- options: enums,
276
- help: hint,
277
- wrapperClass: '$remove:formkit-wrapper',
278
- inputClass: `input-${this.theme}`,
279
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
280
- validation: validation,
281
- validationVisibility: 'live',
282
- },
283
- };
284
- case 'select':
285
- const selections = JSON.parse(field.customForm).entries.map((obj) => {
286
- return { value: obj.key, label: obj.value };
287
- });
288
- return {
289
- type: 'FormKit',
290
- props: {
291
- type: 'select', // JSON.parse(field.customForm).displayAs
292
- id: field.id,
293
- name: name,
294
- label: field.label,
295
- required: field.required,
296
- value: field.defaultValue,
297
- options: selections,
298
- placeholder: placeholder,
299
- help: hint,
300
- wrapperClass: '$remove:formkit-wrapper',
301
- inputClass: `input-${this.theme}`,
302
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
303
- validation: validation,
304
- validationVisibility: 'live',
305
- },
306
- };
307
- case 'string':
308
- return {
309
- type: 'FormKit',
310
- props: {
311
- type: 'text',
312
- id: field.id,
313
- name: name,
314
- label: field.label,
315
- required: field.required,
316
- value: field.defaultValue,
317
- help: hint,
318
- placeholder: placeholder,
319
- wrapperClass: '$remove:formkit-wrapper',
320
- inputClass: `input-${this.theme}`,
321
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
322
- validation: validation,
323
- validationVisibility: 'live',
324
- },
325
- };
326
- case 'boolean':
327
- return {
328
- type: 'FormKit',
329
- props: {
330
- type: 'checkbox',
331
- id: field.id,
332
- name: name,
333
- label: field.label,
334
- required: field.required,
335
- value: field.defaultValue,
336
- help: hint,
337
- inputClass: `input-${this.theme}`,
338
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
339
- validation: validation,
340
- validationVisibility: 'live',
341
- },
342
- };
343
- case 'file':
344
- return {
345
- type: 'FormKit',
346
- props: {
347
- type: 'file',
348
- id: field.id,
349
- name: name,
350
- label: field.label,
351
- required: field.required,
352
- value: field.defaultValue,
353
- help: hint,
354
- innerClass: 'reset-background',
355
- wrapperClass: '$remove:formkit-wrapper',
356
- inputClass: `input-${this.theme}`,
357
- // innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
358
- validation: validation,
359
- validationVisibility: 'live',
360
- },
361
- };
362
- case 'checkbox':
363
- const options = JSON.parse(field.customForm).entries.map((obj) => {
364
- return { value: obj.key, label: obj.value };
365
- });
366
- return {
367
- type: 'FormKit',
368
- props: {
369
- type: 'checkbox',
370
- id: field.id,
371
- name: name,
372
- label: field.label,
373
- required: field.required,
374
- value: field.defaultValue,
375
- options: options,
376
- help: hint,
377
- fieldsetClass: 'custom-fieldset',
378
- inputClass: `input-${this.theme}`,
379
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
380
- validation: validation,
381
- validationVisibility: 'live',
382
- },
383
- };
384
- case 'color':
385
- return {
386
- type: 'FormKit',
387
- props: {
388
- type: 'color',
389
- id: field.id,
390
- name: name,
391
- label: field.label,
392
- required: field.required,
393
- value: field.defaultValue,
394
- help: hint,
395
- validation: validation,
396
- validationVisibility: 'live',
397
- },
398
- };
399
- case 'datetime-local':
400
- return {
401
- type: 'FormKit',
402
- props: {
403
- type: 'datetime-local',
404
- id: field.id,
405
- name: name,
406
- label: field.label,
407
- required: field.required,
408
- value: field.defaultValue,
409
- help: hint,
410
- wrapperClass: '$remove:formkit-wrapper',
411
- inputClass: `input-${this.theme}`,
412
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
413
- validation: validation,
414
- validationVisibility: 'live',
415
- },
416
- };
417
- case 'email':
418
- return {
419
- type: 'FormKit',
420
- props: {
421
- type: 'email',
422
- id: field.id,
423
- name: name,
424
- label: field.label,
425
- required: field.required,
426
- value: field.defaultValue,
427
- help: hint,
428
- validation: 'email',
429
- validationVisibility: 'live',
430
- placeholder: placeholder,
431
- wrapperClass: '$remove:formkit-wrapper',
432
- inputClass: `input-${this.theme}`,
433
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
434
- validation: validation,
435
- validationVisibility: 'live',
436
- },
437
- };
438
- case 'header':
439
- let typeToUse = 'h1';
440
- if (field.customForm && JSON.parse(field.customForm).style == 'heading_2') {
441
- typeToUse = 'h2';
442
- }
443
- if (field.customForm && JSON.parse(field.customForm).style == 'heading_3') {
444
- typeToUse = 'h3';
445
- }
446
- return {
447
- type: typeToUse,
448
- innerText: field.defaultValue,
449
- };
450
- case 'hidden':
451
- return {
452
- type: 'input',
453
- props: {
454
- type: 'hidden',
455
- value: field.defaultValue,
456
- },
457
- };
458
- case 'month':
459
- return {
460
- type: 'FormKit',
461
- props: {
462
- type: 'month',
463
- id: field.id,
464
- name: name,
465
- label: field.label,
466
- required: field.required,
467
- value: field.defaultValue,
468
- help: hint,
469
- wrapperClass: '$remove:formkit-wrapper',
470
- inputClass: `input-${this.theme}`,
471
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
472
- validation: validation,
473
- validationVisibility: 'live',
474
- },
475
- };
476
- case 'paragraph':
477
- return {
478
- type: 'p',
479
- innerText: field.defaultValue,
480
- };
481
- case 'password':
482
- return {
483
- type: 'FormKit',
484
- props: {
485
- type: 'password',
486
- id: field.id,
487
- name: name,
488
- label: field.label,
489
- required: field.required,
490
- value: field.defaultValue,
491
- help: hint,
492
- placeholder: placeholder,
493
- wrapperClass: '$remove:formkit-wrapper',
494
- inputClass: `input-${this.theme}`,
495
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
496
- validation: validation,
497
- validationVisibility: 'live',
498
- },
499
- };
500
- case 'radio':
501
- const radioOptions = JSON.parse(field.customForm).entries.map((obj) => {
502
- return { value: obj.key, label: obj.value };
503
- });
504
- return {
505
- type: 'FormKit',
506
- props: {
507
- type: 'radio',
508
- id: field.id,
509
- name: name,
510
- label: field.label,
511
- required: field.required,
512
- value: field.defaultValue,
513
- options: radioOptions,
514
- help: hint,
515
- fieldsetClass: 'custom-fieldset',
516
- inputClass: `input-${this.theme}`,
517
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
518
- validation: validation,
519
- validationVisibility: 'live',
520
- },
521
- };
522
- case 'range':
523
- const customForm = JSON.parse(field.customForm);
524
- return {
525
- type: 'v-slider',
526
- props: {
527
- id: field.id,
528
- name: name,
529
- // label: field.label,
530
- required: field.required,
531
- // value: field.defaultValue,
532
- // help: hint,
533
- min: customForm.min,
534
- max: customForm.max,
535
- step: customForm.step,
536
- thumbLabel: true,
537
- // wrapperClass: '$remove:formkit-wrapper',
538
- // inputClass: `input-${this.theme}`,
539
- // innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
540
- validation: validation,
541
- validationVisibility: 'live',
542
- },
543
- };
544
- case 'tel':
545
- return {
546
- type: 'FormKit',
547
- props: {
548
- type: 'tel' /* with pro component mask more good */,
549
- id: field.id,
550
- name: name,
551
- label: field.label,
552
- required: field.required,
553
- value: field.defaultValue,
554
- help: hint,
555
- placeholder: placeholder,
556
- wrapperClass: '$remove:formkit-wrapper',
557
- inputClass: `input-${this.theme}`,
558
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
559
- validation: validation,
560
- validationVisibility: 'live',
561
- },
562
- };
563
- case 'textarea':
564
- const rows = field.customForm ? JSON.parse(field.customForm).rows : undefined;
565
- return {
566
- type: 'FormKit',
567
- props: {
568
- type: 'textarea' /* with pro component mask more good */,
569
- id: field.id,
570
- name: name,
571
- label: field.label,
572
- required: field.required,
573
- value: field.defaultValue,
574
- rows: rows,
575
- help: hint,
576
- placeholder: placeholder,
577
- wrapperClass: '$remove:formkit-wrapper',
578
- inputClass: `input-${this.theme}`,
579
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
580
- validation: validation,
581
- validationVisibility: 'live',
582
- },
583
- };
584
- case 'time':
585
- return {
586
- type: 'FormKit',
587
- props: {
588
- type: 'time' /* with pro component mask more good */,
589
- id: field.id,
590
- name: name,
591
- label: field.label,
592
- required: field.required,
593
- value: field.defaultValue,
594
- help: hint,
595
- placeholder: placeholder,
596
- wrapperClass: '$remove:formkit-wrapper',
597
- inputClass: `input-${this.theme}`,
598
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
599
- validation: validation,
600
- validationVisibility: 'live',
601
- },
602
- };
603
- case 'url':
604
- return {
605
- type: 'FormKit',
606
- props: {
607
- type: 'url',
608
- id: field.id,
609
- name: name,
610
- label: field.label,
611
- required: field.required,
612
- value: field.defaultValue,
613
- help: hint,
614
- placeholder: placeholder,
615
- validation: 'url',
616
- validationVisibility: 'live',
617
- wrapperClass: '$remove:formkit-wrapper',
618
- inputClass: `input-${this.theme}`,
619
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
620
- validation: validation,
621
- validationVisibility: 'live',
622
- },
623
- };
624
- case 'week':
625
- return {
626
- type: 'FormKit',
627
- props: {
628
- type: 'week',
629
- id: field.id,
630
- name: name,
631
- label: field.label,
632
- required: field.required,
633
- value: field.defaultValue,
634
- help: hint,
635
- placeholder: placeholder,
636
- wrapperClass: '$remove:formkit-wrapper',
637
- inputClass: `input-${this.theme}`,
638
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
639
- validation: validation,
640
- validationVisibility: 'live',
641
- },
642
- };
643
- default:
644
- return {
645
- type: 'FormKit',
646
- props: {
647
- type: field.type,
648
- id: field.id,
649
- name: name,
650
- label: field.label,
651
- required: field.required,
652
- value: field.defaultValue,
653
- help: hint,
654
- inputClass: `input-${this.theme}`,
655
- innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
656
- validation: validation,
657
- validationVisibility: 'live',
658
- },
659
- };
660
- }
190
+ this.$socket?.off('widget-load' + this.id)
191
+ this.$socket?.off('msg-input:' + this.id)
661
192
  },
662
- checkFormState(state) {
663
- // const field = this.$formkit.get('field_01');
664
- // console.info(field.context.state.valid);
193
+ components: {
194
+ FormKit
195
+ },
196
+ methods: {
197
+ createComponent (field) {
198
+ const hint = field.customForm ? JSON.parse(field.customForm).hint : undefined
199
+ const placeholder = field.customForm ? JSON.parse(field.customForm).placeholder : undefined
200
+ const validation = field.customForm ? JSON.parse(field.customForm).validation : undefined
201
+ const name = field.id
665
202
 
666
- return true;
203
+ switch (field.type) {
204
+ case 'long':
205
+ return {
206
+ type: 'FormKit',
207
+ props: {
208
+ type: 'number',
209
+ id: field.id,
210
+ name,
211
+ label: field.label,
212
+ required: field.required,
213
+ value: field.defaultValue,
214
+ number: 'integer',
215
+ help: hint,
216
+ wrapperClass: '$remove:formkit-wrapper',
217
+ inputClass: `input-${this.theme}`,
218
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
219
+ validation,
220
+ validationVisibility: 'live'
221
+ }
222
+ }
223
+ case 'number':
224
+ const step = field.customForm ? JSON.parse(field.customForm).step : undefined
225
+ return {
226
+ type: 'FormKit',
227
+ props: {
228
+ type: 'number',
229
+ id: field.id,
230
+ name,
231
+ label: field.label,
232
+ required: field.required,
233
+ value: field.defaultValue,
234
+ step,
235
+ help: hint,
236
+ wrapperClass: '$remove:formkit-wrapper',
237
+ inputClass: `input-${this.theme}`,
238
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
239
+ validation,
240
+ validationVisibility: 'live'
241
+ }
242
+ }
243
+ case 'date':
244
+ return {
245
+ type: 'FormKit',
246
+ props: {
247
+ type: 'date',
248
+ id: field.id,
249
+ name,
250
+ label: field.label,
251
+ required: field.required,
252
+ value: field.defaultValue,
253
+ help: hint,
254
+ wrapperClass: '$remove:formkit-wrapper',
255
+ inputClass: `input-${this.theme}`,
256
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
257
+ validation,
258
+ validationVisibility: 'live'
259
+ }
260
+ }
261
+ case 'enum':
262
+ const enums = field.enumValues.map((obj) => {
263
+ return { value: obj.id, label: obj.name }
264
+ })
265
+ return {
266
+ type: 'FormKit',
267
+ props: {
268
+ type: 'select', // JSON.parse(field.customForm).displayAs
269
+ id: field.id,
270
+ name,
271
+ label: field.label,
272
+ required: field.required,
273
+ value: field.defaultValue,
274
+ options: enums,
275
+ help: hint,
276
+ wrapperClass: '$remove:formkit-wrapper',
277
+ inputClass: `input-${this.theme}`,
278
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
279
+ validation,
280
+ validationVisibility: 'live'
281
+ }
282
+ }
283
+ case 'select':
284
+ const selections = JSON.parse(field.customForm).entries.map((obj) => {
285
+ return { value: obj.key, label: obj.value }
286
+ })
287
+ return {
288
+ type: 'FormKit',
289
+ props: {
290
+ type: 'select', // JSON.parse(field.customForm).displayAs
291
+ id: field.id,
292
+ name,
293
+ label: field.label,
294
+ required: field.required,
295
+ value: field.defaultValue,
296
+ options: selections,
297
+ placeholder,
298
+ help: hint,
299
+ wrapperClass: '$remove:formkit-wrapper',
300
+ inputClass: `input-${this.theme}`,
301
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
302
+ validation,
303
+ validationVisibility: 'live'
304
+ }
305
+ }
306
+ case 'string':
307
+ return {
308
+ type: 'FormKit',
309
+ props: {
310
+ type: 'text',
311
+ id: field.id,
312
+ name,
313
+ label: field.label,
314
+ required: field.required,
315
+ value: field.defaultValue,
316
+ help: hint,
317
+ placeholder,
318
+ wrapperClass: '$remove:formkit-wrapper',
319
+ inputClass: `input-${this.theme}`,
320
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
321
+ validation,
322
+ validationVisibility: 'live'
323
+ }
324
+ }
325
+ case 'boolean':
326
+ return {
327
+ type: 'FormKit',
328
+ props: {
329
+ type: 'checkbox',
330
+ id: field.id,
331
+ name,
332
+ label: field.label,
333
+ required: field.required,
334
+ value: field.defaultValue,
335
+ help: hint,
336
+ inputClass: `input-${this.theme}`,
337
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
338
+ validation,
339
+ validationVisibility: 'live'
340
+ }
341
+ }
342
+ case 'file':
343
+ return {
344
+ type: 'FormKit',
345
+ props: {
346
+ type: 'file',
347
+ id: field.id,
348
+ name,
349
+ label: field.label,
350
+ required: field.required,
351
+ value: field.defaultValue,
352
+ help: hint,
353
+ innerClass: 'reset-background',
354
+ wrapperClass: '$remove:formkit-wrapper',
355
+ inputClass: `input-${this.theme}`,
356
+ // innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
357
+ validation,
358
+ validationVisibility: 'live'
359
+ }
360
+ }
361
+ case 'checkbox':
362
+ const options = JSON.parse(field.customForm).entries.map((obj) => {
363
+ return { value: obj.key, label: obj.value }
364
+ })
365
+ return {
366
+ type: 'FormKit',
367
+ props: {
368
+ type: 'checkbox',
369
+ id: field.id,
370
+ name,
371
+ label: field.label,
372
+ required: field.required,
373
+ value: field.defaultValue,
374
+ options,
375
+ help: hint,
376
+ fieldsetClass: 'custom-fieldset',
377
+ inputClass: `input-${this.theme}`,
378
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
379
+ validation,
380
+ validationVisibility: 'live'
381
+ }
382
+ }
383
+ case 'color':
384
+ return {
385
+ type: 'FormKit',
386
+ props: {
387
+ type: 'color',
388
+ id: field.id,
389
+ name,
390
+ label: field.label,
391
+ required: field.required,
392
+ value: field.defaultValue,
393
+ help: hint,
394
+ validation,
395
+ validationVisibility: 'live'
396
+ }
397
+ }
398
+ case 'datetime-local':
399
+ return {
400
+ type: 'FormKit',
401
+ props: {
402
+ type: 'datetime-local',
403
+ id: field.id,
404
+ name,
405
+ label: field.label,
406
+ required: field.required,
407
+ value: field.defaultValue,
408
+ help: hint,
409
+ wrapperClass: '$remove:formkit-wrapper',
410
+ inputClass: `input-${this.theme}`,
411
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
412
+ validation,
413
+ validationVisibility: 'live'
414
+ }
415
+ }
416
+ case 'email':
417
+ return {
418
+ type: 'FormKit',
419
+ props: {
420
+ type: 'email',
421
+ id: field.id,
422
+ name,
423
+ label: field.label,
424
+ required: field.required,
425
+ value: field.defaultValue,
426
+ help: hint,
427
+ validation: 'email',
428
+ validationVisibility: 'live',
429
+ placeholder,
430
+ wrapperClass: '$remove:formkit-wrapper',
431
+ inputClass: `input-${this.theme}`,
432
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
433
+ validation,
434
+ validationVisibility: 'live'
435
+ }
436
+ }
437
+ case 'header':
438
+ let typeToUse = 'h1'
439
+ if (field.customForm && JSON.parse(field.customForm).style == 'heading_2') {
440
+ typeToUse = 'h2'
441
+ }
442
+ if (field.customForm && JSON.parse(field.customForm).style == 'heading_3') {
443
+ typeToUse = 'h3'
444
+ }
445
+ return {
446
+ type: typeToUse,
447
+ innerText: field.defaultValue
448
+ }
449
+ case 'hidden':
450
+ return {
451
+ type: 'input',
452
+ props: {
453
+ type: 'hidden',
454
+ value: field.defaultValue
455
+ }
456
+ }
457
+ case 'month':
458
+ return {
459
+ type: 'FormKit',
460
+ props: {
461
+ type: 'month',
462
+ id: field.id,
463
+ name,
464
+ label: field.label,
465
+ required: field.required,
466
+ value: field.defaultValue,
467
+ help: hint,
468
+ wrapperClass: '$remove:formkit-wrapper',
469
+ inputClass: `input-${this.theme}`,
470
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
471
+ validation,
472
+ validationVisibility: 'live'
473
+ }
474
+ }
475
+ case 'paragraph':
476
+ return {
477
+ type: 'p',
478
+ innerText: field.defaultValue
479
+ }
480
+ case 'password':
481
+ return {
482
+ type: 'FormKit',
483
+ props: {
484
+ type: 'password',
485
+ id: field.id,
486
+ name,
487
+ label: field.label,
488
+ required: field.required,
489
+ value: field.defaultValue,
490
+ help: hint,
491
+ placeholder,
492
+ wrapperClass: '$remove:formkit-wrapper',
493
+ inputClass: `input-${this.theme}`,
494
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
495
+ validation,
496
+ validationVisibility: 'live'
497
+ }
498
+ }
499
+ case 'radio':
500
+ const radioOptions = JSON.parse(field.customForm).entries.map((obj) => {
501
+ return { value: obj.key, label: obj.value }
502
+ })
503
+ return {
504
+ type: 'FormKit',
505
+ props: {
506
+ type: 'radio',
507
+ id: field.id,
508
+ name,
509
+ label: field.label,
510
+ required: field.required,
511
+ value: field.defaultValue,
512
+ options: radioOptions,
513
+ help: hint,
514
+ fieldsetClass: 'custom-fieldset',
515
+ inputClass: `input-${this.theme}`,
516
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
517
+ validation,
518
+ validationVisibility: 'live'
519
+ }
520
+ }
521
+ case 'range':
522
+ const customForm = JSON.parse(field.customForm)
523
+ return {
524
+ type: 'v-slider',
525
+ props: {
526
+ id: field.id,
527
+ name,
528
+ // label: field.label,
529
+ required: field.required,
530
+ // value: field.defaultValue,
531
+ // help: hint,
532
+ min: customForm.min,
533
+ max: customForm.max,
534
+ step: customForm.step,
535
+ thumbLabel: true,
536
+ // wrapperClass: '$remove:formkit-wrapper',
537
+ // inputClass: `input-${this.theme}`,
538
+ // innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
539
+ validation,
540
+ validationVisibility: 'live'
541
+ }
542
+ }
543
+ case 'tel':
544
+ return {
545
+ type: 'FormKit',
546
+ props: {
547
+ type: 'tel' /* with pro component mask more good */,
548
+ id: field.id,
549
+ name,
550
+ label: field.label,
551
+ required: field.required,
552
+ value: field.defaultValue,
553
+ help: hint,
554
+ placeholder,
555
+ wrapperClass: '$remove:formkit-wrapper',
556
+ inputClass: `input-${this.theme}`,
557
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
558
+ validation,
559
+ validationVisibility: 'live'
560
+ }
561
+ }
562
+ case 'textarea':
563
+ const rows = field.customForm ? JSON.parse(field.customForm).rows : undefined
564
+ return {
565
+ type: 'FormKit',
566
+ props: {
567
+ type: 'textarea' /* with pro component mask more good */,
568
+ id: field.id,
569
+ name,
570
+ label: field.label,
571
+ required: field.required,
572
+ value: field.defaultValue,
573
+ rows,
574
+ help: hint,
575
+ placeholder,
576
+ wrapperClass: '$remove:formkit-wrapper',
577
+ inputClass: `input-${this.theme}`,
578
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
579
+ validation,
580
+ validationVisibility: 'live'
581
+ }
582
+ }
583
+ case 'time':
584
+ return {
585
+ type: 'FormKit',
586
+ props: {
587
+ type: 'time' /* with pro component mask more good */,
588
+ id: field.id,
589
+ name,
590
+ label: field.label,
591
+ required: field.required,
592
+ value: field.defaultValue,
593
+ help: hint,
594
+ placeholder,
595
+ wrapperClass: '$remove:formkit-wrapper',
596
+ inputClass: `input-${this.theme}`,
597
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
598
+ validation,
599
+ validationVisibility: 'live'
600
+ }
601
+ }
602
+ case 'url':
603
+ return {
604
+ type: 'FormKit',
605
+ props: {
606
+ type: 'url',
607
+ id: field.id,
608
+ name,
609
+ label: field.label,
610
+ required: field.required,
611
+ value: field.defaultValue,
612
+ help: hint,
613
+ placeholder,
614
+ validation: 'url',
615
+ validationVisibility: 'live',
616
+ wrapperClass: '$remove:formkit-wrapper',
617
+ inputClass: `input-${this.theme}`,
618
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
619
+ validation,
620
+ validationVisibility: 'live'
621
+ }
622
+ }
623
+ case 'week':
624
+ return {
625
+ type: 'FormKit',
626
+ props: {
627
+ type: 'week',
628
+ id: field.id,
629
+ name,
630
+ label: field.label,
631
+ required: field.required,
632
+ value: field.defaultValue,
633
+ help: hint,
634
+ placeholder,
635
+ wrapperClass: '$remove:formkit-wrapper',
636
+ inputClass: `input-${this.theme}`,
637
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
638
+ validation,
639
+ validationVisibility: 'live'
640
+ }
641
+ }
642
+ default:
643
+ return {
644
+ type: 'FormKit',
645
+ props: {
646
+ type: field.type,
647
+ id: field.id,
648
+ name,
649
+ label: field.label,
650
+ required: field.required,
651
+ value: field.defaultValue,
652
+ help: hint,
653
+ inputClass: `input-${this.theme}`,
654
+ innerClass: `${this.theme == 'dark' ? '$remove:formkit-inner' : ''}`,
655
+ validation,
656
+ validationVisibility: 'live'
657
+ }
658
+ }
659
+ }
660
+ },
661
+ checkFormState (state) {
662
+ // const field = this.$formkit.get('field_01');
663
+ // console.info(field.context.state.valid);
667
664
 
668
- // loop over fields then this.$formkit.get(this.id) -> check error state if all ok return true else return false
669
- // ?? wie unterscheiden wir welche actions dieser validierungsfehler betrifft ??
670
- // ?? wie machen wir formkit validierung auch im Studio available ??
671
- // \_ vllt macht es sinn das schema von formkit zu übernehmen oder alternativ nur unsere validierung zu nutzen.
672
- },
673
- hasUserTask() {
674
- return this.messages && this.messages[this.id] && this.messages[this.id].payload.userTask;
675
- },
676
- userTask() {
677
- return this.hasUserTask() ? this.messages[this.id].payload.userTask : {};
678
- },
679
- fields() {
680
- const aFields = this.hasUserTask() ? this.userTask().userTaskConfig.formFields : [];
681
- const fieldMap = aFields.map((field) => ({
682
- ...field,
683
- items: mapItems(field.type, field),
684
- }));
665
+ return true
685
666
 
686
- return fieldMap;
687
- },
688
- hasFields() {
689
- return this.messages && this.messages[this.id] && this.messages[this.id].payload.userTask !== undefined;
690
- },
691
- /*
667
+ // loop over fields then this.$formkit.get(this.id) -> check error state if all ok return true else return false
668
+ // ?? wie unterscheiden wir welche actions dieser validierungsfehler betrifft ??
669
+ // ?? wie machen wir formkit validierung auch im Studio available ??
670
+ // \_ vllt macht es sinn das schema von formkit zu übernehmen oder alternativ nur unsere validierung zu nutzen.
671
+ },
672
+ hasUserTask () {
673
+ return this.messages && this.messages[this.id] && this.messages[this.id].payload.userTask
674
+ },
675
+ userTask () {
676
+ return this.hasUserTask() ? this.messages[this.id].payload.userTask : {}
677
+ },
678
+ fields () {
679
+ const aFields = this.hasUserTask() ? this.userTask().userTaskConfig.formFields : []
680
+ const fieldMap = aFields.map((field) => ({
681
+ ...field,
682
+ items: mapItems(field.type, field)
683
+ }))
684
+
685
+ return fieldMap
686
+ },
687
+ hasFields () {
688
+ return this.messages && this.messages[this.id] && this.messages[this.id].payload.userTask !== undefined
689
+ },
690
+ /*
692
691
  widget-action just sends a msg to Node-RED, it does not store the msg state server-side
693
692
  alternatively, you can use widget-change, which will also store the msg in the Node's datastore
694
693
  */
695
- send(msg, index) {
696
- const msgArr = [];
697
- msgArr[index] = msg;
698
- this.$socket.emit('widget-action', this.id, msgArr);
699
- },
700
- init() {
701
- this.actions = this.props.options;
702
- },
703
- actionFn(action) {
704
- // this.checkFormState();
694
+ send (msg, index) {
695
+ const msgArr = []
696
+ msgArr[index] = msg
697
+ this.$socket.emit('widget-action', this.id, msgArr)
698
+ },
699
+ init () {
700
+ this.actions = this.props.options
701
+ },
702
+ actionFn (action) {
703
+ // this.checkFormState();
705
704
 
706
- if (action.label === 'Speichern' || action.label === 'Speichern und nächster') {
707
- const formkitInputs = this.$refs.form.$el.querySelectorAll('.formkit-outer');
708
- let allComplete = true;
705
+ if (action.label === 'Speichern' || action.label === 'Speichern und nächster') {
706
+ const formkitInputs = this.$refs.form.$el.querySelectorAll('.formkit-outer')
707
+ let allComplete = true
709
708
 
710
- formkitInputs.forEach((input) => {
711
- const dataComplete = input.getAttribute('data-complete');
712
- const dataInvalid = input.getAttribute('data-invalid')
713
-
714
- if (dataComplete == null && dataInvalid === "true") {
715
- allComplete = false;
716
- }
717
- });
709
+ formkitInputs.forEach((input) => {
710
+ const dataComplete = input.getAttribute('data-complete')
711
+ const dataInvalid = input.getAttribute('data-invalid')
718
712
 
719
- if (!allComplete) return;
720
- }
713
+ if (dataComplete == null && dataInvalid === 'true') {
714
+ allComplete = false
715
+ }
716
+ })
721
717
 
722
- if (this.checkCondition(action.condition)) {
723
- this.showError(false, '');
724
- // TODO: MM - begin
725
- // this.send(
726
- // { payload: { formData: this.formData, userTask: this.userTask() } },
727
- // this.actions.findIndex((element) => element.label === action.label)
728
- // );
729
- const msg = this.messages[this.id] || {};
730
- msg.payload = { formData: this.formData, userTask: this.userTask() };
731
- this.send(
732
- msg,
733
- this.actions.findIndex((element) => element.label === action.label)
734
- );
735
- // TODO: mm - end
736
- } else {
737
- this.showError(true, action.errorMessage);
738
- }
739
- },
740
- checkCondition(condition) {
741
- if (condition == '') return true;
742
- try {
743
- const func = Function('fields', 'userTask', 'msg', '"use strict"; return (' + condition + ')');
744
- const result = func(this.formData, this.taskInput, this.messages[this.id]);
745
- console.log(this.formData, result);
746
- return Boolean(result);
747
- } catch (err) {
748
- console.error('Error while evaluating condition: ' + err);
749
- return false;
750
- }
751
- },
752
- showError(bool, errMsg) {
753
- this.error = bool;
754
- this.errorMsg = errMsg;
755
- },
756
- },
757
- };
718
+ if (!allComplete) return
719
+ }
758
720
 
759
- function mapItems(type, field) {
760
- if (type === 'enum') {
761
- return field.enumValues.map((enumValue) => ({
762
- title: enumValue.name,
763
- value: enumValue.id,
764
- }));
765
- } else {
766
- return null;
767
- }
721
+ if (this.checkCondition(action.condition)) {
722
+ this.showError(false, '')
723
+ // TODO: MM - begin
724
+ // this.send(
725
+ // { payload: { formData: this.formData, userTask: this.userTask() } },
726
+ // this.actions.findIndex((element) => element.label === action.label)
727
+ // );
728
+ const msg = this.messages[this.id] || {}
729
+ msg.payload = { formData: this.formData, userTask: this.userTask() }
730
+ this.send(
731
+ msg,
732
+ this.actions.findIndex((element) => element.label === action.label)
733
+ )
734
+ // TODO: mm - end
735
+ } else {
736
+ this.showError(true, action.errorMessage)
737
+ }
738
+ },
739
+ checkCondition (condition) {
740
+ if (condition == '') return true
741
+ try {
742
+ const func = Function('fields', 'userTask', 'msg', '"use strict"; return (' + condition + ')')
743
+ const result = func(this.formData, this.taskInput, this.messages[this.id])
744
+ console.log(this.formData, result)
745
+ return Boolean(result)
746
+ } catch (err) {
747
+ console.error('Error while evaluating condition: ' + err)
748
+ return false
749
+ }
750
+ },
751
+ showError (bool, errMsg) {
752
+ this.error = bool
753
+ this.errorMsg = errMsg
754
+ }
755
+ }
756
+ }
757
+
758
+ function mapItems (type, field) {
759
+ if (type === 'enum') {
760
+ return field.enumValues.map((enumValue) => ({
761
+ title: enumValue.name,
762
+ value: enumValue.id
763
+ }))
764
+ } else {
765
+ return null
766
+ }
768
767
  }
769
768
  </script>
770
769