Update
This commit is contained in:
parent
8739522915
commit
c09f27da86
|
|
@ -138,7 +138,7 @@ export default class LineConnection {
|
||||||
this.client.on('close', () => {
|
this.client.on('close', () => {
|
||||||
console.log(`🔌 Line ${lineNumber} disconnected`)
|
console.log(`🔌 Line ${lineNumber} disconnected`)
|
||||||
this.config.status = 'disconnected'
|
this.config.status = 'disconnected'
|
||||||
this.config.inventory = undefined
|
// this.config.inventory = undefined
|
||||||
this.socketIO.emit('line_disconnected', {
|
this.socketIO.emit('line_disconnected', {
|
||||||
stationId,
|
stationId,
|
||||||
lineId: id,
|
lineId: id,
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,13 @@ export class WebSocketIo {
|
||||||
socket.on('disconnect', () => {
|
socket.on('disconnect', () => {
|
||||||
console.log(`FE disconnected: ${socket.id}`)
|
console.log(`FE disconnected: ${socket.id}`)
|
||||||
this.userConnecting.delete(userId)
|
this.userConnecting.delete(userId)
|
||||||
|
const listLineS = Array.from(this.lineMap.values()).map((el) => el.config)
|
||||||
|
listLineS.forEach((el) => {
|
||||||
|
if (el.userOpenCLI === userName) {
|
||||||
|
const line = this.lineMap.get(el.id)
|
||||||
|
if (line) line.userCloseCLI()
|
||||||
|
}
|
||||||
|
})
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
io.emit('user_connecting', Array.from(this.userConnecting.values()))
|
io.emit('user_connecting', Array.from(this.userConnecting.values()))
|
||||||
}, 200)
|
}, 200)
|
||||||
|
|
@ -559,7 +566,15 @@ export class WebSocketIo {
|
||||||
const username = station.switch_control_username as string
|
const username = station.switch_control_username as string
|
||||||
const password = station.switch_control_password as string
|
const password = station.switch_control_password as string
|
||||||
|
|
||||||
if (!ip || !port || !password) throw new Error(`Missing Switch configuration`)
|
if (!ip || !port || !password) {
|
||||||
|
socket.emit('switch_output', {
|
||||||
|
stationId: station.id,
|
||||||
|
portGroups: [],
|
||||||
|
status: 'DISCONNECTED',
|
||||||
|
message: `Missing Switch configuration`,
|
||||||
|
})
|
||||||
|
throw new Error(`Missing Switch configuration`)
|
||||||
|
}
|
||||||
|
|
||||||
// Tạo APC Controller instance
|
// Tạo APC Controller instance
|
||||||
const infoSwitch = new SwitchController({
|
const infoSwitch = new SwitchController({
|
||||||
|
|
|
||||||
|
|
@ -364,6 +364,17 @@ function App() {
|
||||||
setSelectedLine(data);
|
setSelectedLine(data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
console.log("CLEANUP SOCKET CLI", selectedLine);
|
||||||
|
if (selectedLine)
|
||||||
|
socket?.emit("close_cli", {
|
||||||
|
lineId: selectedLine?.id,
|
||||||
|
stationId: selectedLine?.station_id,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container w={"100%"} style={{ maxWidth: "100%" }}>
|
<Container w={"100%"} style={{ maxWidth: "100%" }}>
|
||||||
<DraggableTabs
|
<DraggableTabs
|
||||||
|
|
|
||||||
|
|
@ -111,9 +111,9 @@ const CardLine = ({
|
||||||
line_id={Number(line?.id)}
|
line_id={Number(line?.id)}
|
||||||
station_id={Number(stationItem.id)}
|
station_id={Number(stationItem.id)}
|
||||||
isDisabled={
|
isDisabled={
|
||||||
typeof line?.userEmailOpenCLI !== "undefined" &&
|
typeof line?.userOpenCLI !== "undefined" &&
|
||||||
typeof line?.userEmailOpenCLI !== "string" &&
|
typeof line?.userOpenCLI === "string" &&
|
||||||
line?.userEmailOpenCLI !== user?.email
|
line?.userOpenCLI !== user?.userName
|
||||||
}
|
}
|
||||||
line_status={line?.status || ""}
|
line_status={line?.status || ""}
|
||||||
fontSize={11}
|
fontSize={11}
|
||||||
|
|
|
||||||
|
|
@ -813,6 +813,13 @@ export const DrawerSwitchControl: React.FC<DrawerProps> = ({
|
||||||
}
|
}
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (loading)
|
||||||
|
setTimeout(() => {
|
||||||
|
setLoading(false);
|
||||||
|
}, 15000);
|
||||||
|
}, [loading]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
socket?.on("switch_output", (data) => {
|
socket?.on("switch_output", (data) => {
|
||||||
if (data.stationId !== stationAPI.id) return;
|
if (data.stationId !== stationAPI.id) return;
|
||||||
|
|
|
||||||
|
|
@ -64,15 +64,15 @@ const ModalTerminal = ({
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (
|
if (
|
||||||
typeof dataRequestTakeOver?.userName !== "undefined" &&
|
typeof dataRequestTakeOver?.userName !== "undefined" &&
|
||||||
line?.userEmailOpenCLI === user?.email &&
|
line?.userOpenCLI === user?.userName &&
|
||||||
dataRequestTakeOver?.userName !== user?.email
|
dataRequestTakeOver?.userName !== user?.userName
|
||||||
) {
|
) {
|
||||||
if (dataRequestTakeOver?.userName) {
|
if (dataRequestTakeOver?.userName) {
|
||||||
intervalTakeOverRef.current = setInterval(() => {
|
intervalTakeOverRef.current = setInterval(() => {
|
||||||
socket?.emit("open_cli", {
|
socket?.emit("open_cli", {
|
||||||
lineId: line?.id,
|
lineId: line?.id,
|
||||||
stationId: line?.station_id,
|
stationId: line?.station_id,
|
||||||
userEmail: user?.email,
|
userEmail: user?.userName,
|
||||||
userName: user?.userName,
|
userName: user?.userName,
|
||||||
});
|
});
|
||||||
socket?.emit("request_take_over", {
|
socket?.emit("request_take_over", {
|
||||||
|
|
@ -96,7 +96,7 @@ const ModalTerminal = ({
|
||||||
opened={opened}
|
opened={opened}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
onClose();
|
onClose();
|
||||||
if (line?.userEmailOpenCLI === user?.email)
|
if (line?.userOpenCLI === user?.userName)
|
||||||
socket?.emit("close_cli", {
|
socket?.emit("close_cli", {
|
||||||
lineId: line?.id,
|
lineId: line?.id,
|
||||||
stationId: line?.station_id,
|
stationId: line?.station_id,
|
||||||
|
|
@ -133,7 +133,9 @@ const ModalTerminal = ({
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{line?.userOpenCLI
|
{line?.userOpenCLI
|
||||||
? line?.userOpenCLI + " is using"
|
? (line?.userOpenCLI === user?.userName
|
||||||
|
? "You are"
|
||||||
|
: line?.userOpenCLI + " is") + " using"
|
||||||
: "Terminal is used"}
|
: "Terminal is used"}
|
||||||
</div>
|
</div>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
@ -170,8 +172,8 @@ const ModalTerminal = ({
|
||||||
line_id={Number(line?.id)}
|
line_id={Number(line?.id)}
|
||||||
station_id={Number(stationItem?.id)}
|
station_id={Number(stationItem?.id)}
|
||||||
isDisabled={
|
isDisabled={
|
||||||
typeof line?.userEmailOpenCLI !== "undefined" &&
|
typeof line?.userOpenCLI !== "undefined" &&
|
||||||
line?.userEmailOpenCLI !== user?.email
|
line?.userOpenCLI !== user?.userName
|
||||||
}
|
}
|
||||||
line_status={line?.status || ""}
|
line_status={line?.status || ""}
|
||||||
/>
|
/>
|
||||||
|
|
@ -194,8 +196,8 @@ const ModalTerminal = ({
|
||||||
<Button
|
<Button
|
||||||
disabled={
|
disabled={
|
||||||
isDisable ||
|
isDisable ||
|
||||||
(typeof line?.userEmailOpenCLI !== "undefined" &&
|
(typeof line?.userOpenCLI !== "undefined" &&
|
||||||
line?.userEmailOpenCLI !== user?.email)
|
line?.userOpenCLI !== user?.userName)
|
||||||
}
|
}
|
||||||
className={classes.buttonScenario}
|
className={classes.buttonScenario}
|
||||||
key={scenario.id}
|
key={scenario.id}
|
||||||
|
|
@ -230,8 +232,8 @@ const ModalTerminal = ({
|
||||||
<Button
|
<Button
|
||||||
disabled={
|
disabled={
|
||||||
disableRequestTakeOver ||
|
disableRequestTakeOver ||
|
||||||
!line?.userEmailOpenCLI ||
|
!line?.userOpenCLI ||
|
||||||
line?.userEmailOpenCLI === user?.email
|
line?.userOpenCLI === user?.userName
|
||||||
}
|
}
|
||||||
variant="filled"
|
variant="filled"
|
||||||
size="xs"
|
size="xs"
|
||||||
|
|
@ -243,7 +245,7 @@ const ModalTerminal = ({
|
||||||
line_id: line?.id,
|
line_id: line?.id,
|
||||||
station_id: Number(line?.station_id),
|
station_id: Number(line?.station_id),
|
||||||
userName: user?.userName?.trim() || "",
|
userName: user?.userName?.trim() || "",
|
||||||
userEmail: user?.email || "",
|
userEmail: user?.userName || "",
|
||||||
});
|
});
|
||||||
setDisableRequestTakeOver(true);
|
setDisableRequestTakeOver(true);
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
|
@ -264,7 +266,7 @@ const ModalTerminal = ({
|
||||||
Take over{" "}
|
Take over{" "}
|
||||||
{countDownRequest > 0 &&
|
{countDownRequest > 0 &&
|
||||||
(typeof dataRequestTakeOver?.userName === "undefined" ||
|
(typeof dataRequestTakeOver?.userName === "undefined" ||
|
||||||
dataRequestTakeOver?.userEmail === user?.email)
|
dataRequestTakeOver?.userEmail === user?.userName)
|
||||||
? `(${countDownRequest}s)`
|
? `(${countDownRequest}s)`
|
||||||
: ""}
|
: ""}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
@ -274,8 +276,8 @@ const ModalTerminal = ({
|
||||||
<Dialog
|
<Dialog
|
||||||
opened={
|
opened={
|
||||||
typeof dataRequestTakeOver?.userName !== "undefined" &&
|
typeof dataRequestTakeOver?.userName !== "undefined" &&
|
||||||
line?.userEmailOpenCLI === user?.email &&
|
line?.userOpenCLI === user?.userName &&
|
||||||
dataRequestTakeOver?.userName !== user?.email
|
dataRequestTakeOver?.userName !== user?.userName
|
||||||
}
|
}
|
||||||
position={{ bottom: 20, right: 20 }}
|
position={{ bottom: 20, right: 20 }}
|
||||||
withCloseButton
|
withCloseButton
|
||||||
|
|
@ -286,14 +288,14 @@ const ModalTerminal = ({
|
||||||
radius="md"
|
radius="md"
|
||||||
>
|
>
|
||||||
<Text size="sm" mb="xs" fw={700} c={"#ff6c6b"}>
|
<Text size="sm" mb="xs" fw={700} c={"#ff6c6b"}>
|
||||||
{`${
|
{`${`${dataRequestTakeOver?.userName} ${
|
||||||
dataRequestTakeOver?.userName
|
dataRequestTakeOver?.userEmail
|
||||||
? `${dataRequestTakeOver?.userName} (${dataRequestTakeOver?.userEmail})`
|
? `(${dataRequestTakeOver?.userEmail})`
|
||||||
: ""
|
: ""
|
||||||
} want to take over this line? ${
|
}`} want to take over this line? ${
|
||||||
countDownRequest > 0 &&
|
countDownRequest > 0 &&
|
||||||
typeof dataRequestTakeOver?.userName !== "undefined" &&
|
typeof dataRequestTakeOver?.userName !== "undefined" &&
|
||||||
line?.userEmailOpenCLI === user?.email
|
line?.userOpenCLI === user?.userName
|
||||||
? `(${countDownRequest}s)`
|
? `(${countDownRequest}s)`
|
||||||
: ""
|
: ""
|
||||||
}`}
|
}`}
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ const TerminalCLI: React.FC<TerminalCLIProps> = ({
|
||||||
}, [cliOpened]);
|
}, [cliOpened]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (cliOpened) {
|
if (cliOpened && isInit) {
|
||||||
if (terminal.current)
|
if (terminal.current)
|
||||||
setTimeout(() => terminal.current?.write(content), 200);
|
setTimeout(() => terminal.current?.write(content), 200);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue