bfg-common 1.2.36 → 1.2.37

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 (89) hide show
  1. package/assets/localization/local_be.json +2 -2
  2. package/assets/localization/local_en.json +2 -2
  3. package/assets/localization/local_hy.json +2 -2
  4. package/assets/localization/local_kk.json +2 -2
  5. package/assets/localization/local_ru.json +9 -9
  6. package/assets/localization/local_zh.json +2 -2
  7. package/components/atoms/TheIcon2.vue +1 -0
  8. package/components/atoms/alert/Notification.vue +167 -167
  9. package/components/atoms/autocomplete/Autocomplete.vue +236 -236
  10. package/components/atoms/datepicker/Datepicker.vue +612 -612
  11. package/components/atoms/list/SelectList.vue +62 -62
  12. package/components/atoms/nav/NavBar.vue +116 -116
  13. package/components/atoms/nav/VerticalNavBar.vue +89 -89
  14. package/components/atoms/notificationBar/NotificationBar.vue +175 -175
  15. package/components/atoms/perPage/PerPage.vue +52 -52
  16. package/components/atoms/popup/SimplePopup.vue +90 -90
  17. package/components/atoms/step/VerticalStep.vue +104 -104
  18. package/components/atoms/switch/Switch.vue +107 -107
  19. package/components/atoms/table/dataGrid/DataGridColumnSwitch.vue +206 -206
  20. package/components/atoms/table/dataGrid/DataGridPage.vue +189 -189
  21. package/components/atoms/tabs/Tabs.vue +189 -189
  22. package/components/atoms/tooltip/Signpost.vue +224 -224
  23. package/components/common/BadBrowser.vue +5 -24
  24. package/components/common/adapterManager/AddAdapterWarningModal.vue +82 -82
  25. package/components/common/adapterManager/NoActiveAdaptersModal.vue +62 -62
  26. package/components/common/adapterManager/NoConnectedActiveAdaptersModal.vue +62 -62
  27. package/components/common/addNetworking/AddNetworking.vue +4 -0
  28. package/components/common/addNetworking/config/portPropertiesStep.ts +27 -15
  29. package/components/common/addNetworking/models/interfaces.ts +2 -2
  30. package/components/common/addNetworking/models/types.ts +11 -3
  31. package/components/common/addNetworking/steps/PortProperties.vue +14 -3
  32. package/components/common/browse/Browse.vue +182 -182
  33. package/components/common/browse/blocks/Title.vue +66 -66
  34. package/components/common/diagramMain/Diagram.vue +186 -186
  35. package/components/common/diagramMain/DiagramMain.vue +986 -986
  36. package/components/common/diagramMain/adapter/AdapterItem.vue +227 -227
  37. package/components/common/diagramMain/adapter/AdapterItems.vue +57 -57
  38. package/components/common/diagramMain/modals/editSettings/tabs/port/IpvFourSettings.vue +339 -339
  39. package/components/common/diagramMain/modals/editSettings/tabs/port/PortProperties.vue +202 -202
  40. package/components/common/diagramMain/modals/remove/RemoveModal.vue +226 -226
  41. package/components/common/diagramMain/network/Contents.vue +238 -238
  42. package/components/common/feedback/Buttons.vue +232 -232
  43. package/components/common/feedback/Message.vue +468 -468
  44. package/components/common/feedback/VisitPortal.vue +54 -54
  45. package/components/common/help/navbar/left/Left.vue +159 -159
  46. package/components/common/help/navbar/left/utils/constructAccordion.ts +27 -27
  47. package/components/common/mainNavigationPanel/MainNavigationPanel.vue +359 -359
  48. package/components/common/modals/Rename.vue +165 -165
  49. package/components/common/perPage/PerPage.vue +51 -51
  50. package/components/common/recursionTree/RecursionTree.vue +201 -201
  51. package/components/common/vm/actions/add/config/capabilities.ts +338 -338
  52. package/components/common/vm/actions/add/customizeHardware/virtualHardware/VirtualHardware.vue +657 -657
  53. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/CoresPerSocket.vue +109 -109
  54. package/components/common/vm/actions/add/customizeHardware/virtualHardware/cpu/Cpu.vue +383 -383
  55. package/components/common/vm/actions/add/customizeHardware/virtualHardware/limit/Limit.vue +234 -234
  56. package/components/common/vm/actions/add/customizeHardware/virtualHardware/limit/config/options.ts +28 -28
  57. package/components/common/vm/actions/add/customizeHardware/virtualHardware/memory/Memory.vue +316 -316
  58. package/components/common/vm/actions/add/customizeHardware/virtualHardware/memory/config/memoryOptions.ts +35 -35
  59. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newHardDisk/NewHardDisk.vue +445 -445
  60. package/components/common/vm/actions/add/customizeHardware/virtualHardware/newNetwork/NewNetwork.vue +288 -288
  61. package/components/common/vm/actions/add/customizeHardware/virtualHardware/reservation/Reservation.vue +235 -235
  62. package/components/common/vm/actions/add/customizeHardware/virtualHardware/videoCard/VideoCard.vue +177 -177
  63. package/components/common/vm/actions/add/customizeHardware/vmoptions/bootOptions/order/Order.vue +197 -197
  64. package/components/common/vm/actions/add/customizeHardware/vmoptions/generalOptions/GeneralOptions.vue +181 -181
  65. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/CopyPaste.vue +51 -51
  66. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/RemoteConsoleOptions.vue +253 -253
  67. package/components/common/vm/actions/add/customizeHardware/vmoptions/remoteConsoleOptions/keymap/Keymap.vue +55 -55
  68. package/components/common/vm/actions/add/select/storage/config/config.ts +154 -154
  69. package/components/common/vm/actions/clone/Clone.vue +544 -544
  70. package/components/common/vm/actions/clone/select/options/Options.vue +65 -65
  71. package/components/common/vm/actions/clone/utils.ts +43 -43
  72. package/components/common/wizards/datastore/add/Add.vue +1 -0
  73. package/components/common/wizards/datastore/add/nfs/Nfs.vue +94 -91
  74. package/components/common/wizards/datastore/add/nfs/configuration/Configuration.vue +377 -373
  75. package/components/common/wizards/datastore/add/nfs/configuration/serversList/ServersList.vue +123 -123
  76. package/components/common/wizards/datastore/add/nfs/kerberosAuthentication/KerberosAuthentication.vue +54 -54
  77. package/components/common/wizards/datastore/add/sharedStorm/deviceSelection/hostTable/HostTable.vue +131 -131
  78. package/components/common/wizards/datastore/add/sharedStorm/partitionConfiguration/PartitionConfiguration.vue +230 -230
  79. package/composables/useLocal.ts +38 -38
  80. package/minify.js +146 -146
  81. package/models/store/interfaces.ts +37 -37
  82. package/models/store/storage/interfaces.ts +32 -32
  83. package/models/store/types.ts +32 -32
  84. package/modules/fixContentBuild/utils/methods.ts +114 -114
  85. package/package.json +1 -1
  86. package/public/spice-console/application/codec.js +257 -257
  87. package/public/spice-console/lib/rasterEngine.js +907 -907
  88. package/public/spice-console/network/spicechannel.js +369 -369
  89. package/utils/contentBuild.ts +34 -34
