bfg-common 1.5.490 → 1.5.492

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,248 +1,251 @@
1
- <template>
2
- <common-backup-storage-actions-add-new
3
- v-if="isNewView"
4
- v-model="form"
5
- :project="props.project"
6
- :wizard="wizard"
7
- :selected-scheme="selectedScheme"
8
- :alert-messages="alertMessages"
9
- :title="title"
10
- :hosts="props.hosts"
11
- :datastore="props.datastore"
12
- :is-datastore-loading="props.isDatastoreLoading"
13
- :get-datastore-table-func="props.getDatastoreTableFunc"
14
- @change-steps="onChangeSteps"
15
- @change-storage="onChangeStorage"
16
- @submit="onCreate"
17
- @hide="onHideModal"
18
- />
19
- <common-backup-storage-actions-add-old
20
- v-else
21
- v-model="form"
22
- :project="props.project"
23
- :wizard="wizard"
24
- :selected-scheme="selectedScheme"
25
- :alert-messages="alertMessages"
26
- :title="title"
27
- :hosts="props.hosts"
28
- :datastore="props.datastore"
29
- :is-datastore-loading="props.isDatastoreLoading"
30
- :get-datastore-table-func="props.getDatastoreTableFunc"
31
- @change-steps="onChangeSteps"
32
- @change-storage="onChangeStorage"
33
- @submit="onCreate"
34
- @hide="onHideModal"
35
- />
36
- </template>
37
-
38
- <script setup lang="ts">
39
- import type {
40
- UI_I_ValidationReturn,
41
- UI_I_WizardStep,
42
- } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/interfaces'
43
- import Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
44
- import type { UI_T_Project } from '~/lib/models/types'
45
- import type { UI_I_CreateDatastoreForm } from '~/components/common/backup/storage/actions/add/lib/models/interfaces'
46
- import type { UI_I_DatastoreTableItem } from '~/lib/models/store/storage/interfaces'
47
- import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
48
- import type { UI_I_Localization } from '~/lib/models/interfaces'
49
- import type { UI_T_DatastoreTypeCode } from '~/components/common/backup/storage/actions/add/lib/models/types'
50
- // TODO use from uikit
51
- import {
52
- stepsFunc,
53
- stepsSchemeInitial,
54
- } from '~/components/common/backup/storage/actions/add/lib/config/steps'
55
- import { datastoreDefaultFormFunc } from '~/components/common/backup/storage/actions/add/lib/config/createDatastore'
56
- import {
57
- dynamicSteps,
58
- getStepScheme,
59
- } from '~/components/common/backup/storage/actions/add/lib/config/steps'
60
- import * as validation from '~/components/common/backup/storage/actions/add/lib/validations'
61
-
62
- const props = withDefaults(
63
- defineProps<{
64
- project: UI_T_Project
65
- datastore: UI_I_DatastoreTableItem[]
66
- isDatastoreLoading: boolean
67
- getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
68
- hosts?: any[]
69
- }>(),
70
- { hosts: [] }
71
- )
72
- const emits = defineEmits<{
73
- (event: 'create', value: UI_I_CreateDatastoreForm): void
74
- (event: 'hide'): void
75
- }>()
76
-
77
- const { $store }: any = useNuxtApp()
78
- const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
79
-
80
- const localization = computed<UI_I_Localization>(() => useLocal())
81
-
82
- const title = ref(localization.value.common.newBackupStorage)
83
-
84
- const wizard: Wizard = new Wizard(
85
- stepsFunc(localization.value),
86
- stepsSchemeInitial
87
- )
88
-
89
- const selectedScheme = computed<number[]>(() => wizard.selectedScheme.value)
90
- const alertMessages = computed<string[][]>(() => wizard.alertMessages.value)
91
-
92
- const form = ref<UI_I_CreateDatastoreForm>(
93
- useDeepCopy(datastoreDefaultFormFunc())
94
- )
95
-
96
- const validationFunc = async (
97
- value: UI_I_WizardStep[],
98
- currentStep: UI_I_WizardStep,
99
- nextStep: UI_I_WizardStep
100
- ): Promise<UI_I_ValidationReturn> => {
101
- let stepHasError = false
102
-
103
- if (
104
- wizard.isValidateForStep(dynamicSteps.name, currentStep.id, nextStep.id)
105
- ) {
106
- const nameValidation = await validation.checkDatastoreNameAsync(
107
- localization.value,
108
- value,
109
- form.value,
110
- dynamicSteps.name,
111
- 'name',
112
- wizard,
113
- props.project
114
- )
115
-
116
- value = nameValidation.newValue
117
-
118
- stepHasError = nameValidation.stepHasError
119
- }
120
-
121
- if (
122
- wizard.isValidateForStep(
123
- dynamicSteps.nameAndConfigure,
124
- currentStep.id,
125
- nextStep.id
126
- )
127
- ) {
128
- const nameValidation = await validation.checkDatastoreNameAsync(
129
- localization.value,
130
- value,
131
- form.value,
132
- dynamicSteps.nameAndConfigure,
133
- 'name',
134
- wizard,
135
- props.project
136
- )
137
- value = nameValidation.newValue
138
-
139
- const folderValidation = validation.checkFolderSync(
140
- localization.value,
141
- form.value.folder,
142
- wizard,
143
- value
144
- )
145
- value = folderValidation.newValue
146
-
147
- const serverValidation = validation.checkServerSync(
148
- localization.value,
149
- form.value.server,
150
- wizard,
151
- value
152
- )
153
- value = serverValidation.newValue
154
-
155
- // PC-2542
156
- // const usernameValidation = validation.checkUsernameSync(
157
- // localization.value,
158
- // form.value.user,
159
- // wizard,
160
- // value
161
- // )
162
- // value = usernameValidation.newValue
163
-
164
- // const passwordValidation = validation.checkPasswordSync(
165
- // localization.value,
166
- // form.value.password,
167
- // wizard,
168
- // value
169
- // )
170
- // value = passwordValidation.newValue
171
-
172
- stepHasError =
173
- nameValidation.stepHasError ||
174
- folderValidation.stepHasError ||
175
- serverValidation.stepHasError
176
- }
177
-
178
- if (
179
- wizard.isValidateForStep(
180
- dynamicSteps.hostAccessibility,
181
- currentStep.id,
182
- nextStep.id
183
- )
184
- ) {
185
- const hostsValidation = await validation.checkHostsAccessibilitySync(
186
- localization.value,
187
- form.value.hosts,
188
- wizard,
189
- value
190
- )
191
-
192
- value = hostsValidation.newValue
193
-
194
- stepHasError = hostsValidation.stepHasError
195
- }
196
-
197
- if (
198
- wizard.isValidateForStep(dynamicSteps.storage, currentStep.id, nextStep.id)
199
- ) {
200
- const storageValidation = await validation.checkStorageSync(
201
- localization.value,
202
- form.value.storm_id,
203
- wizard,
204
- value
205
- )
206
-
207
- value = storageValidation.newValue
208
-
209
- stepHasError = storageValidation.stepHasError
210
- }
211
-
212
- return {
213
- newValue: value,
214
- stepHasError,
215
- }
216
- }
217
-
218
- const onChangeSteps = async (value: UI_I_WizardStep[]): Promise<void> =>
219
- wizard.changeSteps(value, validationFunc)
220
-
221
- // Choosing Scheme
222
- watch(
223
- () => form.value.type_code,
224
- (newValue: UI_T_DatastoreTypeCode) => {
225
- const step = getStepScheme(props.project, newValue)
226
- if (step !== undefined) {
227
- wizard.changeScheme(step)
228
- }
229
- },
230
- { immediate: true }
231
- )
232
-
233
- const onChangeStorage = (storage: UI_I_DatastoreTableItem | null): void => {
234
- if (!storage) return
235
-
236
- form.value.storm_id = storage.id
237
- }
238
-
239
- const onCreate = async (): Promise<void> => {
240
- emits('create', form.value)
241
- }
242
-
243
- const onHideModal = (): void => {
244
- emits('hide')
245
- }
246
- </script>
247
-
248
- <style scoped lang="scss"></style>
1
+ <template>
2
+ <common-backup-storage-actions-add-new
3
+ v-if="isNewView"
4
+ v-model="form"
5
+ :project="props.project"
6
+ :wizard="wizard"
7
+ :selected-scheme="selectedScheme"
8
+ :alert-messages="alertMessages"
9
+ :title="title"
10
+ :hosts="props.hosts"
11
+ :datastore="props.datastore"
12
+ :is-datastore-loading="props.isDatastoreLoading"
13
+ :get-datastore-table-func="props.getDatastoreTableFunc"
14
+ @change-steps="onChangeSteps"
15
+ @change-storage="onChangeStorage"
16
+ @submit="onCreate"
17
+ @hide="onHideModal"
18
+ />
19
+ <common-backup-storage-actions-add-old
20
+ v-else
21
+ v-model="form"
22
+ :project="props.project"
23
+ :wizard="wizard"
24
+ :selected-scheme="selectedScheme"
25
+ :alert-messages="alertMessages"
26
+ :title="title"
27
+ :hosts="props.hosts"
28
+ :datastore="props.datastore"
29
+ :is-datastore-loading="props.isDatastoreLoading"
30
+ :get-datastore-table-func="props.getDatastoreTableFunc"
31
+ @change-steps="onChangeSteps"
32
+ @change-storage="onChangeStorage"
33
+ @submit="onCreate"
34
+ @hide="onHideModal"
35
+ />
36
+ </template>
37
+
38
+ <script setup lang="ts">
39
+ import type {
40
+ UI_I_ValidationReturn,
41
+ UI_I_WizardStep,
42
+ } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/interfaces'
43
+ import Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
44
+ import type { UI_T_Project } from '~/lib/models/types'
45
+ import type { UI_I_CreateDatastoreForm } from '~/components/common/backup/storage/actions/add/lib/models/interfaces'
46
+ import type { UI_I_DatastoreTableItem } from '~/lib/models/store/storage/interfaces'
47
+ import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
48
+ import type { UI_I_Localization } from '~/lib/models/interfaces'
49
+ import type { UI_T_DatastoreTypeCode } from '~/components/common/backup/storage/actions/add/lib/models/types'
50
+ // TODO use from uikit
51
+ import {
52
+ stepsFunc,
53
+ stepsSchemeInitial,
54
+ } from '~/components/common/backup/storage/actions/add/lib/config/steps'
55
+ import { datastoreDefaultFormFunc } from '~/components/common/backup/storage/actions/add/lib/config/createDatastore'
56
+ import {
57
+ dynamicSteps,
58
+ getStepScheme,
59
+ } from '~/components/common/backup/storage/actions/add/lib/config/steps'
60
+ import * as validation from '~/components/common/backup/storage/actions/add/lib/validations'
61
+
62
+ const props = withDefaults(
63
+ defineProps<{
64
+ project: UI_T_Project
65
+ datastore: UI_I_DatastoreTableItem[]
66
+ isDatastoreLoading: boolean
67
+ getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
68
+ hosts?: any[]
69
+ datacenterId?: string
70
+ }>(),
71
+ { hosts: [], datacenterId: '' }
72
+ )
73
+ const emits = defineEmits<{
74
+ (event: 'create', value: UI_I_CreateDatastoreForm): void
75
+ (event: 'hide'): void
76
+ }>()
77
+
78
+ const { $store }: any = useNuxtApp()
79
+ const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
80
+
81
+ const localization = computed<UI_I_Localization>(() => useLocal())
82
+
83
+ const title = ref(localization.value.common.newBackupStorage)
84
+
85
+ const wizard: Wizard = new Wizard(
86
+ stepsFunc(localization.value),
87
+ stepsSchemeInitial
88
+ )
89
+
90
+ const selectedScheme = computed<number[]>(() => wizard.selectedScheme.value)
91
+ const alertMessages = computed<string[][]>(() => wizard.alertMessages.value)
92
+
93
+ const form = ref<UI_I_CreateDatastoreForm>(
94
+ useDeepCopy(datastoreDefaultFormFunc())
95
+ )
96
+
97
+ const validationFunc = async (
98
+ value: UI_I_WizardStep[],
99
+ currentStep: UI_I_WizardStep,
100
+ nextStep: UI_I_WizardStep
101
+ ): Promise<UI_I_ValidationReturn> => {
102
+ let stepHasError = false
103
+
104
+ if (
105
+ wizard.isValidateForStep(dynamicSteps.name, currentStep.id, nextStep.id)
106
+ ) {
107
+ const nameValidation = await validation.checkDatastoreNameAsync(
108
+ localization.value,
109
+ value,
110
+ form.value,
111
+ dynamicSteps.name,
112
+ 'name',
113
+ wizard,
114
+ props.project,
115
+ props.datacenterId
116
+ )
117
+
118
+ value = nameValidation.newValue
119
+
120
+ stepHasError = nameValidation.stepHasError
121
+ }
122
+
123
+ if (
124
+ wizard.isValidateForStep(
125
+ dynamicSteps.nameAndConfigure,
126
+ currentStep.id,
127
+ nextStep.id
128
+ )
129
+ ) {
130
+ const nameValidation = await validation.checkDatastoreNameAsync(
131
+ localization.value,
132
+ value,
133
+ form.value,
134
+ dynamicSteps.nameAndConfigure,
135
+ 'name',
136
+ wizard,
137
+ props.project,
138
+ props.datacenterId
139
+ )
140
+ value = nameValidation.newValue
141
+
142
+ const folderValidation = validation.checkFolderSync(
143
+ localization.value,
144
+ form.value.folder,
145
+ wizard,
146
+ value
147
+ )
148
+ value = folderValidation.newValue
149
+
150
+ const serverValidation = validation.checkServerSync(
151
+ localization.value,
152
+ form.value.server,
153
+ wizard,
154
+ value
155
+ )
156
+ value = serverValidation.newValue
157
+
158
+ // PC-2542
159
+ // const usernameValidation = validation.checkUsernameSync(
160
+ // localization.value,
161
+ // form.value.user,
162
+ // wizard,
163
+ // value
164
+ // )
165
+ // value = usernameValidation.newValue
166
+
167
+ // const passwordValidation = validation.checkPasswordSync(
168
+ // localization.value,
169
+ // form.value.password,
170
+ // wizard,
171
+ // value
172
+ // )
173
+ // value = passwordValidation.newValue
174
+
175
+ stepHasError =
176
+ nameValidation.stepHasError ||
177
+ folderValidation.stepHasError ||
178
+ serverValidation.stepHasError
179
+ }
180
+
181
+ if (
182
+ wizard.isValidateForStep(
183
+ dynamicSteps.hostAccessibility,
184
+ currentStep.id,
185
+ nextStep.id
186
+ )
187
+ ) {
188
+ const hostsValidation = await validation.checkHostsAccessibilitySync(
189
+ localization.value,
190
+ form.value.hosts,
191
+ wizard,
192
+ value
193
+ )
194
+
195
+ value = hostsValidation.newValue
196
+
197
+ stepHasError = hostsValidation.stepHasError
198
+ }
199
+
200
+ if (
201
+ wizard.isValidateForStep(dynamicSteps.storage, currentStep.id, nextStep.id)
202
+ ) {
203
+ const storageValidation = await validation.checkStorageSync(
204
+ localization.value,
205
+ form.value.storm_id,
206
+ wizard,
207
+ value
208
+ )
209
+
210
+ value = storageValidation.newValue
211
+
212
+ stepHasError = storageValidation.stepHasError
213
+ }
214
+
215
+ return {
216
+ newValue: value,
217
+ stepHasError,
218
+ }
219
+ }
220
+
221
+ const onChangeSteps = async (value: UI_I_WizardStep[]): Promise<void> =>
222
+ wizard.changeSteps(value, validationFunc)
223
+
224
+ // Choosing Scheme
225
+ watch(
226
+ () => form.value.type_code,
227
+ (newValue: UI_T_DatastoreTypeCode) => {
228
+ const step = getStepScheme(props.project, newValue)
229
+ if (step !== undefined) {
230
+ wizard.changeScheme(step)
231
+ }
232
+ },
233
+ { immediate: true }
234
+ )
235
+
236
+ const onChangeStorage = (storage: UI_I_DatastoreTableItem | null): void => {
237
+ if (!storage) return
238
+
239
+ form.value.storm_id = storage.id
240
+ }
241
+
242
+ const onCreate = async (): Promise<void> => {
243
+ emits('create', form.value)
244
+ }
245
+
246
+ const onHideModal = (): void => {
247
+ emits('hide')
248
+ }
249
+ </script>
250
+
251
+ <style scoped lang="scss"></style>
@@ -1,30 +1,62 @@
1
- import type Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
2
- import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
3
- import type { UI_T_Project } from '~/lib/models/types'
4
- import { UI_E_Kind } from '~/lib/models/enums'
5
-
6
- export const checkValidityName = async (
7
- name: string,
8
- wizard: Wizard,
9
- project: UI_T_Project,
10
- sendMessage: (message: string) => void
11
- ): Promise<void> => {
12
-
13
- wizard.setLoader(true)
14
- const url =
15
- project === 'procurator'
16
- ? `/ui/ds/validate?name=${encodeURIComponent(name)}`
17
- : `/ui/object/validate_name?name=${encodeURIComponent(name)}&kind=${UI_E_Kind.STORAGE_VALIDATION_NAME}`
18
- // @ts-ignore
19
- const { error } = await useMyFetch<null, API_UI_I_Error>(url, {
20
- method: 'GET',
21
- })
22
- wizard.setLoader(false)
23
-
24
- if (error.value && error.value.data.error_code !== 0) {
25
- const existError = error.value.data?.error_message || error.value.data
26
- sendMessage(existError)
27
- return
28
- }
29
- sendMessage('')
30
- }
1
+ import type Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
2
+ import type { API_UI_I_Error } from '~/lib/models/store/interfaces'
3
+ import type { UI_T_Project } from '~/lib/models/types'
4
+ import { UI_E_Kind } from '~/lib/models/enums'
5
+
6
+ export const checkValidityName = async ({
7
+ name,
8
+ wizard,
9
+ project,
10
+ sendMessage,
11
+ datacenterId,
12
+ }: {
13
+ name: string
14
+ wizard: Wizard
15
+ project: UI_T_Project
16
+ sendMessage: (message: string) => void
17
+ datacenterId?: string
18
+ }): Promise<void> => {
19
+ wizard.setLoader(true)
20
+
21
+ try {
22
+ const url = buildValidationUrl(name, project, datacenterId)
23
+
24
+ const { error } = await useMyFetch<null, API_UI_I_Error>(url, {
25
+ method: 'GET',
26
+ })
27
+
28
+ if (
29
+ error?.value?.data?.error_code !== 0
30
+ ) {
31
+ const existError =
32
+ error.value.data?.error_message ?? String(error.value.data)
33
+ sendMessage(existError)
34
+ return
35
+ }
36
+
37
+ sendMessage('')
38
+ } catch (e) {
39
+ const msg = e instanceof Error ? e.message : 'Unknown error'
40
+ sendMessage(msg)
41
+ } finally {
42
+ wizard.setLoader(false)
43
+ }
44
+ }
45
+
46
+ const buildValidationUrl = (
47
+ name: string,
48
+ project: UI_T_Project,
49
+ datacenterId?: string
50
+ ): string => {
51
+ if (project === 'procurator') {
52
+ const params = new URLSearchParams({ name })
53
+ return `/ui/ds/validate?${params.toString()}`
54
+ }
55
+
56
+ const params = new URLSearchParams()
57
+ params.set('name', name)
58
+ params.set('kind', String(UI_E_Kind.STORAGE_VALIDATION_NAME))
59
+ if (datacenterId) params.set('datacenter', datacenterId)
60
+
61
+ return `/ui/object/validate_name?${params.toString()}`
62
+ }
@@ -14,15 +14,22 @@ const checkName = async (
14
14
  form: UI_I_CreateDatastoreForm,
15
15
  localization: UI_I_Localization,
16
16
  wizard: Wizard,
17
- project: UI_T_Project
17
+ project: UI_T_Project,
18
+ datacenterId?: string
18
19
  ): Promise<UI_I_AsyncCheckReturn> => {
19
20
  if (form.name) {
20
21
  return new Promise((resolve, _reject) =>
21
- checkValidityName(form.name, wizard, project, (message: string) => {
22
- resolve({
23
- isValid: message === '',
24
- message: message === '' ? '' : message,
25
- })
22
+ checkValidityName({
23
+ name: form.name,
24
+ wizard,
25
+ project,
26
+ datacenterId,
27
+ sendMessage: (message: string) => {
28
+ resolve({
29
+ isValid: message === '',
30
+ message: message === '' ? '' : message,
31
+ })
32
+ },
26
33
  })
27
34
  )
28
35
  } else {
@@ -39,14 +46,15 @@ export const checkDatastoreNameAsync = async (
39
46
  stepId: number,
40
47
  fieldName: string,
41
48
  wizard: Wizard,
42
- project: UI_T_Project
49
+ project: UI_T_Project,
50
+ datacenterId?: string
43
51
  ): Promise<UI_I_ValidationReturn> => {
44
52
  let stepHasError = false
45
53
 
46
54
  const labelValidation: {
47
55
  isValid: boolean
48
56
  message: string
49
- } = await checkName(form, localization, wizard, project)
57
+ } = await checkName(form, localization, wizard, project, datacenterId)
50
58
 
51
59
  if (!labelValidation.isValid) {
52
60
  stepHasError = wizard.setValidation(stepId, fieldName, {
@@ -297,7 +297,7 @@ const selectedCreateType = ref<string>('0')
297
297
  if (props.isVmt) selectedCreateType.value = '-1'
298
298
 
299
299
  const wizard: Wizard = new Wizard(
300
- stepsFunc(localization.value, props.isVmt),
300
+ stepsFunc(localization.value, props.isVmt, isSphere.value),
301
301
  stepsSchemeInitial
302
302
  )
303
303
  watch(
@@ -311,7 +311,7 @@ watch(
311
311
  wizard.changeScheme(isSphere.value ? 6 : 2)
312
312
  break
313
313
  case '-1':
314
- wizard.changeScheme(10)
314
+ wizard.changeScheme(isSphere.value ? 11 : 10)
315
315
  break
316
316
  }
317
317
  },
@@ -71,7 +71,7 @@
71
71
  selectedStep.id === dynamicSteps.selectNameFolder
72
72
  "
73
73
  :name-form-submit="props.nameFormSubmit"
74
- :project="props.project"
74
+ :has-location="props.project === 'sphere'"
75
75
  :is-vmt="props.isVmt"
76
76
  :data-center="props.dataCenter"
77
77
  :validate-empty-name="props.validateEmptyName"