bfg-common 1.5.689 → 1.5.691

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 (126) hide show
  1. package/CODE_STYLE.md +109 -109
  2. package/assets/img/icons/icons-sprite-dark-3.svg +227 -227
  3. package/assets/img/icons/icons-sprite-dark-5.svg +488 -488
  4. package/assets/img/icons/icons-sprite-light-3.svg +227 -227
  5. package/assets/img/icons/icons-sprite-light-5.svg +488 -488
  6. package/assets/localization/local_be.json +4 -0
  7. package/assets/localization/local_en.json +4 -0
  8. package/assets/localization/local_hy.json +4 -0
  9. package/assets/localization/local_kk.json +4 -0
  10. package/assets/localization/local_ru.json +4 -0
  11. package/assets/localization/local_zh.json +4 -0
  12. package/components/atoms/TheIcon3.vue +50 -50
  13. package/components/atoms/collapse/CollapseNav.vue +170 -170
  14. package/components/atoms/perPage/PerPage.vue +58 -58
  15. package/components/atoms/switch/Switch.vue +103 -103
  16. package/components/atoms/table/dataGrid/DataGrid.vue +1718 -1718
  17. package/components/atoms/table/dataGrid/DataGridPagination.vue +97 -97
  18. package/components/atoms/table/dataGrid/lib/config/settingsTable.ts +94 -94
  19. package/components/atoms/table/dataGrid/lib/utils/export.ts +16 -16
  20. package/components/common/backup/storage/actions/add/lib/utils.ts +51 -51
  21. package/components/common/browse/blocks/contents/filesNew/Skeleton.vue +18 -18
  22. package/components/common/diagramMain/modals/lib/config/vCenterModal.ts +48 -48
  23. package/components/common/diagramMain/port/Port.vue +580 -580
  24. package/components/common/layout/theHeader/TheHeaderNew.vue +315 -315
  25. package/components/common/layout/theHeader/TheHeaderOld.vue +262 -262
  26. package/components/common/layout/theHeader/helpMenu/About.vue +79 -79
  27. package/components/common/layout/theHeader/helpMenu/aboutOld/AboutOld.vue +79 -79
  28. package/components/common/layout/theHeader/userMenu/modals/preferences/PreferencesNew.vue +13 -0
  29. package/components/common/layout/theHeader/userMenu/modals/preferences/PreferencesOld.vue +144 -144
  30. package/components/common/layout/theHeader/userMenu/modals/preferences/changeLanguage/ChangeLanguage.vue +8 -15
  31. package/components/common/layout/theHeader/userMenu/modals/preferences/changeLanguage/{ChangeLanguageNew.vue → New.vue} +1 -2
  32. package/components/common/layout/theHeader/userMenu/modals/preferences/changeLanguage/{ChangeLanguageOld.vue → Old.vue} +0 -2
  33. package/components/common/layout/theHeader/userMenu/modals/preferences/defaultConsole/DefaultConsole.vue +8 -7
  34. package/components/common/layout/theHeader/userMenu/modals/preferences/defaultConsole/{DefaultConsoleNew.vue → New.vue} +3 -3
  35. package/components/common/layout/theHeader/userMenu/modals/preferences/defaultConsole/{DefaultConsoleOld.vue → Old.vue} +2 -2
  36. package/components/common/layout/theHeader/userMenu/modals/preferences/inventory/Inventory.vue +7 -8
  37. package/components/common/layout/theHeader/userMenu/modals/preferences/inventory/{InventoryNew.vue → New.vue} +3 -2
  38. package/components/common/layout/theHeader/userMenu/modals/preferences/inventory/{InventoryOld.vue → Old.vue} +2 -2
  39. package/components/common/layout/theHeader/userMenu/modals/preferences/lib/models/types.ts +7 -7
  40. package/components/common/layout/theHeader/userMenu/modals/preferences/security/New.vue +277 -12
  41. package/components/common/layout/theHeader/userMenu/modals/preferences/security/Old.vue +184 -216
  42. package/components/common/layout/theHeader/userMenu/modals/preferences/security/Security.vue +90 -31
  43. package/components/common/layout/theHeader/userMenu/modals/preferences/timeFormat/{TimeFormatNew.vue → New.vue} +3 -3
  44. package/components/common/layout/theHeader/userMenu/modals/preferences/timeFormat/{TimeFormatOld.vue → Old.vue} +2 -2
  45. package/components/common/layout/theHeader/userMenu/modals/preferences/timeFormat/TimeFormat.vue +8 -8
  46. package/components/common/layout/theHeader/userMenu/modals/preferences/view/{ViewNew.vue → New.vue} +12 -3
  47. package/components/common/layout/theHeader/userMenu/modals/preferences/view/{ViewOld.vue → Old.vue} +2 -2
  48. package/components/common/layout/theHeader/userMenu/modals/preferences/view/View.vue +8 -7
  49. package/components/common/pages/backups/DetailView.vue +52 -52
  50. package/components/common/pages/backups/lib/models/interfaces.ts +36 -36
  51. package/components/common/pages/backups/modals/Modals.vue +243 -243
  52. package/components/common/pages/backups/modals/createBackup/configuration/maxBandwidth/lib/config/options.ts +6 -6
  53. package/components/common/pages/backups/modals/createBackup/lib/config/readyToCompleteOptions.ts +69 -69
  54. package/components/common/pages/backups/modals/lib/config/restore.ts +115 -115
  55. package/components/common/pages/backups/modals/lib/models/interfaces.ts +186 -186
  56. package/components/common/pages/backups/modals/restore/name/lib/models/interfaces.ts +6 -6
  57. package/components/common/pages/home/lib/models/interfaces.ts +48 -48
  58. package/components/common/pages/home/widgets/hosts/Hosts.vue +27 -27
  59. package/components/common/pages/home/widgets/hosts/lib/config/items.ts +23 -23
  60. package/components/common/pages/home/widgets/vms/VmsOld.vue +35 -35
  61. package/components/common/pages/home/widgets/vms/lib/config/items.ts +19 -19
  62. package/components/common/pages/scheduledTasks/lib/utils/utils.ts +84 -84
  63. package/components/common/qr/Qr.vue +69 -57
  64. package/components/common/readyToComplete/ReadyToComplete.vue +17 -17
  65. package/components/common/select/radio/RadioGroup.vue +137 -137
  66. package/components/common/spiceConsole/Drawer.vue +420 -420
  67. package/components/common/spiceConsole/SpiceConsole.vue +184 -184
  68. package/components/common/spiceConsole/lib/models/interfaces.ts +5 -5
  69. package/components/common/tools/Actions.vue +207 -207
  70. package/components/common/treeView/TreeView.vue +52 -52
  71. package/components/common/vm/actions/clone/lib/config/steps.ts +295 -295
  72. package/components/common/vm/actions/clone/new/New.vue +438 -438
  73. package/components/common/vm/actions/common/customizeHardware/virtualHardware/VirtualHardware.vue +706 -706
  74. package/components/common/vm/actions/common/customizeHardware/virtualHardware/cpu/shares/lib/config/options.ts +28 -28
  75. package/components/common/vm/actions/common/customizeHardware/virtualHardware/memory/Memory.vue +283 -283
  76. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newHardDisk/NewHardDisk.vue +489 -489
  77. package/components/common/vm/actions/common/customizeHardware/virtualHardware/newPciDevice/NewPciDevice.vue +253 -253
  78. package/components/common/vm/actions/common/customizeHardware/vmoptions/bootOptions/order/Order.vue +156 -156
  79. package/components/common/vm/actions/common/select/compatibility/Old.vue +107 -107
  80. package/components/common/vm/actions/common/select/createType/lib/models/interfaces.ts +5 -5
  81. package/components/common/vm/actions/common/select/options/New.vue +264 -264
  82. package/components/common/vm/actions/common/select/options/Old.vue +109 -109
  83. package/components/common/vm/actions/common/select/options/Options.vue +58 -58
  84. package/components/common/vm/actions/common/select/storage/Old.vue +125 -125
  85. package/components/common/vm/actions/common/select/storage/new/New.vue +311 -311
  86. package/components/common/vm/actions/common/select/storage/new/lib/models/interfaces.ts +5 -5
  87. package/components/common/vm/actions/common/select/storage/new/lib/utils/utils.ts +21 -21
  88. package/components/common/vm/actions/common/select/template/old/Old.vue +50 -50
  89. package/components/common/vm/actions/editSettings/new/Skeleton.vue +88 -88
  90. package/components/common/wizards/common/compatibility/Compatibility.vue +35 -35
  91. package/components/common/wizards/common/steps/computeResource/New.vue +93 -93
  92. package/components/common/wizards/common/steps/name/Name.vue +178 -178
  93. package/components/common/wizards/common/steps/name/New.vue +221 -221
  94. package/components/common/wizards/common/steps/name/Old.vue +121 -121
  95. package/components/common/wizards/common/steps/name/lib/models/interfaces.ts +4 -4
  96. package/components/common/wizards/common/steps/name/location/New.vue +40 -40
  97. package/components/common/wizards/datastore/add/Add.vue +228 -228
  98. package/components/common/wizards/datastore/add/lib/utils.ts +85 -85
  99. package/components/common/wizards/datastore/add/steps/nameAndDevice/NameAndDeviceNew.vue +232 -232
  100. package/components/common/wizards/datastore/add/steps/nameAndDevice/NameAndDeviceOld.vue +231 -231
  101. package/components/common/wizards/datastore/add/steps/nameAndDevice/advancedOptions/AdvancedOptions.vue +43 -43
  102. package/components/common/wizards/datastore/add/steps/nameAndDevice/advancedOptions/New.vue +101 -101
  103. package/components/common/wizards/datastore/add/steps/nameAndDevice/advancedOptions/Old.vue +101 -101
  104. package/components/common/wizards/datastore/add/steps/typeMode/lib/config/typeOptions.ts +43 -43
  105. package/composables/useAppVersion.ts +21 -21
  106. package/composables/useEnvLanguage.ts +22 -22
  107. package/composables/useLocal.ts +6 -6
  108. package/composables/useLocalCommon.ts +39 -39
  109. package/package.json +2 -2
  110. package/plugins/console.ts +21 -21
  111. package/plugins/mouse.ts +21 -21
  112. package/plugins/panelStates.ts +70 -70
  113. package/plugins/text.ts +59 -59
  114. package/public/spice-console/application/clientgui.js +854 -854
  115. package/public/spice-console/application/packetfactory.js +211 -211
  116. package/public/spice-console/application/virtualmouse.js +147 -147
  117. package/public/spice-console/lib/images/bitmap.js +203 -203
  118. package/public/spice-console/network/spicechannel.js +440 -440
  119. package/public/spice-console/process/cursorprocess.js +128 -128
  120. package/public/spice-console/process/inputprocess.js +227 -227
  121. package/public/spice-console/process/mainprocess.js +212 -212
  122. package/public/spice-console/run.js +210 -210
  123. package/store/main/mutations.ts +7 -7
  124. package/store/main/state.ts +7 -7
  125. package/store/tasks/mappers/recentTasks.ts +123 -123
  126. package/store/tasks/mutations.ts +82 -82
