Update form report and UI

This commit is contained in:
nguyentrungthat 2026-02-10 08:16:25 +07:00
parent b9c25499aa
commit c7094f0fd8
5 changed files with 94 additions and 33 deletions

View File

@ -1182,7 +1182,7 @@ export default class LineConnection {
*/
endTesting() {
this.physicalTest.done = true
this.physicalTest.resetTestedPorts()
// this.physicalTest.resetTestedPorts()
this.config.runningPhysical = false
this.config.runningScenario = ''
this.testingPortPoE = false
@ -1714,10 +1714,12 @@ ${log}
</tr>
<tr>
<td style="width: 50%;">
Model: <b>${this.config?.inventory?.pid ?? 'N/A'}</b><br/>
Model: <b>${this.config?.inventory?.pid ?? 'N/A'}</b> <b>${this.config?.inventory?.vid ?? 'N/A'}</b><br/>
Serial Number: <b>${this.config?.inventory?.sn ?? 'N/A'}</b><br/>
MAC: <b>${dataShowVersion?.MAC_ADDRESS ?? ''}</b><br/>
IOS: <b>${dataShowVersion?.SOFTWARE_IMAGE ?? ''}</b><br/>
IOS: <b>${dataShowVersion?.SOFTWARE_IMAGE ?? ''}</b> <b>${dataShowVersion?.VERSION ?? ''}</b><br/>
MEM: <b>${dataShowVersion?.MEMORY ?? ''}</b><br/>
FLASH: <b>${dataShowVersion?.USB_FLASH ?? ''}</b><br/>
License: <b>${
dataShowLic
? dataShowLic

View File

@ -208,31 +208,6 @@ export class PhysicalPortTest {
: ''
}
<br/>
<br/>
<b style="color: #008000;">Passed Ports</b><br/>
${
tested.length
? `<table cellpadding="6" cellspacing="0" border="1" style="margin-top: 10px; border-collapse: collapse; width: 100%">
<tr>
${
testedPoE?.length
? `<td>
<div style="column-count: 12;">${testedPoE.map((p) => this.normalizePortName(p.name)).join('<br/>')}</div>
</td>`
: ''
}
${
testedSFP?.length
? `<td>
<div style="column-count: 4;">${testedSFP.map((p) => this.normalizePortName(p.name)).join('<br/>')}</div>
</td>`
: ''
}
</tr>
</table><br/>
`
: ''
}
<br/>
`.trim()
}

View File

@ -1523,3 +1523,41 @@ async function loadKeywordRules(log: string): Promise<KeywordRule[]> {
}
return []
}
export function convertFromKilobytesString(input: string, decimals = 0): string {
if (!input) return '0 KB'
const parts = input.split('/')
if (parts.length === 0) return ''
const totalRamStr = parts[0].trim()
const trimmed = totalRamStr.trim().toUpperCase()
// Bắt dạng: 491520K, 1024KB, 1M, 1.5G, 2T
const match = trimmed.match(/^([\d.]+)\s*(K|M|G|T)?B?$/)
if (!match) return '0 KB'
const value = Number.parseFloat(match[1])
const unit = match[2] || 'K'
// Quy tất cả về KB
const toKB: Record<string, number> = {
K: 1,
M: 1024,
G: 1024 ** 2,
T: 1024 ** 3,
}
let kilobytes = value * toKB[unit]
// ---- Convert KB -> đơn vị đẹp nhất ----
const units = ['KB', 'MB', 'GB', 'TB']
let unitIndex = 0
while (kilobytes >= 1024 && unitIndex < units.length - 1) {
kilobytes /= 1024
unitIndex++
}
return `${kilobytes.toFixed(decimals)} ${units[unitIndex]}`
}

View File

@ -54,7 +54,7 @@ import ModalSelectLicense from "./ModalSelectLicense";
import ModalRunScenario from "./ModalRunScenario";
import DrawerScenario from "./ModalScenario";
import AutoProgress from "../Components/AutoProgress";
import { bodyDPELP } from "../../untils/helper";
import { bodyDPELP, convertFromKilobytesString } from "../../untils/helper";
const apiUrl = import.meta.env.VITE_BACKEND_URL;
const INIT_TICKET = {
@ -645,7 +645,8 @@ const ModalTerminal = ({
setIsDisable(false);
}, 15000);
}
if (activeStep === 2 && !isDisable) {
if (activeStep >= 2 && !isDisable) {
setActiveStep(3);
setIsDisable(true);
setTimeout(() => {
setIsDisable(false);
@ -671,7 +672,7 @@ const ModalTerminal = ({
disabled={isDisable}
label="Completed"
description={
activeStep !== 2
activeStep < 2
? "Complete all to send report"
: "Click to send report"
}
@ -957,7 +958,9 @@ const ModalTerminal = ({
<Text size="md">
{findDataShowVersion() &&
findDataShowVersion()?.MEMORY
? findDataShowVersion()?.MEMORY + " bytes"
? convertFromKilobytesString(
findDataShowVersion()?.MEMORY
)
: ""}
</Text>
</Flex>
@ -968,7 +971,9 @@ const ModalTerminal = ({
<Text size="md">
{findDataShowVersion() &&
findDataShowVersion()?.USB_FLASH
? findDataShowVersion()?.USB_FLASH + " bytes"
? convertFromKilobytesString(
findDataShowVersion()?.USB_FLASH
)
: ""}
</Text>
</Flex>

View File

@ -196,3 +196,44 @@ export const bodyDPELP = [
note: "",
},
];
export function convertFromKilobytesString(
input: string,
decimals = 0
): string {
if (!input) return "0 KB";
const parts = input.split("/");
if (parts.length === 0) return "";
const totalRamStr = parts[0].trim();
const trimmed = totalRamStr.trim().toUpperCase();
// Bắt dạng: 491520K, 1024KB, 1M, 1.5G, 2T
const match = trimmed.match(/^([\d.]+)\s*(K|M|G|T)?B?$/);
if (!match) return "0 KB";
const value = Number.parseFloat(match[1]);
const unit = match[2] || "K";
// Quy tất cả về KB
const toKB: Record<string, number> = {
K: 1,
M: 1024,
G: 1024 ** 2,
T: 1024 ** 3,
};
let kilobytes = value * toKB[unit];
// ---- Convert KB -> đơn vị đẹp nhất ----
const units = ["KB", "MB", "GB", "TB"];
let unitIndex = 0;
while (kilobytes >= 1024 && unitIndex < units.length - 1) {
kilobytes /= 1024;
unitIndex++;
}
return `${kilobytes.toFixed(decimals)} ${units[unitIndex]}`;
}