bfg-common 1.5.442 → 1.5.443

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.
Files changed (115) hide show
  1. package/assets/localization/local_be.json +9 -3
  2. package/assets/localization/local_en.json +17 -11
  3. package/assets/localization/local_hy.json +9 -3
  4. package/assets/localization/local_kk.json +9 -3
  5. package/assets/localization/local_ru.json +9 -3
  6. package/assets/localization/local_zh.json +9 -3
  7. package/components/atoms/wizard/Wizard.vue +2 -2
  8. package/components/atoms/wizard/step/Step.vue +1 -1
  9. package/components/common/backup/storage/actions/add/Add.vue +5 -5
  10. package/components/common/backup/storage/actions/add/Old.vue +1 -1
  11. package/components/common/backup/storage/actions/add/lib/config/steps.ts +2 -2
  12. package/components/common/backup/storage/actions/add/lib/validations.ts +4 -4
  13. package/components/common/backup/storage/actions/add/steps/name/Name.vue +1 -1
  14. package/components/common/backup/storage/actions/add/steps/name/New.vue +1 -1
  15. package/components/common/backup/storage/actions/add/steps/name/Old.vue +1 -1
  16. package/components/common/backup/storage/actions/add/steps/nameAndConfigure/NameAndConfigure.vue +1 -1
  17. package/components/common/backup/storage/actions/add/steps/nameAndConfigure/NameAndConfigureNew.vue +1 -1
  18. package/components/common/backup/storage/actions/add/steps/nameAndConfigure/NameAndConfigureOld.vue +1 -1
  19. package/components/common/browse/blocks/lib/models/types.ts +1 -1
  20. package/components/common/browse/lib/models/interfaces.ts +5 -5
  21. package/components/common/countdownTimer/CountdownTimer.vue +26 -15
  22. package/components/common/diagramMain/lib/config/initial.ts +50 -50
  23. package/components/common/diagramMain/lib/models/types.ts +21 -21
  24. package/components/common/diagramMain/lib/utils/utils.ts +331 -331
  25. package/components/common/diagramMain/modals/lib/config/vmKernelAdapter.ts +90 -90
  26. package/components/common/diagramMain/modals/lib/mappers/mappers.ts +87 -87
  27. package/components/common/diagramMain/modals/lib/utils/index.ts +24 -24
  28. package/components/common/diagramMain/modals/migrateVmkernelAdapter/MigrateVmkernelAdapter.vue +5 -5
  29. package/components/common/diagramMain/modals/migrateVmkernelAdapter/lib/config/steps.ts +2 -2
  30. package/components/common/diagramMain/modals/migrateVmkernelAdapter/steps/ConnectionSettings.vue +2 -2
  31. package/components/common/diagramMain/modals/migrateVmkernelAdapter/validations/common.ts +14 -14
  32. package/components/common/diagramMain/modals/migrateVmkernelAdapter/validations/connectionSettings.ts +5 -5
  33. package/components/common/diagramMain/modals/migrateVmkernelAdapter/validations/selectVmkernelAdapter.ts +2 -2
  34. package/components/common/diagramMain/modals/migrateVmkernelAdapter/validations/validations.ts +19 -19
  35. package/components/common/diagramMain/port/Ports.vue +47 -47
  36. package/components/common/layout/theHeader/modals/{reconnect/Reconnect.vue → Reconnect.vue} +56 -43
  37. package/components/common/pages/backups/modals/Modals.vue +1 -1
  38. package/components/common/pages/backups/modals/createBackup/CreateBackup.vue +5 -2
  39. package/components/common/pages/backups/modals/createBackup/lib/config/steps.ts +2 -2
  40. package/components/common/pages/backups/modals/restore/Restore.vue +3 -3
  41. package/components/common/pages/backups/modals/restore/lib/config/steps.ts +2 -2
  42. package/components/common/vm/actions/add/Add.vue +5 -5
  43. package/components/common/vm/actions/add/New.vue +2 -2
  44. package/components/common/vm/actions/add/Old.vue +2 -2
  45. package/components/common/vm/actions/add/lib/config/steps.ts +2 -2
  46. package/components/common/vm/actions/clone/Clone.vue +5 -5
  47. package/components/common/vm/actions/clone/lib/config/steps.ts +2 -2
  48. package/components/common/vm/actions/clone/toTemplate/ToTemplate.vue +5 -5
  49. package/components/common/vm/actions/clone/toTemplate/lib/config/steps.ts +2 -2
  50. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newHardDisk/maximumSize/MaximumSize.vue +23 -23
  51. package/components/common/vmt/actions/add/Add.vue +5 -5
  52. package/components/common/vmt/actions/add/New.vue +2 -3
  53. package/components/common/vmt/actions/add/Old.vue +2 -2
  54. package/components/common/vmt/actions/add/lib/config/steps.ts +2 -2
  55. package/components/common/wizards/datastore/add/Add.vue +2 -2
  56. package/components/common/wizards/datastore/add/Old.vue +2 -2
  57. package/components/common/wizards/datastore/add/lib/config/steps.ts +2 -2
  58. package/components/common/wizards/datastore/add/lib/utils.ts +1 -1
  59. package/components/common/wizards/datastore/add/lib/validations.ts +3 -3
  60. package/components/common/wizards/datastore/add/steps/_local/Local.vue +1 -1
  61. package/components/common/wizards/datastore/add/steps/_local/createName/CreateName.vue +1 -1
  62. package/components/common/wizards/datastore/add/steps/nameAndConfigure/NameAndConfigure.vue +2 -1
  63. package/components/common/wizards/datastore/add/steps/nameAndConfigure/NameAndConfigureNew.vue +1 -1
  64. package/components/common/wizards/datastore/add/steps/nameAndConfigure/NameAndConfigureOld.vue +1 -1
  65. package/components/common/wizards/datastore/add/steps/nameAndDevice/NameAndDevice.vue +1 -1
  66. package/components/common/wizards/datastore/add/steps/nameAndDevice/NameAndDeviceNew.vue +1 -1
  67. package/components/common/wizards/datastore/add/steps/nameAndDevice/NameAndDeviceOld.vue +1 -1
  68. package/components/common/wizards/network/add/Add.vue +109 -333
  69. package/components/common/wizards/network/add/AddNew.vue +514 -0
  70. package/components/common/wizards/network/add/AddOld.vue +457 -0
  71. package/components/common/wizards/network/add/lib/config/config.ts +11 -1
  72. package/components/common/wizards/network/add/lib/config/selectConnectionTypeStep.ts +31 -0
  73. package/components/common/wizards/network/add/lib/config/selectSwitch.ts +217 -0
  74. package/components/common/wizards/network/add/lib/config/steps.ts +5 -5
  75. package/components/common/wizards/network/add/lib/models/interfaces.ts +9 -0
  76. package/components/common/wizards/network/add/steps/ConnectionSettings.vue +2 -2
  77. package/components/common/wizards/network/add/steps/IpFourSettings.vue +2 -2
  78. package/components/common/wizards/network/add/steps/PortProperties.vue +2 -2
  79. package/components/common/wizards/network/add/steps/selectConnectionType/SelectConnectionType.vue +35 -0
  80. package/components/common/wizards/network/add/steps/selectConnectionType/SelectConnectionTypeNew.vue +104 -0
  81. package/components/common/wizards/network/add/steps/selectConnectionType/SelectConnectionTypeOld.vue +80 -0
  82. package/components/common/wizards/network/add/steps/selectTargetDevice/SelectTargetDevice.vue +183 -0
  83. package/components/common/wizards/network/add/steps/selectTargetDevice/SelectTargetDeviceNew.vue +393 -0
  84. package/components/common/wizards/network/add/steps/{SelectedTargetDevice.vue → selectTargetDevice/SelectTargetDeviceOld.vue} +42 -139
  85. package/components/common/wizards/network/add/steps/selectTargetDevice/modals/Modals.vue +55 -0
  86. package/components/common/wizards/network/add/steps/selectTargetDevice/modals/SelectNetwork.vue +64 -0
  87. package/components/common/wizards/network/add/steps/selectTargetDevice/modals/SelectStandardSwitch.vue +64 -0
  88. package/components/common/wizards/network/add/steps/selectTargetDevice/modals/SelectSwitch.vue +64 -0
  89. package/components/common/wizards/network/add/steps/selectTargetDevice/modals/new/SelectNetwork.vue +163 -0
  90. package/components/common/wizards/network/add/steps/selectTargetDevice/modals/new/SelectStandardSwitch.vue +163 -0
  91. package/components/common/wizards/network/add/steps/selectTargetDevice/modals/new/SelectSwitch.vue +163 -0
  92. package/components/common/wizards/network/add/{modals → steps/selectTargetDevice/modals/old}/SelectNetwork.vue +53 -56
  93. package/components/common/wizards/network/add/{modals → steps/selectTargetDevice/modals/old}/SelectStandardSwitch.vue +37 -52
  94. package/components/common/wizards/network/add/{modals → steps/selectTargetDevice/modals/old}/SelectSwitch.vue +38 -42
  95. package/components/common/wizards/network/add/validations/connectionSettings.ts +5 -5
  96. package/components/common/wizards/network/add/validations/createStandardSwitch.ts +4 -4
  97. package/components/common/wizards/network/add/validations/ipFourSettings.ts +5 -5
  98. package/components/common/wizards/network/add/validations/networkValidation.ts +4 -4
  99. package/components/common/wizards/network/add/validations/physicalAdapter.ts +4 -4
  100. package/components/common/wizards/network/add/validations/portProperties.ts +2 -2
  101. package/components/common/wizards/network/add/validations/targetDevice.ts +11 -10
  102. package/components/common/wizards/vm/migrate/Migrate.vue +2 -2
  103. package/components/common/wizards/vm/migrate/lib/config/steps.ts +2 -2
  104. package/components/common/wizards/vm/migrate/lib/validations.ts +3 -3
  105. package/components/common/wizards/vm/migrate/select/targetServer/new/New.vue +1 -1
  106. package/components/common/wizards/vm/migrate/select/targetServer/targetServer.vue +1 -1
  107. package/package.json +2 -2
  108. package/components/atoms/wizard/lib/models/enums.ts +0 -8
  109. package/components/atoms/wizard/lib/models/interfaces.ts +0 -59
  110. package/components/atoms/wizard/lib/utils/utils.ts +0 -954
  111. package/components/common/countdownTimer/CountdownTimerNew.vue +0 -53
  112. package/components/common/countdownTimer/CountdownTimerOld.vue +0 -33
  113. package/components/common/layout/theHeader/modals/reconnect/ReconnectNew.vue +0 -74
  114. package/components/common/layout/theHeader/modals/reconnect/ReconnectOld.vue +0 -67
  115. package/components/common/wizards/network/add/steps/SelectConnectionType.vue +0 -112
