bfg-common 1.3.430 → 1.3.432

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,318 +1,322 @@
1
- <template>
2
- <div class="hardware-memory">
3
- <atoms-stack-block :has-children="true">
4
- <template #stackBlockKey>
5
- <div id="vm-wizard-toggle-block-memory" data-id="vm-wizard-toggle-block-memory" class="flex-align-center">
6
- <span>{{ localization.memory }}</span>
7
- <atoms-the-icon
8
- v-show="memoryInvalid"
9
- width="24px"
10
- height="24px"
11
- class="is-error tooltip-trigger"
12
- name="info"
13
- />
14
- </div>
15
- </template>
16
- <template #stackBlockContent>
17
- <div class="flex-align-center">
18
- <atoms-tooltip-error
19
- :has-error="!!memorySizeLocalAndApiErrorsTexts"
20
- selector="#vm-wizard-memory-field input"
21
- @remove="onRemoveValidationError"
22
- >
23
- <template #elem>
24
- <atoms-combobox
25
- id="vm-wizard-memory-field"
26
- v-model="selectedMemory"
27
- :items="memoryOptions"
28
- :disabled="isMemoryDisabled"
29
- test-id="vm-wizard-memory-field"
30
- class="input-text-color"
31
- @click.stop
32
- @select="onSelectMemory"
33
- />
34
- </template>
35
- <template #content>{{ memorySizeLocalAndApiErrorsTexts }}</template>
36
- </atoms-tooltip-error>
37
-
38
- <div class="select ml-1">
39
- <select
40
- id="vm-wizard-memory-type-select"
41
- v-model="memoryType"
42
- data-id="vm-wizard-memory-type-select"
43
- class="input-text-color"
44
- @click.stop
45
- >
46
- <option
47
- v-for="(item, key) in memoryTypeOptions"
48
- :key="key"
49
- :value="item.value"
50
- >
51
- {{ item.text }}
52
- </option>
53
- </select>
54
- </div>
55
- </div>
56
- </template>
57
- <template #stackChildren>
58
- <common-vm-actions-common-customize-hardware-virtual-hardware-reservation
59
- v-model:reservation="reservation"
60
- v-model:reservation-type="reservationType"
61
- v-model:reserve-guest-memory="reserveGuestMemory"
62
- :error-validation-fields="props.errorValidationFields"
63
- :multiply="2"
64
- :disabled="isDisabled"
65
- component-type="memory"
66
- type="mb"
67
- class="memory-reservation"
68
- @remove-error-by-title="emits('remove-error-by-title', $event)"
69
- @invalid="reservationInvalid = $event"
70
- />
71
- <common-vm-actions-common-customize-hardware-virtual-hardware-limit
72
- v-model:limit="limit"
73
- v-model:limit-type="limitType"
74
- :error-validation-fields="props.errorValidationFields"
75
- :limit-options="limitOptions"
76
- :multiply="2"
77
- :disabled="isDisabled"
78
- type="mb"
79
- component-type="memory"
80
- class="memory-limit"
81
- @invalid="limitInvalid = $event"
82
- @remove-error-by-title="emits('remove-error-by-title', $event)"
83
- />
84
- <common-vm-actions-common-customize-hardware-virtual-hardware-memory-hot-plug
85
- v-model:memory-hot-plug="memoryHotPlug"
86
- :disabled="isDisabledMemoryHotPlug"
87
- />
88
- </template>
89
- </atoms-stack-block>
90
- </div>
91
- </template>
92
-
93
- <script setup lang="ts">
94
- import { API_UI_I_VmEditMemory } from '~/lib/models/store/vm/interfaces'
95
- import { UI_I_SendDataMemory } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
96
- import { UI_I_Localization } from '~/lib/models/interfaces'
97
- import { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
98
- import { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
99
- import {
100
- memoryOptionsFunc,
101
- memoryTypeOptionsFunc,
102
- } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/memory/lib/config/memoryOptions'
103
-
104
- const props = defineProps<{
105
- maxMemory: number
106
- isEdit: boolean
107
- errorValidationFields: UI_I_ErrorValidationField[]
108
- state?: string | number
109
- memory?: API_UI_I_VmEditMemory
110
- }>()
111
- const emits = defineEmits<{
112
- (event: 'send-data', value: UI_I_SendDataMemory): void
113
- (event: 'invalid', value: boolean): void
114
- (event: 'remove-error-by-title', value: string): void
115
- }>()
116
-
117
- const localization = computed<UI_I_Localization>(() => useLocal())
118
- const { $binary } = useNuxtApp()
119
-
120
- const minMemoryInMb = 128
121
- watch(
122
- () => props.maxMemory,
123
- (newValue) => {
124
- memoryOptions.value = memoryOptionsFunc(
125
- localization.value,
126
- minMemoryInMb,
127
- newValue
128
- )
129
- }
130
- )
131
-
132
- const isDisabled = computed<boolean>(() => {
133
- return props.state === 2
134
- })
135
-
136
- const isMemoryDisabled = computed<boolean>(
137
- () => isDisabled.value && !memoryHotPlug.value
138
- )
139
-
140
- const selectedMemory = ref<number>(4)
141
- watch(selectedMemory, (newValue) => {
142
- const valueInt = parseInt('' + newValue)
143
- selectedMemory.value = isNaN(valueInt) ? 0 : valueInt
144
- })
145
- const memoryType = ref<string>('gb')
146
- const memoryTypeOptions = ref<UI_I_OptionItem[]>(
147
- memoryTypeOptionsFunc(localization.value)
148
- )
149
- const memoryInMb = computed<number>(() => {
150
- if (memoryType.value === 'mb') {
151
- return +selectedMemory.value
152
- }
153
-
154
- return $binary.universalFromTo(+selectedMemory.value, memoryType.value, 'mb')
155
- })
156
-
157
- const memoryOptions = ref<UI_I_OptionItem[]>(
158
- memoryOptionsFunc(localization.value, minMemoryInMb, props.maxMemory)
159
- )
160
- const onSelectMemory = ({
161
- value,
162
- type,
163
- }: {
164
- value: number
165
- type: string
166
- }): void => {
167
- selectedMemory.value = value
168
- if (memoryType.value !== type) {
169
- memoryType.value = type
170
- }
171
- // if (memoryType.value === 'mb') {
172
- // selectedMemory.value = mb
173
- // return
174
- // }
175
- //
176
- // selectedMemory.value = $binary.universalFromTo(mb, 'mb', memoryType.value, 12)
177
- }
178
-
179
- const memoryErrorLocalText = computed<string>(() => {
180
- const validValue = /^\d+(\.\d+)?$/.test(selectedMemory.value + '')
181
- if (!validValue) {
182
- return localization.value.inputContainsInvalidCharacters
183
- }
184
-
185
- const maxMemoryInGb = $binary.mbToGb(props.maxMemory)
186
- if (memoryInMb.value < minMemoryInMb || memoryInMb.value > props.maxMemory) {
187
- return localization.value.memoryMustBe
188
- .replace('{0}', `${minMemoryInMb} ${localization.value.mb}`)
189
- .replace('{1}', `${maxMemoryInGb} ${localization.value.gb}`)
190
- }
191
-
192
- if (memoryInMb.value % 2 !== 0) {
193
- return localization.value.valueShouldMultiple.replace(
194
- '{0}',
195
- `${2} ${localization.value.mb}`
196
- )
197
- }
198
- return ''
199
- })
200
-
201
- const apiErrorLocal = computed<string>(() => {
202
- return (
203
- props.errorValidationFields?.find(
204
- (message) => message.field === 'memory.size_mb'
205
- )?.error_message || ''
206
- )
207
- })
208
-
209
- const memorySizeLocalAndApiErrorsTexts = computed<string>(() => {
210
- const localError = memoryErrorLocalText.value
211
- const apiError = apiErrorLocal.value
212
-
213
- let result = ''
214
- if (localError && !apiError) result = localError
215
- if (apiError && !localError) result = apiError
216
- if (localError && apiError) result = localError + ', ' + apiError
217
- if (!localError && apiError) result = apiError
218
-
219
- return result
220
- })
221
-
222
- const reservationInvalid = ref<boolean>(false)
223
- const limitInvalid = ref<boolean>(false)
224
- const memoryInvalid = computed<boolean>(
225
- () =>
226
- !!memorySizeLocalAndApiErrorsTexts.value ||
227
- reservationInvalid.value ||
228
- limitInvalid.value
229
- )
230
- watch(
231
- memoryInvalid,
232
- (newValue) => {
233
- emits('invalid', newValue)
234
- },
235
- { immediate: true }
236
- )
237
-
238
- const reservation = ref<string>('2')
239
- watch(reservation, (newValue) => {
240
- const valueInt = parseInt('' + newValue)
241
- reservation.value = isNaN(valueInt) ? '0' : '' + valueInt
242
- })
243
- const reservationType = ref<string>('mb')
244
- const reserveGuestMemory = ref<boolean>(false)
245
-
246
- const limit = ref<string>('Unlimited')
247
- watch(limit, (newValue) => {
248
- const valueInt = parseInt('' + newValue)
249
- limit.value !== 'Unlimited' &&
250
- (limit.value = isNaN(valueInt) ? '0' : '' + valueInt)
251
- })
252
- const limitType = ref<string>('mb')
253
- const limitOptions = computed<UI_I_OptionItem[] | undefined>(() => {
254
- if (memoryHotPlug.value)
255
- return memoryOptionsFunc(
256
- localization.value,
257
- memoryInMb.value,
258
- props.maxMemory
259
- )
260
- })
261
-
262
- const memoryHotPlug = ref<boolean>(false)
263
- const isDisabledMemoryHotPlug = computed<boolean>(
264
- () => memoryInMb.value >= props.maxMemory || isDisabled.value
265
- )
266
- watch(isDisabledMemoryHotPlug, (newValue) => {
267
- if (newValue) memoryHotPlug.value = false
268
- })
269
-
270
- watch(
271
- [memoryInMb, memoryHotPlug, reservation, reservationType, limit, limitType],
272
- () => {
273
- const reservationInMb =
274
- reservationType.value === 'mb'
275
- ? reservation.value
276
- : '' +
277
- $binary.universalFromTo(
278
- reservation.value,
279
- reservationType.value,
280
- 'mb',
281
- 12
282
- )
283
- const limitInMb =
284
- limit.value === 'Unlimited'
285
- ? limit.value
286
- : limitType.value === 'gb'
287
- ? $binary.gbToMb(+limit.value)
288
- : +limit.value
289
- emits('send-data', {
290
- memory: '' + memoryInMb.value,
291
- hotplug: memoryHotPlug.value,
292
- reservation_mb: reservationInMb,
293
- limit_mb: limitInMb,
294
- })
295
- },
296
- { immediate: true }
297
- )
298
-
299
- // Добавляем данные для редактирования
300
- watch(
301
- () => props.memory,
302
- (newValue) => {
303
- if (!newValue) return
304
-
305
- selectedMemory.value = $binary.mbToGb(newValue.size_mb)
306
- reservation.value = '' + newValue.reservation_mb
307
- limit.value = '' + newValue.limit_mb
308
- memoryHotPlug.value = newValue.hotplug
309
- },
310
- { immediate: true }
311
- )
312
-
313
- const onRemoveValidationError = (): void => {
314
- emits('remove-error-by-title', 'memory.size_mb')
315
- }
316
- </script>
317
-
318
- <style scoped lang="scss"></style>
1
+ <template>
2
+ <div class="hardware-memory">
3
+ <atoms-stack-block :has-children="true" test-id="memory-stack-block">
4
+ <template #stackBlockKey>
5
+ <div
6
+ id="vm-wizard-toggle-block-memory"
7
+ data-id="vm-wizard-toggle-block-memory"
8
+ class="flex-align-center"
9
+ >
10
+ <span>{{ localization.memory }}</span>
11
+ <atoms-the-icon
12
+ v-show="memoryInvalid"
13
+ width="24px"
14
+ height="24px"
15
+ class="is-error tooltip-trigger"
16
+ name="info"
17
+ />
18
+ </div>
19
+ </template>
20
+ <template #stackBlockContent>
21
+ <div class="flex-align-center">
22
+ <atoms-tooltip-error
23
+ :has-error="!!memorySizeLocalAndApiErrorsTexts"
24
+ selector="#vm-wizard-memory-field input"
25
+ @remove="onRemoveValidationError"
26
+ >
27
+ <template #elem>
28
+ <atoms-combobox
29
+ id="vm-wizard-memory-field"
30
+ v-model="selectedMemory"
31
+ :items="memoryOptions"
32
+ :disabled="isMemoryDisabled"
33
+ test-id="vm-wizard-memory-field"
34
+ class="input-text-color"
35
+ @click.stop
36
+ @select="onSelectMemory"
37
+ />
38
+ </template>
39
+ <template #content>{{ memorySizeLocalAndApiErrorsTexts }}</template>
40
+ </atoms-tooltip-error>
41
+
42
+ <div class="select ml-1">
43
+ <select
44
+ id="vm-wizard-memory-type-select"
45
+ v-model="memoryType"
46
+ data-id="vm-wizard-memory-type-select"
47
+ class="input-text-color"
48
+ @click.stop
49
+ >
50
+ <option
51
+ v-for="(item, key) in memoryTypeOptions"
52
+ :key="key"
53
+ :value="item.value"
54
+ >
55
+ {{ item.text }}
56
+ </option>
57
+ </select>
58
+ </div>
59
+ </div>
60
+ </template>
61
+ <template #stackChildren>
62
+ <common-vm-actions-common-customize-hardware-virtual-hardware-reservation
63
+ v-model:reservation="reservation"
64
+ v-model:reservation-type="reservationType"
65
+ v-model:reserve-guest-memory="reserveGuestMemory"
66
+ :error-validation-fields="props.errorValidationFields"
67
+ :multiply="2"
68
+ :disabled="isDisabled"
69
+ component-type="memory"
70
+ type="mb"
71
+ class="memory-reservation"
72
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
73
+ @invalid="reservationInvalid = $event"
74
+ />
75
+ <common-vm-actions-common-customize-hardware-virtual-hardware-limit
76
+ v-model:limit="limit"
77
+ v-model:limit-type="limitType"
78
+ :error-validation-fields="props.errorValidationFields"
79
+ :limit-options="limitOptions"
80
+ :multiply="2"
81
+ :disabled="isDisabled"
82
+ type="mb"
83
+ component-type="memory"
84
+ class="memory-limit"
85
+ @invalid="limitInvalid = $event"
86
+ @remove-error-by-title="emits('remove-error-by-title', $event)"
87
+ />
88
+ <common-vm-actions-common-customize-hardware-virtual-hardware-memory-hot-plug
89
+ v-model:memory-hot-plug="memoryHotPlug"
90
+ :disabled="isDisabledMemoryHotPlug"
91
+ />
92
+ </template>
93
+ </atoms-stack-block>
94
+ </div>
95
+ </template>
96
+
97
+ <script setup lang="ts">
98
+ import { API_UI_I_VmEditMemory } from '~/lib/models/store/vm/interfaces'
99
+ import { UI_I_SendDataMemory } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/lib/models/interfaces'
100
+ import { UI_I_Localization } from '~/lib/models/interfaces'
101
+ import { UI_I_ErrorValidationField } from '~/lib/models/store/interfaces'
102
+ import { UI_I_OptionItem } from '~/components/atoms/lib/models/interfaces'
103
+ import {
104
+ memoryOptionsFunc,
105
+ memoryTypeOptionsFunc,
106
+ } from '~/components/common/vm/actions/common/customizeHardware/virtualHardware/memory/lib/config/memoryOptions'
107
+
108
+ const props = defineProps<{
109
+ maxMemory: number
110
+ isEdit: boolean
111
+ errorValidationFields: UI_I_ErrorValidationField[]
112
+ state?: string | number
113
+ memory?: API_UI_I_VmEditMemory
114
+ }>()
115
+ const emits = defineEmits<{
116
+ (event: 'send-data', value: UI_I_SendDataMemory): void
117
+ (event: 'invalid', value: boolean): void
118
+ (event: 'remove-error-by-title', value: string): void
119
+ }>()
120
+
121
+ const localization = computed<UI_I_Localization>(() => useLocal())
122
+ const { $binary } = useNuxtApp()
123
+
124
+ const minMemoryInMb = 128
125
+ watch(
126
+ () => props.maxMemory,
127
+ (newValue) => {
128
+ memoryOptions.value = memoryOptionsFunc(
129
+ localization.value,
130
+ minMemoryInMb,
131
+ newValue
132
+ )
133
+ }
134
+ )
135
+
136
+ const isDisabled = computed<boolean>(() => {
137
+ return props.state === 2
138
+ })
139
+
140
+ const isMemoryDisabled = computed<boolean>(
141
+ () => isDisabled.value && !memoryHotPlug.value
142
+ )
143
+
144
+ const selectedMemory = ref<number>(4)
145
+ watch(selectedMemory, (newValue) => {
146
+ const valueInt = parseInt('' + newValue)
147
+ selectedMemory.value = isNaN(valueInt) ? 0 : valueInt
148
+ })
149
+ const memoryType = ref<string>('gb')
150
+ const memoryTypeOptions = ref<UI_I_OptionItem[]>(
151
+ memoryTypeOptionsFunc(localization.value)
152
+ )
153
+ const memoryInMb = computed<number>(() => {
154
+ if (memoryType.value === 'mb') {
155
+ return +selectedMemory.value
156
+ }
157
+
158
+ return $binary.universalFromTo(+selectedMemory.value, memoryType.value, 'mb')
159
+ })
160
+
161
+ const memoryOptions = ref<UI_I_OptionItem[]>(
162
+ memoryOptionsFunc(localization.value, minMemoryInMb, props.maxMemory)
163
+ )
164
+ const onSelectMemory = ({
165
+ value,
166
+ type,
167
+ }: {
168
+ value: number
169
+ type: string
170
+ }): void => {
171
+ selectedMemory.value = value
172
+ if (memoryType.value !== type) {
173
+ memoryType.value = type
174
+ }
175
+ // if (memoryType.value === 'mb') {
176
+ // selectedMemory.value = mb
177
+ // return
178
+ // }
179
+ //
180
+ // selectedMemory.value = $binary.universalFromTo(mb, 'mb', memoryType.value, 12)
181
+ }
182
+
183
+ const memoryErrorLocalText = computed<string>(() => {
184
+ const validValue = /^\d+(\.\d+)?$/.test(selectedMemory.value + '')
185
+ if (!validValue) {
186
+ return localization.value.inputContainsInvalidCharacters
187
+ }
188
+
189
+ const maxMemoryInGb = $binary.mbToGb(props.maxMemory)
190
+ if (memoryInMb.value < minMemoryInMb || memoryInMb.value > props.maxMemory) {
191
+ return localization.value.memoryMustBe
192
+ .replace('{0}', `${minMemoryInMb} ${localization.value.mb}`)
193
+ .replace('{1}', `${maxMemoryInGb} ${localization.value.gb}`)
194
+ }
195
+
196
+ if (memoryInMb.value % 2 !== 0) {
197
+ return localization.value.valueShouldMultiple.replace(
198
+ '{0}',
199
+ `${2} ${localization.value.mb}`
200
+ )
201
+ }
202
+ return ''
203
+ })
204
+
205
+ const apiErrorLocal = computed<string>(() => {
206
+ return (
207
+ props.errorValidationFields?.find(
208
+ (message) => message.field === 'memory.size_mb'
209
+ )?.error_message || ''
210
+ )
211
+ })
212
+
213
+ const memorySizeLocalAndApiErrorsTexts = computed<string>(() => {
214
+ const localError = memoryErrorLocalText.value
215
+ const apiError = apiErrorLocal.value
216
+
217
+ let result = ''
218
+ if (localError && !apiError) result = localError
219
+ if (apiError && !localError) result = apiError
220
+ if (localError && apiError) result = localError + ', ' + apiError
221
+ if (!localError && apiError) result = apiError
222
+
223
+ return result
224
+ })
225
+
226
+ const reservationInvalid = ref<boolean>(false)
227
+ const limitInvalid = ref<boolean>(false)
228
+ const memoryInvalid = computed<boolean>(
229
+ () =>
230
+ !!memorySizeLocalAndApiErrorsTexts.value ||
231
+ reservationInvalid.value ||
232
+ limitInvalid.value
233
+ )
234
+ watch(
235
+ memoryInvalid,
236
+ (newValue) => {
237
+ emits('invalid', newValue)
238
+ },
239
+ { immediate: true }
240
+ )
241
+
242
+ const reservation = ref<string>('2')
243
+ watch(reservation, (newValue) => {
244
+ const valueInt = parseInt('' + newValue)
245
+ reservation.value = isNaN(valueInt) ? '0' : '' + valueInt
246
+ })
247
+ const reservationType = ref<string>('mb')
248
+ const reserveGuestMemory = ref<boolean>(false)
249
+
250
+ const limit = ref<string>('Unlimited')
251
+ watch(limit, (newValue) => {
252
+ const valueInt = parseInt('' + newValue)
253
+ limit.value !== 'Unlimited' &&
254
+ (limit.value = isNaN(valueInt) ? '0' : '' + valueInt)
255
+ })
256
+ const limitType = ref<string>('mb')
257
+ const limitOptions = computed<UI_I_OptionItem[] | undefined>(() => {
258
+ if (memoryHotPlug.value)
259
+ return memoryOptionsFunc(
260
+ localization.value,
261
+ memoryInMb.value,
262
+ props.maxMemory
263
+ )
264
+ })
265
+
266
+ const memoryHotPlug = ref<boolean>(false)
267
+ const isDisabledMemoryHotPlug = computed<boolean>(
268
+ () => memoryInMb.value >= props.maxMemory || isDisabled.value
269
+ )
270
+ watch(isDisabledMemoryHotPlug, (newValue) => {
271
+ if (newValue) memoryHotPlug.value = false
272
+ })
273
+
274
+ watch(
275
+ [memoryInMb, memoryHotPlug, reservation, reservationType, limit, limitType],
276
+ () => {
277
+ const reservationInMb =
278
+ reservationType.value === 'mb'
279
+ ? reservation.value
280
+ : '' +
281
+ $binary.universalFromTo(
282
+ reservation.value,
283
+ reservationType.value,
284
+ 'mb',
285
+ 12
286
+ )
287
+ const limitInMb =
288
+ limit.value === 'Unlimited'
289
+ ? limit.value
290
+ : limitType.value === 'gb'
291
+ ? $binary.gbToMb(+limit.value)
292
+ : +limit.value
293
+ emits('send-data', {
294
+ memory: '' + memoryInMb.value,
295
+ hotplug: memoryHotPlug.value,
296
+ reservation_mb: reservationInMb,
297
+ limit_mb: limitInMb,
298
+ })
299
+ },
300
+ { immediate: true }
301
+ )
302
+
303
+ // Добавляем данные для редактирования
304
+ watch(
305
+ () => props.memory,
306
+ (newValue) => {
307
+ if (!newValue) return
308
+
309
+ selectedMemory.value = $binary.mbToGb(newValue.size_mb)
310
+ reservation.value = '' + newValue.reservation_mb
311
+ limit.value = '' + newValue.limit_mb
312
+ memoryHotPlug.value = newValue.hotplug
313
+ },
314
+ { immediate: true }
315
+ )
316
+
317
+ const onRemoveValidationError = (): void => {
318
+ emits('remove-error-by-title', 'memory.size_mb')
319
+ }
320
+ </script>
321
+
322
+ <style scoped lang="scss"></style>