bfg-common 1.5.466 → 1.5.467

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.
@@ -82,7 +82,14 @@ const isParentDatacenter = (node: UI_I_TreeNode | null): boolean => {
82
82
  const submit = async (cb: Function): Promise<void> => {
83
83
  const name = vmName.value
84
84
 
85
- if (name !== '' || props.validateEmptyName) {
85
+ if (props.validateEmptyName && name === '') {
86
+ showValidationErrors([
87
+ localization.value.common.emptyNameValidationDescription,
88
+ ])
89
+ cb(false)
90
+ return
91
+ }
92
+ if (name !== '') {
86
93
  const isNameValid = await checkNameIsValid(name)
87
94
  if (!isNameValid) {
88
95
  cb(false)
@@ -0,0 +1,268 @@
1
+ <template>
2
+ <div class="register-vm">
3
+ <atoms-wizard
4
+ :wizard="wizard"
5
+ :selected-scheme="selectedScheme"
6
+ :title="localization.common.registerVm"
7
+ :localization="localization"
8
+ test-id="register-wizard"
9
+ show
10
+ @change-steps="onChangeSteps"
11
+ @hide="emits('hide')"
12
+ @submit="emits('finish')"
13
+ >
14
+ <template #modalBody="{ selectedStep }">
15
+ <!-- <atoms-loader-->
16
+ <!-- v-show="props.isLoading"-->
17
+ <!-- id="loader"-->
18
+ <!-- test-id="edit-vm-settings-spinner"-->
19
+ <!-- />-->
20
+ <div class="register-vm-content">
21
+ <common-vm-actions-common-select-name
22
+ v-show="
23
+ selectedStep.id === dynamicSteps.selectName ||
24
+ selectedStep.id === dynamicSteps.selectNameFolder
25
+ "
26
+ :show="
27
+ selectedStep.id === dynamicSteps.selectName ||
28
+ selectedStep.id === dynamicSteps.selectNameFolder
29
+ "
30
+ :name-form-submit="nameFormSubmit"
31
+ :project="props.project"
32
+ :data-center="props.dataCenter"
33
+ validate-empty-name
34
+ @submit="onChangeName(...$event)"
35
+ @check-name="emits('check-name', $event)"
36
+ />
37
+ <common-vm-actions-common-select-compute-resource
38
+ v-if="isSphere"
39
+ v-show="selectedStep.id === dynamicSteps.selectComputeResource"
40
+ v-model="vmForm.computeResource"
41
+ :compute-resource-submit="computeResourceSubmit"
42
+ :data-center="vmForm.dataCenter"
43
+ :compute-resource="props.computeResource"
44
+ :compute-resource-tree="props.computeResourceTree"
45
+ @submit="emits('change-compute-resource', $event)"
46
+ @select-compute-resource-tree="
47
+ emits('select-compute-resource-tree', $event)
48
+ "
49
+ @get-compute-resource-tree="
50
+ emits('get-compute-resource-tree', $event)
51
+ "
52
+ @show-compute-resource-tree="
53
+ emits('show-compute-resource-tree', $event)
54
+ "
55
+ @clear-compute-resource-tree="emits('clear-compute-resource-tree')"
56
+ />
57
+ <common-ready-to-complete
58
+ v-if="selectedStep.id === dynamicSteps.readyComplete"
59
+ :data="props.readyCompleteTableInfo"
60
+ />
61
+ </div>
62
+ </template>
63
+ </atoms-wizard>
64
+ </div>
65
+ </template>
66
+
67
+ <script setup lang="ts">
68
+ import type { UI_I_WizardStep } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/interfaces'
69
+ import type { UI_I_ValidationReturn } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/interfaces'
70
+ import Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
71
+ import type {
72
+ UI_I_Localization,
73
+ } from '~/lib/models/interfaces'
74
+ import type { UI_T_Project } from '~/lib/models/types'
75
+ import type {
76
+ API_UI_I_Error,
77
+ } from '~/lib/models/store/interfaces'
78
+ import type { UI_I_TableInfoItem } from '~/components/atoms/table/info/lib/models/interfaces'
79
+ import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
80
+ import {
81
+ dynamicSteps,
82
+ stepsFunc,
83
+ stepsSchemeInitial,
84
+ } from '~/components/common/vm/actions/register/lib/config/steps'
85
+
86
+ const vmForm = defineModel<any>({required: true})
87
+
88
+ const props = withDefaults(
89
+ defineProps<{
90
+ project: UI_T_Project
91
+ readyCompleteTableInfo: UI_I_TableInfoItem[]
92
+ dataCenter?: UI_I_TreeNode // для сферы
93
+ computeResource?: UI_I_TreeNode // для сферы
94
+ computeResourceTree?: UI_I_TreeNode[] // для сферы
95
+ }>(),
96
+ {
97
+ dataCenter: undefined,
98
+ computeResource: undefined,
99
+ computeResourceTree: undefined,
100
+ }
101
+ )
102
+
103
+ const emits = defineEmits<{
104
+ (event: 'finish'): void
105
+ (
106
+ event: 'check-name',
107
+ value: [[string, UI_I_TreeNode | null], (error: API_UI_I_Error) => void]
108
+ ): void
109
+ (event: 'hide'): void
110
+ (event: 'clear-compute-resource-tree'): void // для сферы
111
+ (event: 'change-compute-resource', value: UI_I_TreeNode): void // для сферы
112
+ (event: 'select-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
113
+ (
114
+ event: 'get-compute-resource-tree',
115
+ value: { id: string | number; cb: () => void }
116
+ ): void // для сферы
117
+ (event: 'show-compute-resource-tree', value: UI_I_TreeNode): void // для сферы
118
+ }>()
119
+
120
+ const { $recursion }: any = useNuxtApp()
121
+
122
+ const localization = computed<UI_I_Localization>(() => useLocal())
123
+ const isSphere = computed<boolean>(() => props.project === 'sphere')
124
+
125
+ const wizard: Wizard = new Wizard(
126
+ stepsFunc(localization.value),
127
+ stepsSchemeInitial
128
+ )
129
+
130
+ const selectedScheme = computed<number[]>(() => wizard.selectedScheme.value)
131
+ const onChangeSteps = async (value: UI_I_WizardStep[]): Promise<void> => {
132
+ wizard.changeSteps(value, validationFunc)
133
+ }
134
+ const validationFunc = async (
135
+ value: UI_I_WizardStep[],
136
+ currentStep: UI_I_WizardStep,
137
+ nextStep: UI_I_WizardStep
138
+ ): Promise<UI_I_ValidationReturn> => {
139
+ let stepHasError = false
140
+ let stepShouldStop = {
141
+ ifOnCurrentStep: false,
142
+ ifFromAnyStep: false,
143
+ stoppageStepId: -1,
144
+ }
145
+
146
+ wizard.setLoader(true)
147
+ if (
148
+ wizard.isValidateForStep(
149
+ isSphere.value ? dynamicSteps.selectNameFolder : dynamicSteps.selectName,
150
+ currentStep.id,
151
+ nextStep.id
152
+ )
153
+ ) {
154
+ const nameValidation = await onCheckName(value)
155
+
156
+ value = nameValidation.newValue
157
+ stepHasError = stepHasError || nameValidation.stepHasError
158
+ } else if (
159
+ isSphere.value &&
160
+ wizard.isValidateForStep(
161
+ dynamicSteps.selectComputeResource,
162
+ currentStep.id,
163
+ nextStep.id
164
+ )
165
+ ) {
166
+ const computeResourceValidation = await checkComputeResource(value)
167
+
168
+ value = computeResourceValidation.newValue
169
+ stepHasError = stepHasError || computeResourceValidation.stepHasError
170
+ }
171
+ wizard.setLoader(false)
172
+
173
+ return {
174
+ newValue: value,
175
+ stepHasError,
176
+ stepShouldStop,
177
+ }
178
+ }
179
+
180
+ const nameFormSubmit = ref<null | Function>(null)
181
+ const computeResourceSubmit = ref<null | Function>(null)
182
+ const onCheckName = async (
183
+ value: UI_I_WizardStep[]
184
+ ): Promise<UI_I_ValidationReturn> => {
185
+ let stepHasError = false
186
+
187
+ return new Promise((resolve) => {
188
+ const step = isSphere.value
189
+ ? dynamicSteps.selectNameFolder
190
+ : dynamicSteps.selectName
191
+ nameFormSubmit.value = (isValid: boolean) => {
192
+ if (!isValid) {
193
+ stepHasError = wizard.setValidation(step, 'name', {
194
+ fieldMessage: 'aaa',
195
+ alertMessage: 'aaa',
196
+ })
197
+ } else if (wizard.hasMessage(step, 'name')) {
198
+ value = wizard.removeValidation(step, 'name', value)
199
+ }
200
+
201
+ resolve({
202
+ stepHasError,
203
+ newValue: value,
204
+ })
205
+ nameFormSubmit.value = null
206
+ }
207
+ })
208
+ }
209
+ const checkComputeResource = async (
210
+ value: UI_I_WizardStep[]
211
+ ): Promise<UI_I_ValidationReturn> => {
212
+ let stepHasError = false
213
+
214
+ return new Promise((resolve) => {
215
+ computeResourceSubmit.value = (isValid: boolean) => {
216
+ if (!isValid) {
217
+ stepHasError = wizard.setValidation(
218
+ dynamicSteps.selectComputeResource,
219
+ 'computeResource',
220
+ {
221
+ fieldMessage: 'aaa',
222
+ alertMessage: 'aaa',
223
+ }
224
+ )
225
+ } else if (
226
+ wizard.hasMessage(dynamicSteps.selectComputeResource, 'computeResource')
227
+ ) {
228
+ value = wizard.removeValidation(
229
+ dynamicSteps.selectComputeResource,
230
+ 'computeResource',
231
+ value
232
+ )
233
+ }
234
+
235
+ resolve({
236
+ stepHasError,
237
+ newValue: value,
238
+ })
239
+ computeResourceSubmit.value = null
240
+ }
241
+ })
242
+ }
243
+
244
+ const onChangeName = (name: string, node: UI_I_TreeNode | null): void => {
245
+ vmForm.value.name = name
246
+ if (isSphere.value) {
247
+ vmForm.value.locationPath = node.id
248
+ vmForm.value.dataCenter = $recursion.findParentByValue(
249
+ node,
250
+ 'datacenter',
251
+ 'type',
252
+ 'parent'
253
+ )
254
+ }
255
+ }
256
+ </script>
257
+
258
+ <style scoped lang="scss">
259
+ :deep(.modal-body) {
260
+ display: flex;
261
+ flex-direction: column;
262
+ }
263
+ .register-vm-content {
264
+ display: flex;
265
+ flex-direction: column;
266
+ flex: 1;
267
+ }
268
+ </style>
@@ -0,0 +1,86 @@
1
+ import type { UI_I_WizardStep } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/interfaces'
2
+ import { UI_E_WIZARD_STATUS } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/enums'
3
+ import type { UI_I_Localization } from '~/lib/models/interfaces'
4
+
5
+ export const dynamicSteps = {
6
+ selectName: 0,
7
+ selectNameFolder: 1,
8
+ selectComputeResource: 2,
9
+ readyComplete: 3,
10
+ }
11
+
12
+ export const stepsFunc = (
13
+ localization: UI_I_Localization
14
+ ): UI_I_WizardStep[] => {
15
+ return [
16
+ // Procurator
17
+ {
18
+ id: dynamicSteps.selectName,
19
+ stepName: '',
20
+ title: localization.common.selectName,
21
+ subTitle: localization.common.specifyUniqueName,
22
+ status: UI_E_WIZARD_STATUS.SELECTED,
23
+ isValid: true,
24
+ testId: 'vm-select-name',
25
+ fields: {
26
+ name: {
27
+ field: '',
28
+ alert: '',
29
+ },
30
+ },
31
+ },
32
+ // Sphere
33
+ {
34
+ id: dynamicSteps.selectNameFolder,
35
+ stepName: '',
36
+ title: localization.vmWizard.selectNameFolder,
37
+ subTitle: localization.common.specifyUniqueNameTargetLocation,
38
+ status: UI_E_WIZARD_STATUS.INACTIVE,
39
+ isValid: true,
40
+ testId: 'vm-select-name-folder',
41
+ fields: {
42
+ name: {
43
+ field: '',
44
+ alert: '',
45
+ },
46
+ },
47
+ },
48
+ // Sphere
49
+ {
50
+ id: dynamicSteps.selectComputeResource,
51
+ stepName: '',
52
+ title: localization.vmWizard.selectComputeResource,
53
+ subTitle: localization.common.selectDestinationComputeResourceOperation,
54
+ status: UI_E_WIZARD_STATUS.INACTIVE,
55
+ isValid: true,
56
+ testId: 'vm-select-compute-resource',
57
+ fields: {
58
+ computeResource: {
59
+ field: '',
60
+ alert: '',
61
+ },
62
+ },
63
+ },
64
+ {
65
+ id: dynamicSteps.readyComplete,
66
+ stepName: '',
67
+ title: localization.vmWizard.readyComplete,
68
+ subTitle: localization.vmWizard.lastCreateSubtitle,
69
+ status: UI_E_WIZARD_STATUS.INACTIVE,
70
+ isValid: true,
71
+ testId: 'vm-ready-complete',
72
+ fields: {},
73
+ },
74
+ ]
75
+ }
76
+
77
+ export const stepsSchemeInitial = [
78
+ // 0 Procurator
79
+ [dynamicSteps.selectName, dynamicSteps.readyComplete],
80
+ // 1 Sphere
81
+ [
82
+ dynamicSteps.selectNameFolder,
83
+ dynamicSteps.selectComputeResource,
84
+ dynamicSteps.readyComplete,
85
+ ],
86
+ ]
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.5.466",
4
+ "version": "1.5.467",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",