@5minds/node-red-dashboard-2-processcube-dynamic-form 2.2.0 → 2.2.1-develop-1f198a-mfc8cyvw

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.
@@ -11,26 +11,6 @@
11
11
  {{ action.label }}
12
12
  </v-btn>
13
13
  </div>
14
- <div>
15
- <v-btn
16
- class="ui-dynamic-form-footer-action-button ui-dynamic-form-footer-action-secondary"
17
- :disabled="formIsFinished"
18
- @click="handleSuspend"
19
- >
20
- Suspend
21
- </v-btn>
22
- </div>
23
- <div>
24
- <v-btn
25
- class="ui-dynamic-form-footer-action-terminate"
26
- :disabled="formIsFinished"
27
- @click="handleTerminate"
28
- variant="text"
29
- size="small"
30
- >
31
- Terminate
32
- </v-btn>
33
- </div>
34
14
  </div>
35
15
  <div class="ui-dynamic-form-footer-actions-right">
36
16
  <div v-for="(action, index) in rightSideActions" :key="`right-${index}`">
@@ -69,8 +49,8 @@ export default {
69
49
  leftSideActions() {
70
50
  const leftActions = this.actions.filter((action) => action.alignment === 'left' || !action.alignment);
71
51
  const sortPrimaryToLeft = (a, b) => {
72
- const aPrimary = a.primary === 'true';
73
- const bPrimary = b.primary === 'true';
52
+ const aPrimary = a.primary === 'primary';
53
+ const bPrimary = b.primary === 'primary';
74
54
  if (aPrimary && !bPrimary) return -1;
75
55
  if (!aPrimary && bPrimary) return 1;
76
56
  return 0;
@@ -81,8 +61,8 @@ export default {
81
61
  rightSideActions() {
82
62
  const rightActions = this.actions.filter((action) => action.alignment === 'right');
83
63
  const sortPrimaryToRight = (a, b) => {
84
- const aPrimary = a.primary === 'true';
85
- const bPrimary = b.primary === 'true';
64
+ const aPrimary = a.primary === 'primary';
65
+ const bPrimary = b.primary === 'primary';
86
66
  if (!aPrimary && bPrimary) return -1;
87
67
  if (aPrimary && !bPrimary) return 1;
88
68
  return 0;
@@ -93,29 +73,15 @@ export default {
93
73
  },
94
74
  methods: {
95
75
  getActionButtonClass(action) {
96
- return action.primary === 'true'
97
- ? 'ui-dynamic-form-footer-action-primary'
98
- : 'ui-dynamic-form-footer-action-secondary';
99
- },
100
- handleTerminate() {
101
- const terminateAction = {
102
- label: 'Terminate',
103
- alignment: 'left',
104
- primary: 'false',
105
- isTerminate: true,
106
- };
107
-
108
- this.actionCallback(terminateAction);
109
- },
110
- handleSuspend() {
111
- const suspendAction = {
112
- label: 'Suspend',
113
- alignment: 'left',
114
- primary: 'false',
115
- isSuspend: true,
116
- };
117
-
118
- this.actionCallback(suspendAction);
76
+ switch (action.primary) {
77
+ case 'primary':
78
+ return 'ui-dynamic-form-footer-action-primary';
79
+ case 'destructive':
80
+ return 'ui-dynamic-form-footer-action-terminate';
81
+ case 'secondary':
82
+ default:
83
+ return 'ui-dynamic-form-footer-action-secondary';
84
+ }
119
85
  },
120
86
  },
121
87
  };
@@ -235,12 +235,13 @@ export default {
235
235
  return !!this.userTask;
236
236
  },
237
237
  totalOutputs() {
238
- const outputsConfirmTerminate = 2;
238
+ const confirmOutputs = this.props.handle_confirmation_dialogs
239
+ ? (this.props.confirm_actions ? this.props.confirm_actions.length : 2)
240
+ : 0;
239
241
  return (
240
242
  this.props.options.length +
241
- (this.props.handle_confirmation_dialogs ? 2 : 0) +
242
- (this.props.trigger_on_change ? 1 : 0) +
243
- outputsConfirmTerminate
243
+ confirmOutputs +
244
+ (this.props.trigger_on_change ? 1 : 0)
244
245
  );
245
246
  },
246
247
  isConfirmDialog() {
@@ -308,16 +309,12 @@ export default {
308
309
  element.classList.add('test');
309
310
  });
310
311
 
311
- this.$socket.on('widget-load:' + this.id, (msg) => {
312
- this.init(msg);
313
- });
314
312
  this.$socket.on('msg-input:' + this.id, (msg) => {
315
313
  this.init(msg);
316
314
  });
317
315
  this.$socket.emit('widget-load', this.id);
318
316
  },
319
317
  unmounted() {
320
- this.$socket?.off('widget-load' + this.id);
321
318
  this.$socket?.off('msg-input:' + this.id);
322
319
  },
323
320
  methods: {
@@ -900,6 +897,8 @@ export default {
900
897
  this.collapsed = this.props.collapse_when_finished;
901
898
  }
902
899
 
900
+ const hasConfirmField = formFields.some((field) => field.type === 'confirm');
901
+
903
902
  if (formFields) {
904
903
  formFields.forEach((field) => {
905
904
  this.formData[field.id] = field.defaultValue;
@@ -908,31 +907,63 @@ export default {
908
907
  const customForm = field.customForm ? JSON.parse(JSON.stringify(field.customForm)) : {};
909
908
  const confirmText = customForm.confirmButtonText ?? 'Confirm';
910
909
  const declineText = customForm.declineButtonText ?? 'Decline';
911
- const confirmActions = [
912
- {
913
- alignment: 'left',
914
- primary: 'true',
915
- label: confirmText,
916
- condition: '',
917
- isConfirmAction: true,
918
- confirmFieldId: field.id,
919
- confirmValue: true,
920
- },
921
- {
922
- alignment: 'left',
923
- primary: 'true',
924
- label: declineText,
925
- condition: '',
926
- isConfirmAction: true,
927
- confirmFieldId: field.id,
928
- confirmValue: false,
929
- },
930
- ];
931
- if (this.props.handle_confirmation_dialogs) {
932
- this.actions = confirmActions;
933
- } else {
934
- this.actions = [...this.actions, ...confirmActions];
910
+
911
+ const confirmActions = [
912
+ {
913
+ alignment: this.props.confirm_actions[1]?.alignment || 'left',
914
+ primary: this.props.confirm_actions[1]?.primary || 'destructive',
915
+ label: declineText,
916
+ condition: '',
917
+ isConfirmAction: true,
918
+ confirmFieldId: field.id,
919
+ confirmValue: false,
920
+ },
921
+ {
922
+ alignment: this.props.confirm_actions[0]?.alignment || 'right',
923
+ primary: this.props.confirm_actions[0]?.primary || 'primary',
924
+ label: confirmText,
925
+ condition: '',
926
+ isConfirmAction: true,
927
+ confirmFieldId: field.id,
928
+ confirmValue: true,
929
+ },
930
+ ];
931
+
932
+ const filteredActions = this.props.options.filter(action => {
933
+ if (!action.condition) return true;
934
+ try {
935
+ const usertaskWithContext = {
936
+ ...this.userTask,
937
+ isConfirmDialog: true
938
+ };
939
+ const func = Function('fields', 'usertask', 'msg', '"use strict"; return (' + action.condition + ')');
940
+ const result = func(this.formData, usertaskWithContext, this.msg);
941
+ return Boolean(result);
942
+ } catch (err) {
943
+ console.error('Error while evaluating condition: ' + err);
944
+ return false;
945
+ }
946
+ });
947
+
948
+ this.actions = [...filteredActions, ...confirmActions];
935
949
  }
950
+ });
951
+ }
952
+
953
+ if (!hasConfirmField && this.props.handle_confirmation_dialogs) {
954
+ this.actions = this.props.options.filter(action => {
955
+ if (!action.condition) return true;
956
+ try {
957
+ const usertaskWithContext = {
958
+ ...this.userTask,
959
+ isConfirmDialog: false
960
+ };
961
+ const func = Function('fields', 'usertask', 'msg', '"use strict"; return (' + action.condition + ')');
962
+ const result = func(this.formData, usertaskWithContext, this.msg);
963
+ return Boolean(result);
964
+ } catch (err) {
965
+ console.error('Error while evaluating condition: ' + err);
966
+ return false;
936
967
  }
937
968
  });
938
969
  }
@@ -958,38 +989,6 @@ export default {
958
989
  });
959
990
  },
960
991
  actionFn(action) {
961
- if (action.isTerminate) {
962
- this.showError('');
963
-
964
- const msg = this.msg ?? {};
965
- msg.payload = {
966
- formData: this.formData,
967
- userTask: this.userTask,
968
- isTerminate: true,
969
- };
970
-
971
- const terminateOutputIndex = this.totalOutputs - 1;
972
-
973
- this.send(msg, terminateOutputIndex);
974
- return;
975
- }
976
-
977
- if (action.isSuspend) {
978
- this.showError('');
979
-
980
- const msg = this.msg ?? {};
981
- msg.payload = {
982
- formData: this.formData,
983
- userTask: this.userTask,
984
- isSuspend: true,
985
- };
986
-
987
- const suspendOutputIndex = this.totalOutputs - 2;
988
-
989
- this.send(msg, suspendOutputIndex);
990
- return;
991
- }
992
-
993
992
  if (action.isConfirmAction && action.confirmFieldId) {
994
993
  this.formData[action.confirmFieldId] = action.confirmValue;
995
994
  }
@@ -1010,7 +1009,7 @@ export default {
1010
1009
  if (!allComplete) return;
1011
1010
  }
1012
1011
 
1013
- if (this.checkCondition(action.condition)) {
1012
+ if (this.checkCondition(action.condition, { isConfirmDialog: this.isConfirmDialog })) {
1014
1013
  this.showError('');
1015
1014
 
1016
1015
  const processedFormData = { ...this.formData };
@@ -1038,20 +1037,29 @@ export default {
1038
1037
 
1039
1038
  const msg = this.msg ?? {};
1040
1039
  msg.payload = { formData: processedFormData, userTask: this.userTask };
1041
- this.send(
1042
- msg,
1043
- this.actions.findIndex((element) => element.label === action.label) +
1044
- (this.isConfirmDialog ? this.props.options.length : 0)
1045
- );
1040
+
1041
+ let outputIndex;
1042
+ if (action.isConfirmAction) {
1043
+ const confirmActionIndex = action.confirmValue ? 1 : 0;
1044
+ outputIndex = this.props.options.length + confirmActionIndex;
1045
+ } else {
1046
+ outputIndex = this.props.options.findIndex((element) => element.label === action.label);
1047
+ }
1048
+ this.send(msg, outputIndex);
1046
1049
  } else {
1047
1050
  this.showError(action.errorMessage);
1048
1051
  }
1049
1052
  },
1050
- checkCondition(condition) {
1053
+ checkCondition(condition, context = {}) {
1051
1054
  if (condition === '') return true;
1052
1055
  try {
1053
- const func = Function('fields', 'userTask', 'msg', '"use strict"; return (' + condition + ')');
1054
- const result = func(this.formData, this.userTask, this.msg);
1056
+ const usertaskWithContext = {
1057
+ ...this.userTask,
1058
+ isConfirmDialog: context.isConfirmDialog || false
1059
+ };
1060
+
1061
+ const func = Function('fields', 'usertask', 'msg', '"use strict"; return (' + condition + ')');
1062
+ const result = func(this.formData, usertaskWithContext, this.msg);
1055
1063
  return Boolean(result);
1056
1064
  } catch (err) {
1057
1065
  console.error('Error while evaluating condition: ' + err);
@@ -168,7 +168,8 @@ code {
168
168
  min-height: 36px;
169
169
  padding: 8px 12px;
170
170
  box-sizing: border-box;
171
- flex-shrink: 0;
171
+ white-space: normal;
172
+ word-wrap: break-word;
172
173
  }
173
174
 
174
175
  @media screen and (min-width: 600px) {
@@ -177,10 +178,8 @@ code {
177
178
  }
178
179
 
179
180
  .ui-dynamic-form-footer-action-button {
180
- max-width: 200px;
181
- white-space: nowrap;
182
- overflow: hidden;
183
- text-overflow: ellipsis;
181
+ white-space: normal;
182
+ word-wrap: break-word;
184
183
  }
185
184
  }
186
185
 
@@ -287,15 +286,13 @@ code {
287
286
  font-size: 16px;
288
287
  width: 100%;
289
288
  box-sizing: border-box;
290
- white-space: nowrap;
291
- overflow: hidden;
292
- text-overflow: ellipsis;
289
+ white-space: normal;
290
+ word-wrap: break-word;
293
291
  }
294
292
 
295
293
  .ui-dynamic-form-footer-action-button .v-btn__content {
296
- white-space: nowrap !important;
297
- overflow: hidden !important;
298
- text-overflow: ellipsis !important;
294
+ white-space: normal !important;
295
+ word-wrap: break-word !important;
299
296
  max-width: 100% !important;
300
297
  display: block !important;
301
298
  }
@@ -310,9 +307,8 @@ code {
310
307
 
311
308
  .ui-dynamic-form-footer-action-primary .v-btn__content,
312
309
  .ui-dynamic-form-footer-action-secondary .v-btn__content {
313
- white-space: nowrap !important;
314
- overflow: hidden !important;
315
- text-overflow: ellipsis !important;
310
+ white-space: normal !important;
311
+ word-wrap: break-word !important;
316
312
  max-width: 100% !important;
317
313
  display: block !important;
318
314
  }