bfg-common 1.1.51 → 1.1.52

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,292 @@
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="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 {
97
+ memoryOptionsFunc,
98
+ memoryTypeOptionsFunc,
99
+ } from '~/components/common/vm/actions/add/customizeHardware/virtualHardware/memory/config/memoryOptions'
100
+
101
+ const props = defineProps<{
102
+ maxMemory: number
103
+ isEdit: boolean
104
+ errorValidationFields: UI_I_ErrorValidationField[]
105
+ state?: string
106
+ memory?: API_UI_I_VmEditMemory
107
+ }>()
108
+ const emits = defineEmits<{
109
+ (event: 'send-data', value: UI_I_SendDataMemory): void
110
+ (event: 'invalid', value: boolean): void
111
+ (event: 'remove-error-by-title', value: string): void
112
+ }>()
113
+
114
+ const localization = computed<UI_I_Localization>(() => useLocal())
115
+ const { $binary } = useNuxtApp()
116
+
117
+ const minMemoryInMb = 128
118
+ watch(
119
+ () => props.maxMemory,
120
+ (newValue) => {
121
+ memoryOptions.value = memoryOptionsFunc(
122
+ localization.value,
123
+ minMemoryInMb,
124
+ newValue
125
+ )
126
+ }
127
+ )
128
+
129
+ const isDisabled = computed<boolean>(() => {
130
+ return props.state === '1'
131
+ })
132
+
133
+ const isMemoryDisabled = computed<boolean>(
134
+ () => isDisabled.value && !memoryHotPlug.value
135
+ )
136
+
137
+ const selectedMemory = ref<number>(4)
138
+ watch(selectedMemory, (newValue) => {
139
+ selectedMemory.value = parseInt('' + newValue)
140
+ })
141
+ const memoryType = ref<string>('gb')
142
+ const memoryTypeOptions = ref<UI_I_OptionItem[]>(
143
+ memoryTypeOptionsFunc(localization.value)
144
+ )
145
+ const memoryInMb = computed<number>(() => {
146
+ if (memoryType.value === 'mb') {
147
+ return +selectedMemory.value
148
+ }
149
+
150
+ return $binary.universalFromTo(+selectedMemory.value, memoryType.value, 'mb')
151
+ })
152
+
153
+ const memoryOptions = ref<UI_I_OptionItem[]>(
154
+ memoryOptionsFunc(localization.value, minMemoryInMb, props.maxMemory)
155
+ )
156
+ const selectMemory = (mb: number): void => {
157
+ if (memoryType.value === 'mb') {
158
+ selectedMemory.value = mb
159
+ return
160
+ }
161
+
162
+ selectedMemory.value = $binary.universalFromTo(mb, 'mb', memoryType.value, 12)
163
+ }
164
+
165
+ const memoryErrorLocalText = computed<string>(() => {
166
+ const validValue = /^\d+(\.\d+)?$/.test(selectedMemory.value + '')
167
+ if (!validValue) {
168
+ return localization.value.inputContainsInvalidCharacters
169
+ }
170
+
171
+ const maxMemoryInGb = $binary.mbToGb(props.maxMemory)
172
+ if (memoryInMb.value < minMemoryInMb || memoryInMb.value > props.maxMemory) {
173
+ return localization.value.memoryMustBe
174
+ .replace('{0}', `${minMemoryInMb} ${localization.value.mb}`)
175
+ .replace('{1}', `${maxMemoryInGb} ${localization.value.gb}`)
176
+ }
177
+
178
+ if (memoryInMb.value % 2 !== 0) {
179
+ return localization.value.valueShouldMultiple.replace(
180
+ '{0}',
181
+ `${2} ${localization.value.mb}`
182
+ )
183
+ }
184
+ return ''
185
+ })
186
+
187
+ const apiErrorLocal = computed<string>(() => {
188
+ return (
189
+ props.errorValidationFields?.find(
190
+ (message) => message.field === 'memory.size_mb'
191
+ )?.error_message || ''
192
+ )
193
+ })
194
+
195
+ const memorySizeLocalAndApiErrorsTexts = computed<string>(() => {
196
+ const localError = memoryErrorLocalText.value
197
+ const apiError = apiErrorLocal.value
198
+
199
+ let result = ''
200
+ if (localError && !apiError) result = localError
201
+ if (apiError && !localError) result = apiError
202
+ if (localError && apiError) result = localError + ', ' + apiError
203
+ if (!localError && apiError) result = apiError
204
+
205
+ return result
206
+ })
207
+
208
+ const reservationInvalid = ref<boolean>(false)
209
+ const limitInvalid = ref<boolean>(false)
210
+ const memoryInvalid = computed<boolean>(
211
+ () =>
212
+ !!memorySizeLocalAndApiErrorsTexts.value ||
213
+ reservationInvalid.value ||
214
+ limitInvalid.value
215
+ )
216
+ watch(
217
+ memoryInvalid,
218
+ (newValue) => {
219
+ emits('invalid', newValue)
220
+ },
221
+ { immediate: true }
222
+ )
223
+
224
+ const reservation = ref<string>('2')
225
+ watch(reservation, (newValue) => {
226
+ reservation.value = '' + parseInt(newValue)
227
+ })
228
+ const reservationType = ref<string>('mb')
229
+ const reserveGuestMemory = ref<boolean>(false)
230
+
231
+ const limit = ref<string>('Unlimited')
232
+ const limitType = ref<string>('mb')
233
+ const limitOptions = computed<UI_I_OptionItem[] | undefined>(() => {
234
+ if (memoryHotPlug.value)
235
+ return memoryOptionsFunc(
236
+ localization.value,
237
+ memoryInMb.value,
238
+ props.maxMemory
239
+ )
240
+ })
241
+
242
+ const memoryHotPlug = ref<boolean>(false)
243
+ const isDisabledMemoryHotPlug = computed<boolean>(
244
+ () => memoryInMb.value >= props.maxMemory || isDisabled.value
245
+ )
246
+ watch(isDisabledMemoryHotPlug, (newValue) => {
247
+ if (newValue) memoryHotPlug.value = false
248
+ })
249
+
250
+ watch(
251
+ [memoryInMb, memoryHotPlug, reservation, reservationType, limit],
252
+ () => {
253
+ const reservationInMb =
254
+ reservationType.value === 'mb'
255
+ ? reservation.value
256
+ : '' +
257
+ $binary.universalFromTo(
258
+ reservation.value,
259
+ reservationType.value,
260
+ 'mb',
261
+ 12
262
+ )
263
+ emits('send-data', {
264
+ memory: '' + memoryInMb.value,
265
+ hotplug: memoryHotPlug.value,
266
+ reservation_mb: reservationInMb,
267
+ limit_mb: limit.value,
268
+ })
269
+ },
270
+ { immediate: true }
271
+ )
272
+
273
+ // Добавляем данные для редактирования
274
+ watch(
275
+ () => props.memory,
276
+ (newValue) => {
277
+ if (!newValue) return
278
+
279
+ selectedMemory.value = $binary.mbToGb(newValue.size_mb)
280
+ reservation.value = '' + newValue.reservation_mb
281
+ limit.value = '' + newValue.limit_mb
282
+ memoryHotPlug.value = newValue.hotplug
283
+ },
284
+ { immediate: true }
285
+ )
286
+
287
+ const onRemoveValidationError = (): void => {
288
+ emits('remove-error-by-title', 'memory.size_mb')
289
+ }
290
+ </script>
291
+
292
+ <style scoped lang="scss"></style>
@@ -1,23 +1,32 @@
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
+ return [
11
+ {
12
+ text: `${localization.minimum}: ${$binary.round(min)}`,
13
+ // text: `${localization.minimum} ${min} ${localization.mb}`,
14
+ value: { value: min, type: 'mb' },
15
+ },
16
+ {
17
+ text: `${localization.maximum}: ${$binary.mbToGb(max, 0)} ${
18
+ localization.gb
19
+ }`,
20
+ value: { value: max, type: 'gb' },
21
+ },
22
+ ]
23
+ }
24
+
25
+ export const memoryTypeOptionsFunc = (
26
+ localization: UI_I_Localization
27
+ ): UI_I_OptionItem[] => {
28
+ return [
29
+ { text: localization.mb, value: 'mb' },
30
+ { text: localization.gb, value: 'gb' },
31
+ ]
32
+ }