Update view Physical test và report

This commit is contained in:
nguyentrungthat 2026-02-02 16:24:28 +07:00
parent 5812e1742b
commit d33878c112
2 changed files with 539 additions and 511 deletions

View File

@ -68,11 +68,11 @@ export class PhysicalPortTest {
} }
// 3⃣ POE DISCONNECT // 3⃣ POE DISCONNECT
match = line.match(POE_DISCONNECT_REGEX) // match = line.match(POE_DISCONNECT_REGEX)
if (match) { // if (match) {
iface = normalizeInterface(match[1]) // iface = normalizeInterface(match[1])
markTested = true // markTested = true
} // }
if (!iface) continue if (!iface) continue
@ -159,34 +159,37 @@ export class PhysicalPortTest {
const status = missing.length === 0 ? 'PASS' : 'WARNING' const status = missing.length === 0 ? 'PASS' : 'WARNING'
return ` return `
Physical Port Test Report<br/> <b>Physical Port Test Report</b><br/>
<br/> <table cellpadding="6" cellspacing="0" border="1" style="margin-top: 10px; border-collapse: collapse; width: 100%">
Model : <b>${report.device.model ?? 'N/A'}</b><br/> <tr>
Serial Number : <b>${report.device.serial ?? 'N/A'}</b><br/> <td style="width: 50%;">
Started At : ${moment(report.startTime).format('YYYY/MM/DD, HH:mm:ss')}<br/> Model : <b>${report.device.model ?? 'N/A'}</b><br/>
Finished At : ${moment(report.endTime).format('YYYY/MM/DD, HH:mm:ss')}<br/> Serial Number : <b>${report.device.serial ?? 'N/A'}</b><br/>
Duration : ${this.formatDuration(report.durationMs)}<br/> Status : ${status === 'PASS' ? '✅ PASS' : '⚠️ WARNING'}<br/>
Status : ${status === 'PASS' ? '✅ PASS' : '⚠️ WARNING'}<br/> </td>
<br/> <td>
<br/> Total Ports : ${report.ports.length}<br/>
<b>Test Summary</b><br/>
<br/>
Total Ports : ${report.ports.length}<br/>
Ports Tested (UP) : ${tested.length}<br/> Ports Tested (UP) : ${tested.length}<br/>
Ports Missing : ${missing.length}<br/> Ports Missing : ${missing.length}<br/>
</td>
</tr>
</table>
<br/> <br/>
<br/> <br/>
<b>Passed Ports</b><br/> <b>Passed Ports</b><br/>
<br/> ${
${tested.map((p) => p.name).join('<br/>')}<br/> tested.length
? `<div style="margin-top: 10px; border: 1px solid #ccc; padding: 5px; column-count: 12;">${tested.map((p) => this.normalizePortName(p.name)).join('<br/>')}</div><br/>
`
: ''
}
<br/> <br/>
${ ${
missing.length missing.length
? ` ? `
<br/> <br/>
<b>Missing Ports</b><br/> <b>Missing Ports</b><br/>
<br/> <div style="margin-top: 10px; border: 1px solid #ccc; padding: 5px; column-count: 12;">${missing.map((p) => this.normalizePortName(p.name)).join('<br/>')}</div><br/>
${missing.map((p) => p.name).join('<br/>')}
` `
: '' : ''
}<br/> }<br/>
@ -201,4 +204,23 @@ export class PhysicalPortTest {
return `${minutes}m ${seconds}s` return `${minutes}m ${seconds}s`
} }
normalizePortName(port: string): string {
if (!port) return ''
// Example inputs: "Fa0/1", "Gi0/0/1", "Fa0/0/2"
const match = port.match(/^([A-Za-z]+)([\d/]+)$/)
if (!match) return port
const type = match[1] // Fa, Gi, Te, etc.
const numbers = match[2] // "0/1" / "0/0/1" / "0/0/2"
// Get the last part after slash
const parts = numbers.split('/')
const last = parts[parts.length - 1]
const preLast = parts?.length > 1 ? parts[parts.length - 2] : ''
return `${type?.slice(0, 2)}${preLast ? preLast + '/' : ''}${last}`
}
} }

File diff suppressed because it is too large Load Diff