|
|
|
@ -4,7 +4,7 @@ import Arguments from "../arguments"; |
|
|
|
|
import {OptionInterface} from "../option"; |
|
|
|
|
import {ArgumentInterface} from "../argument"; |
|
|
|
|
import {Provider} from "./context"; |
|
|
|
|
import {useState} from "react"; |
|
|
|
|
import {useEffect, useState} from "react"; |
|
|
|
|
|
|
|
|
|
export interface CommandInterface { |
|
|
|
|
class: string, |
|
|
|
@ -14,28 +14,19 @@ export interface CommandInterface { |
|
|
|
|
arguments: ArgumentInterface[], |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default function Command(command: CommandInterface) { |
|
|
|
|
interface CommandComponentInterface { |
|
|
|
|
command: CommandInterface, |
|
|
|
|
callback: any, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export default function Command({command, callback}: CommandComponentInterface) { |
|
|
|
|
const [optionList, setOptionList] = useState<Record<string, any>>({}); |
|
|
|
|
const [argumentList, setArgumentList] = useState<Record<string, any>>({}); |
|
|
|
|
|
|
|
|
|
let onClick = async (event: any) => { |
|
|
|
|
let url = `http://fmw.sipachev.sv/system-monitoring/commands/${command.name}/run` |
|
|
|
|
let data = { |
|
|
|
|
options: optionList, |
|
|
|
|
arguments: argumentList, |
|
|
|
|
} |
|
|
|
|
console.log('data', data) |
|
|
|
|
let response = await fetch(url, { |
|
|
|
|
method: 'POST', |
|
|
|
|
headers: { |
|
|
|
|
'Content-Type': 'application/json;charset=utf-8', |
|
|
|
|
'X-Plugin-Token': 'passw0rd' |
|
|
|
|
}, |
|
|
|
|
body: JSON.stringify(data) |
|
|
|
|
}); |
|
|
|
|
let result = await response.json(); |
|
|
|
|
console.log('result', result) |
|
|
|
|
} |
|
|
|
|
useEffect(() => { |
|
|
|
|
callback && callback(command.name, optionList, argumentList) |
|
|
|
|
}, [optionList, argumentList]) |
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
|
<Provider value={{optionList, setOptionList, argumentList, setArgumentList}}> |
|
|
|
|
<div className={styles.task}> |
|
|
|
@ -44,9 +35,6 @@ export default function Command(command: CommandInterface) { |
|
|
|
|
<Options optionList={command.options} /> |
|
|
|
|
<Arguments argumentList={command.arguments} /> |
|
|
|
|
</div> |
|
|
|
|
<div> |
|
|
|
|
<button onClick={onClick}>Run</button> |
|
|
|
|
</div> |
|
|
|
|
</div> |
|
|
|
|
</Provider> |
|
|
|
|
) |
|
|
|
|