Поправил логику вывода прогресса

Добавил апрув
jwt
Rinsvent 2 years ago
parent 473a9a1993
commit fbf3c06efd
  1. 3
      api/sm/requests/approve-process.ts
  2. 1
      api/sm/responses/processes.ts
  3. 10
      api/sm/schemas/approve-process.ts
  4. 10
      api/sm/sm-client.ts
  5. 34
      components/elements/processes/index.tsx

@ -0,0 +1,3 @@
export interface ApproveProcessRequest {
id: string
}

@ -37,6 +37,7 @@ export interface ProcessInterface {
canRepeat: boolean canRepeat: boolean
canStop: boolean canStop: boolean
canKill: boolean canKill: boolean
canApprove: boolean
} }
export enum Status { export enum Status {

@ -0,0 +1,10 @@
import {Method, SchemaInterface} from "../../schema-client";
class ApproveProcessSchema implements SchemaInterface {
method = Method.POST
url = '/system-monitoring/processes/{id}/approve'
contentType = null
}
export let approveProcessSchema = new ApproveProcessSchema()
export default approveProcessSchema

@ -8,7 +8,9 @@ import {CommandInterface} from "./responses/comamnds";
import commandsSchema from "./schemas/commands"; import commandsSchema from "./schemas/commands";
import runCommandsSchema from "./schemas/run-commands"; import runCommandsSchema from "./schemas/run-commands";
import {RepeatProcessRequest} from "./requests/repeat-process"; import {RepeatProcessRequest} from "./requests/repeat-process";
import {ApproveProcessRequest} from "./requests/approve-process";
import repeatProcessSchema from "./schemas/repeat-process"; import repeatProcessSchema from "./schemas/repeat-process";
import approveProcessSchema from "./schemas/approve-process";
import processOutputSchema from "./schemas/process-output"; import processOutputSchema from "./schemas/process-output";
import {ProcessOutputRequest} from "./requests/process-ouput"; import {ProcessOutputRequest} from "./requests/process-ouput";
import playProcessSchema from "./schemas/play-process"; import playProcessSchema from "./schemas/play-process";
@ -52,6 +54,14 @@ export class SMClient extends SchemaClient {
} }
} }
async approveProcess(data: ApproveProcessRequest): Promise<ResponseInterface> {
let { responseData, headers } = await this.send(approveProcessSchema, data)
return {
data: responseData as ProcessInterface[],
headers: headers
}
}
async repeatProcess(data: RepeatProcessRequest): Promise<ResponseInterface> { async repeatProcess(data: RepeatProcessRequest): Promise<ResponseInterface> {
let { responseData, headers } = await this.send(repeatProcessSchema, data) let { responseData, headers } = await this.send(repeatProcessSchema, data)
return { return {

@ -1,5 +1,5 @@
import styles from './styles.module.css' import styles from './styles.module.css'
import {useEffect, useState} from "react" import {useContext, useEffect, useState} from "react"
import DeleteForeverOutlined from "@mui/icons-material/DeleteForeverOutlined" import DeleteForeverOutlined from "@mui/icons-material/DeleteForeverOutlined"
import StopCircleOutlined from "@mui/icons-material/StopCircleOutlined" import StopCircleOutlined from "@mui/icons-material/StopCircleOutlined"
import PauseCircleOutline from "@mui/icons-material/PauseCircleOutline" import PauseCircleOutline from "@mui/icons-material/PauseCircleOutline"
@ -10,6 +10,7 @@ import ErrorOutline from "@mui/icons-material/ErrorOutline"
import ReplayOutlined from "@mui/icons-material/ReplayOutlined" import ReplayOutlined from "@mui/icons-material/ReplayOutlined"
import RunCircleOutlined from "@mui/icons-material/RunCircleOutlined" import RunCircleOutlined from "@mui/icons-material/RunCircleOutlined"
import FactCheckOutlined from "@mui/icons-material/FactCheckOutlined" import FactCheckOutlined from "@mui/icons-material/FactCheckOutlined"
import ThumbUpAltOutlined from '@mui/icons-material/ThumbUpAltOutlined'
import { import {
Box, Box,
TextField, TextField,
@ -30,6 +31,7 @@ import Command from "../commands/elements/command";
import {CommandInterface} from "../../../api/sm/responses/comamnds"; import {CommandInterface} from "../../../api/sm/responses/comamnds";
import Grid from '@mui/material/Grid'; import Grid from '@mui/material/Grid';
import {useApi} from "../../../hooks/use-api"; import {useApi} from "../../../hooks/use-api";
import Context from "../../../context/token";
enum Action { enum Action {
Run, Run,
@ -38,9 +40,11 @@ enum Action {
Kill, Kill,
Play, Play,
Pause, Pause,
Approve,
} }
export default function Processes() { export default function Processes() {
const {token} = useContext(Context)
const [processes, setProcesses] = useState<ProcessInterface[]>([]); const [processes, setProcesses] = useState<ProcessInterface[]>([]);
const [commands, setCommands] = useState<CommandInterface[]>([]); const [commands, setCommands] = useState<CommandInterface[]>([]);
const [page, setPage] = useState<number>(0); const [page, setPage] = useState<number>(0);
@ -116,6 +120,8 @@ export default function Processes() {
}, [action]); }, [action]);
let isFinished = (process: ProcessInterface) => process.cancelledAt || process.completedAt let isFinished = (process: ProcessInterface) => process.cancelledAt || process.completedAt
let isCancelled = (process: ProcessInterface) => process.cancelledAt
let isRunning = (process: ProcessInterface) => process.startedAt && !isFinished(process)
const handleChangePage = (event: any, page: number) => { const handleChangePage = (event: any, page: number) => {
setPage(page); setPage(page);
@ -145,6 +151,12 @@ export default function Processes() {
}) })
} }
if (action === Action.Approve) {
await api.approveProcess({
id: selectedProcess.id,
})
}
if (action === Action.Repeat) { if (action === Action.Repeat) {
await api.repeatProcess({ await api.repeatProcess({
id: selectedProcess.id, id: selectedProcess.id,
@ -213,12 +225,14 @@ export default function Processes() {
<TableRow key={process.id}> <TableRow key={process.id}>
<TableCell>{process.name}</TableCell> <TableCell>{process.name}</TableCell>
<TableCell> <TableCell>
{!process.progress && !isFinished(process) && <LinearProgress/>} {!process.progress && !isFinished(process) && isRunning(process) && <LinearProgress/>}
{!process.progress && isFinished(process) && <LinearProgress variant="determinate" value={100}/>} {!process.progress && !isFinished(process) && !isRunning(process) && <LinearProgress variant="determinate" value={0}/>}
{!process.progress && isFinished(process) && !isCancelled(process) && <LinearProgress variant="determinate" value={100}/>}
{!process.progress && isFinished(process) && isCancelled(process) && <LinearProgress variant="determinate" value={0}/>}
{process.progress && <LinearProgress variant="determinate" value={process.progress.percent}/>} {process.progress && <LinearProgress variant="determinate" value={process.progress.percent}/>}
{process.progress && <span> {process.progress && <span>
{`${process.progress.progress}`} / {`${process.progress.total}`} - {process.progress.percent}% [{process.progress.memory}] / {process.progress.remaining} {`${process.progress.progress}`} / {`${process.progress.total}`} - {process.progress.percent}% [{process.progress.memory}] / {process.progress.remaining}
</span>} </span>}
{process.canPlay && <IconButton onClick={() => openDialog(process, Action.Play)} title={`Play`} aria-label="Play"> {process.canPlay && <IconButton onClick={() => openDialog(process, Action.Play)} title={`Play`} aria-label="Play">
<PlayCircleOutline/> <PlayCircleOutline/>
</IconButton>} </IconButton>}
@ -247,6 +261,9 @@ export default function Processes() {
</IconButton>} </IconButton>}
</TableCell> </TableCell>
<TableCell> <TableCell>
{process.canApprove && token?.permissions.indexOf('approve_process') > -1 && <IconButton onClick={() => openDialog(process, Action.Approve)} title={`Approve`} aria-label="Approve">
<ThumbUpAltOutlined/>
</IconButton>}
{process.canRepeat && <IconButton onClick={() => openDialog(process, Action.Repeat)} title={`Repeat`} aria-label="Repeat"> {process.canRepeat && <IconButton onClick={() => openDialog(process, Action.Repeat)} title={`Repeat`} aria-label="Repeat">
<ReplayOutlined/> <ReplayOutlined/>
</IconButton>} </IconButton>}
@ -300,6 +317,13 @@ export default function Processes() {
argumentsParams={selectedProcess.arguments} argumentsParams={selectedProcess.arguments}
callback={callback}/>} callback={callback}/>}
</ConfirmDialog>} </ConfirmDialog>}
{selectedProcess && <ConfirmDialog
title={selectedProcess.name}
open={Action.Approve === action}
agreeCallback={agreeCallback}
closeCallback={() => {setAction(null)}}>
Approve?
</ConfirmDialog>}
{selectedProcess && <ConfirmDialog {selectedProcess && <ConfirmDialog
title={`Are you sure?`} title={`Are you sure?`}
open={ !!action && ([Action.Play, Action.Pause, Action.Stop, Action.Kill].indexOf(action) > -1) } open={ !!action && ([Action.Play, Action.Pause, Action.Stop, Action.Kill].indexOf(action) > -1) }

Loading…
Cancel
Save