1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-07 17:17:41 +03:00

B #6337: Add decimals when resize capacity (#2770)

This commit is contained in:
Jorge Miguel Lobo Escalona 2023-10-05 11:06:48 +02:00 committed by GitHub
parent 45a8543ab8
commit 556e3513da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 10 deletions

View File

@ -121,7 +121,7 @@ const VirtualMachineCard = memo(
const error = useMemo(() => getErrorMessage(vm), [vm]) const error = useMemo(() => getErrorMessage(vm), [vm])
const ips = useMemo(() => getIps(vm), [vm]) const ips = useMemo(() => getIps(vm), [vm])
const memValue = useMemo(() => prettyBytes(+MEMORY, 'MB'), [MEMORY]) const memValue = useMemo(() => prettyBytes(+MEMORY, 'MB', 2), [MEMORY])
const labels = useMemo( const labels = useMemo(
() => () =>

View File

@ -80,7 +80,7 @@ const CapacityPanel = ({ vm = {}, actions, oneConfig, adminGroup }) => {
{ {
icon: <MemoryIcon />, icon: <MemoryIcon />,
name: T.Memory, name: T.Memory,
value: prettyBytes(+MEMORY, 'MB'), value: prettyBytes(+MEMORY, 'MB', 2),
dataCy: 'memory', dataCy: 'memory',
}, },
![CORES, SOCKETS].includes(undefined) && { ![CORES, SOCKETS].includes(undefined) && {

View File

@ -133,12 +133,14 @@ export const prettyBytes = (value, unit = UNITS.KB, fractionDigits = 0) => {
let idxUnit = units.indexOf(unit) let idxUnit = units.indexOf(unit)
while (ensuredValue > 1024) { while (ensuredValue >= 1024) {
ensuredValue /= 1024 ensuredValue /= 1024
idxUnit += 1 idxUnit += 1
} }
return `${ensuredValue.toFixed(fractionDigits)} ${units[idxUnit]}` const decimals = fractionDigits && ensuredValue % 1 !== 0 ? fractionDigits : 0
return `${ensuredValue.toFixed(decimals)} ${units[idxUnit]}`
} }
/** /**

View File

@ -737,6 +737,9 @@ define(function(require) {
$("div.mb_input", context).on("change", "input.visor, select", function(e){ $("div.mb_input", context).on("change", "input.visor, select", function(e){
var element = $(this); var element = $(this);
var step = '1'
var baseCal = 1;
var unit = "MB";
var min = parseInt(element.attr("data-min"),10); var min = parseInt(element.attr("data-min"),10);
var max = parseInt(element.attr("data-max"),10); var max = parseInt(element.attr("data-max"),10);
var value = element.val(); var value = element.val();
@ -745,26 +748,24 @@ define(function(require) {
switch (mb_input_unit_val) { switch (mb_input_unit_val) {
case "TB": case "TB":
baseCal = base*base; baseCal = base*base;
step = '0.001'
unit = "TB"; unit = "TB";
break; break;
case "GB": case "GB":
baseCal = base; baseCal = base;
step = '0.01'
unit = "GB"; unit = "GB";
break; break;
default:
baseCal = 1;
unit = "MB";
break;
} }
if (value >= 0) { if (value >= 0) {
valueInMB = value * baseCal; valueInMB = value * baseCal;
if(!isNaN(min) && parseInt(min, 10) > valueInMB ){ if(!isNaN(min) && parseInt(min, 10) > valueInMB ){
valueInMB = min; valueInMB = min;
} }
$("input, select", contextElement).val(valueInMB); $("input, select", contextElement).val(Math.ceil(valueInMB));
valueInUnit = valueInMB / baseCal; valueInUnit = valueInMB / baseCal;
} }
$("input.visor", contextElement).val(valueInUnit); $("input.visor", contextElement).attr('step', step).val(valueInUnit);
var contextUnit = contextElement.siblings(".input-group-button"); var contextUnit = contextElement.siblings(".input-group-button");
$(".mb_input_unit", contextUnit).val(unit); $(".mb_input_unit", contextUnit).val(unit);
}); });