saurabhkushwaha438 commented on code in PR #14413:
URL: https://github.com/apache/cloudstack/pull/14413#discussion_r4548320014


##########
ui/src/views/compute/wizard/ComputeSelection.vue:
##########
@@ -224,40 +303,95 @@ export default {
       if (this.preFillContent.cpuspeed) {
         this.cpuSpeedInputValue = this.preFillContent.cpuspeed
       }
-      if (this.preFillContent.memory) {
-        this.memoryInputValue = this.preFillContent.memory
-      }
+
       this.updateComputeCpuNumber(this.preFillContent.cpunumber || 
this.cpuNumberInputValue)
       this.updateComputeCpuSpeed(this.preFillContent.cpuspeed || 
this.cpuSpeedInputValue)
-      this.updateComputeMemory(this.preFillContent.memory || 
this.memoryInputValue)
+      // Emit exact prefilled MiB without any conversion on load
+      this.$emit('update-compute-memory', this.memoryInputDecorator, 
this.memoryInputValue)
+    },
+    handleUnitChange (newUnit) {
+      if (newUnit === 'GiB') {
+        const currentMiB = this.memoryUnit === 'MiB' ? this.memoryDisplayValue 
: this.memoryInputValue
+        if (!this.isGiBAllowed || (currentMiB > 0 && currentMiB % 256 !== 0)) {
+          this.memoryUnit = 'MiB'
+          this.$nextTick(() => {
+            this.memoryUnit = 'MiB'
+          })
+          message.warning(
+            this.$t('message.memory.gib.not.supported') ||
+            'GiB unit is not available because memory limits or values must be 
multiples of 256 MiB (0.25 GiB). Please use MiB.'
+          )
+          return
+        }
+      }
+
+      if (newUnit === 'MiB') {
+        this.memoryDisplayValue = (this.memoryInputValue !== undefined && 
this.memoryInputValue !== null)
+          ? this.memoryInputValue
+          : (this.memoryDisplayValue ? Math.round(this.memoryDisplayValue * 
1024) : undefined)
+      } else {
+        this.memoryDisplayValue = (this.memoryInputValue !== undefined && 
this.memoryInputValue !== null)
+          ? this.memoryInputValue / 1024
+          : (this.memoryDisplayValue ? this.memoryDisplayValue : undefined)
+      }
+      if (this.isConstrained) {
+        if (this.memoryDisplayValue < this.minMemoryInUnit) {
+          this.memoryDisplayValue = this.minMemoryInUnit
+        } else if (this.maxMemoryInUnit > 0 && this.memoryDisplayValue > 
this.maxMemoryInUnit) {
+          this.memoryDisplayValue = this.maxMemoryInUnit
+        }
+      }
+      this.updateComputeMemory(this.memoryDisplayValue)
     },
     updateComputeCpuNumber (value) {
-      if (!value) this.cpuNumberInputValue = 0
+      this.cpuNumberInputValue = value
       if (!this.validateInput('cpu', value)) {
+        this.$emit('update-compute-cpunumber', this.cpuNumberInputDecorator, 
undefined)
         return
       }
       this.$emit('update-compute-cpunumber', this.cpuNumberInputDecorator, 
value)
     },
     updateComputeCpuSpeed (value) {
       this.$emit('update-compute-cpuspeed', this.cpuSpeedInputDecorator, value)
     },
-    updateComputeMemory (value) {
-      if (!value) this.memoryInputValue = 0
-      if (!this.validateInput('memory', value)) {
+    updateComputeMemory (displayValue) {
+      this.memoryDisplayValue = displayValue
+      if (!this.validateInput('memory', displayValue)) {
+        this.memoryInputValue = undefined
+        this.$emit('update-compute-memory', this.memoryInputDecorator, 
undefined)
         return
       }
-      this.$emit('update-compute-memory', this.memoryInputDecorator, value)
+      let memoryInMiB
+      if (this.memoryUnit === 'GiB') {
+        memoryInMiB = Math.round(displayValue * 1024)
+      } else {
+        memoryInMiB = Math.round(displayValue)
+      }
+
+      this.memoryInputValue = memoryInMiB
+      this.$emit('update-compute-memory', this.memoryInputDecorator, 
memoryInMiB)
     },
     validateInput (input, value) {
       this.errors[input].status = ''
       this.errors[input].message = ''
 
-      if (value === null || value === undefined || value.length === 0) {
+      if (value === null || value === undefined || value.length === 0 || value 
=== '' || value === 0) {
         this.errors[input].status = 'error'
         this.errors[input].message = this.$t('message.error.required.input')
         return false
       }
 
+      if (input === 'memory') {
+        if (this.memoryUnit === 'GiB') {
+          const isStepMultiple = Math.abs(value * 4 - Math.round(value * 4)) < 
0.001
+          if (!isStepMultiple) {
+            this.errors.memory.status = 'error'
+            this.errors.memory.message = 
this.$t('message.error.memory.gib.step') || 'Please enter memory in multiples 
of 0.25 GiB (256 MiB), or switch to MiB.'
+            return false
+          }
+        }
+      }

Review Comment:
   In later commits GiB stepping to 0.25 is implemented



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to