|
|
|
@ -10,7 +10,7 @@ import ErrorOutline from "@mui/icons-material/ErrorOutline" |
|
|
|
|
import Replay from "@mui/icons-material/Replay" |
|
|
|
|
import RunCircle from "@mui/icons-material/RunCircle" |
|
|
|
|
import {IconButton, LinearProgress, TableContainer, Table, TableBody, TableCell, TableHead, TableRow, TablePagination} from "@mui/material" |
|
|
|
|
import { v4 } from "uuid" |
|
|
|
|
import ConfirmDialog from "../confirm-dialog"; |
|
|
|
|
|
|
|
|
|
export interface ProcessExceptionInterface { |
|
|
|
|
message: string, |
|
|
|
@ -56,7 +56,8 @@ export default function Processes() { |
|
|
|
|
const [processes, setProcesses] = useState<ProcessInterface[]>([]); |
|
|
|
|
const [page, setPage] = useState<number>(0); |
|
|
|
|
const [count, setCount] = useState<number>(0); |
|
|
|
|
let requestId = v4() |
|
|
|
|
const [open, setOpen] = useState<boolean>(false); |
|
|
|
|
const [selectedProcess, setSelectedProcess] = useState<ProcessInterface | null>(null); |
|
|
|
|
|
|
|
|
|
let refreshLock = false |
|
|
|
|
let refreshProcesses = async () => { |
|
|
|
@ -80,6 +81,17 @@ export default function Processes() { |
|
|
|
|
setCount(Number(response.headers.get('X-Pagination-Count'))) |
|
|
|
|
refreshLock = false |
|
|
|
|
} |
|
|
|
|
let output = async (process: string) => { |
|
|
|
|
let response = await fetch(`http://fmw.sipachev.sv/system-monitoring/processes/${process}/output`, |
|
|
|
|
{ |
|
|
|
|
method: 'GET', |
|
|
|
|
headers: { |
|
|
|
|
'X-Plugin-Token': 'passw0rd', |
|
|
|
|
'X-Pagination-Count': '0', |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
const processes: ProcessInterface[] = await response.json() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const timer = setInterval(() => refreshProcesses(), 1000) |
|
|
|
@ -114,8 +126,35 @@ export default function Processes() { |
|
|
|
|
setPage(page); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const repeat = (event: any) => { |
|
|
|
|
const openRepeatDialog = (process: ProcessInterface) => { |
|
|
|
|
setSelectedProcess(process) |
|
|
|
|
setOpen(true) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let lock = false |
|
|
|
|
const repeat = async (dialogId: string) => { |
|
|
|
|
if (lock) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
if (!selectedProcess) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
lock = true |
|
|
|
|
let url = `http://fmw.sipachev.sv/system-monitoring/processes/${selectedProcess.id}/repeat` |
|
|
|
|
let data = { |
|
|
|
|
requestId: dialogId |
|
|
|
|
} |
|
|
|
|
let response = await fetch(url, { |
|
|
|
|
method: 'POST', |
|
|
|
|
headers: { |
|
|
|
|
'Content-Type': 'application/json;charset=utf-8', |
|
|
|
|
'X-Plugin-Token': 'passw0rd' |
|
|
|
|
}, |
|
|
|
|
body: JSON.stringify(data) |
|
|
|
|
}); |
|
|
|
|
lock = false |
|
|
|
|
setSelectedProcess(null) |
|
|
|
|
setOpen(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
@ -156,7 +195,7 @@ export default function Processes() { |
|
|
|
|
{Status.Error === status(process) && <IconButton title={`Error`} aria-label="Error"> |
|
|
|
|
<ErrorOutline/> |
|
|
|
|
</IconButton>} |
|
|
|
|
{Status.Success === status(process) && <IconButton title={`Success`} aria-label="Success"> |
|
|
|
|
{Status.Success === status(process) && <IconButton onClick={() => output(process.id)} title={`Success`} aria-label="Success"> |
|
|
|
|
<CheckCircleOutline/> |
|
|
|
|
</IconButton>} |
|
|
|
|
{Status.Running === status(process) && <IconButton title={`Running`} aria-label="Running"> |
|
|
|
@ -170,7 +209,7 @@ export default function Processes() { |
|
|
|
|
</IconButton>} |
|
|
|
|
</TableCell> |
|
|
|
|
<TableCell> |
|
|
|
|
{canRepeat(process) && <IconButton onClick={repeat} title={`Repeat`} aria-label="Repeat"> |
|
|
|
|
{canRepeat(process) && <IconButton onClick={() => openRepeatDialog(process)} title={`Repeat`} aria-label="Repeat"> |
|
|
|
|
<Replay/> |
|
|
|
|
</IconButton>} |
|
|
|
|
{canKill(process) && <IconButton title={`Kill`} aria-label="Kill"> |
|
|
|
@ -192,6 +231,10 @@ export default function Processes() { |
|
|
|
|
page={page} |
|
|
|
|
onPageChange={handleChangePage} |
|
|
|
|
/> |
|
|
|
|
<ConfirmDialog open={open} text={'!!!'} agreeCallback={repeat} closeCallback={() => { |
|
|
|
|
setSelectedProcess(null) |
|
|
|
|
setOpen(false) |
|
|
|
|
}}/> |
|
|
|
|
</> |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|