Skip to content

Commit db7c8a0

Browse files
UI: Allow memory setting in flex compute offering in GiB with unit selector (#14082)
1 parent 7ed0cec commit db7c8a0

1 file changed

Lines changed: 106 additions & 20 deletions

File tree

‎ui/src/views/compute/wizard/ComputeSelection.vue‎

Lines changed: 106 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,38 @@
5757
</a-col>
5858
<a-col :md="colContraned" :lg="colContraned" v-if="isCustomized">
5959
<a-form-item
60-
:label="$t('label.memory.mb')"
60+
:label="$t('label.memory')"
6161
:validate-status="errors.memory.status"
6262
:help="errors.memory.message">
6363
<a-row :gutter="12">
64-
<a-col :md="10" :lg="10" v-show="isConstrained && maxMemory && !isNaN(maxMemory)">
64+
<a-col :md="14" :lg="14" v-show="isConstrained && maxMemory && !isNaN(maxMemory)">
6565
<a-slider
66-
:min="minMemory"
67-
:max="maxMemory"
68-
v-model:value="memoryInputValue"
66+
:min="minMemoryInUnit"
67+
:max="maxMemoryInUnit"
68+
:step="memoryStep"
69+
v-model:value="memoryDisplayValue"
6970
@change="($event) => updateComputeMemory($event)"
7071
/>
7172
</a-col>
72-
<a-col :md="4" :lg="4">
73-
<a-input-number
74-
v-model:value="memoryInputValue"
75-
@change="($event) => updateComputeMemory($event)"
76-
/>
73+
<a-col :md="isConstrained ? 10 : 8" :lg="isConstrained ? 10 : 8">
74+
<a-input-group compact style="display: flex">
75+
<a-input-number
76+
style="flex: 1"
77+
:min="isConstrained ? minMemoryInUnit : 0"
78+
:max="isConstrained ? maxMemoryInUnit : undefined"
79+
:step="memoryStep"
80+
:precision="memoryUnit === 'GiB' ? 2 : 0"
81+
v-model:value="memoryDisplayValue"
82+
@change="($event) => updateComputeMemory($event)"
83+
/>
84+
<a-select
85+
v-model:value="memoryUnit"
86+
style="width: 75px"
87+
@change="handleUnitChange">
88+
<a-select-option value="GiB">GiB</a-select-option>
89+
<a-select-option value="MiB">MiB</a-select-option>
90+
</a-select>
91+
</a-input-group>
7792
</a-col>
7893
</a-row>
7994
</a-form-item>
@@ -165,6 +180,8 @@ export default {
165180
cpuNumberInputValue: 0,
166181
cpuSpeedInputValue: 0,
167182
memoryInputValue: 0,
183+
memoryDisplayValue: 0,
184+
memoryUnit: 'GiB',
168185
errors: {
169186
cpu: {
170187
status: '',
@@ -192,6 +209,34 @@ export default {
192209
}
193210
194211
return 8
212+
},
213+
minMemoryInUnit () {
214+
if (!this.minMemory) return 0
215+
if (this.memoryUnit === 'GiB') {
216+
return parseFloat((this.minMemory / 1024).toFixed(2))
217+
}
218+
return this.minMemory
219+
},
220+
maxMemoryInUnit () {
221+
if (!this.maxMemory) return 0
222+
if (this.memoryUnit === 'GiB') {
223+
return parseFloat((this.maxMemory / 1024).toFixed(2))
224+
}
225+
return this.maxMemory
226+
},
227+
memoryStep () {
228+
if (this.memoryUnit === 'MiB') {
229+
return 1
230+
}
231+
const range = this.maxMemoryInUnit - this.minMemoryInUnit
232+
if (range <= 1) {
233+
return 0.01
234+
} else if (range <= 4) {
235+
return 0.05
236+
} else if (range <= 16) {
237+
return 0.25
238+
}
239+
return 0.5
195240
}
196241
},
197242
watch: {
@@ -209,13 +254,16 @@ export default {
209254
methods: {
210255
fillValue () {
211256
this.cpuNumberInputValue = this.initialCpuValue > 0 ? this.initialCpuValue : this.minCpu
212-
this.memoryInputValue = this.initialMemoryValue > 0 ? this.initialMemoryValue : this.minMemory
257+
const rawMemory = this.initialMemoryValue > 0 ? this.initialMemoryValue : this.minMemory
258+
this.memoryInputValue = rawMemory
259+
this.memoryUnit = 'GiB'
260+
this.memoryDisplayValue = rawMemory > 0 ? parseFloat((rawMemory / 1024).toFixed(2)) : 0
213261
this.cpuSpeedInputValue = this.cpuSpeed
214262
215263
if (!this.preFillContent) {
216264
this.updateComputeCpuNumber(this.cpuNumberInputValue)
217265
this.updateComputeCpuSpeed(this.cpuSpeedInputValue)
218-
this.updateComputeMemory(this.memoryInputValue)
266+
this.updateComputeMemory(this.memoryDisplayValue)
219267
return
220268
}
221269
if (this.preFillContent.cpunumber) {
@@ -226,10 +274,28 @@ export default {
226274
}
227275
if (this.preFillContent.memory) {
228276
this.memoryInputValue = this.preFillContent.memory
277+
this.memoryDisplayValue = parseFloat((this.memoryInputValue / 1024).toFixed(2))
229278
}
230279
this.updateComputeCpuNumber(this.preFillContent.cpunumber || this.cpuNumberInputValue)
231280
this.updateComputeCpuSpeed(this.preFillContent.cpuspeed || this.cpuSpeedInputValue)
232-
this.updateComputeMemory(this.preFillContent.memory || this.memoryInputValue)
281+
this.updateComputeMemory(this.memoryDisplayValue)
282+
},
283+
handleUnitChange (newUnit) {
284+
if (newUnit === 'MiB') {
285+
this.memoryDisplayValue = this.memoryInputValue > 0
286+
? this.memoryInputValue
287+
: Math.round(this.memoryDisplayValue * 1024)
288+
} else {
289+
this.memoryDisplayValue = parseFloat((this.memoryInputValue / 1024).toFixed(2))
290+
}
291+
if (this.isConstrained) {
292+
if (this.memoryDisplayValue < this.minMemoryInUnit) {
293+
this.memoryDisplayValue = this.minMemoryInUnit
294+
} else if (this.memoryDisplayValue > this.maxMemoryInUnit) {
295+
this.memoryDisplayValue = this.maxMemoryInUnit
296+
}
297+
}
298+
this.updateComputeMemory(this.memoryDisplayValue)
233299
},
234300
updateComputeCpuNumber (value) {
235301
if (!value) this.cpuNumberInputValue = 0
@@ -241,12 +307,31 @@ export default {
241307
updateComputeCpuSpeed (value) {
242308
this.$emit('update-compute-cpuspeed', this.cpuSpeedInputDecorator, value)
243309
},
244-
updateComputeMemory (value) {
245-
if (!value) this.memoryInputValue = 0
246-
if (!this.validateInput('memory', value)) {
310+
updateComputeMemory (displayValue) {
311+
if (displayValue === null || displayValue === undefined) {
312+
this.memoryDisplayValue = 0
313+
displayValue = 0
314+
} else {
315+
this.memoryDisplayValue = displayValue
316+
}
317+
if (!this.validateInput('memory', displayValue)) {
247318
return
248319
}
249-
this.$emit('update-compute-memory', this.memoryInputDecorator, value)
320+
let memoryInMiB
321+
if (this.memoryUnit === 'GiB') {
322+
if (this.isConstrained && displayValue === this.minMemoryInUnit) {
323+
memoryInMiB = this.minMemory
324+
} else if (this.isConstrained && displayValue === this.maxMemoryInUnit) {
325+
memoryInMiB = this.maxMemory
326+
} else {
327+
memoryInMiB = Math.round(displayValue * 1024)
328+
}
329+
} else {
330+
memoryInMiB = Math.round(displayValue)
331+
}
332+
333+
this.memoryInputValue = memoryInMiB
334+
this.$emit('update-compute-memory', this.memoryInputDecorator, memoryInMiB)
250335
},
251336
validateInput (input, value) {
252337
this.errors[input].status = ''
@@ -271,8 +356,8 @@ export default {
271356
max = this.maxCpu
272357
break
273358
case 'memory':
274-
min = this.minMemory
275-
max = this.maxMemory
359+
min = this.minMemoryInUnit
360+
max = this.maxMemoryInUnit
276361
break
277362
}
278363
@@ -285,7 +370,8 @@ export default {
285370
return true
286371
},
287372
checkValidRange (value, min, max) {
288-
if (value < min || value > max) {
373+
const epsilon = 0.001
374+
if (value < (min - epsilon) || value > (max + epsilon)) {
289375
return false
290376
}
291377

0 commit comments

Comments
 (0)