Update disable Station

This commit is contained in:
nguyentrungthat 2026-01-15 15:39:43 +07:00
parent f6620edc35
commit c4a5b1c499
8 changed files with 198 additions and 99 deletions

View File

@ -6,6 +6,7 @@ import zulip from 'zulip-js'
import { ErrorRow, LogRule, ParsedLog, TestError, TestResult } from './types.js'
import axios from 'axios'
import moment from 'moment'
import Station from '#models/station'
const mailTo = 'andrew.ng@apactech.io'
const mailCC = ['ips@ipsupply.com.au', 'kay@ipsupply.com.au', 'joseph@apactech.io']
@ -1386,3 +1387,8 @@ export function parseLicenseReport(output: string) {
failed: [...failed],
}
}
export async function checkStationActive(stationId: string): Promise<boolean> {
const station = await Station.find(stationId)
return station?.is_active || false
}

View File

@ -13,6 +13,7 @@ import Station from '#models/station'
import APCController from '#services/apc_connection'
import {
appendLog,
checkStationActive,
cleanData,
sendMessageToMail,
sendMessageToZulip,
@ -171,12 +172,21 @@ export class WebSocketIo {
// FE gửi yêu cầu connect lines
socket.on('connect_lines', async (data) => {
const { stationData, linesData } = data
// Check station is active
const activeStation = await checkStationActive(stationData.id)
if (!activeStation) return
await this.connectLine(io, linesData, stationData)
})
socket.on('write_command_line_from_web', async (data) => {
const { lineIds, stationId, command } = data
// Check station is active
// const activeStation = await checkStationActive(stationId)
// if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
@ -190,6 +200,10 @@ export class WebSocketIo {
socket.on('run_scenario', async (data) => {
const lineId = data.id
const scenario = data.scenario
// Check station is active
const activeStation = await checkStationActive(data.stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
data.stationId,
@ -206,6 +220,10 @@ export class WebSocketIo {
const lineId = data.lineId
const baud = data.baud
const line = await Line.find(lineId)
// Check station is active
const activeStation = await checkStationActive(data.stationId)
if (!activeStation) return
if (!line) {
console.log(`Line [${lineId}] not found!!!`)
return
@ -341,6 +359,10 @@ export class WebSocketIo {
socket.on('control_apc', async (data) => {
try {
const { outletNumbers, action, station, apcName } = data
// Check station is active
const activeStation = await checkStationActive(station.id)
if (!activeStation) return
if (action === 'reconnect') {
if (!station) return
const apcIp = (station as any)[`${apcName}_ip`] as string
@ -401,6 +423,10 @@ export class WebSocketIo {
socket.on('connect_apc', async (data) => {
try {
const { apcIp, station, apcName } = data
// Check station is active
const activeStation = await checkStationActive(station.id)
if (!activeStation) return
const apc = this.apcsControl.get(apcIp)
if (apc && apc.status === 'CONNECTED') {
socket.emit('apc_output', {
@ -423,6 +449,10 @@ export class WebSocketIo {
socket.on('connect_switch', async (data) => {
try {
const { ip, station } = data
// Check station is active
const activeStation = await checkStationActive(station.id)
if (!activeStation) return
const element = this.switchControl.get(ip)
// Connect station if not connected
@ -452,6 +482,10 @@ export class WebSocketIo {
socket.on('control_switch', async (data) => {
const { ports, command, ip, station } = data
// Check station is active
const activeStation = await checkStationActive(station.id)
if (!activeStation) return
const element1 = this.switchControl.get(ip)
if (!element1) {
await this.connectSwitch(io, station)
@ -573,6 +607,9 @@ export class WebSocketIo {
const stationId = data.stationId || ''
const scenarioName = data.scenarioName || ''
const station = await Station.find(stationId)
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
// Check station sendWiki flag
console.log('[DPELP] Received run all dpelp', lineIds)
if (!station || !station?.send_wiki) return
@ -608,6 +645,10 @@ export class WebSocketIo {
socket.on('clear_terminal', async (data) => {
const { stationId, lineId } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
@ -619,6 +660,10 @@ export class WebSocketIo {
socket.on('run_physical_test', async (data) => {
const { stationId, lineId } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
@ -630,6 +675,10 @@ export class WebSocketIo {
socket.on('end_run_physical_test', async (data) => {
const { stationId, lineId } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
@ -644,6 +693,10 @@ export class WebSocketIo {
socket.on('reset_physical_test', async (data) => {
const { stationId, lineId } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
@ -664,6 +717,10 @@ export class WebSocketIo {
socket.on('load_ios_router', async (data) => {
const { stationId, lineId, iosName, outletNumber, station, apcName, isReboot } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
@ -695,6 +752,10 @@ export class WebSocketIo {
socket.on('load_ios_switch', async (data) => {
const { stationId, lineId, iosName } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
@ -708,6 +769,10 @@ export class WebSocketIo {
socket.on('load_license_router', async (data) => {
const { stationId, lineId, licenseName, portName } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,
@ -721,6 +786,10 @@ export class WebSocketIo {
socket.on('load_license_switch', async (data) => {
const { stationId, lineId, licenseName, portName } = data
// Check station is active
const activeStation = await checkStationActive(stationId)
if (!activeStation) return
await this.handleLineOperation(
io,
stationId,

View File

@ -108,6 +108,7 @@ function App() {
const [listLicense, setListLicense] = useState<FileInfo[]>([]);
const connectApcSwitch = (station: TStation) => {
if (!station?.is_active) return;
if (station?.apc_1_ip && station?.apc_1_port) {
socket?.emit("connect_apc", {
station: station,

View File

@ -187,6 +187,7 @@ const BottomToolBar = ({
</Tabs.List>
<Tabs.Panel
className={!station?.is_active ? classes.isDisabled : ""}
value="command"
p={4}
style={{ height: "200px", overflow: "auto" }}
@ -423,6 +424,7 @@ const BottomToolBar = ({
</Flex>
</Tabs.Panel>
<Tabs.Panel
className={!station?.is_active ? classes.isDisabled : ""}
value="apc"
p={0}
ps={"xs"}
@ -448,6 +450,7 @@ const BottomToolBar = ({
</Box>
</Tabs.Panel>
<Tabs.Panel
className={!station?.is_active ? classes.isDisabled : ""}
value="switch"
ps={"xs"}
style={{
@ -467,7 +470,10 @@ const BottomToolBar = ({
</Tabs.Panel>
</Tabs>
) : (
<Box p={3}>
<Box
p={3}
className={!station?.is_active ? classes.isDisabled : ""}
>
<Flex
direction="row"
align="center"

View File

@ -128,7 +128,9 @@ const CardLine = ({
shadow="sm"
radius="md"
withBorder
className={classes.card_line}
className={`${classes.card_line} ${
!stationItem?.is_active ? classes.isDisabled : ""
}`}
style={{
...(selectedLines.find((val) => val.id === line.id)
? { backgroundColor: "#8bf55940" }

View File

@ -107,7 +107,12 @@ function SortableTab({
c="#747474"
>
<Box className={classes.stationName}>
<Text fw={600} fz="md" className={classes.stationText}>
<Text
fw={600}
fz="md"
className={classes.stationText}
c={!tab?.is_active ? `red` : ""}
>
{tab.name}
</Text>
</Box>

View File

@ -441,54 +441,59 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
gap: "10px",
paddingTop: "8px",
paddingBottom: "8px",
minHeight: "60px",
}}
>
{listOutlet
.filter((el) => el.apc === 1)
.map((outlet, i) => (
<Card
key={i}
shadow="sm"
padding="xs"
radius="md"
withBorder
className={`${
isSubmit || !dataStation?.apc_1_ip
? classes.isDisabled
: ""
}`}
style={{
paddingLeft: 0,
paddingRight: 0,
width: "55px",
position: "relative",
cursor: "pointer",
textAlign: "center",
border: listOutletSelected.find(
(el) => el.name === outlet.name && el.apc === outlet.apc
)?.name
? "1px solid #0018ff"
: "",
}}
onClick={() => {
toggleSelect(outlet, i + 1);
}}
>
<Text
fw={500}
fz={"12px"}
style={{
color: outlet.status === "ON" ? "#40c057" : "#f03e3e",
}}
>
{findLineByOutlet(outlet)
? "Line " +
(findLineByOutlet(outlet)?.lineNumber ||
findLineByOutlet(outlet)?.line_number)
: outlet.name}
</Text>
</Card>
))}
{dataStation?.apc_1_ip
? listOutlet
.filter((el) => el.apc === 1)
.map((outlet, i) => (
<Card
key={i}
shadow="sm"
padding="xs"
radius="md"
withBorder
className={`${
isSubmit || !dataStation?.apc_1_ip
? classes.isDisabled
: ""
}`}
style={{
paddingLeft: 0,
paddingRight: 0,
width: "55px",
position: "relative",
cursor: "pointer",
textAlign: "center",
border: listOutletSelected.find(
(el) =>
el.name === outlet.name && el.apc === outlet.apc
)?.name
? "1px solid #0018ff"
: "",
}}
onClick={() => {
toggleSelect(outlet, i + 1);
}}
>
<Text
fw={500}
fz={"12px"}
style={{
color:
outlet.status === "ON" ? "#40c057" : "#f03e3e",
}}
>
{findLineByOutlet(outlet)
? "Line " +
(findLineByOutlet(outlet)?.lineNumber ||
findLineByOutlet(outlet)?.line_number)
: outlet.name}
</Text>
</Card>
))
: ""}
</Box>
</Box>
</fieldset>
@ -674,54 +679,59 @@ export const DrawerAPCControl: React.FC<DrawerProps> = ({
gap: "10px",
paddingTop: "8px",
paddingBottom: "8px",
minHeight: "60px",
}}
>
{listOutlet
.filter((el) => el.apc === 2)
.map((outlet, i) => (
<Card
key={i}
shadow="sm"
padding="xs"
radius="md"
withBorder
className={`${
isSubmit || !dataStation?.apc_2_ip
? classes.isDisabled
: ""
}`}
style={{
paddingLeft: 0,
paddingRight: 0,
width: "55px",
position: "relative",
cursor: "pointer",
textAlign: "center",
border: listOutletSelected.find(
(el) => el.name === outlet.name && el.apc === outlet.apc
)?.name
? "1px solid #0018ff"
: "",
}}
onClick={() => {
toggleSelect(outlet, i + 1);
}}
>
<Text
fw={500}
fz={"12px"}
style={{
color: outlet.status === "ON" ? "#40c057" : "#f03e3e",
}}
>
{findLineByOutlet(outlet)
? "Line " +
(findLineByOutlet(outlet)?.lineNumber ||
findLineByOutlet(outlet)?.line_number)
: outlet.name}
</Text>
</Card>
))}
{dataStation?.apc_2_ip
? listOutlet
.filter((el) => el.apc === 2)
.map((outlet, i) => (
<Card
key={i}
shadow="sm"
padding="xs"
radius="md"
withBorder
className={`${
isSubmit || !dataStation?.apc_2_ip
? classes.isDisabled
: ""
}`}
style={{
paddingLeft: 0,
paddingRight: 0,
width: "55px",
position: "relative",
cursor: "pointer",
textAlign: "center",
border: listOutletSelected.find(
(el) =>
el.name === outlet.name && el.apc === outlet.apc
)?.name
? "1px solid #0018ff"
: "",
}}
onClick={() => {
toggleSelect(outlet, i + 1);
}}
>
<Text
fw={500}
fz={"12px"}
style={{
color:
outlet.status === "ON" ? "#40c057" : "#f03e3e",
}}
>
{findLineByOutlet(outlet)
? "Line " +
(findLineByOutlet(outlet)?.lineNumber ||
findLineByOutlet(outlet)?.line_number)
: outlet.name}
</Text>
</Card>
))
: ""}
</Box>
</Box>
</fieldset>
@ -1169,7 +1179,7 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
</div>
<Grid.Col span={12} pt={"0px"}>
{listPorts?.length > 0 && (
{dataStation?.switch_control_ip && listPorts?.length > 0 && (
<Box>
<Flex gap={"8px"} wrap={"wrap"}>
{listPorts?.map((group, key) => {

View File

@ -82,7 +82,7 @@ const StationSetting = ({
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("is_active", dataStation?.is_active);
form.setFieldValue("is_active", dataStation?.is_active);
form.setFieldValue(
"switch_control_port",
dataStation.switch_control_port
@ -403,7 +403,7 @@ const StationSetting = ({
form.setFieldValue("send_wiki", event.currentTarget.checked)
}
/>
{/* <Checkbox
<Checkbox
c={"yellow"}
color="yellow"
ml={"12px"}
@ -412,7 +412,7 @@ const StationSetting = ({
onChange={(event) =>
form.setFieldValue("is_active", event.currentTarget.checked)
}
/> */}
/>
</div>
}
size={"90%"}