From f902db9d8515994c95ff5371f08a5a745d3effe6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E4=B8=96=E5=86=9B?= <30999793+AllForNothing@users.noreply.github.com> Date: Wed, 30 Jun 2021 10:22:32 +0800 Subject: [PATCH] Change quota unit to Mebibyte (#15220) Signed-off-by: AllForNothing --- .../src/app/shared/entities/shared.const.ts | 10 +++++----- src/portal/src/app/shared/units/utils.spec.ts | 13 ++++++------ src/portal/src/app/shared/units/utils.ts | 20 +++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/portal/src/app/shared/entities/shared.const.ts b/src/portal/src/app/shared/entities/shared.const.ts index d1f8ea51da..ebfae035ab 100644 --- a/src/portal/src/app/shared/entities/shared.const.ts +++ b/src/portal/src/app/shared/entities/shared.const.ts @@ -87,23 +87,23 @@ export const QuotaUnits = [ UNIT: "Byte", }, { - UNIT: "KB", + UNIT: "KiB", }, { - UNIT: "MB", + UNIT: "MiB", }, { - UNIT: "GB", + UNIT: "GiB", }, { - UNIT: "TB", + UNIT: "TiB", }, ]; export const QuotaUnlimited = -1; export const StorageMultipleConstant = 1024; export const LimitCount = 100000000; export enum QuotaUnit { - TB = "TB", GB = "GB", MB = "MB", KB = "KB", BIT = "Byte" + TB = "TiB", GB = "GiB", MB = "MiB", KB = "KiB", BIT = "Byte" } export enum QuotaProgress { COUNT_USED = "COUNT_USED", COUNT_HARD = "COUNT_HARD", STROAGE_USED = "STORAGE_USED", STORAGE_HARD = "STORAGE_HARD" diff --git a/src/portal/src/app/shared/units/utils.spec.ts b/src/portal/src/app/shared/units/utils.spec.ts index 04c8869b68..e14b0bcd7b 100644 --- a/src/portal/src/app/shared/units/utils.spec.ts +++ b/src/portal/src/app/shared/units/utils.spec.ts @@ -1,5 +1,6 @@ import { delUrlParam, getQueryString, getSizeNumber, getSizeUnit, getSortingString, isSameArrayValue, isSameObject } from "./utils"; import { ClrDatagridStateInterface } from "@clr/angular"; +import {QuotaUnit} from "../entities/shared.const"; describe('functions in utils.ts should work', () => { it('function isSameArrayValue() should work', () => { @@ -60,15 +61,15 @@ describe('functions in utils.ts should work', () => { expect(getSizeNumber(10)).toEqual(10); expect(getSizeNumber(456400)).toEqual('445.70'); expect(getSizeNumber(45640000)).toEqual('43.53'); - expect(getSizeNumber(4564000000000)).toEqual('4.15'); + expect(getSizeNumber(4564000000000)).toEqual('4.15'); }); it('function getSizeUnit() should work', () => { expect(getSizeUnit).toBeTruthy(); - expect(getSizeUnit(4564)).toEqual('KiB'); - expect(getSizeUnit(10)).toEqual('Byte'); - expect(getSizeUnit(4564000)).toEqual('MiB'); - expect(getSizeUnit(4564000000)).toEqual('GiB'); - expect(getSizeUnit(4564000000000)).toEqual('TiB'); + expect(getSizeUnit(4564)).toEqual(QuotaUnit.KB); + expect(getSizeUnit(10)).toEqual(QuotaUnit.BIT); + expect(getSizeUnit(4564000)).toEqual(QuotaUnit.MB); + expect(getSizeUnit(4564000000)).toEqual(QuotaUnit.GB); + expect(getSizeUnit(4564000000000)).toEqual(QuotaUnit.TB); }); }); diff --git a/src/portal/src/app/shared/units/utils.ts b/src/portal/src/app/shared/units/utils.ts index 7d11c31fb8..32a3391790 100644 --- a/src/portal/src/app/shared/units/utils.ts +++ b/src/portal/src/app/shared/units/utils.ts @@ -3,7 +3,7 @@ import { HttpHeaders } from '@angular/common/http'; import { RequestQueryParams } from '../services'; import { DebugElement } from '@angular/core'; import { Comparator, State, HttpOptionInterface, HttpOptionTextInterface, QuotaUnitInterface } from '../services'; -import { QuotaUnits, StorageMultipleConstant } from '../entities/shared.const'; +import {QuotaUnit, QuotaUnits, StorageMultipleConstant} from '../entities/shared.const'; import { AbstractControl } from "@angular/forms"; import { isValidCron } from 'cron-validator'; import { ClrDatagridStateInterface } from "@clr/angular"; @@ -567,14 +567,14 @@ export const validateLimit = unitContrl => { }; export function formatSize(tagSize: string): string { - let size: number = Number.parseInt(tagSize); + const size: number = Number.parseInt(tagSize); if (Math.pow(1024, 1) <= size && size < Math.pow(1024, 2)) { return (size / Math.pow(1024, 1)).toFixed(2) + "KiB"; } else if (Math.pow(1024, 2) <= size && size < Math.pow(1024, 3)) { return (size / Math.pow(1024, 2)).toFixed(2) + "MiB"; } else if (Math.pow(1024, 3) <= size && size < Math.pow(1024, 4)) { return (size / Math.pow(1024, 3)).toFixed(2) + "GiB"; - } else if (Math.pow(1024, 4) <= size && size < Math.pow(1024, 5)) { + } else if (Math.pow(1024, 4) <= size) { return (size / Math.pow(1024, 4)).toFixed(2) + "TiB"; } else { return size + "B"; @@ -592,7 +592,7 @@ export function getSizeNumber(size: number): string | number { return (size / Math.pow(1024, 2)).toFixed(2); } else if (Math.pow(1024, 3) <= size && size < Math.pow(1024, 4)) { return (size / Math.pow(1024, 3)).toFixed(2); - } else if (Math.pow(1024, 4) <= size && size < Math.pow(1024, 5)) { + } else if (Math.pow(1024, 4) <= size) { return (size / Math.pow(1024, 4)).toFixed(2); } else { return size; @@ -605,15 +605,15 @@ export function getSizeNumber(size: number): string | number { */ export function getSizeUnit(size: number): string { if (Math.pow(1024, 1) <= size && size < Math.pow(1024, 2)) { - return "KiB"; + return QuotaUnit.KB; } else if (Math.pow(1024, 2) <= size && size < Math.pow(1024, 3)) { - return "MiB"; + return QuotaUnit.MB; } else if (Math.pow(1024, 3) <= size && size < Math.pow(1024, 4)) { - return "GiB"; - } else if (Math.pow(1024, 4) <= size && size < Math.pow(1024, 5)) { - return "TiB"; + return QuotaUnit.GB; + } else if (Math.pow(1024, 4) <= size) { + return QuotaUnit.TB; } else { - return "Byte"; + return QuotaUnit.BIT; } }