Improved stability
This commit is contained in:
@@ -2,7 +2,7 @@ import { Button, Group, Space, TextInput, Notification, Switch, NativeSelect } f
|
||||
import { useForm } from '@mantine/hooks';
|
||||
import React, { useState } from 'react';
|
||||
import { RegexAddForm } from '../js/models';
|
||||
import { addregex, b64encode, validateRegex } from '../js/utils';
|
||||
import { addregex, b64encode, getHumanReadableRegex, okNotify, validateRegex } from '../js/utils';
|
||||
import { ImCross } from "react-icons/im"
|
||||
import FilterTypeSelector from './FilterTypeSelector';
|
||||
|
||||
@@ -58,6 +58,7 @@ function AddNewRegex({ closePopup, service }:{ closePopup:()=>void, service:stri
|
||||
if (!res){
|
||||
setSubmitLoading(false)
|
||||
closePopup();
|
||||
okNotify(`Regex ${getHumanReadableRegex(request.regex)} has been added`, `Successfully added ${request.is_blacklist?"blacklist":"whitelist"} regex to ${request.service_id} service`)
|
||||
}else{
|
||||
setSubmitLoading(false)
|
||||
setError("Invalid request! [ "+res+" ]")
|
||||
|
||||
@@ -2,7 +2,7 @@ import { Button, Group, NumberInput, Space, TextInput, Notification } from '@man
|
||||
import { useForm } from '@mantine/hooks';
|
||||
import React, { useState } from 'react';
|
||||
import { ServiceAddForm } from '../js/models';
|
||||
import { addservice } from '../js/utils';
|
||||
import { addservice, okNotify } from '../js/utils';
|
||||
import { ImCross } from "react-icons/im"
|
||||
|
||||
function AddNewService({ closePopup }:{ closePopup:()=>void }) {
|
||||
@@ -27,6 +27,7 @@ function AddNewService({ closePopup }:{ closePopup:()=>void }) {
|
||||
if (!res){
|
||||
setSubmitLoading(false)
|
||||
closePopup();
|
||||
okNotify(`Service ${values.name} has been added`, `Successfully added ${values.name} with port ${values.port}`)
|
||||
}else{
|
||||
setSubmitLoading(false)
|
||||
setError("Invalid request! [ "+res+" ]")
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Grid, Text, Title, Badge, Space, ActionIcon } from '@mantine/core';
|
||||
import React, { useState } from 'react';
|
||||
import { RegexFilter } from '../../js/models';
|
||||
import { getHumanReadableRegex } from '../../js/utils';
|
||||
import { deleteregex, errorNotify, getHumanReadableRegex, okNotify } from '../../js/utils';
|
||||
import style from "./RegexView.module.scss";
|
||||
import { BsTrashFill } from "react-icons/bs"
|
||||
import YesNoModal from '../YesNoModal';
|
||||
@@ -24,6 +24,16 @@ function RegexView({ regexInfo }:{ regexInfo:RegexFilter }) {
|
||||
|
||||
const [deleteModal, setDeleteModal] = useState(false);
|
||||
|
||||
const deleteRegex = () => {
|
||||
deleteregex(regexInfo.id).then(res => {
|
||||
if(!res){
|
||||
okNotify(`Regex ${regex_expr} deleted successfully!`,`Regex '${regex_expr}' ID:${regexInfo.id} has been deleted!`)
|
||||
}else{
|
||||
errorNotify(`Regex ${regex_expr} deleation failed!`,`Error: ${res}`)
|
||||
}
|
||||
}).catch( err => errorNotify(`Regex ${regex_expr} deleation failed!`,`Error: ${err}`))
|
||||
}
|
||||
|
||||
return <div className={style.box}>
|
||||
<Grid>
|
||||
<Grid.Col span={2}>
|
||||
@@ -66,7 +76,7 @@ function RegexView({ regexInfo }:{ regexInfo:RegexFilter }) {
|
||||
title='Are you sure to delete this regex?'
|
||||
description={`You are going to delete the regex '${regex_expr}', causing the restart of the firewall if it is active.`}
|
||||
onClose={()=>setDeleteModal(false)}
|
||||
action={()=>console.log("Delete regex please!")}
|
||||
action={deleteRegex}
|
||||
opened={deleteModal}
|
||||
/>
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Service } from '../../js/models';
|
||||
import { MdOutlineArrowForwardIos } from "react-icons/md"
|
||||
import style from "./ServiceRow.module.scss";
|
||||
import YesNoModal from '../YesNoModal';
|
||||
import { errorNotify, okNotify, pauseservice, startservice, stopservice } from '../../js/utils';
|
||||
|
||||
//"status":"stop"/"wait"/"active"/"pause",
|
||||
function ServiceRow({ service, onClick, additional_buttons }:{ service:Service, onClick?:()=>void, additional_buttons?:any }) {
|
||||
@@ -20,26 +21,48 @@ function ServiceRow({ service, onClick, additional_buttons }:{ service:Service,
|
||||
const [stopModal, setStopModal] = useState(false);
|
||||
const [buttonLoading, setButtonLoading] = useState(false)
|
||||
|
||||
const stopService = () => {
|
||||
const stopService = async () => {
|
||||
setButtonLoading(true)
|
||||
console.log("Stop this service please!")
|
||||
await stopservice(service.id).then(res => {
|
||||
if(!res){
|
||||
okNotify(`Service ${service.id} stopped successfully!`,`The service ${service.name} has been stopped!`)
|
||||
}else{
|
||||
errorNotify(`An error as occurred during the stopping of the service ${service.id}`,`Error: ${res}`)
|
||||
}
|
||||
}).catch(err => {
|
||||
errorNotify(`An error as occurred during the stopping of the service ${service.id}`,`Error: ${err}`)
|
||||
})
|
||||
setButtonLoading(false)
|
||||
}
|
||||
|
||||
const startService = () => {
|
||||
const startService = async () => {
|
||||
setButtonLoading(true)
|
||||
console.log("Start this service please!")
|
||||
await startservice(service.id).then(res => {
|
||||
if(!res){
|
||||
okNotify(`Service ${service.id} started successfully!`,`The service ${service.name} has been started!`)
|
||||
}else{
|
||||
errorNotify(`An error as occurred during the starting of the service ${service.id}`,`Error: ${res}`)
|
||||
}
|
||||
}).catch(err => {
|
||||
errorNotify(`An error as occurred during the starting of the service ${service.id}`,`Error: ${err}`)
|
||||
})
|
||||
setButtonLoading(false)
|
||||
}
|
||||
|
||||
const pauseService = () => {
|
||||
if (service.status === "pause") return setStopModal(true)
|
||||
const pauseService = async () => {
|
||||
setButtonLoading(true)
|
||||
console.log("Pause this service please!")
|
||||
await pauseservice(service.id).then(res => {
|
||||
if(!res){
|
||||
okNotify(`Service ${service.id} paused successfully!`,`The service ${service.name} has been paused (Transparent mode)!`)
|
||||
}else{
|
||||
errorNotify(`An error as occurred during the pausing of the service ${service.id}`,`Error: ${res}`)
|
||||
}
|
||||
}).catch(err => {
|
||||
errorNotify(`An error as occurred during the pausing of the service ${service.id}`,`Error: ${err}`)
|
||||
})
|
||||
setButtonLoading(false)
|
||||
}
|
||||
|
||||
|
||||
|
||||
return <>
|
||||
<Grid className={style.row} style={{width:"100%"}}>
|
||||
@@ -59,11 +82,19 @@ function ServiceRow({ service, onClick, additional_buttons }:{ service:Service,
|
||||
<Space w="xl" /><Space w="xl" />
|
||||
<div className="center-flex">
|
||||
{additional_buttons}
|
||||
<ActionIcon color={service.status === "pause"?"yellow":"red"} loading={buttonLoading}
|
||||
{["pause","wait"].includes(service.status)?
|
||||
<ActionIcon color="yellow" loading={buttonLoading}
|
||||
onClick={stopService} size="xl" radius="md" variant="filled"
|
||||
disabled={service.status === "stop"}>
|
||||
<FaStop size="20px" />
|
||||
</ActionIcon>:
|
||||
<ActionIcon color="red" loading={buttonLoading}
|
||||
onClick={pauseService} size="xl" radius="md" variant="filled"
|
||||
disabled={!["wait","active","pause"].includes(service.status)?true:false}>
|
||||
{service.status === "pause"?<FaStop size="20px" />:<FaPause size="20px" />}
|
||||
</ActionIcon>
|
||||
disabled={service.status === "stop"}>
|
||||
<FaPause size="20px" />
|
||||
</ActionIcon>
|
||||
}
|
||||
|
||||
<Space w="md"/>
|
||||
<ActionIcon color="teal" size="xl" radius="md" onClick={startService} loading={buttonLoading}
|
||||
variant="filled" disabled={!["stop","pause"].includes(service.status)?true:false}>
|
||||
|
||||
Reference in New Issue
Block a user