@@ -1,954 +0,0 @@
1
- import { ref, computed, Ref, ComputedRef } from 'vue'
2
- import { useDeepCopy } from '~/composables/deepCopy'
3
- import type {
4
- UI_I_ErrorFields,
5
- UI_I_Loader,
6
- UI_I_ValidationReturn,
7
- UI_I_WizardStep,
8
- UI_I_WizardStepNavigation,
9
- UI_I_WizardSchemeData,
10
- } from '~/components/atoms/wizard/lib/models/interfaces'
11
- import { UI_E_WIZARD_STATUS } from '~/components/atoms/wizard/lib/models/enums'
12
-
13
- export default class Wizard {
14
- private _initialSteps: Ref<UI_I_WizardStep[]>
15
- private _initialStepsScheme: Ref<(number | UI_I_WizardSchemeData)[][]>
16
- private _steps: Ref<UI_I_WizardStep[]>
17
- private _stepsScheme: Ref<(number | UI_I_WizardSchemeData)[][]>
18
- private _selectedSchemeId: Ref<number>
19
- private _wizardLoader: Ref<UI_I_Loader>
20
- private _waitingStepId: Ref<number>
21
- isDisabledNextButton: Ref<boolean>
22
- selectedScheme: ComputedRef<(number | UI_I_WizardSchemeData)[]>
23
- alertMessages: ComputedRef<string[][]>
24
- stepsInSelectedScheme: ComputedRef<UI_I_WizardStep[]>
25
- stepsInSelectedSchemeWithStatus: ComputedRef<UI_I_WizardStepNavigation[]>
26
- isLastStepCom: ComputedRef<boolean>
27
- isFirstStepCom: ComputedRef<boolean>
28
- selectedStepCom: ComputedRef<UI_I_WizardStep>
29
- selectedStepDataFromScheme: ComputedRef<undefined | UI_I_WizardSchemeData>
30
-
31
- constructor(
32
- steps: UI_I_WizardStep[],
33
- stepsSchemeInitial: (number | UI_I_WizardSchemeData)[][]
34
- ) {
35
- this._steps = ref<UI_I_WizardStep[]>(useDeepCopy(steps))
36
- this._initialSteps = ref<UI_I_WizardStep[]>(useDeepCopy(steps))
37
- this._stepsScheme = ref<(number | UI_I_WizardSchemeData)[][]>(
38
- useDeepCopy(stepsSchemeInitial)
39
- )
40
- this._initialStepsScheme = ref<(number | UI_I_WizardSchemeData)[][]>(
41
- useDeepCopy(stepsSchemeInitial)
42
- )
43
- this._selectedSchemeId = ref<number>(0)
44
- this._wizardLoader = ref<UI_I_Loader>({
45
- status: false,
46
- messages: [],
47
- })
48
- this._waitingStepId = ref<number>(-1)
49
- this.isDisabledNextButton = ref<boolean>(false)
50
- this.selectedScheme = computed<(number | UI_I_WizardSchemeData)[]>(
51
- () => this._stepsScheme.value[this._selectedSchemeId.value]
52
- )
53
-
54
- this.alertMessages = computed<string[][]>(() =>
55
- this._steps.value.map((step: UI_I_WizardStep) =>
56
- Object.values(step.fields).reduce(
57
- (result: string[], obj: UI_I_ErrorFields) =>
58
- obj.alert ? [...result, obj.alert] : result,
59
- []
60
- )
61
- )
62
- )
63
-
64
- this.stepsInSelectedScheme = computed<UI_I_WizardStep[]>(() =>
65
- this._steps.value.reduce(
66
- (stepsInScheme: UI_I_WizardStep[], step: UI_I_WizardStep) => {
67
- const isStandardStepFromScheme = this.selectedScheme.value.includes(
68
- step.id
69
- )
70
-
71
- if (isStandardStepFromScheme) {
72
- return [...stepsInScheme, step]
73
- }
74
-
75
- const stepDataFromScheme = this.selectedScheme.value.find(
76
- (scheme: number | UI_I_WizardSchemeData) =>
77
- typeof scheme !== 'number' && scheme.stepId === step.id
78
- )
79
-
80
- if (!!stepDataFromScheme) {
81
- return [
82
- ...stepsInScheme,
83
- {
84
- ...step,
85
- dataId: stepDataFromScheme.dataId,
86
- },
87
- ]
88
- }
89
-
90
- return stepsInScheme
91
- },
92
- []
93
- )
94
- )
95
-
96
- this.selectedStepDataFromScheme = computed<
97
- undefined | UI_I_WizardSchemeData
98
- >(() =>
99
- this.selectedScheme.value.find(
100
- (scheme: number | UI_I_WizardSchemeData) =>
101
- typeof scheme !== 'number' &&
102
- scheme.stepId === this.selectedStepCom.value.id
103
- )
104
- )
105
-
106
- this.stepsInSelectedSchemeWithStatus = computed<
107
- UI_I_WizardStepNavigation[]
108
- >(() =>
109
- this.stepsInSelectedScheme.value.map((step: UI_I_WizardStep) => {
110
- return {
111
- ...step,
112
- status: {
113
- disabled: step.status === UI_E_WIZARD_STATUS.INACTIVE,
114
- active:
115
- step.status === UI_E_WIZARD_STATUS.SELECTED ||
116
- step.status === UI_E_WIZARD_STATUS.INVALID_SELECTED,
117
- error:
118
- step.status === UI_E_WIZARD_STATUS.INVALID_SELECTED ||
119
- step.status === UI_E_WIZARD_STATUS.INVALID,
120
- complete:
121
- step.status === UI_E_WIZARD_STATUS.COMPLETED ||
122
- ((step.status === UI_E_WIZARD_STATUS.SELECTED ||
123
- step.status === UI_E_WIZARD_STATUS.INVALID_SELECTED ||
124
- step.status === UI_E_WIZARD_STATUS.INVALID) &&
125
- this.wasCompleted()),
126
- },
127
- }
128
- })
129
- )
130
-
131
- this.isLastStepCom = computed<boolean>(() => {
132
- const lastStepStatus =
133
- this.stepsInSelectedScheme.value[
134
- this.stepsInSelectedScheme.value.length - 1
135
- ].status
136
- return this.isSelected(lastStepStatus)
137
- })
138
-
139
- this.isFirstStepCom = computed<boolean>(() => {
140
- const firstStepStatus = this.stepsInSelectedScheme.value[0].status
141
- return this.isSelected(firstStepStatus)
142
- })
143
-
144
- this.selectedStepCom = computed<UI_I_WizardStep>(
145
- () =>
146
- this.stepsInSelectedScheme.value.find((step: UI_I_WizardStep) =>
147
- this.isSelected(step.status)
148
- ) || this.stepsInSelectedScheme.value[0]
149
- )
150
- }
151
-
152
- get steps(): UI_I_WizardStep[] {
153
- return this._steps.value
154
- }
155
-
156
- set steps(newSteps: UI_I_WizardStep[]) {
157
- this._steps.value = newSteps
158
- }
159
-
160
- set stepsScheme(newStepsScheme: (number | UI_I_WizardSchemeData)[][]) {
161
- this._stepsScheme.value = newStepsScheme
162
- }
163
-
164
- get stepsScheme(): (number | UI_I_WizardSchemeData)[][] {
165
- return this._stepsScheme.value
166
- }
167
-
168
- set selectedSchemeId(newSelectedSchemeId: number) {
169
- this._selectedSchemeId.value = newSelectedSchemeId
170
- }
171
-
172
- get selectedSchemeId(): number {
173
- return this._selectedSchemeId.value
174
- }
175
-
176
- set waitingStepId(id: number) {
177
- this._waitingStepId.value = id
178
- }
179
-
180
- get waitingStepId(): number {
181
- return this._waitingStepId.value
182
- }
183
-
184
- get wizardLoader(): UI_I_Loader {
185
- return this._wizardLoader.value
186
- }
187
-
188
- get nextAvailableStep(): number {
189
- const currentStepIndex = this.selectedScheme.value.indexOf(
190
- this.selectedStepId
191
- )
192
- return this.selectedScheme.value[currentStepIndex + 1]
193
- }
194
-
195
- get nextStepData(): UI_I_WizardStep[] {
196
- const currentStepIndex: number = this.stepsInSelectedScheme.value.findIndex(
197
- (st: UI_I_WizardStep) => this.isSelected(st.status)
198
- )
199
- const stepIndex: number = currentStepIndex + 1
200
- const step: UI_I_WizardStep = this.stepsInSelectedScheme.value[stepIndex]
201
-
202
- if (!step) return []
203
-
204
- const index = this.stepsInSelectedScheme.value.findIndex(
205
- (st: UI_I_WizardStep) => st.id === step.id
206
- )
207
-
208
- return this.stepsInSelectedScheme.value.map(
209
- (st: UI_I_WizardStep, i: number) => {
210
- if (!st.isValid && index === i)
211
- return { ...st, status: UI_E_WIZARD_STATUS.INVALID_SELECTED }
212
-
213
- if (!st.isValid && index !== i)
214
- return { ...st, status: UI_E_WIZARD_STATUS.INVALID }
215
-
216
- const indexInactive = this.stepsInSelectedScheme.value.findIndex(
217
- (st: UI_I_WizardStep) => st.status === UI_E_WIZARD_STATUS.INACTIVE
218
- )
219
-
220
- // If current step is not equal selected step, and it is not inactive or active, set it as completed
221
- if (
222
- index !== i &&
223
- st.status !== UI_E_WIZARD_STATUS.INACTIVE &&
224
- st.status !== UI_E_WIZARD_STATUS.ACTIVE
225
- )
226
- return { ...st, status: UI_E_WIZARD_STATUS.COMPLETED }
227
-
228
- if (index === i) {
229
- return { ...st, status: UI_E_WIZARD_STATUS.SELECTED }
230
- }
231
-
232
- if (stepIndex !== indexInactive && indexInactive - 1 === i)
233
- return { ...st, status: UI_E_WIZARD_STATUS.ACTIVE }
234
-
235
- return st
236
- }
237
- )
238
- }
239
-
240
- get previousStepData(): UI_I_WizardStep[] {
241
- const currentStepIndex: number = this.stepsInSelectedScheme.value.findIndex(
242
- (st: UI_I_WizardStep) => this.isSelected(st.status)
243
- )
244
- const stepIndex: number = currentStepIndex - 1
245
- const step: UI_I_WizardStep = this.stepsInSelectedScheme.value[stepIndex]
246
-
247
- const indexInactive = this.stepsInSelectedScheme.value.findIndex(
248
- (st: UI_I_WizardStep) => st.status === UI_E_WIZARD_STATUS.INACTIVE
249
- )
250
-
251
- if (!step) return []
252
- const index = this.stepsInSelectedScheme.value.findIndex(
253
- (st: UI_I_WizardStep) => st.title === step.title
254
- )
255
-
256
- return this.stepsInSelectedScheme.value.map(
257
- (st: UI_I_WizardStep, i: number) => {
258
- if (!st.isValid && index === i)
259
- return { ...st, status: UI_E_WIZARD_STATUS.INVALID_SELECTED }
260
-
261
- if (index === i) return { ...st, status: UI_E_WIZARD_STATUS.SELECTED }
262
-
263
- if (!st.isValid && index !== i)
264
- return { ...st, status: UI_E_WIZARD_STATUS.INVALID }
265
-
266
- // If current step is before first inactive, and it is not to be selected or hasn't inactive index, and it is last step
267
- if (
268
- (indexInactive - 1 === i && index !== indexInactive - 1) ||
269
- (indexInactive < 0 &&
270
- this.stepsInSelectedScheme.value.length - 1 === i)
271
- )
272
- return { ...st, status: UI_E_WIZARD_STATUS.ACTIVE }
273
-
274
- if (index !== i && st.status !== UI_E_WIZARD_STATUS.INACTIVE)
275
- return { ...st, status: UI_E_WIZARD_STATUS.COMPLETED }
276
-
277
- return st
278
- }
279
- )
280
- }
281
-
282
- setDisabledNextButton(newValue: boolean) {
283
- this.isDisabledNextButton.value = newValue
284
- }
285
-
286
- selectedStepData(step: UI_I_WizardStepNavigation): UI_I_WizardStep[] {
287
- const index = this.stepsInSelectedScheme.value.findIndex(
288
- (st: UI_I_WizardStep) => st.id === step.id
289
- )
290
- const indexInactive = this.stepsInSelectedScheme.value.findIndex(
291
- (st: UI_I_WizardStep) => st.status === UI_E_WIZARD_STATUS.INACTIVE
292
- )
293
-
294
- return this.stepsInSelectedScheme.value.map(
295
- (st: UI_I_WizardStep, i: number) => {
296
- if (!st.isValid && index === i)
297
- return { ...st, status: UI_E_WIZARD_STATUS.INVALID_SELECTED }
298
-
299
- if (index === i) return { ...st, status: UI_E_WIZARD_STATUS.SELECTED }
300
-
301
- if (!st.isValid && index !== i)
302
- return { ...st, status: UI_E_WIZARD_STATUS.INVALID }
303
-
304
- // If current step is before first inactive, and it is not to be selected or hasn't inactive index, and it is last step, but it is not to be selected, set it as active
305
- if (
306
- (indexInactive - 1 === i && index !== indexInactive - 1) ||
307
- (indexInactive < 0 &&
308
- this.stepsInSelectedScheme.value.length - 1 === i &&
309
- index !== i)
310
- )
311
- return { ...st, status: UI_E_WIZARD_STATUS.ACTIVE }
312
-
313
- if (index !== i && st.status !== UI_E_WIZARD_STATUS.INACTIVE)
314
- return { ...st, status: UI_E_WIZARD_STATUS.COMPLETED }
315
-
316
- return st
317
- }
318
- )
319
- }
320
-
321
- setLoader(status: boolean, messages?: string[]): void {
322
- this._wizardLoader.value.status = status
323
-
324
- if (!messages && !!this._wizardLoader.value?.messages?.length) {
325
- this._wizardLoader.value.messages = []
326
- return
327
- }
328
- if (!messages) return
329
-
330
- messages.length > 0 && (this._wizardLoader.value.messages = messages)
331
- }
332
-
333
- changeScheme(schemeId: number): void {
334
- this.selectedSchemeId = schemeId
335
- this.resetAfterSelected()
336
- }
337
-
338
- goToFirstInvalidStep(): void {
339
- const firstInvalidStep: UI_I_WizardStep | undefined = this.steps.find(
340
- (step: UI_I_WizardStep) => this.isInvalid(step.status)
341
- )
342
-
343
- if (!firstInvalidStep) return
344
-
345
- const firstInvalidStepId: number = firstInvalidStep.id
346
-
347
- this.steps = this.steps.map((step: UI_I_WizardStep): UI_I_WizardStep => {
348
- if (step.id === firstInvalidStepId) {
349
- return { ...step, status: UI_E_WIZARD_STATUS.INVALID_SELECTED }
350
- }
351
- if (step.status === UI_E_WIZARD_STATUS.SELECTED) {
352
- return { ...step, status: UI_E_WIZARD_STATUS.COMPLETED }
353
- }
354
-
355
- return step
356
- })
357
- }
358
-
359
- goToFirstStoppageStep(stoppageStepId: number): void {
360
- console.log('goToFirstStoppageStep', stoppageStepId)
361
- }
362
-
363
- hasMessage(stepId: number, field: string): boolean {
364
- return (
365
- !!this.steps[stepId].fields?.[field].field ||
366
- !!this.steps[stepId].fields?.[field].alert
367
- )
368
- }
369
-
370
- setValidationError(stepId: number, field: string, message: string): void {
371
- const invalidStep: UI_I_WizardStep | undefined = this.steps.find(
372
- (step: UI_I_WizardStep): boolean => step.id === stepId
373
- )
374
-
375
- if (!invalidStep) return
376
-
377
- invalidStep.fields[field].field = message
378
-
379
- if (message) {
380
- invalidStep.isValid = false
381
-
382
- if (this.isSelected(invalidStep.status)) {
383
- invalidStep.status = UI_E_WIZARD_STATUS.INVALID_SELECTED
384
- return
385
- }
386
-
387
- invalidStep.status = UI_E_WIZARD_STATUS.INVALID
388
- } else {
389
- invalidStep.isValid = true
390
- if (this.isSelected(invalidStep.status)) {
391
- invalidStep.status = UI_E_WIZARD_STATUS.SELECTED
392
- } else {
393
- invalidStep.status = UI_E_WIZARD_STATUS.COMPLETED
394
- }
395
- }
396
- }
397
-
398
- setAlertMessage(stepId: number, field: string, message: string): void {
399
- this.steps[stepId].fields[field].alert = message
400
- }
401
-
402
- removeAlertMessage(
403
- stepId: number,
404
- field: string,
405
- value?: UI_I_WizardStep[]
406
- ): UI_I_WizardStep[] {
407
- const invalidStep: UI_I_WizardStep = this.steps[stepId]
408
-
409
- invalidStep.fields[field].alert = ''
410
- if (!value) return this.steps
411
-
412
- return value.map(
413
- (step: UI_I_WizardStep): UI_I_WizardStep =>
414
- step.id === invalidStep.id ? invalidStep : step
415
- )
416
- }
417
-
418
- private removeValidationError(
419
- stepId: number,
420
- field: string,
421
- nextStep: boolean,
422
- value?: UI_I_WizardStep[]
423
- ): UI_I_WizardStep[] {
424
- const invalidStep: UI_I_WizardStep = this.steps[stepId]
425
-
426
- if (!invalidStep) return this.steps
427
-
428
- invalidStep.fields[field].field = ''
429
-
430
- const messages: UI_I_ErrorFields[] = Object.values(
431
- invalidStep.fields
432
- ).filter((message: UI_I_ErrorFields): boolean => message.field !== '')
433
-
434
- invalidStep.isValid = !messages.length
435
-
436
- if (nextStep && invalidStep.isValid && this.isInvalid(invalidStep.status)) {
437
- invalidStep.status = UI_E_WIZARD_STATUS.COMPLETED
438
- }
439
-
440
- if (
441
- !nextStep &&
442
- invalidStep.isValid &&
443
- invalidStep.status === UI_E_WIZARD_STATUS.INVALID_SELECTED
444
- ) {
445
- invalidStep.status = UI_E_WIZARD_STATUS.SELECTED
446
- }
447
-
448
- if (nextStep) this.goToFirstInvalidStep()
449
-
450
- if (!value) return this.steps
451
-
452
- return value.map(
453
- (step: UI_I_WizardStep): UI_I_WizardStep =>
454
- step.id === invalidStep.id ? invalidStep : step
455
- )
456
- }
457
-
458
- hideAlertMessagesByStepId(stepId: number): UI_I_WizardStep[] {
459
- const modifiedStep: UI_I_WizardStep = this.steps[stepId]
460
-
461
- for (const field in modifiedStep.fields) {
462
- modifiedStep.fields[field].alert = ''
463
- }
464
-
465
- return (this.steps = this.steps.map((step: UI_I_WizardStep) =>
466
- step.id === stepId ? modifiedStep : step
467
- ))
468
- }
469
-
470
- changeStep(value: UI_I_WizardStep[]): void {
471
- this.steps = this.steps.map(
472
- (step: UI_I_WizardStep): UI_I_WizardStep => ({
473
- ...step,
474
- ...(value.find(
475
- (stepFind: UI_I_WizardStep): boolean => stepFind.id === step.id
476
- ) || step),
477
- })
478
- )
479
- }
480
-
481
- isSelected(status: UI_E_WIZARD_STATUS): boolean {
482
- return (
483
- status === UI_E_WIZARD_STATUS.SELECTED ||
484
- status === UI_E_WIZARD_STATUS.INVALID_SELECTED
485
- )
486
- }
487
-
488
- isInvalid(status: UI_E_WIZARD_STATUS): boolean {
489
- return (
490
- status === UI_E_WIZARD_STATUS.INVALID ||
491
- status === UI_E_WIZARD_STATUS.INVALID_SELECTED
492
- )
493
- }
494
-
495
- get selectedStepId(): number {
496
- const selectedStep: UI_I_WizardStep | undefined = this.steps.find(
497
- (step: UI_I_WizardStep) =>
498
- step.status === UI_E_WIZARD_STATUS.SELECTED ||
499
- step.status === UI_E_WIZARD_STATUS.INVALID_SELECTED
500
- )
501
-
502
- return selectedStep !== undefined ? selectedStep.id : this.steps[0].id
503
- }
504
-
505
- get selectedStep(): UI_I_WizardStep {
506
- return this.steps.find(
507
- (step: UI_I_WizardStep) => step.id === this.selectedStepId
508
- )
509
- }
510
-
511
- private async finalValidationFunc(
512
- value: UI_I_WizardStep[],
513
- currentStep: UI_I_WizardStep,
514
- nextStep: UI_I_WizardStep,
515
- finalValidationFunc: (
516
- value: UI_I_WizardStep[],
517
- currentStep: UI_I_WizardStep,
518
- nextStep: UI_I_WizardStep
519
- ) => Promise<UI_I_ValidationReturn>,
520
- isOnlyFinalValidation = false
521
- ) {
522
- const finalValidation: UI_I_ValidationReturn = await finalValidationFunc(
523
- value,
524
- currentStep,
525
- nextStep
526
- )
527
-
528
- if (
529
- finalValidation.stepHasError ||
530
- finalValidation.stepShouldStop?.ifFromAnyStep ||
531
- finalValidation.stepShouldStop?.ifOnCurrentStep
532
- ) {
533
- finalValidation.stepShouldStop?.ifFromAnyStep &&
534
- currentStep.id < finalValidation.stepShouldStop?.stoppageStepId &&
535
- this.selectStepHard(finalValidation.stepShouldStop?.stoppageStepId)
536
-
537
- finalValidation.stepShouldStop?.ifOnCurrentStep &&
538
- this.selectStepHard(finalValidation.stepShouldStop?.stoppageStepId)
539
-
540
- finalValidation.stepHasError && this.goToFirstInvalidStep()
541
-
542
- return
543
- } else {
544
- currentStep.status = UI_E_WIZARD_STATUS.COMPLETED
545
- }
546
-
547
- this.changeStep(finalValidation.newValue)
548
- }
549
-
550
- addNewStepToSteps(): void {
551
- const lastStepOfType = this.steps.findLast(
552
- (step: UI_I_WizardStep) => step.type === this.selectedStep.type
553
- )
554
-
555
- if (!lastStepOfType) return
556
-
557
- this.steps = this.steps.reduce(
558
- (acc: UI_I_WizardStep[], step: UI_I_WizardStep) => {
559
- if (step.id < lastStepOfType.id) acc.push(step)
560
- if (step.id === lastStepOfType.id) {
561
- acc.push(step)
562
-
563
- const lastStepOfTypeTitleNumber =
564
- +lastStepOfType.title.match(/\d+/)[0]
565
-
566
- acc.push({
567
- ...step,
568
- status: UI_E_WIZARD_STATUS.INACTIVE,
569
- id: step.id + 1,
570
- title: lastStepOfType.title.replace(
571
- lastStepOfTypeTitleNumber,
572
- lastStepOfTypeTitleNumber + 1
573
- ),
574
- })
575
- }
576
- if (step.id > lastStepOfType.id) {
577
- acc.push({
578
- ...step,
579
- id: step.id + 1,
580
- })
581
- }
582
-
583
- return acc
584
- },
585
- []
586
- )
587
-
588
- this.stepsScheme = [
589
- ...this.stepsScheme.slice(0, this.selectedSchemeId),
590
- this.stepsScheme[this.selectedSchemeId].reduce(
591
- (acc: number[], step: number) => {
592
- if (step < lastStepOfType.id) acc.push(step)
593
- if (step === lastStepOfType.id) {
594
- acc.push(step)
595
- acc.push(step + 1)
596
- }
597
- if (step > lastStepOfType.id) {
598
- acc.push(step + 1)
599
- }
600
-
601
- return acc
602
- },
603
- []
604
- ),
605
- ...this.stepsScheme.slice(this.selectedSchemeId + 1),
606
- ]
607
- }
608
-
609
- removeSelectedStepFromSteps(title = ''): void {
610
- const removedType = this.steps.find(
611
- (step) => step.id === this.selectedStepId
612
- )?.type
613
- this.selectStepHard(this.selectedStepId - 1)
614
-
615
- let count = 0
616
-
617
- this.steps = this.steps.reduce(
618
- (acc: UI_I_WizardStep[], step: UI_I_WizardStep) => {
619
- const currentTitle =
620
- step?.type === removedType ? title + ' ' + ++count : step.title
621
- if (step.id < this.selectedStepId + 1)
622
- acc.push({
623
- ...step,
624
- title: currentTitle,
625
- })
626
-
627
- if (step.id > this.selectedStepId + 1) {
628
- acc.push({
629
- ...step,
630
- id: step.id - 1,
631
- title: currentTitle,
632
- })
633
- }
634
-
635
- return acc
636
- },
637
- []
638
- )
639
- this.stepsScheme[this.selectedSchemeId].pop()
640
-
641
- this.stepsScheme = [
642
- ...this.stepsScheme.slice(0, this.selectedSchemeId),
643
- this.stepsScheme[this.selectedSchemeId],
644
- ...this.stepsScheme.slice(this.selectedSchemeId + 1),
645
- ]
646
- }
647
-
648
- async changeSteps(
649
- value: UI_I_WizardStep[],
650
- validationFunc?: (
651
- value: UI_I_WizardStep[],
652
- currentStep: UI_I_WizardStep,
653
- nextStep: UI_I_WizardStep
654
- ) => Promise<UI_I_ValidationReturn>,
655
- finalValidationFunc?: (
656
- value: UI_I_WizardStep[],
657
- currentStep: UI_I_WizardStep,
658
- nextStep: UI_I_WizardStep
659
- ) => Promise<UI_I_ValidationReturn>,
660
- isOnlyFinalValidation = false
661
- ): Promise<void> {
662
- const currentStep: UI_I_WizardStep | undefined = this.steps.find(
663
- (step: UI_I_WizardStep) => this.isSelected(step.status)
664
- )
665
-
666
- const nextStep: UI_I_WizardStep | undefined = value.find(
667
- (step: UI_I_WizardStep) => this.isSelected(step.status)
668
- )
669
-
670
- if (!currentStep || !nextStep) return
671
- if (currentStep.id > nextStep.id) return this.changeStep(value)
672
-
673
- if (
674
- isOnlyFinalValidation &&
675
- (this.isLastStep() ||
676
- nextStep.id ===
677
- this.selectedScheme.value[this.selectedScheme.value.length - 1]) &&
678
- finalValidationFunc
679
- ) {
680
- this.finalValidationFunc(
681
- value,
682
- currentStep,
683
- nextStep,
684
- finalValidationFunc,
685
- isOnlyFinalValidation
686
- )
687
-
688
- return
689
- }
690
-
691
- if (validationFunc) {
692
- const validation: UI_I_ValidationReturn = await validationFunc(
693
- value,
694
- currentStep,
695
- nextStep
696
- )
697
-
698
- if (
699
- validation.stepHasError ||
700
- validation.stepShouldStop?.ifFromAnyStep ||
701
- validation.stepShouldStop?.ifOnCurrentStep
702
- ) {
703
- validation.stepShouldStop?.ifFromAnyStep &&
704
- currentStep.id < validation.stepShouldStop?.stoppageStepId &&
705
- this.selectStepHard(validation.stepShouldStop?.stoppageStepId)
706
-
707
- validation.stepShouldStop?.ifOnCurrentStep &&
708
- this.selectStepHard(validation.stepShouldStop?.stoppageStepId)
709
-
710
- validation.stepHasError && this.goToFirstInvalidStep()
711
-
712
- return
713
- } else if (
714
- (this.isLastStep() ||
715
- nextStep.id ===
716
- this.selectedScheme.value[this.selectedScheme.value.length - 1]) &&
717
- finalValidationFunc
718
- ) {
719
- this.finalValidationFunc(
720
- validation.newValue,
721
- currentStep,
722
- nextStep,
723
- finalValidationFunc,
724
- isOnlyFinalValidation
725
- )
726
-
727
- return
728
- } else {
729
- currentStep.status = UI_E_WIZARD_STATUS.COMPLETED
730
- }
731
-
732
- this.changeStep(validation.newValue)
733
-
734
- return
735
- }
736
-
737
- this.changeStep(value)
738
- }
739
-
740
- selectStepHard(stepId: number): void {
741
- const newSteps = this.steps.map((st: UI_I_WizardStep) => {
742
- if (st.id < stepId) return { ...st, status: UI_E_WIZARD_STATUS.COMPLETED }
743
-
744
- if (st.id === stepId)
745
- return { ...st, status: UI_E_WIZARD_STATUS.SELECTED }
746
-
747
- // TODO Было сделано на скорую руку
748
- if (st.id > stepId && st.status === UI_E_WIZARD_STATUS.SELECTED)
749
- return { ...st, status: UI_E_WIZARD_STATUS.COMPLETED }
750
-
751
- return st
752
- })
753
-
754
- this.changeStep(newSteps)
755
- }
756
-
757
- isValidateForStep(
758
- step: number,
759
- currentStepId: number,
760
- nextStepId: number
761
- ): boolean {
762
- return (
763
- nextStepId > step &&
764
- currentStepId <= step &&
765
- this.selectedScheme.value.includes(step)
766
- )
767
- }
768
-
769
- setValidation(
770
- stepId: number,
771
- field: string,
772
- message: {
773
- fieldMessage?: string
774
- alertMessage?: string
775
- }
776
- ): true {
777
- message.fieldMessage &&
778
- this.setValidationError(stepId, field, message.fieldMessage)
779
- message.alertMessage &&
780
- this.setAlertMessage(stepId, field, message.alertMessage)
781
-
782
- return true
783
- }
784
-
785
- removeValidationLocal(stepId: number, field: string): void {
786
- this.setValidationError(stepId, field, '')
787
- this.setAlertMessage(stepId, field, '')
788
- }
789
-
790
- removeValidation(
791
- stepId: number,
792
- field: string,
793
- value: UI_I_WizardStep[]
794
- ): UI_I_WizardStep[] {
795
- let newValue: UI_I_WizardStep[] = this.removeValidationError(
796
- stepId,
797
- field,
798
- true,
799
- value
800
- )
801
-
802
- newValue = this.removeAlertMessage(stepId, field, newValue)
803
- return newValue
804
- }
805
-
806
- reset(): void {
807
- this.steps = useDeepCopy(this._initialSteps.value)
808
- this.stepsScheme = useDeepCopy(this._initialStepsScheme.value)
809
- this.selectedSchemeId = 0
810
- }
811
-
812
- setEmptyErrorFields(fields: { [key: string]: UI_I_ErrorFields }): {
813
- [key: string]: UI_I_ErrorFields
814
- } {
815
- const keys: string[] = Object.keys(fields)
816
- const obj: { [key: string]: UI_I_ErrorFields } = {}
817
-
818
- keys.forEach((key: string): void => {
819
- obj[key] = {
820
- alert: '',
821
- field: '',
822
- }
823
- })
824
-
825
- return obj
826
- }
827
-
828
- resetAfterSelected(): void {
829
- this.steps = this.steps.map(
830
- (step: UI_I_WizardStep): UI_I_WizardStep =>
831
- step.id > this.selectedStepId
832
- ? {
833
- ...step,
834
- status: UI_E_WIZARD_STATUS.INACTIVE,
835
- isValid: true,
836
- fields: this.setEmptyErrorFields(step.fields),
837
- }
838
- : step
839
- )
840
- }
841
-
842
- activeStepId(): number {
843
- const activeStep = this.steps.find(
844
- (step: UI_I_WizardStep) => step.status === UI_E_WIZARD_STATUS.ACTIVE
845
- )?.id
846
-
847
- const invalidStep = this.steps.find(
848
- (step: UI_I_WizardStep) => step.status === UI_E_WIZARD_STATUS.INVALID
849
- )?.id
850
-
851
- return activeStep || invalidStep || 0
852
- }
853
-
854
- wasCompleted(): boolean {
855
- return this.activeStepId() > this.selectedStepId
856
- }
857
-
858
- isLastStep(): boolean {
859
- return (
860
- this.selectedScheme.value[this.selectedScheme.value.length - 2] ===
861
- this.selectedStepId
862
- )
863
- }
864
-
865
- isSelectedScheme(schemeId: number): boolean {
866
- return schemeId === this.selectedSchemeId
867
- }
868
-
869
- getStepIdByFieldName(fieldName: string): number {
870
- return this.steps.find((step) => step.fields[fieldName])?.id || -1
871
- }
872
-
873
- setDynamicValidationField(fieldName: string | string[]): void {
874
- const fields: {
875
- [key: string]: UI_I_ErrorFields
876
- } = this.steps[this.selectedStepId].fields
877
-
878
- if (typeof fieldName === 'string') {
879
- fields[fieldName] = {
880
- alert: '',
881
- field: '',
882
- }
883
- } else {
884
- fieldName.forEach((name: string) => {
885
- fields[name] = {
886
- alert: '',
887
- field: '',
888
- }
889
- })
890
- }
891
-
892
- this.steps = this.steps.map((step: UI_I_WizardStep) =>
893
- step.id === this.selectedStepId
894
- ? {
895
- ...step,
896
- fields,
897
- }
898
- : step
899
- )
900
- }
901
-
902
- removeDynamicValidationField(fieldName: string | string[]): void {
903
- const newFields: {
904
- [key: string]: UI_I_ErrorFields
905
- } = this.steps[this.selectedStepId].fields
906
-
907
- if (typeof fieldName === 'string') {
908
- delete newFields[fieldName]
909
- } else {
910
- fieldName.forEach((name: string) => {
911
- delete newFields[name]
912
- })
913
- }
914
-
915
- this.steps = this.steps.map((step: UI_I_WizardStep) =>
916
- step.id === this.selectedStepId
917
- ? {
918
- ...step,
919
- fields: newFields,
920
- }
921
- : step
922
- )
923
- }
924
-
925
- validateFieldLocal(
926
- stepId: number,
927
- field: string,
928
- rule: boolean | boolean[],
929
- fieldMessage: string | string[],
930
- alertMessage: string | string[]
931
- ): void {
932
- if (typeof rule === 'boolean') {
933
- if (rule) {
934
- this.setValidation(stepId, field, {
935
- fieldMessage: fieldMessage as string,
936
- alertMessage: alertMessage as string,
937
- })
938
- } else if (this.hasMessage(stepId, field)) {
939
- this.removeValidationLocal(stepId, field)
940
- }
941
- } else {
942
- const ruleIndex = rule.indexOf(true)
943
-
944
- if (ruleIndex !== -1) {
945
- this.setValidation(stepId, field, {
946
- fieldMessage: fieldMessage[ruleIndex],
947
- alertMessage: alertMessage[ruleIndex],
948
- })
949
- } else if (this.hasMessage(stepId, field)) {
950
- this.removeValidationLocal(stepId, field)
951
- }
952
- }
953
- }
954
- }