Add remote editing of master config

Add commands and web UI for editing the master configuration remotely.
This commit is contained in:
Hornwitser committed 2021-02-24 22:16:03 +01:00
1 parent 38b7d0f600
commit bec30c9927
9 files changed
+225 -4

No files matched your search

@@ -0,0 +1,44 @@
import React, { useContext } from "react";
import { Typography } from "antd";
import libLink from "@clusterio/lib/link";
import libConfig from "@clusterio/lib/config";
import BaseConfigTree from "./BaseConfigTree";
import ControlContext from "./ControlContext";
export default function MasterConfigTree(props) {
let control = useContext(ControlContext);
async function retrieveConfig() {
let result = await libLink.messages.getMasterConfig.send(control);
return result.serialized_config;
}
async function setField(field, value) {
await libLink.messages.setMasterConfigField.send(control, {
field,
value: String(value),
});
}
async function setProp(field, prop, value) {
let data = { field, prop };
if (value) {
try {
data.value = JSON.parse(value);
} catch (err) {
return;
}
}
await libLink.messages.setMasterConfigProp.send(control, data);
}
return <BaseConfigTree
ConfigClass={libConfig.MasterConfig}
retrieveConfig={retrieveConfig}
setField={setField}
setProp={setProp}
/>;
}
@@ -0,0 +1,12 @@
import React, { useContext } from "react";
import MasterConfigTree from "./MasterConfigTree";
import PageLayout from "./PageLayout";
export default function SlavesPage() {
return <PageLayout nav={[{ name: "Master" }]}>
<h2>Master</h2>
<MasterConfigTree />
</PageLayout>;
};
@@ -9,6 +9,7 @@ import ErrorPage from "./ErrorPage";
const { Header, Sider } = Layout;
import MasterPage from "./MasterPage";
import SlavesPage from "./SlavesPage";
import InstancesPage from "./InstancesPage";
import InstanceViewPage from "./InstanceViewPage";
@@ -24,6 +25,7 @@ const pages = [
];
const sidebar = [
{ name: "Master", path: "/master", content: <MasterPage /> },
{ name: "Slaves", path: "/slaves", content: <SlavesPage /> },
{ name: "Instances", path: "/instances", content: <InstancesPage />},
{ name: "Users", path: "/users", content: <UsersPage /> },