@@ -1,706 +1,706 @@
1
- <template>
2
- <component
3
- :is="currentComponent"
4
- v-model="model"
5
- v-model:cpu-invalid="cpuInvalid"
6
- v-model:memory-invalid="memoryInvalid"
7
- v-model:video-card-invalid="videoCardInvalid"
8
- :nodes="props.nodes"
9
- :files="props.files"
10
- :is-edit="props.isEdit"
11
- :storage="props.storage"
12
- :storage-free="storageFree"
13
- :project="props.project"
14
- :max-memory="props.maxMemory"
15
- :cpu-models="props.cpuModels"
16
- :datastore="props.datastore"
17
- :is-datastore-loading="props.isDatastoreLoading"
18
- :networks-type="networksType"
19
- :networks-table="props.networksTable"
20
- :dropdown-items="dropdownItems"
21
- :hard-disks-type="hardDisksType"
22
- :networks-index="networksIndex"
23
- :hard-disks-index="hardDisksIndex"
24
- :pci-devices-type="pciDevicesType"
25
- :is-show-file-modal="isShowFileModal"
26
- :pci-devices-index="pciDevicesIndex"
27
- :cd-dvd-drives-type="cdDvdDrivesType"
28
- :cd-dvd-drives-index="cdDvdDrivesIndex"
29
- :error-validation-fields="errorValidationFields"
30
- :get-datastore-table-func="getDatastoreTableFunc"
31
- :state="state"
32
- :video-card="videoCard"
33
- :guest-machine-type="guestMachineType"
34
- :passthrough-devices="passthroughDevices"
35
- :mediated-devices="mediatedDevices"
36
- :vm-cpu-help-text-second="vmCpuHelpTextSecond"
37
- :compute-resource="props.computeResource"
38
- :compatibility-info="props.compatibilityInfo"
39
- :network-value-prop="networkValueProp"
40
- @add-device="onAddDevice"
41
- @get-storage="emits('get-storage', $event)"
42
- @remove-network="onRemoveNetwork"
43
- @hide-file-modal="isShowFileModal = false"
44
- @remove-hard-disk="onRemoveHardDisk(...$event)"
45
- @remove-pci-device="onRemovePciDevice"
46
- @get-networks-table="emits('get-networks-table', $event)"
47
- @add-exist-hard-disk="onAddExistHardDisk"
48
- @roll-back-hard-disk="onRollBackHardDisk"
49
- @set-invalid-network="onSetInvalidNetwork(...$event)"
50
- @remove-cd-dvd-drive="onRemoveCdDvdDrive(...$event)"
51
- @show-datastore-child="emits('show-datastore-child', $event)"
52
- @get-folders-or-files="emits('get-folders-or-files', $event)"
53
- @set-invalid-hard-disk="onSetInvalidHardDisk(...$event)"
54
- @remove-error-by-title="emits('remove-error-by-title', $event)"
55
- @roll-back-cd-dvd-drive="onRollBackCdDvdDrive"
56
- @set-invalid-pci-device="onSetInvalidPciDevice(...$event)"
57
- @get-active-device-child="emits('get-active-device-child', $event)"
58
- @send-data-new-hard-disk-method="onSendDataNewHardDiskMethod(...$event)"
59
- @send-data-new-cd-dvd-drive-method="sendDataNewCdDvdDriveMethod(...$event)"
60
- />
61
- </template>
62
-
63
- <script setup lang="ts">
64
- import type { UI_T_Project } from '~/lib/models/types'
65
- import type { UI_I_DatastoreTableItem } from '~/lib/models/store/storage/interfaces'
66
- import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
67
- import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
68
- import type { UI_I_FolderOrFileTreePayload } from '~/lib/models/store/storage/interfaces'
69
- import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
70
- import type {
71
- UI_I_SendDataNewHardDisk,
72
- UI_I_SendDataVideoCard,
73
- UI_I_InvalidKeys,
74
- UI_I_SendDataNewCdDvdDrive,
75
- // UI_I_HardDisk,
76
- UI_I_SendDataNewPciDevice,
77
- } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
78
- import type { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
79
- import type {
80
- UI_T_HardDiskType,
81
- UI_T_NetworkType,
82
- UI_T_CdDvdType,
83
- } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/types'
84
- import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
85
- import type {
86
- UI_I_DropdownTreeItem,
87
- UI_I_DropdownTreeItemChild,
88
- } from '~/components/atoms/dropdown/tree/lib/models/interfaces'
89
- import type { UI_I_Localization } from '~/lib/models/interfaces'
90
- import type {
91
- UI_I_MediatedDevice,
92
- UI_I_PciDevice,
93
- } from '~/lib/models/store/vm/interfaces'
94
- import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
95
- import type { UI_I_CreateVmData } from '~/components/common/vm/actions/common/lib/models/interfaces'
96
- import { dropdownItemsFunc } from './lib/config/dropdownItems'
97
-
98
- const model = defineModel<UI_I_CreateVmData>({ required: true })
99
-
100
- const props = withDefaults(
101
- defineProps<{
102
- storage: UI_I_DatastoreTableItem | null
103
- cpuModels: UI_I_OptionItem[]
104
- maxMemory: number
105
- isEdit: boolean
106
- isClone: boolean
107
- errorValidationFields: UI_I_ErrorValidationField[]
108
- nodes: UI_I_FileTreeNode[]
109
- files: UI_I_FileTreeNode[]
110
- networksTable: UI_I_NetworkTableItem[]
111
- getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
112
- datastore: UI_I_DatastoreTableItem[]
113
- isDatastoreLoading: boolean
114
- project: UI_T_Project
115
- state?: string | number
116
- vmCpuHelpTextSecond?: string
117
- hardDisks?: UI_I_SendDataNewHardDisk[] | null
118
- cdDvdDrives?: UI_I_SendDataNewCdDvdDrive[] | null
119
- videoCard?: UI_I_SendDataVideoCard
120
- // pciDevices?: UI_I_SendDataNewPciDevice[]
121
- passthroughDevices?: UI_I_PciDevice[]
122
- mediatedDevices?: UI_I_MediatedDevice[]
123
- guestMachineType?: UI_I_OptionItem | null
124
- computeResource?: UI_I_TreeNode | null
125
- compatibilityInfo?: string
126
- }>(),
127
- {
128
- state: undefined,
129
- vmCpuHelpTextSecond: undefined,
130
- hardDisks: undefined,
131
- cdDvdDrives: undefined,
132
- videoCard: undefined,
133
- // pciDevices: undefined,
134
- passthroughDevices: undefined,
135
- mediatedDevices: undefined,
136
- guestMachineType: undefined,
137
- computeResource: undefined,
138
- compatibilityInfo: undefined,
139
- }
140
- )
141
- const emits = defineEmits<{
142
- (event: 'invalid', value: string[]): void
143
- (event: 'get-storage', value: UI_I_TablePayload): void
144
- (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
145
- (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
146
- (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
147
- (event: 'remove-error-by-title', value: string): void
148
- (event: 'get-networks-table', value: UI_I_TablePayload): void
149
- (event: 'get-pci-devices'): void
150
- }>()
151
-
152
- const { $store, $binary }: any = useNuxtApp()
153
- const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
154
- const currentComponent = computed(() =>
155
- isNewView.value
156
- ? defineAsyncComponent(() => import('./New.vue'))
157
- : defineAsyncComponent(() => import('./Old.vue'))
158
- )
159
-
160
- const localization = computed<UI_I_Localization>(() => useLocal())
161
-
162
- const dropdownItems = computed<UI_I_DropdownTreeItem[]>(() =>
163
- dropdownItemsFunc(
164
- localization.value,
165
- props.state,
166
- props.passthroughDevices,
167
- props.mediatedDevices
168
- )
169
- )
170
-
171
- const hardDisksIndex = ref<number[]>([0])
172
- const hardDisksType = ref<UI_T_HardDiskType[]>(['new'])
173
- // const hardDisksLocal = ref<UI_I_SendDataNewHardDisk[]>([
174
- // {
175
- // create: true,
176
- // size: 90,
177
- // source: '',
178
- // boot_order: -1,
179
- // },
180
- // ])
181
- if (!model.value.disk_devices?.length) {
182
- hardDisksType.value = []
183
- hardDisksIndex.value = []
184
- } else {
185
- model.value.disk_devices
186
- .filter((disk) => disk.device_type !== 'cdrom')
187
- .forEach((_disk, _index, array) => {
188
- if (!props.isEdit && !props.isClone) return
189
-
190
- const count = array.length
191
- hardDisksIndex.value = [...Array(count).keys()]
192
- if (props.isEdit) {
193
- hardDisksType.value = Array(count).fill('edit')
194
- } else if (props.isClone) {
195
- hardDisksType.value = Array(count).fill('clone')
196
- }
197
- })
198
- }
199
-
200
- // watch(
201
- // () => props.hardDisks,
202
- // (newValue) => {
203
- // if ((!props.isEdit && !props.isClone) || !newValue) return
204
- //
205
- // const count = newValue?.length || 0
206
- // hardDisksIndex.value = [...Array(count).keys()]
207
- // hardDisksLocal.value = newValue
208
- // if (props.isEdit) {
209
- // hardDisksType.value = Array(count).fill('edit')
210
- // } else if (props.isClone) {
211
- // hardDisksType.value = Array(count).fill('clone')
212
- // hardDisksLocal.value = newValue.map((hardDisk) => {
213
- // hardDisk.create = true
214
- // return hardDisk
215
- // })
216
- // }
217
- // },
218
- // { immediate: true }
219
- // )
220
-
221
- const getDisksSize = (): number => {
222
- return (
223
- model.value.disk_devices.reduce(
224
- (acum, disk) => (acum += disk.size || 0),
225
- 0
226
- ) || 0
227
- )
228
- }
229
- const initialDisksSize = getDisksSize()
230
- const storageFree = computed<number>(() => {
231
- if (!props.storage) return 0
232
- const free = (props.storage.capacity.free_mb || props.storage.free) as number // TODO fix
233
-
234
- const disksSize = getDisksSize()
235
-
236
- return free + initialDisksSize - (disksSize - initialDisksSize)
237
- })
238
-
239
- const addHardDisk = (
240
- create = true,
241
- size = 92_160, // 90GB
242
- source = '',
243
- type: UI_T_HardDiskType = 'new',
244
- provisioned_type?: number // При добавлении существующей
245
- ): void => {
246
- const newIndex = (hardDisksIndex.value.at(-1) ?? -1) + 1
247
- hardDisksIndex.value.push(newIndex)
248
- hardDisksType.value.push(type)
249
-
250
- let provisionType = 'thick'
251
- if (provisioned_type === 1) provisionType = 'thin'
252
-
253
- model.value.disk_devices = [
254
- ...model.value.disk_devices.filter((disk) => disk.device_type !== 'cdrom'),
255
- // {
256
- // create,
257
- // size,
258
- // source,
259
- // attach: true,
260
- // boot_order: 0, // Убираем галочку
261
- // provision_type: provisionType,
262
- // },
263
- {
264
- create,
265
- size,
266
- source,
267
- bus: 'virtio',
268
- storage_id: '',
269
- provision_type: 'thick',
270
- disk_mode: 'dependent',
271
- boot_order: 0, // Убираем галочку
272
- device_type: 'disk',
273
- sharing: false,
274
- shares: 0,
275
- cache: 'none',
276
- io: '',
277
- limit_iops: 0,
278
- attach: true,
279
- },
280
- ...model.value.disk_devices.filter((disk) => disk.device_type === 'cdrom'),
281
- ]
282
- // hardDisksLocal.value.push({
283
- // create,
284
- // size,
285
- // source,
286
- // attach: true,
287
- // boot_order: 0, // Убираем галочку
288
- // provision_type: provisionType,
289
- // })
290
- }
291
- const onAddExistHardDisk = (file: UI_I_FileTreeNode): void => {
292
- addHardDisk(
293
- false,
294
- $binary.bToMb(file.size),
295
- file.path,
296
- 'exist',
297
- file.provisioned_type
298
- )
299
- }
300
- const onRemoveHardDisk = (
301
- index: number,
302
- hardDisk: UI_I_SendDataNewHardDisk
303
- ): void => {
304
- const removeIndex = hardDisksIndex.value.indexOf(index)
305
-
306
- if (!hardDisk.create && !hardDisk.attach) {
307
- hardDisksType.value = hardDisksType.value.map((item, key) => {
308
- if (key === removeIndex) return 'removed'
309
- return item
310
- })
311
- return
312
- }
313
-
314
- hardDisksIndex.value = hardDisksIndex.value.filter((item) => item !== index)
315
- hardDisksType.value = hardDisksType.value.filter(
316
- (_item, key) => key !== removeIndex
317
- )
318
-
319
- model.value.disk_devices = model.value.disk_devices.filter(
320
- (_hardDisk, key: number) => {
321
- return removeIndex !== key
322
- }
323
- )
324
- // hardDisksLocal.value = hardDisksLocal.value.filter(
325
- // (_hardDisk, key: number) => {
326
- // return removeIndex !== key
327
- // }
328
- // )
329
-
330
- delete newHardDiskInvalidKeys.value[index]
331
- }
332
- const onRollBackHardDisk = (index: number): void => {
333
- const removeIndex = hardDisksIndex.value.indexOf(index)
334
- hardDisksType.value = hardDisksType.value.map((item, key) => {
335
- if (key === removeIndex) return 'edit'
336
- return item
337
- })
338
- }
339
-
340
- const networkValueProp = props.project === 'sphere' ? 'network' : 'net_bridge'
341
- const networksType = ref<UI_T_NetworkType[]>(['new'])
342
- const networksIndex = ref<number[]>([0])
343
- if (!model.value.network_devices?.length) {
344
- networksType.value = []
345
- networksIndex.value = []
346
- } else {
347
- model.value.network_devices.forEach(() => {
348
- if (!props.isEdit && !props.isClone) return
349
-
350
- const count = model.value.network_devices.length || 0
351
- networksIndex.value = [...Array(count).keys()]
352
- if (props.isEdit) {
353
- networksType.value = Array(count).fill('edit')
354
- } else if (props.isClone) {
355
- networksType.value = Array(count).fill('clone')
356
- }
357
- })
358
- }
359
-
360
- const defaultNetwork = {
361
- network: '',
362
- net_bridge: '',
363
- mac: '',
364
- target: '',
365
- model: 'virtio',
366
- boot_order: 0,
367
- }
368
- const addNetwork = (): void => {
369
- const index = (networksIndex.value.at(-1) ?? -1) + 1
370
- networksIndex.value.push(index)
371
- networksType.value.push('new')
372
-
373
- model.value.network_devices.push({
374
- ...useDeepCopy(defaultNetwork),
375
- })
376
- }
377
- const onRemoveNetwork = (index: number): void => {
378
- const removeIndex = networksIndex.value.indexOf(index)
379
- networksIndex.value = networksIndex.value.filter((item) => item !== index)
380
- networksType.value = networksType.value.filter(
381
- (_item, key) => key !== removeIndex
382
- )
383
- model.value.network_devices = model.value.network_devices.filter(
384
- (_network, key: number) => removeIndex !== key
385
- )
386
-
387
- delete newNetworkInvalidKeys.value[index]
388
- }
389
-
390
- // const defaultCdDvdDriver: UI_I_SendDataNewCdDvdDrive = {
391
- // create: false,
392
- // attach: false,
393
- // source: '',
394
- // bus: '',
395
- // device_type: 'cdrom',
396
- // boot_order: -1,
397
- // }
398
- const defaultCdDvdDriver: UI_I_SendDataNewCdDvdDrive = {
399
- source: '',
400
- storage_id: '',
401
- device_type: 'cdrom',
402
- bus: '',
403
- target: '',
404
- boot_order: 0,
405
- provision_type: 'thick',
406
- disk_mode: 'dependent',
407
- sharing: false,
408
- read_only: true,
409
- shares: 0,
410
- cache: 'none',
411
- io: 'native',
412
- limit_iops: 0,
413
- discard: 'unmap',
414
- attach: false,
415
- detach: false,
416
- remove: false,
417
- create: false,
418
- }
419
- // const cdDvdDrivesLocal = ref<UI_I_SendDataNewCdDvdDrive[]>([
420
- // useDeepCopy(defaultCdDvdDriver),
421
- // ])
422
- const cdDvdDrivesIndex = ref<number[]>([0])
423
- const cdDvdDrivesType = ref<UI_T_CdDvdType[]>(['new'])
424
- if (!model.value.disk_devices?.length) {
425
- cdDvdDrivesIndex.value = []
426
- cdDvdDrivesType.value = []
427
- } else {
428
- model.value.disk_devices
429
- .filter((disk) => disk.device_type === 'cdrom')
430
- .forEach((_disk, _index, array) => {
431
- if (!props.isEdit && !props.isClone) return
432
-
433
- const count = array.length
434
- cdDvdDrivesIndex.value = [...Array(count).keys()]
435
- if (props.isEdit) {
436
- cdDvdDrivesType.value = Array(count).fill('edit')
437
- } else if (props.isClone) {
438
- cdDvdDrivesType.value = Array(count).fill('clone')
439
- }
440
- })
441
- }
442
- // watch(
443
- // () => props.cdDvdDrives,
444
- // (newValue) => {
445
- // if ((!props.isEdit && !props.isClone) || !newValue) return
446
- //
447
- // // cdDvdDrivesLocal.value = newValue
448
- // // cdDvdDrivesType.value = Array(newValue.length).fill('edit')
449
- // const count = newValue?.length || 0
450
- // cdDvdDrivesIndex.value = [...Array(count).keys()]
451
- // cdDvdDrivesLocal.value = newValue
452
- // if (props.isEdit) {
453
- // cdDvdDrivesType.value = Array(count).fill('edit')
454
- // } else if (props.isClone) {
455
- // cdDvdDrivesType.value = Array(count).fill('new')
456
- // }
457
- // },
458
- // { immediate: true }
459
- // )
460
- const addCdDvdDrive = (): void => {
461
- const value = (cdDvdDrivesIndex.value.at(-1) ?? -1) + 1
462
- cdDvdDrivesIndex.value.push(value)
463
- cdDvdDrivesType.value.push('new')
464
- model.value.disk_devices.push({
465
- ...useDeepCopy(defaultCdDvdDriver),
466
- attach: true,
467
- boot_order: 0, // Убираем галочку
468
- })
469
- // cdDvdDrivesLocal.value.push({
470
- // ...useDeepCopy(defaultCdDvdDriver),
471
- // attach: true,
472
- // boot_order: 0, // Убираем галочку
473
- // })
474
- }
475
- const onRemoveCdDvdDrive = (
476
- index: number,
477
- cdDvdDrive: UI_I_SendDataNewCdDvdDrive
478
- ): void => {
479
- const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
480
-
481
- // if (!cdDvdDrive.create && !cdDvdDrive.attach) {
482
- if (cdDvdDrivesType.value[index] === 'edit' && !cdDvdDrive.attach) {
483
- cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
484
- if (key === removeIndex) return 'removed'
485
- return item
486
- })
487
- return
488
- }
489
-
490
- cdDvdDrivesIndex.value = cdDvdDrivesIndex.value.filter(
491
- (cdDvdDrive) => cdDvdDrive !== index
492
- )
493
- cdDvdDrivesType.value = cdDvdDrivesType.value.filter(
494
- (_item, key) => key !== index
495
- )
496
-
497
- const hardDiskCount = hardDisksIndex.value.length
498
- model.value.disk_devices = model.value.disk_devices.filter(
499
- (_cdDvdDrive, key: number) => hardDiskCount + removeIndex !== key
500
- )
501
- // cdDvdDrivesLocal.value = cdDvdDrivesLocal.value.filter(
502
- // (_cdDvdDrive, key: number) => removeIndex !== key
503
- // )
504
- }
505
- const onRollBackCdDvdDrive = (index: number): void => {
506
- const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
507
- cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
508
- if (key === removeIndex) return 'edit'
509
- return item
510
- })
511
- }
512
-
513
- const defaultPciDevice: UI_I_SendDataNewPciDevice = {
514
- address: '',
515
- vendor_name: '',
516
- class_name: '',
517
- device_name: '',
518
- }
519
- const pciDevicesIndex = ref<number[]>([0])
520
- const pciDevicesType = ref<('new' | 'edit' | 'removed')[]>(['new'])
521
- // const pciDevicesLocal = ref<UI_I_SendDataNewPciDevice[]>([])
522
- if (!model.value.passthrough_pci_devices?.length) {
523
- pciDevicesIndex.value = []
524
- pciDevicesType.value = []
525
- } else {
526
- model.value.passthrough_pci_devices.forEach((_disk, _index, array) => {
527
- if (!props.isEdit && !props.isClone) return
528
-
529
- const count = array.length
530
- pciDevicesIndex.value = [...Array(count).keys()]
531
- if (props.isEdit) {
532
- pciDevicesType.value = Array(count).fill('edit')
533
- } else if (props.isClone) {
534
- pciDevicesType.value = Array(count).fill('clone') // before been new
535
- }
536
- })
537
- }
538
- // watch(
539
- // () => props.pciDevices,
540
- // (newValue) => {
541
- // if ((!props.isEdit && !props.isClone) || !newValue) return
542
- //
543
- // const count = newValue?.length || 0
544
- // pciDevicesIndex.value = [...Array(count).keys()]
545
- // pciDevicesLocal.value = newValue || []
546
- // if (props.isEdit) {
547
- // pciDevicesType.value = Array(count).fill('edit')
548
- // } else if (props.isClone) {
549
- // pciDevicesType.value = Array(count).fill('new')
550
- // }
551
- // },
552
- // { immediate: true }
553
- // )
554
-
555
- const addPciDevice = (): void => {
556
- const newIndex = (pciDevicesIndex.value.at(-1) ?? -1) + 1
557
- pciDevicesIndex.value.push(newIndex)
558
- pciDevicesType.value.push('new')
559
-
560
- // pciDevicesLocal.value.push(useDeepCopy(defaultPciDevice))
561
- model.value.passthrough_pci_devices.push(useDeepCopy(defaultPciDevice))
562
- }
563
- const onRemovePciDevice = (index: number): void => {
564
- const removeIndex = pciDevicesIndex.value.indexOf(index)
565
- pciDevicesIndex.value = pciDevicesIndex.value.filter((item) => item !== index)
566
- pciDevicesType.value = pciDevicesType.value.filter(
567
- (_item, key) => key !== removeIndex
568
- )
569
-
570
- model.value.passthrough_pci_devices =
571
- model.value.passthrough_pci_devices.filter((_pciDevice, key: number) => {
572
- return removeIndex !== key
573
- })
574
- // pciDevicesLocal.value = pciDevicesLocal.value.filter(
575
- // (_pciDevice, key: number) => {
576
- // return removeIndex !== key
577
- // }
578
- // )
579
-
580
- delete newPciDeviceInvalidKeys.value[index]
581
- }
582
-
583
- const isShowFileModal = ref<boolean>(false)
584
- const onAddDevice = (item: UI_I_DropdownTreeItemChild): void => {
585
- switch (item.value) {
586
- case 1:
587
- addHardDisk()
588
- break
589
- case 2:
590
- isShowFileModal.value = true
591
- break
592
- case 5:
593
- addCdDvdDrive()
594
- break
595
- case 10:
596
- addPciDevice()
597
- break
598
- case 14:
599
- addNetwork()
600
- break
601
- }
602
- }
603
-
604
- const cpuInvalid = ref<boolean>(false)
605
- const onSendDataNewHardDiskMethod = (
606
- data: UI_I_SendDataNewHardDisk,
607
- index: number
608
- ): void => {
609
- model.value.disk_devices[index] = {
610
- ...data,
611
- boot_order: model.value.disk_devices[index]?.boot_order || 0,
612
- }
613
- }
614
- const sendDataNewCdDvdDriveMethod = (
615
- data: UI_I_SendDataNewCdDvdDrive,
616
- index: number
617
- ): void => {
618
- const cdromIndexStart = model.value.disk_devices.findIndex(
619
- (disk) => disk.device_type === 'cdrom'
620
- )
621
- model.value.disk_devices[cdromIndexStart + index] = {
622
- ...data,
623
- boot_order:
624
- model.value.disk_devices[cdromIndexStart + index]?.boot_order || 0,
625
- }
626
- }
627
-
628
- const onSetInvalidHardDisk = (invalid: boolean, index: number): void => {
629
- newHardDiskInvalidKeys.value[index] = invalid
630
- }
631
-
632
- const onSetInvalidNetwork = (invalid: boolean, key: number): void => {
633
- newNetworkInvalidKeys.value[key] = invalid
634
- }
635
-
636
- const onSetInvalidPciDevice = (invalid: boolean, key: number): void => {
637
- newPciDeviceInvalidKeys.value[key] = invalid
638
- }
639
-
640
- const memoryInvalid = ref<boolean>(false)
641
- const videoCardInvalid = ref<boolean>(false)
642
- const newHardDiskInvalidKeys = ref<UI_I_InvalidKeys>({})
643
- const newNetworkInvalidKeys = ref<UI_I_InvalidKeys>({})
644
- const newPciDeviceInvalidKeys = ref<UI_I_InvalidKeys>({})
645
-
646
- watch(
647
- [
648
- cpuInvalid,
649
- memoryInvalid,
650
- newHardDiskInvalidKeys,
651
- newNetworkInvalidKeys,
652
- newPciDeviceInvalidKeys,
653
- videoCardInvalid,
654
- ],
655
- () => {
656
- const cpu = cpuInvalid.value ? localization.value.common.cpu : ''
657
- const memory = memoryInvalid.value ? localization.value.common.memory : ''
658
- const videoCard = videoCardInvalid.value
659
- ? localization.value.common.videoCard
660
- : ''
661
- let newHardDisk = ''
662
- Object.keys(newHardDiskInvalidKeys.value).forEach((key) => {
663
- if (!newHardDiskInvalidKeys.value[+key]) {
664
- return
665
- }
666
-
667
- newHardDisk +=
668
- (newHardDisk ? ', ' : '') +
669
- localization.value.common.newHardDisk +
670
- ' ' +
671
- (+key + 1)
672
- })
673
- let newNetwork = ''
674
- Object.keys(newNetworkInvalidKeys.value).forEach((key) => {
675
- if (!newNetworkInvalidKeys.value[+key]) {
676
- return
677
- }
678
-
679
- newNetwork +=
680
- (newNetwork ? ', ' : '') +
681
- localization.value.common.newNetwork +
682
- ' ' +
683
- (+key + 1)
684
- })
685
- // let pciDevice = ''
686
- // Object.keys(newPciDeviceInvalidKeys.value).forEach((key) => {
687
- // if (!newPciDeviceInvalidKeys.value[+key]) {
688
- // return
689
- // }
690
- //
691
- // pciDevice +=
692
- // (pciDevice ? ', ' : '') +
693
- // localization.value.common.pciDevice +
694
- // ' ' +
695
- // (+key + 1)
696
- // })
697
-
698
- emits('invalid', [cpu, memory, newHardDisk, newNetwork, videoCard])
699
- },
700
- { deep: true }
701
- )
702
-
703
- emits('get-pci-devices')
704
- </script>
705
-
706
- <style scoped lang="scss"></style>
1
+ <template>
2
+ <component
3
+ :is="currentComponent"
4
+ v-model="model"
5
+ v-model:cpu-invalid="cpuInvalid"
6
+ v-model:memory-invalid="memoryInvalid"
7
+ v-model:video-card-invalid="videoCardInvalid"
8
+ :nodes="props.nodes"
9
+ :files="props.files"
10
+ :is-edit="props.isEdit"
11
+ :storage="props.storage"
12
+ :storage-free="storageFree"
13
+ :project="props.project"
14
+ :max-memory="props.maxMemory"
15
+ :cpu-models="props.cpuModels"
16
+ :datastore="props.datastore"
17
+ :is-datastore-loading="props.isDatastoreLoading"
18
+ :networks-type="networksType"
19
+ :networks-table="props.networksTable"
20
+ :dropdown-items="dropdownItems"
21
+ :hard-disks-type="hardDisksType"
22
+ :networks-index="networksIndex"
23
+ :hard-disks-index="hardDisksIndex"
24
+ :pci-devices-type="pciDevicesType"
25
+ :is-show-file-modal="isShowFileModal"
26
+ :pci-devices-index="pciDevicesIndex"
27
+ :cd-dvd-drives-type="cdDvdDrivesType"
28
+ :cd-dvd-drives-index="cdDvdDrivesIndex"
29
+ :error-validation-fields="errorValidationFields"
30
+ :get-datastore-table-func="getDatastoreTableFunc"
31
+ :state="state"
32
+ :video-card="videoCard"
33
+ :guest-machine-type="guestMachineType"
34
+ :passthrough-devices="passthroughDevices"
35
+ :mediated-devices="mediatedDevices"
36
+ :vm-cpu-help-text-second="vmCpuHelpTextSecond"
37
+ :compute-resource="props.computeResource"
38
+ :compatibility-info="props.compatibilityInfo"
39
+ :network-value-prop="networkValueProp"
40
+ @add-device="onAddDevice"
41
+ @get-storage="emits('get-storage', $event)"
42
+ @remove-network="onRemoveNetwork"
43
+ @hide-file-modal="isShowFileModal = false"
44
+ @remove-hard-disk="onRemoveHardDisk(...$event)"
45
+ @remove-pci-device="onRemovePciDevice"
46
+ @get-networks-table="emits('get-networks-table', $event)"
47
+ @add-exist-hard-disk="onAddExistHardDisk"
48
+ @roll-back-hard-disk="onRollBackHardDisk"
49
+ @set-invalid-network="onSetInvalidNetwork(...$event)"
50
+ @remove-cd-dvd-drive="onRemoveCdDvdDrive(...$event)"
51
+ @show-datastore-child="emits('show-datastore-child', $event)"
52
+ @get-folders-or-files="emits('get-folders-or-files', $event)"
53
+ @set-invalid-hard-disk="onSetInvalidHardDisk(...$event)"
54
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
55
+ @roll-back-cd-dvd-drive="onRollBackCdDvdDrive"
56
+ @set-invalid-pci-device="onSetInvalidPciDevice(...$event)"
57
+ @get-active-device-child="emits('get-active-device-child', $event)"
58
+ @send-data-new-hard-disk-method="onSendDataNewHardDiskMethod(...$event)"
59
+ @send-data-new-cd-dvd-drive-method="sendDataNewCdDvdDriveMethod(...$event)"
60
+ />
61
+ </template>
62
+
63
+ <script setup lang="ts">
64
+ import type { UI_T_Project } from '~/lib/models/types'
65
+ import type { UI_I_DatastoreTableItem } from '~/lib/models/store/storage/interfaces'
66
+ import type { UI_I_NetworkTableItem } from '~/lib/models/store/network/interfaces'
67
+ import type { UI_I_TablePayload } from '~/lib/models/table/interfaces'
68
+ import type { UI_I_FolderOrFileTreePayload } from '~/lib/models/store/storage/interfaces'
69
+ import type { UI_I_FileTreeNode } from '~/components/lib/models/interfaces'
70
+ import type {
71
+ UI_I_SendDataNewHardDisk,
72
+ UI_I_SendDataVideoCard,
73
+ UI_I_InvalidKeys,
74
+ UI_I_SendDataNewCdDvdDrive,
75
+ // UI_I_HardDisk,
76
+ UI_I_SendDataNewPciDevice,
77
+ } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
78
+ import type { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
79
+ import type {
80
+ UI_T_HardDiskType,
81
+ UI_T_NetworkType,
82
+ UI_T_CdDvdType,
83
+ } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/types'
84
+ import type { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
85
+ import type {
86
+ UI_I_DropdownTreeItem,
87
+ UI_I_DropdownTreeItemChild,
88
+ } from '~/components/atoms/dropdown/tree/lib/models/interfaces'
89
+ import type { UI_I_Localization } from '~/lib/models/interfaces'
90
+ import type {
91
+ UI_I_MediatedDevice,
92
+ UI_I_PciDevice,
93
+ } from '~/lib/models/store/vm/interfaces'
94
+ import type { UI_I_TreeNode } from '~/components/common/recursionTree/lib/models/interfaces'
95
+ import type { UI_I_CreateVmData } from '~/components/common/vm/actions/common/lib/models/interfaces'
96
+ import { dropdownItemsFunc } from './lib/config/dropdownItems'
97
+
98
+ const model = defineModel<UI_I_CreateVmData>({ required: true })
99
+
100
+ const props = withDefaults(
101
+ defineProps<{
102
+ storage: UI_I_DatastoreTableItem | null
103
+ cpuModels: UI_I_OptionItem[]
104
+ maxMemory: number
105
+ isEdit: boolean
106
+ isClone: boolean
107
+ errorValidationFields: UI_I_ErrorValidationField[]
108
+ nodes: UI_I_FileTreeNode[]
109
+ files: UI_I_FileTreeNode[]
110
+ networksTable: UI_I_NetworkTableItem[]
111
+ getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
112
+ datastore: UI_I_DatastoreTableItem[]
113
+ isDatastoreLoading: boolean
114
+ project: UI_T_Project
115
+ state?: string | number
116
+ vmCpuHelpTextSecond?: string
117
+ hardDisks?: UI_I_SendDataNewHardDisk[] | null
118
+ cdDvdDrives?: UI_I_SendDataNewCdDvdDrive[] | null
119
+ videoCard?: UI_I_SendDataVideoCard
120
+ // pciDevices?: UI_I_SendDataNewPciDevice[]
121
+ passthroughDevices?: UI_I_PciDevice[]
122
+ mediatedDevices?: UI_I_MediatedDevice[]
123
+ guestMachineType?: UI_I_OptionItem | null
124
+ computeResource?: UI_I_TreeNode | null
125
+ compatibilityInfo?: string
126
+ }>(),
127
+ {
128
+ state: undefined,
129
+ vmCpuHelpTextSecond: undefined,
130
+ hardDisks: undefined,
131
+ cdDvdDrives: undefined,
132
+ videoCard: undefined,
133
+ // pciDevices: undefined,
134
+ passthroughDevices: undefined,
135
+ mediatedDevices: undefined,
136
+ guestMachineType: undefined,
137
+ computeResource: undefined,
138
+ compatibilityInfo: undefined,
139
+ }
140
+ )
141
+ const emits = defineEmits<{
142
+ (event: 'invalid', value: string[]): void
143
+ (event: 'get-storage', value: UI_I_TablePayload): void
144
+ (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
145
+ (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
146
+ (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
147
+ (event: 'remove-error-by-title', value: string): void
148
+ (event: 'get-networks-table', value: UI_I_TablePayload): void
149
+ (event: 'get-pci-devices'): void
150
+ }>()
151
+
152
+ const { $store, $binary }: any = useNuxtApp()
153
+ const isNewView = computed<boolean>(() => $store.getters['main/getIsNewView'])
154
+ const currentComponent = computed(() =>
155
+ isNewView.value
156
+ ? defineAsyncComponent(() => import('./New.vue'))
157
+ : defineAsyncComponent(() => import('./Old.vue'))
158
+ )
159
+
160
+ const localization = computed<UI_I_Localization>(() => useLocal())
161
+
162
+ const dropdownItems = computed<UI_I_DropdownTreeItem[]>(() =>
163
+ dropdownItemsFunc(
164
+ localization.value,
165
+ props.state,
166
+ props.passthroughDevices,
167
+ props.mediatedDevices
168
+ )
169
+ )
170
+
171
+ const hardDisksIndex = ref<number[]>([0])
172
+ const hardDisksType = ref<UI_T_HardDiskType[]>(['new'])
173
+ // const hardDisksLocal = ref<UI_I_SendDataNewHardDisk[]>([
174
+ // {
175
+ // create: true,
176
+ // size: 90,
177
+ // source: '',
178
+ // boot_order: -1,
179
+ // },
180
+ // ])
181
+ if (!model.value.disk_devices?.length) {
182
+ hardDisksType.value = []
183
+ hardDisksIndex.value = []
184
+ } else {
185
+ model.value.disk_devices
186
+ .filter((disk) => disk.device_type !== 'cdrom')
187
+ .forEach((_disk, _index, array) => {
188
+ if (!props.isEdit && !props.isClone) return
189
+
190
+ const count = array.length
191
+ hardDisksIndex.value = [...Array(count).keys()]
192
+ if (props.isEdit) {
193
+ hardDisksType.value = Array(count).fill('edit')
194
+ } else if (props.isClone) {
195
+ hardDisksType.value = Array(count).fill('clone')
196
+ }
197
+ })
198
+ }
199
+
200
+ // watch(
201
+ // () => props.hardDisks,
202
+ // (newValue) => {
203
+ // if ((!props.isEdit && !props.isClone) || !newValue) return
204
+ //
205
+ // const count = newValue?.length || 0
206
+ // hardDisksIndex.value = [...Array(count).keys()]
207
+ // hardDisksLocal.value = newValue
208
+ // if (props.isEdit) {
209
+ // hardDisksType.value = Array(count).fill('edit')
210
+ // } else if (props.isClone) {
211
+ // hardDisksType.value = Array(count).fill('clone')
212
+ // hardDisksLocal.value = newValue.map((hardDisk) => {
213
+ // hardDisk.create = true
214
+ // return hardDisk
215
+ // })
216
+ // }
217
+ // },
218
+ // { immediate: true }
219
+ // )
220
+
221
+ const getDisksSize = (): number => {
222
+ return (
223
+ model.value.disk_devices.reduce(
224
+ (acum, disk) => (acum += disk.size || 0),
225
+ 0
226
+ ) || 0
227
+ )
228
+ }
229
+ const initialDisksSize = getDisksSize()
230
+ const storageFree = computed<number>(() => {
231
+ if (!props.storage) return 0
232
+ const free = (props.storage.capacity.free_mb || props.storage.free) as number // TODO fix
233
+
234
+ const disksSize = getDisksSize()
235
+
236
+ return free + initialDisksSize - (disksSize - initialDisksSize)
237
+ })
238
+
239
+ const addHardDisk = (
240
+ create = true,
241
+ size = 92_160, // 90GB
242
+ source = '',
243
+ type: UI_T_HardDiskType = 'new',
244
+ provisioned_type?: number // При добавлении существующей
245
+ ): void => {
246
+ const newIndex = (hardDisksIndex.value.at(-1) ?? -1) + 1
247
+ hardDisksIndex.value.push(newIndex)
248
+ hardDisksType.value.push(type)
249
+
250
+ let provisionType = 'thick'
251
+ if (provisioned_type === 1) provisionType = 'thin'
252
+
253
+ model.value.disk_devices = [
254
+ ...model.value.disk_devices.filter((disk) => disk.device_type !== 'cdrom'),
255
+ // {
256
+ // create,
257
+ // size,
258
+ // source,
259
+ // attach: true,
260
+ // boot_order: 0, // Убираем галочку
261
+ // provision_type: provisionType,
262
+ // },
263
+ {
264
+ create,
265
+ size,
266
+ source,
267
+ bus: 'virtio',
268
+ storage_id: '',
269
+ provision_type: 'thick',
270
+ disk_mode: 'dependent',
271
+ boot_order: 0, // Убираем галочку
272
+ device_type: 'disk',
273
+ sharing: false,
274
+ shares: 0,
275
+ cache: 'none',
276
+ io: '',
277
+ limit_iops: 0,
278
+ attach: true,
279
+ },
280
+ ...model.value.disk_devices.filter((disk) => disk.device_type === 'cdrom'),
281
+ ]
282
+ // hardDisksLocal.value.push({
283
+ // create,
284
+ // size,
285
+ // source,
286
+ // attach: true,
287
+ // boot_order: 0, // Убираем галочку
288
+ // provision_type: provisionType,
289
+ // })
290
+ }
291
+ const onAddExistHardDisk = (file: UI_I_FileTreeNode): void => {
292
+ addHardDisk(
293
+ false,
294
+ $binary.bToMb(file.size),
295
+ file.path,
296
+ 'exist',
297
+ file.provisioned_type
298
+ )
299
+ }
300
+ const onRemoveHardDisk = (
301
+ index: number,
302
+ hardDisk: UI_I_SendDataNewHardDisk
303
+ ): void => {
304
+ const removeIndex = hardDisksIndex.value.indexOf(index)
305
+
306
+ if (!hardDisk.create && !hardDisk.attach) {
307
+ hardDisksType.value = hardDisksType.value.map((item, key) => {
308
+ if (key === removeIndex) return 'removed'
309
+ return item
310
+ })
311
+ return
312
+ }
313
+
314
+ hardDisksIndex.value = hardDisksIndex.value.filter((item) => item !== index)
315
+ hardDisksType.value = hardDisksType.value.filter(
316
+ (_item, key) => key !== removeIndex
317
+ )
318
+
319
+ model.value.disk_devices = model.value.disk_devices.filter(
320
+ (_hardDisk, key: number) => {
321
+ return removeIndex !== key
322
+ }
323
+ )
324
+ // hardDisksLocal.value = hardDisksLocal.value.filter(
325
+ // (_hardDisk, key: number) => {
326
+ // return removeIndex !== key
327
+ // }
328
+ // )
329
+
330
+ delete newHardDiskInvalidKeys.value[index]
331
+ }
332
+ const onRollBackHardDisk = (index: number): void => {
333
+ const removeIndex = hardDisksIndex.value.indexOf(index)
334
+ hardDisksType.value = hardDisksType.value.map((item, key) => {
335
+ if (key === removeIndex) return 'edit'
336
+ return item
337
+ })
338
+ }
339
+
340
+ const networkValueProp = props.project === 'sphere' ? 'network' : 'net_bridge'
341
+ const networksType = ref<UI_T_NetworkType[]>(['new'])
342
+ const networksIndex = ref<number[]>([0])
343
+ if (!model.value.network_devices?.length) {
344
+ networksType.value = []
345
+ networksIndex.value = []
346
+ } else {
347
+ model.value.network_devices.forEach(() => {
348
+ if (!props.isEdit && !props.isClone) return
349
+
350
+ const count = model.value.network_devices.length || 0
351
+ networksIndex.value = [...Array(count).keys()]
352
+ if (props.isEdit) {
353
+ networksType.value = Array(count).fill('edit')
354
+ } else if (props.isClone) {
355
+ networksType.value = Array(count).fill('clone')
356
+ }
357
+ })
358
+ }
359
+
360
+ const defaultNetwork = {
361
+ network: '',
362
+ net_bridge: '',
363
+ mac: '',
364
+ target: '',
365
+ model: 'virtio',
366
+ boot_order: 0,
367
+ }
368
+ const addNetwork = (): void => {
369
+ const index = (networksIndex.value.at(-1) ?? -1) + 1
370
+ networksIndex.value.push(index)
371
+ networksType.value.push('new')
372
+
373
+ model.value.network_devices.push({
374
+ ...useDeepCopy(defaultNetwork),
375
+ })
376
+ }
377
+ const onRemoveNetwork = (index: number): void => {
378
+ const removeIndex = networksIndex.value.indexOf(index)
379
+ networksIndex.value = networksIndex.value.filter((item) => item !== index)
380
+ networksType.value = networksType.value.filter(
381
+ (_item, key) => key !== removeIndex
382
+ )
383
+ model.value.network_devices = model.value.network_devices.filter(
384
+ (_network, key: number) => removeIndex !== key
385
+ )
386
+
387
+ delete newNetworkInvalidKeys.value[index]
388
+ }
389
+
390
+ // const defaultCdDvdDriver: UI_I_SendDataNewCdDvdDrive = {
391
+ // create: false,
392
+ // attach: false,
393
+ // source: '',
394
+ // bus: '',
395
+ // device_type: 'cdrom',
396
+ // boot_order: -1,
397
+ // }
398
+ const defaultCdDvdDriver: UI_I_SendDataNewCdDvdDrive = {
399
+ source: '',
400
+ storage_id: '',
401
+ device_type: 'cdrom',
402
+ bus: '',
403
+ target: '',
404
+ boot_order: 0,
405
+ provision_type: 'thick',
406
+ disk_mode: 'dependent',
407
+ sharing: false,
408
+ read_only: true,
409
+ shares: 0,
410
+ cache: 'none',
411
+ io: 'native',
412
+ limit_iops: 0,
413
+ discard: 'unmap',
414
+ attach: false,
415
+ detach: false,
416
+ remove: false,
417
+ create: false,
418
+ }
419
+ // const cdDvdDrivesLocal = ref<UI_I_SendDataNewCdDvdDrive[]>([
420
+ // useDeepCopy(defaultCdDvdDriver),
421
+ // ])
422
+ const cdDvdDrivesIndex = ref<number[]>([0])
423
+ const cdDvdDrivesType = ref<UI_T_CdDvdType[]>(['new'])
424
+ if (!model.value.disk_devices?.length) {
425
+ cdDvdDrivesIndex.value = []
426
+ cdDvdDrivesType.value = []
427
+ } else {
428
+ model.value.disk_devices
429
+ .filter((disk) => disk.device_type === 'cdrom')
430
+ .forEach((_disk, _index, array) => {
431
+ if (!props.isEdit && !props.isClone) return
432
+
433
+ const count = array.length
434
+ cdDvdDrivesIndex.value = [...Array(count).keys()]
435
+ if (props.isEdit) {
436
+ cdDvdDrivesType.value = Array(count).fill('edit')
437
+ } else if (props.isClone) {
438
+ cdDvdDrivesType.value = Array(count).fill('clone')
439
+ }
440
+ })
441
+ }
442
+ // watch(
443
+ // () => props.cdDvdDrives,
444
+ // (newValue) => {
445
+ // if ((!props.isEdit && !props.isClone) || !newValue) return
446
+ //
447
+ // // cdDvdDrivesLocal.value = newValue
448
+ // // cdDvdDrivesType.value = Array(newValue.length).fill('edit')
449
+ // const count = newValue?.length || 0
450
+ // cdDvdDrivesIndex.value = [...Array(count).keys()]
451
+ // cdDvdDrivesLocal.value = newValue
452
+ // if (props.isEdit) {
453
+ // cdDvdDrivesType.value = Array(count).fill('edit')
454
+ // } else if (props.isClone) {
455
+ // cdDvdDrivesType.value = Array(count).fill('new')
456
+ // }
457
+ // },
458
+ // { immediate: true }
459
+ // )
460
+ const addCdDvdDrive = (): void => {
461
+ const value = (cdDvdDrivesIndex.value.at(-1) ?? -1) + 1
462
+ cdDvdDrivesIndex.value.push(value)
463
+ cdDvdDrivesType.value.push('new')
464
+ model.value.disk_devices.push({
465
+ ...useDeepCopy(defaultCdDvdDriver),
466
+ attach: true,
467
+ boot_order: 0, // Убираем галочку
468
+ })
469
+ // cdDvdDrivesLocal.value.push({
470
+ // ...useDeepCopy(defaultCdDvdDriver),
471
+ // attach: true,
472
+ // boot_order: 0, // Убираем галочку
473
+ // })
474
+ }
475
+ const onRemoveCdDvdDrive = (
476
+ index: number,
477
+ cdDvdDrive: UI_I_SendDataNewCdDvdDrive
478
+ ): void => {
479
+ const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
480
+
481
+ // if (!cdDvdDrive.create && !cdDvdDrive.attach) {
482
+ if (cdDvdDrivesType.value[index] === 'edit' && !cdDvdDrive.attach) {
483
+ cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
484
+ if (key === removeIndex) return 'removed'
485
+ return item
486
+ })
487
+ return
488
+ }
489
+
490
+ cdDvdDrivesIndex.value = cdDvdDrivesIndex.value.filter(
491
+ (cdDvdDrive) => cdDvdDrive !== index
492
+ )
493
+ cdDvdDrivesType.value = cdDvdDrivesType.value.filter(
494
+ (_item, key) => key !== index
495
+ )
496
+
497
+ const hardDiskCount = hardDisksIndex.value.length
498
+ model.value.disk_devices = model.value.disk_devices.filter(
499
+ (_cdDvdDrive, key: number) => hardDiskCount + removeIndex !== key
500
+ )
501
+ // cdDvdDrivesLocal.value = cdDvdDrivesLocal.value.filter(
502
+ // (_cdDvdDrive, key: number) => removeIndex !== key
503
+ // )
504
+ }
505
+ const onRollBackCdDvdDrive = (index: number): void => {
506
+ const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
507
+ cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
508
+ if (key === removeIndex) return 'edit'
509
+ return item
510
+ })
511
+ }
512
+
513
+ const defaultPciDevice: UI_I_SendDataNewPciDevice = {
514
+ address: '',
515
+ vendor_name: '',
516
+ class_name: '',
517
+ device_name: '',
518
+ }
519
+ const pciDevicesIndex = ref<number[]>([0])
520
+ const pciDevicesType = ref<('new' | 'edit' | 'removed')[]>(['new'])
521
+ // const pciDevicesLocal = ref<UI_I_SendDataNewPciDevice[]>([])
522
+ if (!model.value.passthrough_pci_devices?.length) {
523
+ pciDevicesIndex.value = []
524
+ pciDevicesType.value = []
525
+ } else {
526
+ model.value.passthrough_pci_devices.forEach((_disk, _index, array) => {
527
+ if (!props.isEdit && !props.isClone) return
528
+
529
+ const count = array.length
530
+ pciDevicesIndex.value = [...Array(count).keys()]
531
+ if (props.isEdit) {
532
+ pciDevicesType.value = Array(count).fill('edit')
533
+ } else if (props.isClone) {
534
+ pciDevicesType.value = Array(count).fill('clone') // before been new
535
+ }
536
+ })
537
+ }
538
+ // watch(
539
+ // () => props.pciDevices,
540
+ // (newValue) => {
541
+ // if ((!props.isEdit && !props.isClone) || !newValue) return
542
+ //
543
+ // const count = newValue?.length || 0
544
+ // pciDevicesIndex.value = [...Array(count).keys()]
545
+ // pciDevicesLocal.value = newValue || []
546
+ // if (props.isEdit) {
547
+ // pciDevicesType.value = Array(count).fill('edit')
548
+ // } else if (props.isClone) {
549
+ // pciDevicesType.value = Array(count).fill('new')
550
+ // }
551
+ // },
552
+ // { immediate: true }
553
+ // )
554
+
555
+ const addPciDevice = (): void => {
556
+ const newIndex = (pciDevicesIndex.value.at(-1) ?? -1) + 1
557
+ pciDevicesIndex.value.push(newIndex)
558
+ pciDevicesType.value.push('new')
559
+
560
+ // pciDevicesLocal.value.push(useDeepCopy(defaultPciDevice))
561
+ model.value.passthrough_pci_devices.push(useDeepCopy(defaultPciDevice))
562
+ }
563
+ const onRemovePciDevice = (index: number): void => {
564
+ const removeIndex = pciDevicesIndex.value.indexOf(index)
565
+ pciDevicesIndex.value = pciDevicesIndex.value.filter((item) => item !== index)
566
+ pciDevicesType.value = pciDevicesType.value.filter(
567
+ (_item, key) => key !== removeIndex
568
+ )
569
+
570
+ model.value.passthrough_pci_devices =
571
+ model.value.passthrough_pci_devices.filter((_pciDevice, key: number) => {
572
+ return removeIndex !== key
573
+ })
574
+ // pciDevicesLocal.value = pciDevicesLocal.value.filter(
575
+ // (_pciDevice, key: number) => {
576
+ // return removeIndex !== key
577
+ // }
578
+ // )
579
+
580
+ delete newPciDeviceInvalidKeys.value[index]
581
+ }
582
+
583
+ const isShowFileModal = ref<boolean>(false)
584
+ const onAddDevice = (item: UI_I_DropdownTreeItemChild): void => {
585
+ switch (item.value) {
586
+ case 1:
587
+ addHardDisk()
588
+ break
589
+ case 2:
590
+ isShowFileModal.value = true
591
+ break
592
+ case 5:
593
+ addCdDvdDrive()
594
+ break
595
+ case 10:
596
+ addPciDevice()
597
+ break
598
+ case 14:
599
+ addNetwork()
600
+ break
601
+ }
602
+ }
603
+
604
+ const cpuInvalid = ref<boolean>(false)
605
+ const onSendDataNewHardDiskMethod = (
606
+ data: UI_I_SendDataNewHardDisk,
607
+ index: number
608
+ ): void => {
609
+ model.value.disk_devices[index] = {
610
+ ...data,
611
+ boot_order: model.value.disk_devices[index]?.boot_order || 0,
612
+ }
613
+ }
614
+ const sendDataNewCdDvdDriveMethod = (
615
+ data: UI_I_SendDataNewCdDvdDrive,
616
+ index: number
617
+ ): void => {
618
+ const cdromIndexStart = model.value.disk_devices.findIndex(
619
+ (disk) => disk.device_type === 'cdrom'
620
+ )
621
+ model.value.disk_devices[cdromIndexStart + index] = {
622
+ ...data,
623
+ boot_order:
624
+ model.value.disk_devices[cdromIndexStart + index]?.boot_order || 0,
625
+ }
626
+ }
627
+
628
+ const onSetInvalidHardDisk = (invalid: boolean, index: number): void => {
629
+ newHardDiskInvalidKeys.value[index] = invalid
630
+ }
631
+
632
+ const onSetInvalidNetwork = (invalid: boolean, key: number): void => {
633
+ newNetworkInvalidKeys.value[key] = invalid
634
+ }
635
+
636
+ const onSetInvalidPciDevice = (invalid: boolean, key: number): void => {
637
+ newPciDeviceInvalidKeys.value[key] = invalid
638
+ }
639
+
640
+ const memoryInvalid = ref<boolean>(false)
641
+ const videoCardInvalid = ref<boolean>(false)
642
+ const newHardDiskInvalidKeys = ref<UI_I_InvalidKeys>({})
643
+ const newNetworkInvalidKeys = ref<UI_I_InvalidKeys>({})
644
+ const newPciDeviceInvalidKeys = ref<UI_I_InvalidKeys>({})
645
+
646
+ watch(
647
+ [
648
+ cpuInvalid,
649
+ memoryInvalid,
650
+ newHardDiskInvalidKeys,
651
+ newNetworkInvalidKeys,
652
+ newPciDeviceInvalidKeys,
653
+ videoCardInvalid,
654
+ ],
655
+ () => {
656
+ const cpu = cpuInvalid.value ? localization.value.common.cpu : ''
657
+ const memory = memoryInvalid.value ? localization.value.common.memory : ''
658
+ const videoCard = videoCardInvalid.value
659
+ ? localization.value.common.videoCard
660
+ : ''
661
+ let newHardDisk = ''
662
+ Object.keys(newHardDiskInvalidKeys.value).forEach((key) => {
663
+ if (!newHardDiskInvalidKeys.value[+key]) {
664
+ return
665
+ }
666
+
667
+ newHardDisk +=
668
+ (newHardDisk ? ', ' : '') +
669
+ localization.value.common.newHardDisk +
670
+ ' ' +
671
+ (+key + 1)
672
+ })
673
+ let newNetwork = ''
674
+ Object.keys(newNetworkInvalidKeys.value).forEach((key) => {
675
+ if (!newNetworkInvalidKeys.value[+key]) {
676
+ return
677
+ }
678
+
679
+ newNetwork +=
680
+ (newNetwork ? ', ' : '') +
681
+ localization.value.common.newNetwork +
682
+ ' ' +
683
+ (+key + 1)
684
+ })
685
+ // let pciDevice = ''
686
+ // Object.keys(newPciDeviceInvalidKeys.value).forEach((key) => {
687
+ // if (!newPciDeviceInvalidKeys.value[+key]) {
688
+ // return
689
+ // }
690
+ //
691
+ // pciDevice +=
692
+ // (pciDevice ? ', ' : '') +
693
+ // localization.value.common.pciDevice +
694
+ // ' ' +
695
+ // (+key + 1)
696
+ // })
697
+
698
+ emits('invalid', [cpu, memory, newHardDisk, newNetwork, videoCard])
699
+ },
700
+ { deep: true }
701
+ )
702
+
703
+ emits('get-pci-devices')
704
+ </script>
705
+
706
+ <style scoped lang="scss"></style>