bfg-common 1.1.51 → 1.1.53

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