Update send Wiki

This commit is contained in:
nguyentrungthat 2025-12-04 15:54:18 +07:00
parent 17e5aad8d9
commit 2ad1ee195f
8 changed files with 155 additions and 62 deletions

View File

@ -79,4 +79,7 @@ export default class Station extends BaseModel {
@column.dateTime({ autoCreate: true, autoUpdate: true })
declare updatedAt: DateTime
@column()
declare sendWiki: boolean
}

View File

@ -164,7 +164,13 @@ export function mapToLineFormat(input: InputData) {
// MAC
let mac = ''
let ios = ''
const showVersion = input.data?.find((d) => d.command === 'show version')
const showVersion = input.data?.find(
(d) =>
d.command === 'show version' ||
d.command === 'sh version' ||
d.command === 'show ver' ||
d.command === 'sh ver'
)
if (showVersion?.textfsm?.[0]?.MAC_ADDRESS) {
mac = showVersion.textfsm[0].MAC_ADDRESS
}

View File

@ -0,0 +1,17 @@
import { BaseSchema } from '@adonisjs/lucid/schema'
export default class extends BaseSchema {
protected tableName = 'stations'
async up() {
this.schema.alterTable(this.tableName, (table) => {
table.boolean('send_wiki').defaultTo(true)
})
}
async down() {
this.schema.alterTable(this.tableName, (table) => {
table.dropColumn('send_wiki')
})
}
}

View File

@ -545,6 +545,11 @@ export class WebSocketIo {
socket.on('run_all_dpelp', async (data) => {
try {
const lineIds = data.lineIds
const stationName = data.stationName || ''
const stationId = data.stationId || ''
const station = await Station.find(stationId)
// Check station sendWiki flag
if (!station || !station?.sendWiki) return
console.log('[DPELP] Received run all dpelp')
const results = await this.waitUntilAllReady(lineIds)
@ -557,13 +562,13 @@ export class WebSocketIo {
process.env.LINK_WIKI || 'https://logs.danielvu.com/api/wiki/page/insert?title=Dev_test'
await axios.post(linkWiki, {
data: tableHTML,
titleAuto: '[DPELP] Report AUTO - ' + dataFormat,
titleAuto: `[DPELP] Report AUTO - ${stationName} - ` + dataFormat,
})
await sendMessageToMail(
'andrew.ng@apactech.io',
`[DPELP] Report AUTO - ${dataFormat}`,
`[DPELP] Report AUTO - ${stationName} - ${dataFormat}`,
tableHTML,
['ips@ipsupply.com.au', 'kay@ipsupply.com.au']
['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io']
)
} catch (error) {
console.log(error)

View File

@ -781,6 +781,8 @@ const BottomToolBar = ({
) {
socket?.emit("run_all_dpelp", {
lineIds: selectedLines.map((line) => line.id),
stationName: station.name,
stationId: station.id,
});
}
setIsDisable(true);

View File

@ -2,6 +2,7 @@ import {
ActionIcon,
Box,
Button,
Checkbox,
Flex,
Group,
Input,
@ -80,6 +81,7 @@ const StationSetting = ({
form.setFieldValue("apc_2_username", dataStation.apc_2_username);
form.setFieldValue("apc_2_password", dataStation.apc_2_password);
form.setFieldValue("switch_control_ip", dataStation.switch_control_ip);
form.setFieldValue("send_wiki", dataStation?.send_wiki);
form.setFieldValue(
"switch_control_port",
dataStation.switch_control_port
@ -391,6 +393,14 @@ const StationSetting = ({
Delete
</Button>
)}
<Checkbox
ml={"12px"}
label="Send Wiki/email when run all DPELP"
checked={form.values.send_wiki}
onChange={(event) =>
form.setFieldValue("send_wiki", event.currentTarget.checked)
}
/>
</div>
}
size={"90%"}

View File

@ -9,12 +9,15 @@ import {
Modal,
ScrollArea,
Text,
Textarea,
Tooltip,
} from "@mantine/core";
import type {
IScenario,
SwitchPortsProps,
TDataTicket,
TextFSM,
TextTSMLicense,
THistoryTicket,
TLine,
TStation,
@ -75,6 +78,8 @@ const ModalTerminal = ({
const [latestTicket, setLatestTicket] = useState<TDataTicket>(INIT_TICKET);
const [dataTicket, setDataTicket] = useState<TDataTicket>(INIT_TICKET);
const [valueBaud, setValueBaud] = useState<string>("");
const [valueIssue, setValueIssue] = useState<string>("");
const [dataTextfsm, setDataTextfsm] = useState<TextFSM[]>([]);
useEffect(() => {
if (opened && line?.tickets && line?.tickets?.length > 0) {
@ -88,6 +93,28 @@ const ModalTerminal = ({
}
}, [opened, line?.tickets]);
useEffect(() => {
if (opened && line?.latestScenario?.detectAI) {
const data =
line?.latestScenario?.detectAI?.issue &&
Array.isArray(line?.latestScenario?.detectAI?.issue)
? "- " + line?.latestScenario?.detectAI?.issue?.join("\n- ")
: "";
setValueIssue(data);
} else {
setValueIssue("");
}
}, [opened, line?.latestScenario?.detectAI]);
useEffect(() => {
if (opened && line?.data) {
const data = Array.isArray(line?.data) ? line?.data : [];
setDataTextfsm(data);
} else {
setDataTextfsm([]);
}
}, [opened, line?.data]);
useEffect(() => {
setListPorts([]);
}, [stationItem?.id]);
@ -383,6 +410,32 @@ const ModalTerminal = ({
return `${type?.slice(0, 2)}${last}`;
};
const findDataShowVersion = () => {
const showVersion = dataTextfsm?.find(
(d) =>
d.command?.trim() === "show version" ||
d.command?.trim() === "sh version" ||
d.command?.trim() === "show ver" ||
d.command?.trim() === "sh ver"
);
return showVersion?.textfsm && showVersion?.textfsm?.[0]
? showVersion?.textfsm?.[0]
: null;
};
const findDataShowLicense = () => {
const showLicense = dataTextfsm?.find(
(d) =>
d.command?.trim() === "show license" ||
d.command?.trim() === "sh license" ||
d.command?.trim() === "show lic" ||
d.command?.trim() === "sh lic"
);
return showLicense?.textfsm && Array.isArray(showLicense?.textfsm)
? showLicense?.textfsm
: null;
};
return (
<Box>
<Modal
@ -542,7 +595,11 @@ const ModalTerminal = ({
<CopyIcon
value={
line?.inventory?.pid && line?.inventory?.sn
? `Line ${line?.lineNumber || line?.line_number || ""}: ${line.inventory?.pid}${line.inventory?.vid ? ` ${line.inventory.vid}` : ""} - ${line.inventory?.sn}`
? `Line ${
line?.lineNumber || line?.line_number || ""
}: ${line.inventory?.pid}${
line.inventory?.vid ? ` ${line.inventory.vid}` : ""
} - ${line.inventory?.sn}`
: ""
}
label="Copy PID + SN"
@ -555,14 +612,32 @@ const ModalTerminal = ({
<Text size="md" mr={"6px"} fw={"bold"}>
IOS:
</Text>
<Text size="md">{""}</Text>
<Text size="md">
{findDataShowVersion()
? findDataShowVersion()?.SOFTWARE_IMAGE
? findDataShowVersion()?.SOFTWARE_IMAGE +
" " +
(findDataShowVersion()?.VERSION || "")
: ""
: ""}
</Text>
</Flex>
</Box>
<Flex>
<Text size="md" mr={"sm"} fw={"bold"}>
License:
</Text>
<Text size="md">{""}</Text>
<Text size="md">
{findDataShowLicense()
? findDataShowLicense()
?.filter(
(el: TextTSMLicense) =>
el.LICENSE_TYPE === "Permanent"
)
?.map((v: TextTSMLicense) => v.FEATURE)
?.join(", ")
: ""}
</Text>
</Flex>
<Flex>
<Text size="md" mr={"sm"} fw={"bold"}>
@ -574,56 +649,30 @@ const ModalTerminal = ({
<Text size="md" mr={"sm"} fw={"bold"}>
Mem/Flash:
</Text>
<Text size="md">{""}</Text>
<Text size="md">
{findDataShowVersion()
? findDataShowVersion()?.MEMORY +
(findDataShowVersion()?.USB_FLASH
? "/" + findDataShowVersion()?.USB_FLASH
: "")
: ""}
</Text>
</Flex>
<Box>
<Text size="md" mr={"sm"} fw={"bold"}>
Warning from test report: AI
</Text>
<ScrollArea
h={"150px"}
style={{
border: "1px solid #ccc",
borderRadius: "8px",
padding: "4px",
}}
>
{line?.latestScenario?.detectAI ? (
<Box>
{/* <Box>
<Text size="sm" fw={"bold"}>
Status:
</Text>
{line?.latestScenario?.detectAI?.status?.map(
(el, i) => (
<Box key={i}>
<Text size="sm">- {el}</Text>
</Box>
)
)}
</Box> */}
{line?.latestScenario?.detectAI?.issue &&
Array.isArray(line?.latestScenario?.detectAI?.issue) ? (
<Box>
<Text size="sm" fw={"bold"}>
Issue:
</Text>
{line?.latestScenario?.detectAI?.issue?.map(
(el, i) => (
<Box key={i}>
<Text size="sm">- {el}</Text>
</Box>
)
)}
</Box>
) : (
""
)}
</Box>
) : (
""
)}
</ScrollArea>
<Box>
<Textarea
rows={5}
size="sm"
placeholder="Report from AI"
value={valueIssue}
onChange={(event) =>
setValueIssue(event.currentTarget.value)
}
/>
</Box>
</Box>
<Box
style={{

View File

@ -55,6 +55,7 @@ export type TStation = {
switch_control_password?: string; // Optional
switches?: SwitchesProps[];
switch?: SwitchesProps;
send_wiki?: boolean;
};
export type TLine = {
@ -228,13 +229,13 @@ export type THistoryTicket = {
userId: number;
};
interface HistoryItem {
pid: string;
vid: string;
sn: string;
scenario: string;
id: number;
number: number;
stationId: number;
timestamp?: number;
}
export type TextTSMLicense = {
INDEX: string;
FEATURE: string;
PERIOD_LEFT: string;
PERIOD_USED: string;
LICENSE_TYPE: string;
LICENSE_STATE: string;
LICENSE_COUNT: string;
LICENSE_PRIORITY: string;
};