@@ -1,657 +1,657 @@
1
- <template>
2
- <div class="virtual-hardware">
3
- <div class="clr-row clr-justify-content-end">
4
- <atoms-dropdown-tree
5
- :title="localization.addNewDevice"
6
- :items="dropdownItems"
7
- @select="onAddDevice"
8
- />
9
- </div>
10
-
11
- <div class="clr-component">
12
- <div class="stack-view">
13
- <common-vm-actions-add-customize-hardware-virtual-hardware-cpu
14
- :max-cpus="props.maxCpus"
15
- :cpu-models="props.cpuModels"
16
- :cpu="props.cpu"
17
- :is-edit="props.isEdit"
18
- :state="props.state"
19
- :error-validation-fields="props.errorValidationFields"
20
- :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
21
- @send-data="onSendDataCpuMethod"
22
- @remove-error-by-title="emits('remove-error-by-title', $event)"
23
- @invalid="cpuInvalid = $event"
24
- />
25
- <common-vm-actions-add-customize-hardware-virtual-hardware-memory
26
- :max-memory="props.maxMemory"
27
- :is-edit="props.isEdit"
28
- :memory="props.memory"
29
- :state="props.state"
30
- :error-validation-fields="props.errorValidationFields"
31
- @send-data="onSendDataMemoryMethod"
32
- @invalid="memoryInvalid = $event"
33
- @remove-error-by-title="emits('remove-error-by-title', $event)"
34
- />
35
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk
36
- v-for="(item, key) in hardDisks"
37
- :key="hardDisksIndex[key]"
38
- :index="hardDisksIndex[key]"
39
- :type="hardDisksType[key]"
40
- :storage="props.storage"
41
- :hard-disk="item"
42
- :error-validation-fields="props.errorValidationFields"
43
- :get-datastore-table-func="props.getDatastoreTableFunc"
44
- :datastore="props.datastore"
45
- :is-edit="props.isEdit"
46
- :state="props.state"
47
- @remove="onRemoveHardDisk(hardDisksIndex[key], item)"
48
- @roll-back="onRollBackHardDisk(hardDisksIndex[key])"
49
- @send-data="onSendDataNewHardDiskMethod($event, hardDisksIndex[key])"
50
- @invalid="onSetInvalidHardDisk($event, hardDisksIndex[key])"
51
- @remove-error-by-title="emits('remove-error-by-title', $event)"
52
- />
53
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-network
54
- v-for="(item, key) in networks"
55
- :key="networksIndex[key]"
56
- :index="networksIndex[key]"
57
- :type="networksType[key]"
58
- :network="item"
59
- :networks-table="props.networksTable"
60
- :error-validation-fields="props.errorValidationFields"
61
- :is-edit="props.isEdit"
62
- :state="props.state"
63
- @remove="onRemoveNetwork(networksIndex[key])"
64
- @send-data="sendDataNewNetworkMethod($event, networksIndex[key])"
65
- @invalid="onSetInvalidNetwork($event, networksIndex[key])"
66
- @remove-error-by-title="emits('remove-error-by-title', $event)"
67
- @get-networks-table="emits('get-networks-table', $event)"
68
- />
69
- <common-vm-actions-add-customize-hardware-virtual-hardware-cd-dvd-drive
70
- v-for="(item, key) in cdDvdDrives"
71
- :key="cdDvdDrivesIndex[key]"
72
- :index="cdDvdDrivesIndex[key]"
73
- :hard-disks-count="hardDisks.length"
74
- :type="cdDvdDrivesType[key]"
75
- :cd-dvd-drive="item"
76
- :nodes="props.nodes"
77
- :files="props.files"
78
- :error-validation-fields="props.errorValidationFields"
79
- :is-edit="props.isEdit"
80
- :state="props.state"
81
- @remove-error-by-title="emits('remove-error-by-title', $event)"
82
- @get-storage="emits('get-storage', $event)"
83
- @get-folders-or-files="emits('get-folders-or-files', $event)"
84
- @get-active-device-child="emits('get-active-device-child', $event)"
85
- @show-datastore-child="emits('show-datastore-child', $event)"
86
- @remove="onRemoveCdDvdDrive(cdDvdDrivesIndex[key], item)"
87
- @roll-back="onRollBackCdDvdDrive(cdDvdDrivesIndex[key])"
88
- @send-data="
89
- sendDataNewCdDvdDriveMethod($event, cdDvdDrivesIndex[key])
90
- "
91
- />
92
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-usb-controller
93
- :usb-controller="props.usbController"
94
- :is-edit="props.isEdit"
95
- :state="props.state"
96
- @send-data="onSendDataNewUsbControllerMethod"
97
- />
98
- <template v-if="props.passthroughDevices">
99
- <common-vm-actions-add-customize-hardware-virtual-hardware-new-pci-device
100
- v-for="(item, key) in pciDevices"
101
- :key="pciDevicesIndex[key]"
102
- :index="pciDevicesIndex[key]"
103
- :pci-device="item"
104
- :error-validation-fields="props.errorValidationFields"
105
- :passthrough-devices="props.passthroughDevices"
106
- :type="pciDevicesType[key]"
107
- @remove="onRemovePciDevice(pciDevicesIndex[key])"
108
- @send-data="
109
- onSendDataPciDevicesMethod($event, pciDevicesIndex[key])
110
- "
111
- @invalid="onSetInvalidPciDevice($event, pciDevicesIndex[key])"
112
- @remove-error-by-title="emits('remove-error-by-title', $event)"
113
- />
114
- </template>
115
- <common-vm-actions-add-customize-hardware-virtual-hardware-video-card
116
- :is-edit="props.isEdit"
117
- :video-card="props.videoCard"
118
- :error-validation-fields="props.errorValidationFields"
119
- :state="props.state"
120
- @send-data="onSendDataVideoCardMethod"
121
- @invalid="videoCardInvalid = $event"
122
- @remove-error-by-title="emits('remove-error-by-title', $event)"
123
- />
124
- <common-vm-actions-add-customize-hardware-virtual-hardware-other />
125
- </div>
126
- </div>
127
-
128
- <Teleport to="body">
129
- <common-vm-actions-add-customize-hardware-virtual-hardware-browse-view
130
- v-if="isShowFileModal"
131
- :show="isShowFileModal"
132
- :nodes="props.nodes"
133
- :files="props.files"
134
- @submit="onAddExistHardDisk"
135
- @get-storage="emits('get-storage', $event)"
136
- @get-folders-or-files="emits('get-folders-or-files', $event)"
137
- @get-active-device-child="emits('get-active-device-child', $event)"
138
- @show-datastore-child="emits('show-datastore-child', $event)"
139
- @hide="isShowFileModal = false"
140
- />
141
- </Teleport>
142
- </div>
143
- </template>
144
-
145
- <script setup lang="ts">
146
- import { UI_I_DatastoreTableItem } from '~/models/store/storage/interfaces'
147
- import { UI_I_NetworkTableItem } from '~/models/store/network/interfaces'
148
- import { UI_I_TablePayload } from '~/models/store/interfaces'
149
- import { UI_I_FolderOrFileTreePayload } from '~/models/store/storage/interfaces'
150
- import { UI_I_FileTreeNode } from '~/components/models/interfaces'
151
- import {
152
- UI_I_SendDataCpu,
153
- UI_I_SendDataMemory,
154
- UI_I_SendDataNewHardDisk,
155
- UI_I_SendDataNewNetwork,
156
- UI_I_SendDataVideoCard,
157
- UI_I_InvalidKeys,
158
- UI_I_SendDataVirtualHardware,
159
- UI_I_SendDataNewCdDvdDrive,
160
- UI_I_HardDisk,
161
- UI_I_PciDevice,
162
- UI_I_SendDataNewPciDevice,
163
- } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/interfaces'
164
- import { UI_I_ErrorValidationField } from '~/models/store/interfaces'
165
- import {
166
- UI_T_HardDiskType,
167
- UI_T_NetworkType,
168
- UI_T_CdDvdType,
169
- } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/types'
170
- import { UI_I_OptionItem } from '~/components/atoms/models/interfaces'
171
- import {
172
- UI_I_DropdownTreeItem,
173
- UI_I_DropdownTreeItemChild,
174
- } from '~/components/atoms/dropdown/tree/models/interfaces'
175
- import { UI_I_Localization } from '~/models/interfaces'
176
- import { UI_I_ConfigurePciDevicesTable } from '~/models/store/host/interfaces'
177
- import {
178
- API_UI_I_VmEditCpu,
179
- API_UI_I_VmEditMemory,
180
- } from '~/models/store/vm/interfaces'
181
- import { dropdownItemsFunc } from './config/dropdownItems'
182
-
183
- const props = defineProps<{
184
- storage: UI_I_DatastoreTableItem | null
185
- cpuModels: UI_I_OptionItem[]
186
- vmName: string
187
- maxCpus: number
188
- maxMemory: number
189
- isEdit: boolean
190
- errorValidationFields: UI_I_ErrorValidationField<string>[]
191
- nodes: UI_I_FileTreeNode[]
192
- files: UI_I_FileTreeNode[]
193
- networksTable: UI_I_NetworkTableItem[]
194
- getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
195
- datastore: UI_I_DatastoreTableItem[]
196
- state?: string | number
197
- cpu?: API_UI_I_VmEditCpu
198
- memory?: API_UI_I_VmEditMemory
199
- vmCpuHelpTextSecond?: string
200
- hardDisks?: UI_I_SendDataNewHardDisk[] | null
201
- cdDvdDrives?: UI_I_SendDataNewCdDvdDrive[] | null
202
- networks?: UI_I_SendDataNewNetwork[] | null
203
- videoCard?: UI_I_SendDataVideoCard
204
- usbController?: string
205
- pciDevices?: UI_I_PciDevice[]
206
- passthroughDevices?: UI_I_ConfigurePciDevicesTable | null
207
- }>()
208
- const emits = defineEmits<{
209
- (event: 'send-data', value: UI_I_SendDataVirtualHardware): void
210
- (event: 'invalid', value: string[]): void
211
- (event: 'get-storage', value: UI_I_TablePayload): void
212
- (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
213
- (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
214
- (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
215
- (event: 'remove-error-by-title', value: string): void
216
- (event: 'get-networks-table', value: UI_I_TablePayload): void
217
- (event: 'get-pci-devices'): void
218
- }>()
219
-
220
- const localization = computed<UI_I_Localization>(() => useLocal())
221
- const { $binary } = useNuxtApp()
222
-
223
- const dropdownItems = computed<UI_I_DropdownTreeItem[]>(() =>
224
- dropdownItemsFunc(localization.value)
225
- )
226
-
227
- const hardDisksIndex = ref<number[]>([0])
228
- const hardDisksType = ref<UI_T_HardDiskType[]>(['new'])
229
- const hardDisks = ref<UI_I_SendDataNewHardDisk[]>([
230
- {
231
- create: true,
232
- size: 90,
233
- source: '',
234
- boot_order: -1,
235
- },
236
- ])
237
- watch(
238
- () => props.hardDisks,
239
- (newValue) => {
240
- if (!props.isEdit || !newValue) return
241
-
242
- const count = newValue?.length || 0
243
- hardDisksIndex.value = [...Array(count).keys()]
244
- hardDisksType.value = Array(count).fill('edit')
245
- hardDisks.value = newValue
246
- },
247
- { immediate: true }
248
- )
249
-
250
- const addHardDisk = (
251
- create = true,
252
- size = 90,
253
- source = '',
254
- type: UI_T_HardDiskType = 'new'
255
- ): void => {
256
- const newIndex = (hardDisksIndex.value.at(-1) ?? -1) + 1
257
- hardDisksIndex.value.push(newIndex)
258
- hardDisksType.value.push(type)
259
-
260
- hardDisks.value.push({
261
- create,
262
- size,
263
- source,
264
- attach: true,
265
- boot_order: 0, // Убираем галочку
266
- })
267
- sendData()
268
- }
269
- const onAddExistHardDisk = (hardDisk: UI_I_HardDisk): void => {
270
- addHardDisk(false, $binary.bToGb(hardDisk.size), hardDisk.path, 'exist')
271
- }
272
- const onRemoveHardDisk = (
273
- index: number,
274
- hardDisk: UI_I_SendDataNewHardDisk
275
- ): void => {
276
- const removeIndex = hardDisksIndex.value.indexOf(index)
277
-
278
- if (!hardDisk.create && !hardDisk.attach) {
279
- hardDisksType.value = hardDisksType.value.map((item, key) => {
280
- if (key === removeIndex) return 'removed'
281
- return item
282
- })
283
- sendData()
284
- return
285
- }
286
-
287
- hardDisksIndex.value = hardDisksIndex.value.filter((item) => item !== index)
288
- hardDisksType.value = hardDisksType.value.filter(
289
- (_item, key) => key !== removeIndex
290
- )
291
-
292
- hardDisks.value = hardDisks.value.filter((_hardDisk, key: number) => {
293
- return removeIndex !== key
294
- })
295
-
296
- delete newHardDiskInvalidKeys.value[index]
297
- delete sendDataNewHardDisk.value[index]
298
- sendData()
299
- }
300
- const onRollBackHardDisk = (index: number): void => {
301
- const removeIndex = hardDisksIndex.value.indexOf(index)
302
- hardDisksType.value = hardDisksType.value.map((item, key) => {
303
- if (key === removeIndex) return 'edit'
304
- return item
305
- })
306
- }
307
-
308
- const defaultNetwork = {
309
- network: '',
310
- net_bridge: '',
311
- mac: '',
312
- target: '',
313
- model: '',
314
- boot_order: -1,
315
- }
316
- const networks = ref<UI_I_SendDataNewNetwork[]>([useDeepCopy(defaultNetwork)])
317
- const networksType = ref<UI_T_NetworkType[]>(['new'])
318
- const networksIndex = ref<number[]>([0])
319
- watch(
320
- () => props.networks,
321
- (newValue) => {
322
- if (!props.isEdit || !newValue) return
323
-
324
- // networks.value = newValue
325
- // networksType.value = Array(newValue.length).fill('edit')
326
- const count = newValue?.length || 0
327
- networksIndex.value = [...Array(count).keys()]
328
- networksType.value = Array(count).fill('edit')
329
- networks.value = newValue
330
- },
331
- { immediate: true }
332
- )
333
- const addNetwork = (): void => {
334
- const index = (networksIndex.value.at(-1) || 0) + 1
335
- networksIndex.value.push(index)
336
- networksType.value.push('new')
337
-
338
- networks.value.push({
339
- ...useDeepCopy(defaultNetwork),
340
- boot_order: 0, // Убираем галочку
341
- })
342
- }
343
- const onRemoveNetwork = (index: number): void => {
344
- const removeIndex = networksIndex.value.indexOf(index)
345
- networksIndex.value = networksIndex.value.filter((item) => item !== index)
346
- networksType.value = networksType.value.filter(
347
- (_item, key) => key !== removeIndex
348
- )
349
- networks.value = networks.value.filter(
350
- (_network, key: number) => removeIndex !== key
351
- )
352
-
353
- delete newNetworkInvalidKeys.value[index]
354
- delete sendDataNewNetwork.value[index]
355
- sendData()
356
- }
357
-
358
- const defaultCdDvdDriver: UI_I_SendDataNewCdDvdDrive = {
359
- create: false,
360
- attach: false,
361
- source: '',
362
- bus: '',
363
- device_type: 'cdrom',
364
- boot_order: -1,
365
- }
366
- const cdDvdDrives = ref<UI_I_SendDataNewCdDvdDrive[]>([
367
- useDeepCopy(defaultCdDvdDriver),
368
- ])
369
- const cdDvdDrivesIndex = ref<number[]>([0])
370
- const cdDvdDrivesType = ref<UI_T_CdDvdType[]>(['new'])
371
- watch(
372
- () => props.cdDvdDrives,
373
- (newValue) => {
374
- if (!props.isEdit || !newValue) return
375
-
376
- // cdDvdDrives.value = newValue
377
- // cdDvdDrivesType.value = Array(newValue.length).fill('edit')
378
- const count = newValue?.length || 0
379
- cdDvdDrivesIndex.value = [...Array(count).keys()]
380
- cdDvdDrivesType.value = Array(count).fill('edit')
381
- cdDvdDrives.value = newValue
382
- },
383
- { immediate: true }
384
- )
385
- const addCdDvdDrive = (): void => {
386
- const value = (cdDvdDrivesIndex.value.at(-1) || 0) + 1
387
- cdDvdDrivesIndex.value.push(value)
388
- cdDvdDrivesType.value.push('new')
389
- cdDvdDrives.value.push({
390
- ...useDeepCopy(defaultCdDvdDriver),
391
- attach: true,
392
- boot_order: 0 // Убираем галочку
393
- })
394
- }
395
- const onRemoveCdDvdDrive = (
396
- index: number,
397
- cdDvdDrive: UI_I_SendDataNewCdDvdDrive
398
- ): void => {
399
- const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
400
-
401
- // if (!cdDvdDrive.create && !cdDvdDrive.attach) {
402
- if (cdDvdDrivesType.value[index] === 'edit' && !cdDvdDrive.attach) {
403
- cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
404
- if (key === removeIndex) return 'removed'
405
- return item
406
- })
407
- sendData()
408
- return
409
- }
410
-
411
- cdDvdDrivesIndex.value = cdDvdDrivesIndex.value.filter(
412
- (cdDvdDrive) => cdDvdDrive !== index
413
- )
414
- cdDvdDrivesType.value = cdDvdDrivesType.value.filter(
415
- (_item, key) => key !== index
416
- )
417
- cdDvdDrives.value = cdDvdDrives.value.filter(
418
- (_cdDvdDrive, key: number) => removeIndex !== key
419
- )
420
-
421
- delete sendDataNewCdDvdDrive.value[index]
422
- sendData()
423
- }
424
- const onRollBackCdDvdDrive = (index: number): void => {
425
- const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
426
- cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
427
- if (key === removeIndex) return 'edit'
428
- return item
429
- })
430
- }
431
-
432
- const defaultPciDevice: UI_I_PciDevice = {
433
- id: '',
434
- vendor_name: '',
435
- class_name: 'cdrom',
436
- device_name: 'cdrom',
437
- }
438
- const pciDevicesIndex = ref<number[]>([0])
439
- const pciDevicesType = ref<('new' | 'edit')[]>(['new'])
440
- const pciDevices = ref<UI_I_PciDevice[]>([])
441
- watch(
442
- () => props.pciDevices,
443
- (newValue) => {
444
- if (!props.isEdit) return
445
-
446
- const count = newValue?.length || 0
447
- pciDevicesIndex.value = [...Array(count).keys()]
448
- pciDevicesType.value = Array(count).fill('edit')
449
- pciDevices.value = newValue || []
450
- },
451
- { immediate: true }
452
- )
453
-
454
- const addPciDevice = (): void => {
455
- const newIndex = (pciDevicesIndex.value.at(-1) ?? -1) + 1
456
- pciDevicesIndex.value.push(newIndex)
457
- pciDevicesType.value.push('new')
458
-
459
- pciDevices.value.push(useDeepCopy(defaultPciDevice))
460
- }
461
- const onRemovePciDevice = (index: number): void => {
462
- const removeIndex = pciDevicesIndex.value.indexOf(index)
463
- pciDevicesIndex.value = pciDevicesIndex.value.filter((item) => item !== index)
464
- pciDevicesType.value = pciDevicesType.value.filter(
465
- (_item, key) => key !== removeIndex
466
- )
467
-
468
- pciDevices.value = pciDevices.value.filter((_pciDevice, key: number) => {
469
- return removeIndex !== key
470
- })
471
-
472
- delete newPciDeviceInvalidKeys.value[index]
473
- delete sendDataNewPciDevices.value[index]
474
- sendData()
475
- }
476
-
477
- const isShowFileModal = ref<boolean>(false)
478
- const onAddDevice = (item: UI_I_DropdownTreeItemChild): void => {
479
- switch (item.value) {
480
- case 1:
481
- addHardDisk()
482
- break
483
- case 2:
484
- isShowFileModal.value = true
485
- break
486
- case 5:
487
- addCdDvdDrive()
488
- break
489
- case 10:
490
- addPciDevice()
491
- break
492
- case 14:
493
- addNetwork()
494
- break
495
- }
496
- }
497
-
498
- const cpuInvalid = ref<boolean>(false)
499
- const sendDataCpu = ref<UI_I_SendDataCpu | null>(null)
500
- const onSendDataCpuMethod = (data: UI_I_SendDataCpu): void => {
501
- sendDataCpu.value = data
502
- sendData()
503
- }
504
- const sendDataMemory = ref<UI_I_SendDataMemory | null>(null)
505
- const onSendDataMemoryMethod = (data: UI_I_SendDataMemory): void => {
506
- sendDataMemory.value = data
507
- sendData()
508
- }
509
- const sendDataNewHardDisk = ref<UI_I_SendDataNewHardDisk[]>([])
510
- const onSendDataNewHardDiskMethod = (
511
- data: UI_I_SendDataNewHardDisk,
512
- index: number
513
- ): void => {
514
- sendDataNewHardDisk.value[index] = data
515
- sendData()
516
- }
517
- const sendDataNewNetwork = ref<UI_I_SendDataNewNetwork[]>([])
518
- const sendDataNewNetworkMethod = (
519
- data: UI_I_SendDataNewNetwork,
520
- index: number
521
- ): void => {
522
- sendDataNewNetwork.value[index] = data
523
- sendData()
524
- }
525
- const sendDataNewCdDvdDrive = ref<UI_I_SendDataNewCdDvdDrive[]>([])
526
- const sendDataNewCdDvdDriveMethod = (
527
- data: UI_I_SendDataNewCdDvdDrive,
528
- index: number
529
- ): void => {
530
- sendDataNewCdDvdDrive.value[index] = data
531
- sendData()
532
- }
533
- const sendDataNewUsbController = ref<string | null>(null)
534
- const onSendDataNewUsbControllerMethod = (data: string): void => {
535
- sendDataNewUsbController.value = data
536
- sendData()
537
- }
538
- const sendDataNewPciDevices = ref<UI_I_SendDataNewPciDevice[]>([])
539
- const onSendDataPciDevicesMethod = (
540
- data: UI_I_SendDataNewPciDevice,
541
- index: number
542
- ): void => {
543
- sendDataNewPciDevices.value[index] = data
544
- sendData()
545
- }
546
- const sendDataVideoCard = ref<UI_I_SendDataVideoCard | null>(null)
547
- const onSendDataVideoCardMethod = (data: UI_I_SendDataVideoCard): void => {
548
- sendDataVideoCard.value = data
549
- sendData()
550
- }
551
-
552
- const sendData = (): void => {
553
- const cpu = sendDataCpu.value
554
- const memory = sendDataMemory.value
555
- const hardDisks = sendDataNewHardDisk.value.flat(2)
556
- const networks = sendDataNewNetwork.value.flat(2)
557
- const cdDvdDrives = sendDataNewCdDvdDrive.value.flat(2)
558
- const pciDevices = sendDataNewPciDevices.value.flat()
559
- const usbController = sendDataNewUsbController.value
560
- const videoCard = sendDataVideoCard.value
561
-
562
- const sendData: UI_I_SendDataVirtualHardware = {
563
- cpu,
564
- memory,
565
- usbController,
566
- pciDevices,
567
- networks,
568
- hardDisks,
569
- cdDvdDrives,
570
- videoCard,
571
- }
572
- emits('send-data', sendData)
573
- }
574
-
575
- const onSetInvalidHardDisk = (invalid: boolean, index: number): void => {
576
- newHardDiskInvalidKeys.value[index] = invalid
577
- }
578
-
579
- const onSetInvalidNetwork = (invalid: boolean, key: number): void => {
580
- newNetworkInvalidKeys.value[key] = invalid
581
- }
582
-
583
- const onSetInvalidPciDevice = (invalid: boolean, key: number): void => {
584
- newPciDeviceInvalidKeys.value[key] = invalid
585
- }
586
-
587
- const memoryInvalid = ref<boolean>(false)
588
- const videoCardInvalid = ref<boolean>(false)
589
- const newHardDiskInvalidKeys = ref<UI_I_InvalidKeys>({})
590
- const newNetworkInvalidKeys = ref<UI_I_InvalidKeys>({})
591
- const newPciDeviceInvalidKeys = ref<UI_I_InvalidKeys>({})
592
-
593
- watch(
594
- [
595
- cpuInvalid,
596
- memoryInvalid,
597
- newHardDiskInvalidKeys,
598
- newNetworkInvalidKeys,
599
- newPciDeviceInvalidKeys,
600
- videoCardInvalid,
601
- ],
602
- () => {
603
- const cpu = cpuInvalid.value ? localization.value.cpu : ''
604
- const memory = memoryInvalid.value ? localization.value.memory : ''
605
- const videoCard = videoCardInvalid.value ? localization.value.videoCard : ''
606
- let newHardDisk = ''
607
- Object.keys(newHardDiskInvalidKeys.value).forEach((key) => {
608
- if (!newHardDiskInvalidKeys.value[+key]) {
609
- return
610
- }
611
-
612
- newHardDisk +=
613
- (newHardDisk ? ', ' : '') +
614
- localization.value.newHardDisk +
615
- ' ' +
616
- (+key + 1)
617
- })
618
- let newNetwork = ''
619
- Object.keys(newNetworkInvalidKeys.value).forEach((key) => {
620
- if (!newNetworkInvalidKeys.value[+key]) {
621
- return
622
- }
623
-
624
- newNetwork +=
625
- (newNetwork ? ', ' : '') +
626
- localization.value.newNetwork +
627
- ' ' +
628
- (+key + 1)
629
- })
630
- // let pciDevice = ''
631
- // Object.keys(newPciDeviceInvalidKeys.value).forEach((key) => {
632
- // if (!newPciDeviceInvalidKeys.value[+key]) {
633
- // return
634
- // }
635
- //
636
- // pciDevice +=
637
- // (pciDevice ? ', ' : '') +
638
- // localization.value.pciDevice +
639
- // ' ' +
640
- // (+key + 1)
641
- // })
642
-
643
- emits('invalid', [cpu, memory, newHardDisk, newNetwork, videoCard])
644
- },
645
- { deep: true }
646
- )
647
-
648
- emits('get-pci-devices')
649
- </script>
650
-
651
- <style scoped lang="scss">
652
- .virtual-hardware {
653
- .content-dropdown {
654
- width: 200px;
655
- }
656
- }
657
- </style>
1
+ <template>
2
+ <div class="virtual-hardware">
3
+ <div class="clr-row clr-justify-content-end">
4
+ <atoms-dropdown-tree
5
+ :title="localization.addNewDevice"
6
+ :items="dropdownItems"
7
+ @select="onAddDevice"
8
+ />
9
+ </div>
10
+
11
+ <div class="clr-component">
12
+ <div class="stack-view">
13
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cpu
14
+ :max-cpus="props.maxCpus"
15
+ :cpu-models="props.cpuModels"
16
+ :cpu="props.cpu"
17
+ :is-edit="props.isEdit"
18
+ :state="props.state"
19
+ :error-validation-fields="props.errorValidationFields"
20
+ :vm-cpu-help-text-second="props.vmCpuHelpTextSecond"
21
+ @send-data="onSendDataCpuMethod"
22
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
23
+ @invalid="cpuInvalid = $event"
24
+ />
25
+ <common-vm-actions-add-customize-hardware-virtual-hardware-memory
26
+ :max-memory="props.maxMemory"
27
+ :is-edit="props.isEdit"
28
+ :memory="props.memory"
29
+ :state="props.state"
30
+ :error-validation-fields="props.errorValidationFields"
31
+ @send-data="onSendDataMemoryMethod"
32
+ @invalid="memoryInvalid = $event"
33
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
34
+ />
35
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-hard-disk
36
+ v-for="(item, key) in hardDisks"
37
+ :key="hardDisksIndex[key]"
38
+ :index="hardDisksIndex[key]"
39
+ :type="hardDisksType[key]"
40
+ :storage="props.storage"
41
+ :hard-disk="item"
42
+ :error-validation-fields="props.errorValidationFields"
43
+ :get-datastore-table-func="props.getDatastoreTableFunc"
44
+ :datastore="props.datastore"
45
+ :is-edit="props.isEdit"
46
+ :state="props.state"
47
+ @remove="onRemoveHardDisk(hardDisksIndex[key], item)"
48
+ @roll-back="onRollBackHardDisk(hardDisksIndex[key])"
49
+ @send-data="onSendDataNewHardDiskMethod($event, hardDisksIndex[key])"
50
+ @invalid="onSetInvalidHardDisk($event, hardDisksIndex[key])"
51
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
52
+ />
53
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-network
54
+ v-for="(item, key) in networks"
55
+ :key="networksIndex[key]"
56
+ :index="networksIndex[key]"
57
+ :type="networksType[key]"
58
+ :network="item"
59
+ :networks-table="props.networksTable"
60
+ :error-validation-fields="props.errorValidationFields"
61
+ :is-edit="props.isEdit"
62
+ :state="props.state"
63
+ @remove="onRemoveNetwork(networksIndex[key])"
64
+ @send-data="sendDataNewNetworkMethod($event, networksIndex[key])"
65
+ @invalid="onSetInvalidNetwork($event, networksIndex[key])"
66
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
67
+ @get-networks-table="emits('get-networks-table', $event)"
68
+ />
69
+ <common-vm-actions-add-customize-hardware-virtual-hardware-cd-dvd-drive
70
+ v-for="(item, key) in cdDvdDrives"
71
+ :key="cdDvdDrivesIndex[key]"
72
+ :index="cdDvdDrivesIndex[key]"
73
+ :hard-disks-count="hardDisks.length"
74
+ :type="cdDvdDrivesType[key]"
75
+ :cd-dvd-drive="item"
76
+ :nodes="props.nodes"
77
+ :files="props.files"
78
+ :error-validation-fields="props.errorValidationFields"
79
+ :is-edit="props.isEdit"
80
+ :state="props.state"
81
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
82
+ @get-storage="emits('get-storage', $event)"
83
+ @get-folders-or-files="emits('get-folders-or-files', $event)"
84
+ @get-active-device-child="emits('get-active-device-child', $event)"
85
+ @show-datastore-child="emits('show-datastore-child', $event)"
86
+ @remove="onRemoveCdDvdDrive(cdDvdDrivesIndex[key], item)"
87
+ @roll-back="onRollBackCdDvdDrive(cdDvdDrivesIndex[key])"
88
+ @send-data="
89
+ sendDataNewCdDvdDriveMethod($event, cdDvdDrivesIndex[key])
90
+ "
91
+ />
92
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-usb-controller
93
+ :usb-controller="props.usbController"
94
+ :is-edit="props.isEdit"
95
+ :state="props.state"
96
+ @send-data="onSendDataNewUsbControllerMethod"
97
+ />
98
+ <template v-if="props.passthroughDevices">
99
+ <common-vm-actions-add-customize-hardware-virtual-hardware-new-pci-device
100
+ v-for="(item, key) in pciDevices"
101
+ :key="pciDevicesIndex[key]"
102
+ :index="pciDevicesIndex[key]"
103
+ :pci-device="item"
104
+ :error-validation-fields="props.errorValidationFields"
105
+ :passthrough-devices="props.passthroughDevices"
106
+ :type="pciDevicesType[key]"
107
+ @remove="onRemovePciDevice(pciDevicesIndex[key])"
108
+ @send-data="
109
+ onSendDataPciDevicesMethod($event, pciDevicesIndex[key])
110
+ "
111
+ @invalid="onSetInvalidPciDevice($event, pciDevicesIndex[key])"
112
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
113
+ />
114
+ </template>
115
+ <common-vm-actions-add-customize-hardware-virtual-hardware-video-card
116
+ :is-edit="props.isEdit"
117
+ :video-card="props.videoCard"
118
+ :error-validation-fields="props.errorValidationFields"
119
+ :state="props.state"
120
+ @send-data="onSendDataVideoCardMethod"
121
+ @invalid="videoCardInvalid = $event"
122
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
123
+ />
124
+ <common-vm-actions-add-customize-hardware-virtual-hardware-other />
125
+ </div>
126
+ </div>
127
+
128
+ <Teleport to="body">
129
+ <common-vm-actions-add-customize-hardware-virtual-hardware-browse-view
130
+ v-if="isShowFileModal"
131
+ :show="isShowFileModal"
132
+ :nodes="props.nodes"
133
+ :files="props.files"
134
+ @submit="onAddExistHardDisk"
135
+ @get-storage="emits('get-storage', $event)"
136
+ @get-folders-or-files="emits('get-folders-or-files', $event)"
137
+ @get-active-device-child="emits('get-active-device-child', $event)"
138
+ @show-datastore-child="emits('show-datastore-child', $event)"
139
+ @hide="isShowFileModal = false"
140
+ />
141
+ </Teleport>
142
+ </div>
143
+ </template>
144
+
145
+ <script setup lang="ts">
146
+ import { UI_I_DatastoreTableItem } from '~/models/store/storage/interfaces'
147
+ import { UI_I_NetworkTableItem } from '~/models/store/network/interfaces'
148
+ import { UI_I_TablePayload } from '~/models/store/interfaces'
149
+ import { UI_I_FolderOrFileTreePayload } from '~/models/store/storage/interfaces'
150
+ import { UI_I_FileTreeNode } from '~/components/models/interfaces'
151
+ import {
152
+ UI_I_SendDataCpu,
153
+ UI_I_SendDataMemory,
154
+ UI_I_SendDataNewHardDisk,
155
+ UI_I_SendDataNewNetwork,
156
+ UI_I_SendDataVideoCard,
157
+ UI_I_InvalidKeys,
158
+ UI_I_SendDataVirtualHardware,
159
+ UI_I_SendDataNewCdDvdDrive,
160
+ UI_I_HardDisk,
161
+ UI_I_PciDevice,
162
+ UI_I_SendDataNewPciDevice,
163
+ } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/interfaces'
164
+ import { UI_I_ErrorValidationField } from '~/models/store/interfaces'
165
+ import {
166
+ UI_T_HardDiskType,
167
+ UI_T_NetworkType,
168
+ UI_T_CdDvdType,
169
+ } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/models/types'
170
+ import { UI_I_OptionItem } from '~/components/atoms/models/interfaces'
171
+ import {
172
+ UI_I_DropdownTreeItem,
173
+ UI_I_DropdownTreeItemChild,
174
+ } from '~/components/atoms/dropdown/tree/models/interfaces'
175
+ import { UI_I_Localization } from '~/models/interfaces'
176
+ import { UI_I_ConfigurePciDevicesTable } from '~/models/store/host/interfaces'
177
+ import {
178
+ API_UI_I_VmEditCpu,
179
+ API_UI_I_VmEditMemory,
180
+ } from '~/models/store/vm/interfaces'
181
+ import { dropdownItemsFunc } from './config/dropdownItems'
182
+
183
+ const props = defineProps<{
184
+ storage: UI_I_DatastoreTableItem | null
185
+ cpuModels: UI_I_OptionItem[]
186
+ vmName: string
187
+ maxCpus: number
188
+ maxMemory: number
189
+ isEdit: boolean
190
+ errorValidationFields: UI_I_ErrorValidationField<string>[]
191
+ nodes: UI_I_FileTreeNode[]
192
+ files: UI_I_FileTreeNode[]
193
+ networksTable: UI_I_NetworkTableItem[]
194
+ getDatastoreTableFunc: (payload: UI_I_TablePayload) => Promise<void>
195
+ datastore: UI_I_DatastoreTableItem[]
196
+ state?: string | number
197
+ cpu?: API_UI_I_VmEditCpu
198
+ memory?: API_UI_I_VmEditMemory
199
+ vmCpuHelpTextSecond?: string
200
+ hardDisks?: UI_I_SendDataNewHardDisk[] | null
201
+ cdDvdDrives?: UI_I_SendDataNewCdDvdDrive[] | null
202
+ networks?: UI_I_SendDataNewNetwork[] | null
203
+ videoCard?: UI_I_SendDataVideoCard
204
+ usbController?: string
205
+ pciDevices?: UI_I_PciDevice[]
206
+ passthroughDevices?: UI_I_ConfigurePciDevicesTable | null
207
+ }>()
208
+ const emits = defineEmits<{
209
+ (event: 'send-data', value: UI_I_SendDataVirtualHardware): void
210
+ (event: 'invalid', value: string[]): void
211
+ (event: 'get-storage', value: UI_I_TablePayload): void
212
+ (event: 'get-folders-or-files', value: UI_I_FolderOrFileTreePayload): void
213
+ (event: 'get-active-device-child', value: UI_I_FileTreeNode): void
214
+ (event: 'show-datastore-child', value: UI_I_FileTreeNode): void
215
+ (event: 'remove-error-by-title', value: string): void
216
+ (event: 'get-networks-table', value: UI_I_TablePayload): void
217
+ (event: 'get-pci-devices'): void
218
+ }>()
219
+
220
+ const localization = computed<UI_I_Localization>(() => useLocal())
221
+ const { $binary } = useNuxtApp()
222
+
223
+ const dropdownItems = computed<UI_I_DropdownTreeItem[]>(() =>
224
+ dropdownItemsFunc(localization.value)
225
+ )
226
+
227
+ const hardDisksIndex = ref<number[]>([0])
228
+ const hardDisksType = ref<UI_T_HardDiskType[]>(['new'])
229
+ const hardDisks = ref<UI_I_SendDataNewHardDisk[]>([
230
+ {
231
+ create: true,
232
+ size: 90,
233
+ source: '',
234
+ boot_order: -1,
235
+ },
236
+ ])
237
+ watch(
238
+ () => props.hardDisks,
239
+ (newValue) => {
240
+ if (!props.isEdit || !newValue) return
241
+
242
+ const count = newValue?.length || 0
243
+ hardDisksIndex.value = [...Array(count).keys()]
244
+ hardDisksType.value = Array(count).fill('edit')
245
+ hardDisks.value = newValue
246
+ },
247
+ { immediate: true }
248
+ )
249
+
250
+ const addHardDisk = (
251
+ create = true,
252
+ size = 90,
253
+ source = '',
254
+ type: UI_T_HardDiskType = 'new'
255
+ ): void => {
256
+ const newIndex = (hardDisksIndex.value.at(-1) ?? -1) + 1
257
+ hardDisksIndex.value.push(newIndex)
258
+ hardDisksType.value.push(type)
259
+
260
+ hardDisks.value.push({
261
+ create,
262
+ size,
263
+ source,
264
+ attach: true,
265
+ boot_order: 0, // Убираем галочку
266
+ })
267
+ sendData()
268
+ }
269
+ const onAddExistHardDisk = (hardDisk: UI_I_HardDisk): void => {
270
+ addHardDisk(false, $binary.bToGb(hardDisk.size), hardDisk.path, 'exist')
271
+ }
272
+ const onRemoveHardDisk = (
273
+ index: number,
274
+ hardDisk: UI_I_SendDataNewHardDisk
275
+ ): void => {
276
+ const removeIndex = hardDisksIndex.value.indexOf(index)
277
+
278
+ if (!hardDisk.create && !hardDisk.attach) {
279
+ hardDisksType.value = hardDisksType.value.map((item, key) => {
280
+ if (key === removeIndex) return 'removed'
281
+ return item
282
+ })
283
+ sendData()
284
+ return
285
+ }
286
+
287
+ hardDisksIndex.value = hardDisksIndex.value.filter((item) => item !== index)
288
+ hardDisksType.value = hardDisksType.value.filter(
289
+ (_item, key) => key !== removeIndex
290
+ )
291
+
292
+ hardDisks.value = hardDisks.value.filter((_hardDisk, key: number) => {
293
+ return removeIndex !== key
294
+ })
295
+
296
+ delete newHardDiskInvalidKeys.value[index]
297
+ delete sendDataNewHardDisk.value[index]
298
+ sendData()
299
+ }
300
+ const onRollBackHardDisk = (index: number): void => {
301
+ const removeIndex = hardDisksIndex.value.indexOf(index)
302
+ hardDisksType.value = hardDisksType.value.map((item, key) => {
303
+ if (key === removeIndex) return 'edit'
304
+ return item
305
+ })
306
+ }
307
+
308
+ const defaultNetwork = {
309
+ network: '',
310
+ net_bridge: '',
311
+ mac: '',
312
+ target: '',
313
+ model: '',
314
+ boot_order: -1,
315
+ }
316
+ const networks = ref<UI_I_SendDataNewNetwork[]>([useDeepCopy(defaultNetwork)])
317
+ const networksType = ref<UI_T_NetworkType[]>(['new'])
318
+ const networksIndex = ref<number[]>([0])
319
+ watch(
320
+ () => props.networks,
321
+ (newValue) => {
322
+ if (!props.isEdit || !newValue) return
323
+
324
+ // networks.value = newValue
325
+ // networksType.value = Array(newValue.length).fill('edit')
326
+ const count = newValue?.length || 0
327
+ networksIndex.value = [...Array(count).keys()]
328
+ networksType.value = Array(count).fill('edit')
329
+ networks.value = newValue
330
+ },
331
+ { immediate: true }
332
+ )
333
+ const addNetwork = (): void => {
334
+ const index = (networksIndex.value.at(-1) || 0) + 1
335
+ networksIndex.value.push(index)
336
+ networksType.value.push('new')
337
+
338
+ networks.value.push({
339
+ ...useDeepCopy(defaultNetwork),
340
+ boot_order: 0, // Убираем галочку
341
+ })
342
+ }
343
+ const onRemoveNetwork = (index: number): void => {
344
+ const removeIndex = networksIndex.value.indexOf(index)
345
+ networksIndex.value = networksIndex.value.filter((item) => item !== index)
346
+ networksType.value = networksType.value.filter(
347
+ (_item, key) => key !== removeIndex
348
+ )
349
+ networks.value = networks.value.filter(
350
+ (_network, key: number) => removeIndex !== key
351
+ )
352
+
353
+ delete newNetworkInvalidKeys.value[index]
354
+ delete sendDataNewNetwork.value[index]
355
+ sendData()
356
+ }
357
+
358
+ const defaultCdDvdDriver: UI_I_SendDataNewCdDvdDrive = {
359
+ create: false,
360
+ attach: false,
361
+ source: '',
362
+ bus: '',
363
+ device_type: 'cdrom',
364
+ boot_order: -1,
365
+ }
366
+ const cdDvdDrives = ref<UI_I_SendDataNewCdDvdDrive[]>([
367
+ useDeepCopy(defaultCdDvdDriver),
368
+ ])
369
+ const cdDvdDrivesIndex = ref<number[]>([0])
370
+ const cdDvdDrivesType = ref<UI_T_CdDvdType[]>(['new'])
371
+ watch(
372
+ () => props.cdDvdDrives,
373
+ (newValue) => {
374
+ if (!props.isEdit || !newValue) return
375
+
376
+ // cdDvdDrives.value = newValue
377
+ // cdDvdDrivesType.value = Array(newValue.length).fill('edit')
378
+ const count = newValue?.length || 0
379
+ cdDvdDrivesIndex.value = [...Array(count).keys()]
380
+ cdDvdDrivesType.value = Array(count).fill('edit')
381
+ cdDvdDrives.value = newValue
382
+ },
383
+ { immediate: true }
384
+ )
385
+ const addCdDvdDrive = (): void => {
386
+ const value = (cdDvdDrivesIndex.value.at(-1) || 0) + 1
387
+ cdDvdDrivesIndex.value.push(value)
388
+ cdDvdDrivesType.value.push('new')
389
+ cdDvdDrives.value.push({
390
+ ...useDeepCopy(defaultCdDvdDriver),
391
+ attach: true,
392
+ boot_order: 0 // Убираем галочку
393
+ })
394
+ }
395
+ const onRemoveCdDvdDrive = (
396
+ index: number,
397
+ cdDvdDrive: UI_I_SendDataNewCdDvdDrive
398
+ ): void => {
399
+ const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
400
+
401
+ // if (!cdDvdDrive.create && !cdDvdDrive.attach) {
402
+ if (cdDvdDrivesType.value[index] === 'edit' && !cdDvdDrive.attach) {
403
+ cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
404
+ if (key === removeIndex) return 'removed'
405
+ return item
406
+ })
407
+ sendData()
408
+ return
409
+ }
410
+
411
+ cdDvdDrivesIndex.value = cdDvdDrivesIndex.value.filter(
412
+ (cdDvdDrive) => cdDvdDrive !== index
413
+ )
414
+ cdDvdDrivesType.value = cdDvdDrivesType.value.filter(
415
+ (_item, key) => key !== index
416
+ )
417
+ cdDvdDrives.value = cdDvdDrives.value.filter(
418
+ (_cdDvdDrive, key: number) => removeIndex !== key
419
+ )
420
+
421
+ delete sendDataNewCdDvdDrive.value[index]
422
+ sendData()
423
+ }
424
+ const onRollBackCdDvdDrive = (index: number): void => {
425
+ const removeIndex = cdDvdDrivesIndex.value.indexOf(index)
426
+ cdDvdDrivesType.value = cdDvdDrivesType.value.map((item, key) => {
427
+ if (key === removeIndex) return 'edit'
428
+ return item
429
+ })
430
+ }
431
+
432
+ const defaultPciDevice: UI_I_PciDevice = {
433
+ id: '',
434
+ vendor_name: '',
435
+ class_name: 'cdrom',
436
+ device_name: 'cdrom',
437
+ }
438
+ const pciDevicesIndex = ref<number[]>([0])
439
+ const pciDevicesType = ref<('new' | 'edit')[]>(['new'])
440
+ const pciDevices = ref<UI_I_PciDevice[]>([])
441
+ watch(
442
+ () => props.pciDevices,
443
+ (newValue) => {
444
+ if (!props.isEdit) return
445
+
446
+ const count = newValue?.length || 0
447
+ pciDevicesIndex.value = [...Array(count).keys()]
448
+ pciDevicesType.value = Array(count).fill('edit')
449
+ pciDevices.value = newValue || []
450
+ },
451
+ { immediate: true }
452
+ )
453
+
454
+ const addPciDevice = (): void => {
455
+ const newIndex = (pciDevicesIndex.value.at(-1) ?? -1) + 1
456
+ pciDevicesIndex.value.push(newIndex)
457
+ pciDevicesType.value.push('new')
458
+
459
+ pciDevices.value.push(useDeepCopy(defaultPciDevice))
460
+ }
461
+ const onRemovePciDevice = (index: number): void => {
462
+ const removeIndex = pciDevicesIndex.value.indexOf(index)
463
+ pciDevicesIndex.value = pciDevicesIndex.value.filter((item) => item !== index)
464
+ pciDevicesType.value = pciDevicesType.value.filter(
465
+ (_item, key) => key !== removeIndex
466
+ )
467
+
468
+ pciDevices.value = pciDevices.value.filter((_pciDevice, key: number) => {
469
+ return removeIndex !== key
470
+ })
471
+
472
+ delete newPciDeviceInvalidKeys.value[index]
473
+ delete sendDataNewPciDevices.value[index]
474
+ sendData()
475
+ }
476
+
477
+ const isShowFileModal = ref<boolean>(false)
478
+ const onAddDevice = (item: UI_I_DropdownTreeItemChild): void => {
479
+ switch (item.value) {
480
+ case 1:
481
+ addHardDisk()
482
+ break
483
+ case 2:
484
+ isShowFileModal.value = true
485
+ break
486
+ case 5:
487
+ addCdDvdDrive()
488
+ break
489
+ case 10:
490
+ addPciDevice()
491
+ break
492
+ case 14:
493
+ addNetwork()
494
+ break
495
+ }
496
+ }
497
+
498
+ const cpuInvalid = ref<boolean>(false)
499
+ const sendDataCpu = ref<UI_I_SendDataCpu | null>(null)
500
+ const onSendDataCpuMethod = (data: UI_I_SendDataCpu): void => {
501
+ sendDataCpu.value = data
502
+ sendData()
503
+ }
504
+ const sendDataMemory = ref<UI_I_SendDataMemory | null>(null)
505
+ const onSendDataMemoryMethod = (data: UI_I_SendDataMemory): void => {
506
+ sendDataMemory.value = data
507
+ sendData()
508
+ }
509
+ const sendDataNewHardDisk = ref<UI_I_SendDataNewHardDisk[]>([])
510
+ const onSendDataNewHardDiskMethod = (
511
+ data: UI_I_SendDataNewHardDisk,
512
+ index: number
513
+ ): void => {
514
+ sendDataNewHardDisk.value[index] = data
515
+ sendData()
516
+ }
517
+ const sendDataNewNetwork = ref<UI_I_SendDataNewNetwork[]>([])
518
+ const sendDataNewNetworkMethod = (
519
+ data: UI_I_SendDataNewNetwork,
520
+ index: number
521
+ ): void => {
522
+ sendDataNewNetwork.value[index] = data
523
+ sendData()
524
+ }
525
+ const sendDataNewCdDvdDrive = ref<UI_I_SendDataNewCdDvdDrive[]>([])
526
+ const sendDataNewCdDvdDriveMethod = (
527
+ data: UI_I_SendDataNewCdDvdDrive,
528
+ index: number
529
+ ): void => {
530
+ sendDataNewCdDvdDrive.value[index] = data
531
+ sendData()
532
+ }
533
+ const sendDataNewUsbController = ref<string | null>(null)
534
+ const onSendDataNewUsbControllerMethod = (data: string): void => {
535
+ sendDataNewUsbController.value = data
536
+ sendData()
537
+ }
538
+ const sendDataNewPciDevices = ref<UI_I_SendDataNewPciDevice[]>([])
539
+ const onSendDataPciDevicesMethod = (
540
+ data: UI_I_SendDataNewPciDevice,
541
+ index: number
542
+ ): void => {
543
+ sendDataNewPciDevices.value[index] = data
544
+ sendData()
545
+ }
546
+ const sendDataVideoCard = ref<UI_I_SendDataVideoCard | null>(null)
547
+ const onSendDataVideoCardMethod = (data: UI_I_SendDataVideoCard): void => {
548
+ sendDataVideoCard.value = data
549
+ sendData()
550
+ }
551
+
552
+ const sendData = (): void => {
553
+ const cpu = sendDataCpu.value
554
+ const memory = sendDataMemory.value
555
+ const hardDisks = sendDataNewHardDisk.value.flat(2)
556
+ const networks = sendDataNewNetwork.value.flat(2)
557
+ const cdDvdDrives = sendDataNewCdDvdDrive.value.flat(2)
558
+ const pciDevices = sendDataNewPciDevices.value.flat()
559
+ const usbController = sendDataNewUsbController.value
560
+ const videoCard = sendDataVideoCard.value
561
+
562
+ const sendData: UI_I_SendDataVirtualHardware = {
563
+ cpu,
564
+ memory,
565
+ usbController,
566
+ pciDevices,
567
+ networks,
568
+ hardDisks,
569
+ cdDvdDrives,
570
+ videoCard,
571
+ }
572
+ emits('send-data', sendData)
573
+ }
574
+
575
+ const onSetInvalidHardDisk = (invalid: boolean, index: number): void => {
576
+ newHardDiskInvalidKeys.value[index] = invalid
577
+ }
578
+
579
+ const onSetInvalidNetwork = (invalid: boolean, key: number): void => {
580
+ newNetworkInvalidKeys.value[key] = invalid
581
+ }
582
+
583
+ const onSetInvalidPciDevice = (invalid: boolean, key: number): void => {
584
+ newPciDeviceInvalidKeys.value[key] = invalid
585
+ }
586
+
587
+ const memoryInvalid = ref<boolean>(false)
588
+ const videoCardInvalid = ref<boolean>(false)
589
+ const newHardDiskInvalidKeys = ref<UI_I_InvalidKeys>({})
590
+ const newNetworkInvalidKeys = ref<UI_I_InvalidKeys>({})
591
+ const newPciDeviceInvalidKeys = ref<UI_I_InvalidKeys>({})
592
+
593
+ watch(
594
+ [
595
+ cpuInvalid,
596
+ memoryInvalid,
597
+ newHardDiskInvalidKeys,
598
+ newNetworkInvalidKeys,
599
+ newPciDeviceInvalidKeys,
600
+ videoCardInvalid,
601
+ ],
602
+ () => {
603
+ const cpu = cpuInvalid.value ? localization.value.cpu : ''
604
+ const memory = memoryInvalid.value ? localization.value.memory : ''
605
+ const videoCard = videoCardInvalid.value ? localization.value.videoCard : ''
606
+ let newHardDisk = ''
607
+ Object.keys(newHardDiskInvalidKeys.value).forEach((key) => {
608
+ if (!newHardDiskInvalidKeys.value[+key]) {
609
+ return
610
+ }
611
+
612
+ newHardDisk +=
613
+ (newHardDisk ? ', ' : '') +
614
+ localization.value.newHardDisk +
615
+ ' ' +
616
+ (+key + 1)
617
+ })
618
+ let newNetwork = ''
619
+ Object.keys(newNetworkInvalidKeys.value).forEach((key) => {
620
+ if (!newNetworkInvalidKeys.value[+key]) {
621
+ return
622
+ }
623
+
624
+ newNetwork +=
625
+ (newNetwork ? ', ' : '') +
626
+ localization.value.newNetwork +
627
+ ' ' +
628
+ (+key + 1)
629
+ })
630
+ // let pciDevice = ''
631
+ // Object.keys(newPciDeviceInvalidKeys.value).forEach((key) => {
632
+ // if (!newPciDeviceInvalidKeys.value[+key]) {
633
+ // return
634
+ // }
635
+ //
636
+ // pciDevice +=
637
+ // (pciDevice ? ', ' : '') +
638
+ // localization.value.pciDevice +
639
+ // ' ' +
640
+ // (+key + 1)
641
+ // })
642
+
643
+ emits('invalid', [cpu, memory, newHardDisk, newNetwork, videoCard])
644
+ },
645
+ { deep: true }
646
+ )
647
+
648
+ emits('get-pci-devices')
649
+ </script>
650
+
651
+ <style scoped lang="scss">
652
+ .virtual-hardware {
653
+ .content-dropdown {
654
+ width: 200px;
655
+ }
656
+ }
657
+ </style>