Перенес флаги / статусы на бэк
This commit is contained in:
parent
f1de8a69f9
commit
e0a9da229e
@ -26,6 +26,8 @@ export interface ProcessProgressInterface {
|
|||||||
total: number,
|
total: number,
|
||||||
progress: number,
|
progress: number,
|
||||||
memory: any[],
|
memory: any[],
|
||||||
|
remaining: string
|
||||||
|
percent: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ProcessInterface {
|
export interface ProcessInterface {
|
||||||
@ -45,14 +47,20 @@ export interface ProcessInterface {
|
|||||||
pausedAt: string | null,
|
pausedAt: string | null,
|
||||||
cancelledAt: string | null
|
cancelledAt: string | null
|
||||||
completedAt: string | null
|
completedAt: string | null
|
||||||
|
status: Status
|
||||||
|
canPlay: boolean
|
||||||
|
canPause: boolean
|
||||||
|
canRepeat: boolean
|
||||||
|
canStop: boolean
|
||||||
|
canKill: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
enum Status {
|
enum Status {
|
||||||
Wait,
|
Wait = 'wait',
|
||||||
Running,
|
Running = 'running',
|
||||||
Cancelled,
|
Cancelled = 'cancelled',
|
||||||
Error,
|
Error = 'error',
|
||||||
Success
|
Success = 'success',
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function Processes() {
|
export default function Processes() {
|
||||||
@ -99,28 +107,6 @@ export default function Processes() {
|
|||||||
}, [page]);
|
}, [page]);
|
||||||
|
|
||||||
let isFinished = (process: ProcessInterface) => process.cancelledAt || process.completedAt
|
let isFinished = (process: ProcessInterface) => process.cancelledAt || process.completedAt
|
||||||
let canPlay = (process: ProcessInterface) => !isFinished(process) && process.progress && process.pausedAt
|
|
||||||
let canPause = (process: ProcessInterface) => !isFinished(process) && process.progress && !process.pausedAt
|
|
||||||
let canRepeat = (process: ProcessInterface) => isFinished(process)
|
|
||||||
let canStop = (process: ProcessInterface) => !isFinished(process) && process.progress
|
|
||||||
let canKill = (process: ProcessInterface) => !isFinished(process) && process.startedAt
|
|
||||||
let progress = (progress: ProcessProgressInterface) => progress.progress / progress.total * 100
|
|
||||||
|
|
||||||
let status = (process: ProcessInterface): Status => {
|
|
||||||
if (process.cancelledAt && process.completedAt) {
|
|
||||||
return Status.Cancelled
|
|
||||||
}
|
|
||||||
if (process.exception && process.completedAt) {
|
|
||||||
return Status.Error
|
|
||||||
}
|
|
||||||
if (!process.exception && process.completedAt) {
|
|
||||||
return Status.Success
|
|
||||||
}
|
|
||||||
if (process.startedAt && !process.completedAt) {
|
|
||||||
return Status.Running
|
|
||||||
}
|
|
||||||
return Status.Wait
|
|
||||||
}
|
|
||||||
|
|
||||||
const handleChangePage = (event: any, page: number) => {
|
const handleChangePage = (event: any, page: number) => {
|
||||||
setPage(page);
|
setPage(page);
|
||||||
@ -157,55 +143,6 @@ export default function Processes() {
|
|||||||
setOpen(false)
|
setOpen(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
let formatSize = (length: any) => {
|
|
||||||
var i = 0, type = ['b','Kb','Mb','Gb','Tb','Pb'];
|
|
||||||
while((length / 1000 | 0) && i < type.length - 1) {
|
|
||||||
length /= 1024;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return length.toFixed(2) + ' ' + type[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
let remaining = (process: ProcessInterface) =>
|
|
||||||
{
|
|
||||||
if (!process?.progress?.progress || !process.startedAt) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
return Math.round((new Date().getTime() - new Date(process.startedAt).getTime()) / process?.progress.progress * (process?.progress.total - process?.progress.progress));
|
|
||||||
}
|
|
||||||
|
|
||||||
let formatTime = ($secs: number | null) => {
|
|
||||||
if ($secs === null) {
|
|
||||||
return ''
|
|
||||||
}
|
|
||||||
let $timeFormats = [
|
|
||||||
[0, '< 1 sec'],
|
|
||||||
[1, '1 sec'],
|
|
||||||
[2, 'secs', 1],
|
|
||||||
[60, '1 min'],
|
|
||||||
[120, 'mins', 60],
|
|
||||||
[3600, '1 hr'],
|
|
||||||
[7200, 'hrs', 3600],
|
|
||||||
[86400, '1 day'],
|
|
||||||
[172800, 'days', 86400],
|
|
||||||
];
|
|
||||||
|
|
||||||
for (let $index in $timeFormats) {
|
|
||||||
let $format = $timeFormats[$index]
|
|
||||||
if ($secs >= $format[0]) {
|
|
||||||
if ((typeof $timeFormats[$index + 1] !== 'undefined' && $secs < $timeFormats[$index + 1][0])
|
|
||||||
|| $index == $timeFormats.length - 1
|
|
||||||
) {
|
|
||||||
if (2 == $format.length) {
|
|
||||||
return $format[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
return Math.floor($secs / $format[2]) + ' ' + $format[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<TableContainer>
|
<TableContainer>
|
||||||
@ -226,42 +163,42 @@ export default function Processes() {
|
|||||||
<TableCell>
|
<TableCell>
|
||||||
{!process.progress && !isFinished(process) && <LinearProgress/>}
|
{!process.progress && !isFinished(process) && <LinearProgress/>}
|
||||||
{!process.progress && isFinished(process) && <LinearProgress variant="determinate" value={100}/>}
|
{!process.progress && isFinished(process) && <LinearProgress variant="determinate" value={100}/>}
|
||||||
{process.progress && <LinearProgress variant="determinate" value={progress(process.progress)}/>}
|
{process.progress && <LinearProgress variant="determinate" value={process.progress.percent}/>}
|
||||||
{process.progress && <span>
|
{process.progress && <span>
|
||||||
{`${process.progress.progress}`} / {`${process.progress.total}`} - {progress(process.progress)}% [{formatSize(process.progress.memory)}] / {formatTime(remaining(process))}
|
{`${process.progress.progress}`} / {`${process.progress.total}`} - {process.progress.percent}% [{process.progress.memory}] / {process.progress.remaining}
|
||||||
</span>}
|
</span>}
|
||||||
{canPlay(process) && <IconButton title={`Play`} aria-label="Play">
|
{process.canPlay && <IconButton title={`Play`} aria-label="Play">
|
||||||
<PlayCircleOutline/>
|
<PlayCircleOutline/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{canPause(process) && <IconButton title={`Pause`} aria-label="Pause">
|
{process.canPause && <IconButton title={`Pause`} aria-label="Pause">
|
||||||
<PauseCircleOutline/>
|
<PauseCircleOutline/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{canStop(process) && <IconButton title={`Stop`} aria-label="Stop">
|
{process.canStop && <IconButton title={`Stop`} aria-label="Stop">
|
||||||
<StopCircleOutlined/>
|
<StopCircleOutlined/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{Status.Error === status(process) && <IconButton title={`Error`} aria-label="Error">
|
{Status.Error === process.status && <IconButton title={`Error`} aria-label="Error">
|
||||||
<ErrorOutline/>
|
<ErrorOutline/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{Status.Success === status(process) && <IconButton title={`Success`} aria-label="Success">
|
{Status.Success === process.status && <IconButton title={`Success`} aria-label="Success">
|
||||||
<CheckCircleOutline/>
|
<CheckCircleOutline/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{Status.Running === status(process) && <IconButton title={`Running`} aria-label="Running">
|
{Status.Running === process.status && <IconButton title={`Running`} aria-label="Running">
|
||||||
<RunCircleOutlined/>
|
<RunCircleOutlined/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{Status.Cancelled === status(process) && <IconButton title={`Cancelled`} aria-label="Cancelled">
|
{Status.Cancelled === process.status && <IconButton title={`Cancelled`} aria-label="Cancelled">
|
||||||
<StopCircleOutlined/>
|
<StopCircleOutlined/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{Status.Wait === status(process) && <IconButton title={`Wait`} aria-label="Wait">
|
{Status.Wait === process.status && <IconButton title={`Wait`} aria-label="Wait">
|
||||||
<HourglassEmptyOutlined/>
|
<HourglassEmptyOutlined/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>
|
<TableCell>
|
||||||
{canRepeat(process) && <IconButton onClick={() => openRepeatDialog(process)} title={`Repeat`} aria-label="Repeat">
|
{process.canRepeat && <IconButton onClick={() => openRepeatDialog(process)} title={`Repeat`} aria-label="Repeat">
|
||||||
<ReplayOutlined/>
|
<ReplayOutlined/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{canKill(process) && <IconButton title={`Kill`} aria-label="Kill">
|
{process.canKill && <IconButton title={`Kill`} aria-label="Kill">
|
||||||
<DeleteForeverOutlined/>
|
<DeleteForeverOutlined/>
|
||||||
</IconButton>}
|
</IconButton>}
|
||||||
{process?.outputId && <IconButton title={`Output`} onClick={() => output(process)} aria-label="Output">
|
{process?.outputId && <IconButton title={`Output`} onClick={() => output(process)} aria-label="Output">
|
||||||
|
Loading…
Reference in New Issue
Block a user