bfg-common 1.1.52 → 1.1.54

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.
@@ -251,7 +251,8 @@ const addHardDisk = (
251
251
  hardDisksIndex.value.push(newIndex)
252
252
  hardDisksType.value.push(type)
253
253
 
254
- hardDisks.value.push({ create, size, source })
254
+ hardDisks.value.push({ create, size, source, attach: props.isEdit })
255
+ sendData()
255
256
  }
256
257
  const onAddExistHardDisk = (hardDisk: UI_I_HardDisk): void => {
257
258
  addHardDisk(false, $binary.bToGb(hardDisk.size), hardDisk.path, 'exist')
@@ -259,7 +260,7 @@ const onAddExistHardDisk = (hardDisk: UI_I_HardDisk): void => {
259
260
  const onRemoveHardDisk = (index: number, hardDisk: UI_I_SendDataNewHardDisk): void => {
260
261
  const removeIndex = hardDisksIndex.value.indexOf(index)
261
262
 
262
- if (!hardDisk.create) {
263
+ if (!hardDisk.create && !hardDisk.attach) {
263
264
  hardDisksType.value = hardDisksType.value.map((item, key) => {
264
265
  if (key === removeIndex) return 'removed'
265
266
  return item
@@ -66,9 +66,11 @@ const props = withDefaults(
66
66
  errorValidationFields: UI_I_ErrorValidationField<string>[]
67
67
  disabled?: boolean
68
68
  limitOptions?: UI_I_OptionItem[]
69
+ multiply?: number
69
70
  }>(),
70
71
  {
71
72
  limitOptions: undefined,
73
+ multiply: 1,
72
74
  }
73
75
  )
74
76
  const emits = defineEmits<{
@@ -111,24 +113,10 @@ const limitLocalByLocalization = computed<string>({
111
113
  })
112
114
  const limitLocal = computed<string>({
113
115
  get() {
114
- return $binary.universalFromTo(
115
- props.limit,
116
- binaryKeys[0],
117
- limitTypeLocal.value,
118
- 8
119
- )
116
+ return props.limit
120
117
  },
121
118
  set(newValue) {
122
- emits(
123
- 'update:limit',
124
- '' +
125
- $binary.universalFromTo(
126
- newValue,
127
- limitTypeLocal.value,
128
- binaryKeys[0],
129
- 8
130
- )
131
- )
119
+ emits('update:limit', '' + newValue)
132
120
  },
133
121
  })
134
122
  const limitTypeLocal = computed<string>({
@@ -163,21 +151,27 @@ const onSelectLimit = ({
163
151
  }
164
152
 
165
153
  const limitErrorLocalText = computed<string>(() => {
166
- const value = $binary.universalFromTo(
154
+ const valueForMin = $binary.universalFromTo(
155
+ +limitLocal.value,
156
+ limitTypeLocal.value,
157
+ limitOptionsLocal.value[0].value.type,
158
+ 0
159
+ )
160
+ const valueForMax = $binary.universalFromTo(
167
161
  +limitLocal.value,
168
162
  limitTypeLocal.value,
169
- binaryKeys[0],
170
- 8
163
+ limitOptionsLocal.value[1].value.type,
164
+ 0
171
165
  )
172
166
  const minValue = limitOptionsLocal.value[0].value.value
173
167
  const maxValue = limitOptionsLocal.value[1].value.value
174
- if (value < minValue) {
168
+ if (valueForMin < minValue) {
175
169
  return localization.value.limitMustBe.replace(
176
170
  '{0}',
177
171
  `${minValue} ${localization.value[binaryKeys[0]]}`
178
172
  )
179
173
  }
180
- if (props.limitOptions && value > maxValue) {
174
+ if (props.limitOptions && valueForMax > maxValue) {
181
175
  return localization.value.limitMustBeMax.replace(
182
176
  '{0}',
183
177
  `${maxValue} ${localization.value[binaryKeys[0]]}`
@@ -193,6 +187,19 @@ const limitErrorLocalText = computed<string>(() => {
193
187
  return localization.value.inputContainsInvalidCharacters
194
188
  }
195
189
 
190
+ const value = $binary.universalFromTo(
191
+ +limitLocal.value,
192
+ limitTypeLocal.value,
193
+ binaryKeys[0],
194
+ 0
195
+ )
196
+ if (value % props.multiply !== 0) {
197
+ return localization.value.valueShouldMultiple.replace(
198
+ '{0}',
199
+ `${props.multiply} ${binaryKeys[0].toUpperCase()}`
200
+ )
201
+ }
202
+
196
203
  return ''
197
204
  })
198
205
  const limitInvalid = computed<boolean>(() => !!limitErrorLocalText.value)
@@ -8,11 +8,11 @@ export const limitOptionsFunc = (
8
8
  return [
9
9
  {
10
10
  text: `${localization.minimum}: 0 ${localization[binaryKeys[0]]}`,
11
- value: { value: 0, type: 'mb' },
11
+ value: { value: 0, type: binaryKeys[0] },
12
12
  },
13
13
  {
14
14
  text: `${localization.maximum}: ${localization.unlimited}`,
15
- value: { value: 'Unlimited', type: 'mb' },
15
+ value: { value: 'Unlimited', type: binaryKeys[0] },
16
16
  },
17
17
  ]
18
18
  }
@@ -28,7 +28,7 @@
28
28
  :disabled="isMemoryDisabled"
29
29
  class="input-text-color"
30
30
  @click.stop
31
- @select="selectMemory"
31
+ @select="onSelectMemory"
32
32
  />
33
33
  </template>
34
34
  <template #content>{{ memorySizeLocalAndApiErrorsTexts }}</template>
@@ -71,6 +71,7 @@
71
71
  v-model:limit-type="limitType"
72
72
  :error-validation-fields="props.errorValidationFields"
73
73
  :limit-options="limitOptions"
74
+ :multiply="2"
74
75
  :disabled="isDisabled"
75
76
  type="mb"
76
77
  component-type="memory"
@@ -136,7 +137,8 @@ const isMemoryDisabled = computed<boolean>(
136
137
 
137
138
  const selectedMemory = ref<number>(4)
138
139
  watch(selectedMemory, (newValue) => {
139
- selectedMemory.value = parseInt('' + newValue)
140
+ const valueInt = parseInt('' + newValue)
141
+ selectedMemory.value = isNaN(valueInt) ? 0 : valueInt
140
142
  })
141
143
  const memoryType = ref<string>('gb')
142
144
  const memoryTypeOptions = ref<UI_I_OptionItem[]>(
@@ -153,13 +155,23 @@ const memoryInMb = computed<number>(() => {
153
155
  const memoryOptions = ref<UI_I_OptionItem[]>(
154
156
  memoryOptionsFunc(localization.value, minMemoryInMb, props.maxMemory)
155
157
  )
156
- const selectMemory = (mb: number): void => {
157
- if (memoryType.value === 'mb') {
158
- selectedMemory.value = mb
159
- return
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
160
168
  }
161
-
162
- selectedMemory.value = $binary.universalFromTo(mb, 'mb', memoryType.value, 12)
169
+ // if (memoryType.value === 'mb') {
170
+ // selectedMemory.value = mb
171
+ // return
172
+ // }
173
+ //
174
+ // selectedMemory.value = $binary.universalFromTo(mb, 'mb', memoryType.value, 12)
163
175
  }
164
176
 
165
177
  const memoryErrorLocalText = computed<string>(() => {
@@ -223,12 +235,17 @@ watch(
223
235
 
224
236
  const reservation = ref<string>('2')
225
237
  watch(reservation, (newValue) => {
226
- reservation.value = '' + parseInt(newValue)
238
+ const valueInt = parseInt('' + newValue)
239
+ reservation.value = isNaN(valueInt) ? '0' : '' + valueInt
227
240
  })
228
241
  const reservationType = ref<string>('mb')
229
242
  const reserveGuestMemory = ref<boolean>(false)
230
243
 
231
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
+ })
232
249
  const limitType = ref<string>('mb')
233
250
  const limitOptions = computed<UI_I_OptionItem[] | undefined>(() => {
234
251
  if (memoryHotPlug.value)
@@ -7,17 +7,20 @@ export const memoryOptionsFunc = (
7
7
  max: number
8
8
  ): UI_I_OptionItem[] => {
9
9
  const { $binary } = useNuxtApp()
10
+ const minValueText = $binary.round(min)
11
+ const [value, type] = minValueText.split(' ')
12
+ const maxValue = $binary.mbToGb(max, 0)
13
+
10
14
  return [
11
15
  {
12
- text: `${localization.minimum}: ${$binary.round(min)}`,
13
- // text: `${localization.minimum} ${min} ${localization.mb}`,
14
- value: { value: min, type: 'mb' },
16
+ text: `${localization.minimum}: ${minValueText}`,
17
+ value: { value: +value, type: type.toLowerCase() },
15
18
  },
16
19
  {
17
- text: `${localization.maximum}: ${$binary.mbToGb(max, 0)} ${
20
+ text: `${localization.maximum}: ${maxValue} ${
18
21
  localization.gb
19
22
  }`,
20
- value: { value: max, type: 'gb' },
23
+ value: { value: maxValue, type: 'gb' },
21
24
  },
22
25
  ]
23
26
  }
@@ -364,6 +364,7 @@ watch(
364
364
 
365
365
  emits('send-data', {
366
366
  create: props.hardDisk.create,
367
+ attach: props.hardDisk.attach,
367
368
  source: props.hardDisk.source,
368
369
  size: sizeInMb.value,
369
370
  bus: bus.value,
@@ -37,7 +37,7 @@ export const constructDiskDevicesFunc = (
37
37
  io: disk.io ?? '',
38
38
  limit_iops: disk.limit_iops ?? 0,
39
39
  discard: disk.discard ?? '',
40
- attach: disk.attach ?? false,
40
+ attach: disk.attach ?? true,
41
41
  detach: disk.detach ?? false,
42
42
  remove: disk.remove ?? false,
43
43
  create: disk.create ?? true,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bfg-common",
3
3
  "private": false,
4
- "version": "1.1.52",
4
+ "version": "1.1.54",
5
5
  "scripts": {
6
6
  "build": "nuxt build",
7
7
  "dev": "nuxt dev --port=3002",