This commit is contained in:
ACoolName 2024-06-02 13:29:46 +03:00
parent aed23759ce
commit cff965872e

View File

@ -17,7 +17,6 @@ import MenuItem from '@mui/material/MenuItem';
import MenuList from '@mui/material/MenuList';
import { Permission } from "./actions";
import TerminalComponent from "./terminal";
import ReactDOM from "react-dom/client";
export const apiAuthenticatedContext: Context<[boolean, Dispatch<boolean>]> = createContext([false, (value: boolean) => {}] as [boolean, Dispatch<boolean>])
@ -264,28 +263,13 @@ export function ActionItem(p: { action: ActionInfo, identifierSubstring?: string
function onFormChange(args: IChangeEvent<any, RJSFSchema, any>) {
setFormData(args.formData)
}
function openTerminalWindow(websocketUrl: string) {
const terminalWindow = window.open('', '', 'width=800,height=600');
if (terminalWindow) {
terminalWindow.document.write('<div id="root"/>');
terminalWindow.document.title = "Terminal";
var terminal_root = terminalWindow.document.getElementById('terminal-root')!
const root = ReactDOM.createRoot(
terminalWindow.document.getElementById('root') as HTMLElement
);
root.render(
<React.StrictMode>
<TerminalComponent websocket={websocketUrl} />
</React.StrictMode>
);
}
function createTerminalWindow(websocket: string){
window.open(`/terminal.html?ws=${encodeURIComponent(websocket)}`, 'Terminal', 'width=800,height=600');
}
return (<>
<Button variant={p.variant} disabled={!isUserAllowed(user, p.action)} onClick={() => { if (p.onClick) { p.onClick() } p.action.response_action == 'Terminal'?openTerminalWindow(`ws${API_URL.slice("http".length)}${url}`):setForm(true) }} sx={p.sx}>{p.action.name}</Button >
<Button variant={p.variant} disabled={!isUserAllowed(user, p.action)} onClick={() => { if (p.onClick) { p.onClick() } p.action.response_action == 'Terminal'?createTerminalWindow(`ws${API_URL.slice("http".length)}${url}`):setForm(true) }} sx={p.sx}>{p.action.name}</Button >
<Modal
onClose={() => { setForm(false); setFormData({}); }}
open={form}