bfg-common 1.5.490 → 1.5.491

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,549 +0,0 @@
1
- <template>
2
- <common-vmt-actions-add-new
3
- v-if="isNewView"
4
- v-model:vmt-form="vmtForm"
5
- :title="title"
6
- :alert-messages="alertMessages"
7
- :wizard="wizard"
8
- :dynamic-steps="dynamicSteps"
9
- :new-task-form="newTaskForm"
10
- :selected-scheme="selectedScheme"
11
- :name-form-submit="nameFormSubmit"
12
- :storage-submit="storageSubmit"
13
- :customize-hardware-submit="customizeHardwareSubmit"
14
- :is-loading="isLoading"
15
- :selected-nav-item="selectedNavItem"
16
- :machine-types="machineTypes"
17
- :cpu-models="cpuModels"
18
- :max-memory="maxMemory"
19
- :max-cpus="maxCpus"
20
- :guest-os-versions="guestOsVersions"
21
- :virtual-hardware-cd-dvd-drives-local="virtualHardwareCdDvdDrivesLocal"
22
- :virtual-hardware-networks-local="virtualHardwareNetworksLocal"
23
- :virtual-hardware-hard-disks-local="virtualHardwareHardDisksLocal"
24
- :guest-os-families="guestOsFamilies"
25
- :project="props.project"
26
- :nodes="props.nodes"
27
- :files="props.files"
28
- :networks-table="props.networksTable"
29
- :datastore="props.datastore"
30
- :is-datastore-loading="props.isDatastoreLoading"
31
- :error-validation-fields="props.errorValidationFields"
32
- :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
33
- :get-datastore-table-func="props.getDatastoreTableFunc"
34
- :passthrough-devices="props.passthroughDevices"
35
- :mediated-devices="props.mediatedDevices"
36
- :ready-complete-table-info="props.readyCompleteTableInfo"
37
- @remove-error-by-title="emits('remove-error-by-title', $event)"
38
- @get-storage="emits('get-storage', $event)"
39
- @change-steps="onChangeSteps"
40
- @check-name="emits('check-name', $event)"
41
- @get-pci-devices="emits('get-pci-devices')"
42
- @change-storage="onChangeStorage"
43
- @change-boot-order="onChangeBootOrder"
44
- @change-customize-hardware="onChangeCustomizeHardware"
45
- @get-folders-or-files="emits('get-folders-or-files', $event)"
46
- @get-active-device-child="emits('get-active-device-child', $event)"
47
- @show-datastore-child="emits('show-datastore-child', $event)"
48
- @get-networks-table="emits('get-networks-table', $event)"
49
- @change-name="onChangeName(...$event)"
50
- @hide="emits('hide')"
51
- @finish="onFinish"
52
- />
53
- <common-vmt-actions-add-old
54
- v-else
55
- v-model:vmt-form="vmtForm"
56
- :title="title"
57
- :wizard="wizard"
58
- :dynamic-steps="dynamicSteps"
59
- :new-task-form="newTaskForm"
60
- :selected-scheme="selectedScheme"
61
- :name-form-submit="nameFormSubmit"
62
- :storage-submit="storageSubmit"
63
- :customize-hardware-submit="customizeHardwareSubmit"
64
- :is-loading="isLoading"
65
- :selected-nav-item="selectedNavItem"
66
- :virtual-hardware-cd-dvd-drives-local="virtualHardwareCdDvdDrivesLocal"
67
- :virtual-hardware-networks-local="virtualHardwareNetworksLocal"
68
- :virtual-hardware-hard-disks-local="virtualHardwareHardDisksLocal"
69
- :max-memory="maxMemory"
70
- :max-cpus="maxCpus"
71
- :machine-types="machineTypes"
72
- :cpu-models="cpuModels"
73
- :guest-os-versions="guestOsVersions"
74
- :guest-os-families="guestOsFamilies"
75
- :project="props.project"
76
- :nodes="props.nodes"
77
- :files="props.files"
78
- :networks-table="props.networksTable"
79
- :datastore="props.datastore"
80
- :is-datastore-loading="props.isDatastoreLoading"
81
- :error-validation-fields="props.errorValidationFields"
82
- :ready-complete-table-info="props.readyCompleteTableInfo"
83
- :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
84
- :get-datastore-table-func="props.getDatastoreTableFunc"
85
- :passthrough-devices="props.passthroughDevices"
86
- :mediated-devices="props.mediatedDevices"
87
- @change-steps="onChangeSteps"
88
- @check-name="emits('check-name', $event)"
89
- @get-storage="emits('get-storage', $event)"
90
- @get-folders-or-files="emits('get-folders-or-files', $event)"
91
- @get-active-device-child="emits('get-active-device-child', $event)"
92
- @show-datastore-child="emits('show-datastore-child', $event)"
93
- @remove-error-by-title="emits('remove-error-by-title', $event)"
94
- @get-networks-table="emits('get-networks-table', $event)"
95
- @change-boot-order="onChangeBootOrder"
96
- @change-customize-hardware="onChangeCustomizeHardware"
97
- @get-pci-devices="emits('get-pci-devices')"
98
- @change-storage="onChangeStorage"
99
- @change-name="onChangeName"
100
- @hide="emits('hide')"
101
- @finish="onFinish"
102
- />
103
- </template>
104
-
105
- <script setup lang="ts">
106
- // TODO use just add-vm component
107
- import type {
108
- UI_I_ValidationReturn,
109
- UI_I_WizardStep,
110
- } from '~/node_modules/bfg-uikit/components/ui/wizard/lib/models/interfaces'
111
- import Wizard from '~/node_modules/bfg-uikit/components/ui/wizard/lib/utils/utils'
112
- import type {
113
- UI_I_ArbitraryObject,
114
- UI_I_Localization,
115
- } from '~/lib/models/interfaces'
116
- import type { UI_I_VmtForm } from '~/components/common/vmt/actions/add/lib/models/interfaces'
117
- import type {
118
- UI_I_SendDataCpu,
119
- UI_I_SendDataMemory,
120
- UI_I_SendDataNewCdDvdDrive,
121
- UI_I_SendDataNewHardDisk,
122
- UI_I_SendDataNewNetwork,
123
- } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
124
- import type {
125
- API_UI_I_Error,
126
- UI_I_ErrorValidationField,
127
- } from '~/lib/models/store/interfaces'
128
- import type { UI_I_SendDataCustomizeHardware } from '~/components/common/vm/actions/common/customizeHardware/lib/models/interfaces'
129
- import type { UI_I_ScheduleNewTasksForm } from '~/components/common/pages/scheduledTasks/modals/lib/models/interfaces'
130
- import type { UI_T_SelectedNavItem } from '~/components/common/vm/actions/common/lib/models/types'
131
- import type { UI_T_ChangeBootOrder } from '~/components/common/vm/actions/lib/models/types'
132
- import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
133
- import type { UI_T_Project } from '~/lib/models/types'
134
- import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
135
- import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
136
- import type {
137
- UI_I_DatastoreTableItem,
138
- UI_I_FolderOrFileTreePayload,
139
- } from '~/lib/models/store/storage/interfaces'
140
- import type { UI_I_TableInfoItem } from '~/components/atoms/table/info/lib/models/interfaces'
141
- import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
142
- import type {
143
- UI_I_MediatedDevice,
144
- UI_I_PciDevice,
145
- } from '~/lib/models/store/vm/interfaces'
146
- import type { UI_I_Capabilities } from '~/components/common/vm/actions/common/lib/models/interfaces'
147
- import { mapCapabilities } from '~/components/common/vm/actions/common/lib/utils/capabilities'
148
- import {
149
- dynamicSteps,
150
- stepsSchemeInitial,
151
- stepsFunc,
152
- } from '~/components/common/vmt/actions/add/lib/config/steps'
153
- import { scheduledTaskDefaultFormFunc } from '~/components/common/pages/scheduledTasks/modals/lib/config/createScheduledTask'
154
- import { capabilities } from '~/components/common/vm/actions/common/lib/config/capabilities'
155
-
156
- const props = withDefaults(
157
- defineProps<{
158
- project: UI_T_Project
159
- nodes: UI_I_FileTreeNode[]
160
- files: UI_I_FileTreeNode[]
161
- networksTable: UI_I_NetworkTableItem[]
162
- datastore: UI_I_DatastoreTableItem[]
163
- isDatastoreLoading: boolean
164
- errorValidationFields: UI_I_ErrorValidationField[]
165
- readyCompleteTableInfo: UI_I_TableInfoItem[]
166
- vmCpuHelpTextSecond: string
167
- finishFunc: any
168
- getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
169
- validateSendDataFunc: any
170
- passthroughDevices: UI_I_PciDevice[]
171
- mediatedDevices: UI_I_MediatedDevice[]
172
- vmtNameInWizard: string
173
- capabilities?: UI_I_Capabilities
174
- schedulerTask?: any // TODO надо interface переместить глобално
175
- }>(),
176
- {
177
- capabilities: undefined,
178
- schedulerTask: undefined,
179
- }
180
- )
181
-
182
- const emits = defineEmits<{
183
- (event: 'check-name', value: [string, (error: API_UI_I_Error) => void]): void
184
- (event: 'get-storage', value: UI_I_TablePayload): void
185
- (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
186
- (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
187
- (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
188
- (event: 'remove-error-by-title', value: string): void
189
- (event: 'get-networks-table', value: UI_I_TablePayload): void
190
- (event: 'get-pci-devices'): void
191
- (event: 'hide'): void
192
- }>()
193
-
194
- const { $store }: any = useNuxtApp()
195
-
196
- const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
197
-
198
- const localization = computed<UI_I_Localization>(() => useLocal())
199
-
200
- const isScheduledTasks = computed<boolean>(
201
- () => props.schedulerTask?.isSchedulerTask
202
- )
203
-
204
- const wizard: Wizard = new Wizard(
205
- stepsFunc(localization.value, isScheduledTasks.value),
206
- stepsSchemeInitial
207
- )
208
-
209
- const selectedScheme = computed<number[]>(() => wizard.selectedScheme.value)
210
- const alertMessages = computed<string[][]>(() => wizard.alertMessages.value)
211
-
212
- const nameFormSubmit = ref<Function | null>(null)
213
- const storageSubmit = ref<Function | null>(null)
214
- const selectOptionsSubmit = ref<number>(0)
215
- const customizeHardwareSubmit = ref<Function | null>(null)
216
-
217
- const checkName = async (
218
- value: UI_I_WizardStep[]
219
- ): Promise<UI_I_ValidationReturn> => {
220
- let stepHasError = false
221
-
222
- return new Promise((resolve) => {
223
- nameFormSubmit.value = (isValid: boolean) => {
224
- if (!isValid) {
225
- stepHasError = wizard.setValidation(dynamicSteps.selectName, 'name', {
226
- fieldMessage: 'aaa',
227
- alertMessage: 'aaa',
228
- })
229
- } else if (wizard.hasMessage(dynamicSteps.selectName, 'name')) {
230
- value = wizard.removeValidation(dynamicSteps.selectName, 'name', value)
231
- }
232
-
233
- resolve({
234
- stepHasError,
235
- newValue: value,
236
- })
237
- nameFormSubmit.value = null
238
- }
239
- })
240
- }
241
- const checkStorage = async (
242
- value: UI_I_WizardStep[]
243
- ): Promise<UI_I_ValidationReturn> => {
244
- let stepHasError = false
245
-
246
- return new Promise((resolve) => {
247
- storageSubmit.value = (isValid: boolean) => {
248
- if (!isValid) {
249
- stepHasError = wizard.setValidation(
250
- dynamicSteps.selectStorage,
251
- 'storage',
252
- {
253
- fieldMessage: 'aaa',
254
- alertMessage: 'aaa',
255
- }
256
- )
257
- } else if (wizard.hasMessage(dynamicSteps.selectStorage, 'storage')) {
258
- value = wizard.removeValidation(
259
- dynamicSteps.selectStorage,
260
- 'storage',
261
- value
262
- )
263
- }
264
-
265
- resolve({
266
- stepHasError,
267
- newValue: value,
268
- })
269
- storageSubmit.value = null
270
- }
271
- })
272
- }
273
- const checkCustomizeHardware = async (
274
- value: UI_I_WizardStep[]
275
- ): Promise<UI_I_ValidationReturn> => {
276
- let stepHasError = false
277
-
278
- return new Promise((resolve) => {
279
- customizeHardwareSubmit.value = (isValid: boolean) => {
280
- if (!isValid) {
281
- stepHasError = wizard.setValidation(
282
- dynamicSteps.customizeHardware,
283
- 'customizeHardware',
284
- {
285
- fieldMessage: 'aaa',
286
- alertMessage: 'aaa',
287
- }
288
- )
289
- } else if (
290
- wizard.hasMessage(dynamicSteps.customizeHardware, 'customizeHardware')
291
- ) {
292
- value = wizard.removeValidation(
293
- dynamicSteps.customizeHardware,
294
- 'customizeHardware',
295
- value
296
- )
297
- }
298
-
299
- resolve({
300
- stepHasError,
301
- newValue: value,
302
- })
303
- storageSubmit.value = null
304
- }
305
- })
306
- }
307
- const validationFunc = async (
308
- value: UI_I_WizardStep[],
309
- currentStep: UI_I_WizardStep,
310
- nextStep: UI_I_WizardStep
311
- ): Promise<UI_I_ValidationReturn> => {
312
- let stepHasError = false
313
- let stepShouldStop = {
314
- ifOnCurrentStep: false,
315
- ifFromAnyStep: false,
316
- stoppageStepId: -1,
317
- }
318
-
319
- wizard.setLoader(true)
320
- if (
321
- wizard.isValidateForStep(
322
- dynamicSteps.selectName,
323
- currentStep.id,
324
- nextStep.id
325
- )
326
- ) {
327
- const nameValidation = await checkName(value)
328
-
329
- value = nameValidation.newValue
330
- stepHasError = stepHasError || nameValidation.stepHasError
331
- } else if (
332
- wizard.isValidateForStep(
333
- dynamicSteps.selectStorage,
334
- currentStep.id,
335
- nextStep.id
336
- )
337
- ) {
338
- const storageValidation = await checkStorage(value)
339
-
340
- value = storageValidation.newValue
341
-
342
- stepHasError = stepHasError || storageValidation.stepHasError
343
- } else if (
344
- wizard.isValidateForStep(
345
- dynamicSteps.selectOptions,
346
- currentStep.id,
347
- nextStep.id
348
- )
349
- ) {
350
- selectOptionsSubmit.value++
351
- } else if (
352
- wizard.isValidateForStep(
353
- dynamicSteps.customizeHardware,
354
- currentStep.id,
355
- nextStep.id
356
- )
357
- ) {
358
- const customizeHardwareValidation = await checkCustomizeHardware(value)
359
-
360
- value = customizeHardwareValidation.newValue
361
-
362
- stepHasError = stepHasError || customizeHardwareValidation.stepHasError
363
- }
364
- wizard.setLoader(false)
365
-
366
- return {
367
- newValue: value,
368
- stepHasError,
369
- stepShouldStop,
370
- }
371
- }
372
-
373
- const vmtForm = ref<UI_I_VmtForm>({
374
- name: '',
375
- compatibility: '',
376
- guestMachineType: null,
377
- guestOsFamily: null,
378
- guestOsVersion: null,
379
- computeResource: null,
380
- storage: null,
381
- locationPath: '',
382
- // dataCenter: null,
383
- })
384
- const customizeHardware = ref<UI_I_SendDataCustomizeHardware | null>(null)
385
- const virtualHardwareCpu = computed<UI_I_SendDataCpu | null>(
386
- () => customizeHardware.value?.virtualHardware?.cpu || null
387
- )
388
- const virtualHardwareMemory = computed<UI_I_SendDataMemory | null>(
389
- () => customizeHardware.value?.virtualHardware?.memory || null
390
- )
391
- const virtualHardwareNetworks = ref<UI_I_SendDataNewNetwork[] | null>(null)
392
- const virtualHardwareHardDisks = ref<UI_I_SendDataNewHardDisk[] | null>(null)
393
- const virtualHardwareCdDvdDrives = ref<UI_I_SendDataNewCdDvdDrive[] | null>(
394
- null
395
- )
396
- const isPowerOnByDefault = ref<boolean>(true)
397
- const selectedNavItem = ref<UI_T_SelectedNavItem>(0)
398
-
399
- const validateSendData = async (
400
- value: UI_I_WizardStep[]
401
- ): Promise<UI_I_ValidationReturn> => {
402
- wizard.setLoader(true)
403
- let stepHasError = false
404
-
405
- const data = await props.validateSendDataFunc(
406
- vmtForm.value,
407
- virtualHardwareCpu.value,
408
- virtualHardwareMemory.value,
409
- customizeHardware.value,
410
- virtualHardwareNetworks.value,
411
- virtualHardwareHardDisks.value,
412
- virtualHardwareCdDvdDrives.value,
413
- isPowerOnByDefault.value,
414
- localization.value
415
- )
416
-
417
- wizard.setLoader(false)
418
- if (data) {
419
- stepHasError = true
420
- selectedNavItem.value = data[0]
421
- }
422
-
423
- return {
424
- stepHasError,
425
- newValue: value,
426
- }
427
- }
428
-
429
- const onChangeSteps = async (value: UI_I_WizardStep[]): Promise<void> => {
430
- wizard.changeSteps(value, validationFunc, validateSendData)
431
- }
432
-
433
- const title = computed<string>(() => {
434
- const { scheduleNewTasks, scheduleTaskEdit } = localization.value.common
435
-
436
- let result = localization.value.vmt.newTemplate
437
- if (isScheduledTasks.value) {
438
- const schedulerMode = props.schedulerTask.editTask
439
- ? scheduleTaskEdit
440
- : scheduleNewTasks
441
-
442
- result = `${schedulerMode} (${localization.value.vmt.newTemplate})`
443
- }
444
-
445
- return result
446
- })
447
-
448
- // TODO move to common
449
- const newTaskForm = ref<UI_I_ScheduleNewTasksForm>(
450
- useDeepCopy(scheduledTaskDefaultFormFunc())
451
- )
452
- watch(
453
- newTaskForm,
454
- (newValue: UI_I_ScheduleNewTasksForm) => {
455
- if (isScheduledTasks.value) wizard.setDisabledNextButton(newValue.isValid)
456
- },
457
- { immediate: true, deep: true }
458
- )
459
-
460
- const isLoading = ref<boolean>(false)
461
- const onFinish = (): void => {
462
- isLoading.value = true
463
- wizard.setLoader(false)
464
- props
465
- .finishFunc(
466
- vmtForm.value,
467
- virtualHardwareCpu.value,
468
- virtualHardwareMemory.value,
469
- customizeHardware.value,
470
- virtualHardwareNetworks.value,
471
- virtualHardwareHardDisks.value,
472
- virtualHardwareCdDvdDrives.value,
473
- isPowerOnByDefault.value,
474
- localization.value,
475
- false,
476
- newTaskForm.value,
477
- props.schedulerTask
478
- )
479
- .then(() => {
480
- isLoading.value = false
481
- emits('hide')
482
- wizard.setLoader(false)
483
- })
484
- }
485
-
486
- const virtualHardwareCdDvdDrivesLocal = computed<
487
- UI_I_SendDataNewCdDvdDrive[] | null
488
- >(() => customizeHardware.value?.virtualHardware?.cdDvdDrives || null)
489
- const virtualHardwareNetworksLocal = computed<UI_I_SendDataNewNetwork[] | null>(
490
- () => customizeHardware.value?.virtualHardware?.networks || null
491
- )
492
- const virtualHardwareHardDisksLocal = computed<
493
- UI_I_SendDataNewHardDisk[] | null
494
- >(() => customizeHardware.value?.virtualHardware?.hardDisks || null)
495
-
496
- const maxCpus = ref<number>(capabilities.value.maxCpus)
497
- const maxMemory = ref<number>(capabilities.value.maxMemory)
498
- const cpuModels = ref<UI_I_OptionItem[]>(capabilities.value.cpuModels)
499
- const machineTypes = ref<UI_I_OptionItem[]>(capabilities.value.machineTypes)
500
-
501
- const guestOsVersions = ref<UI_I_ArbitraryObject<UI_I_OptionItem[]>>(
502
- capabilities.value.guestOsVersions
503
- )
504
-
505
- const guestOsFamilies = ref<UI_I_OptionItem[]>(
506
- capabilities.value.guestOsFamilies
507
- )
508
-
509
- watch(
510
- () => props.capabilities,
511
- () => {
512
- if (props.capabilities) mapCapabilities(props.capabilities)
513
- },
514
- { deep: true, immediate: true }
515
- )
516
-
517
- const onChangeCustomizeHardware = (
518
- data: UI_I_SendDataCustomizeHardware
519
- ): void => {
520
- customizeHardware.value = data
521
- }
522
-
523
- const storageIdCash = ref<string | null>(null)
524
- const onChangeStorage = (storage: UI_I_DatastoreTableItem | null): void => {
525
- if (!storage) return
526
-
527
- vmtForm.value.storage = storage
528
- storageIdCash.value = storage.id
529
- }
530
-
531
- const onChangeName = (name: string): void => {
532
- vmtForm.value.name = name
533
- }
534
-
535
- const onChangeBootOrder = (data: UI_T_ChangeBootOrder): void => {
536
- virtualHardwareHardDisks.value = data[0]
537
- virtualHardwareCdDvdDrives.value = data[1]
538
- virtualHardwareNetworks.value = data[2]
539
- }
540
-
541
- watch(
542
- () => props.vmtNameInWizard,
543
- (newValue) => {
544
- vmtForm.value.name = newValue
545
- }
546
- )
547
- </script>
548
-
549
- <style scoped lang="scss"></style>