mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 16:23:12 +09:00
Use consistent semi-colon placment
Add semicolons to web interface code to be consistent with project standard.
This commit is contained in:
1 parent
8dce1dd0fd
commit
03b7d22ba6
17 files changed
+296
-296
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
// Calculate basedir of application based on current location and
|
// Calculate basedir of application based on current location and
|
||||||
// the provided web_root from master server.
|
// the provided web_root from master server.
|
||||||
const location = new URL(window.web_root, document.location)
|
const location = new URL(window.web_root, document.location);
|
||||||
const basename = location.pathname !== "/" ? location.pathname : "";
|
const basename = location.pathname !== "/" ? location.pathname : "";
|
||||||
|
|
||||||
export default basename;
|
export default basename;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Collapse, Row, Col, Modal, Table, Form, Input, Button, Popover } from "antd";
|
import { Collapse, Row, Col, Modal, Table, Form, Input, Button, Popover } from "antd";
|
||||||
import PlusOutlined from "@ant-design/icons/PlusOutlined"
|
import PlusOutlined from "@ant-design/icons/PlusOutlined";
|
||||||
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
||||||
|
|
||||||
import notify from "../util/notify";
|
import notify from "../util/notify";
|
||||||
@@ -21,7 +21,7 @@ const { Panel } = Collapse;
|
|||||||
class DataTable extends Component {
|
class DataTable extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
if (!this.props.DataFunction) throw new Error("DataFunction not defined")
|
if (!this.props.DataFunction) throw new Error("DataFunction not defined");
|
||||||
this.state = {
|
this.state = {
|
||||||
pagination: {
|
pagination: {
|
||||||
pageSize: 100,
|
pageSize: 100,
|
||||||
@@ -32,11 +32,11 @@ class DataTable extends Component {
|
|||||||
tableData: [],
|
tableData: [],
|
||||||
showEditModal: false,
|
showEditModal: false,
|
||||||
record: {},
|
record: {},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.getData()
|
this.getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
async getData(pagination, filters, sorter) {
|
async getData(pagination, filters, sorter) {
|
||||||
@@ -51,12 +51,12 @@ class DataTable extends Component {
|
|||||||
}
|
}
|
||||||
sorter = {}
|
sorter = {}
|
||||||
*/
|
*/
|
||||||
pagination = pagination || this.state.pagination
|
pagination = pagination || this.state.pagination;
|
||||||
filters = filters || this.state.filters
|
filters = filters || this.state.filters;
|
||||||
sorter = sorter || this.state.sorter
|
sorter = sorter || this.state.sorter;
|
||||||
// console.log(pagination, filters, sorter)
|
// console.log(pagination, filters, sorter)
|
||||||
|
|
||||||
let data = await this.props.DataFunction()
|
let data = await this.props.DataFunction();
|
||||||
// await fetchApi(this.state.dataUrl, "post", {
|
// await fetchApi(this.state.dataUrl, "post", {
|
||||||
// database: this.props.Database,
|
// database: this.props.Database,
|
||||||
// table: this.props.Table,
|
// table: this.props.Table,
|
||||||
@@ -66,14 +66,14 @@ class DataTable extends Component {
|
|||||||
// sorter,
|
// sorter,
|
||||||
// recordIdField: this.props.RecordIdField || "Id", // Sort by this
|
// recordIdField: this.props.RecordIdField || "Id", // Sort by this
|
||||||
// })
|
// })
|
||||||
console.log(data)
|
console.log(data);
|
||||||
data = data || {}
|
data = data || {};
|
||||||
this.setState({
|
this.setState({
|
||||||
tableData: this.props.CustomDataFilterFunction ? this.props.CustomDataFilterFunction(data) : data,
|
tableData: this.props.CustomDataFilterFunction ? this.props.CustomDataFilterFunction(data) : data,
|
||||||
pagination: { ...pagination, ...data.pagination },
|
pagination: { ...pagination, ...data.pagination },
|
||||||
sorter,
|
sorter,
|
||||||
filters,
|
filters,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showEditModal(record, index) {
|
showEditModal(record, index) {
|
||||||
@@ -81,40 +81,40 @@ class DataTable extends Component {
|
|||||||
this.setState({
|
this.setState({
|
||||||
record: record,
|
record: record,
|
||||||
showEditModal: true,
|
showEditModal: true,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
hideEditModal() {
|
hideEditModal() {
|
||||||
this.setState({
|
this.setState({
|
||||||
showEditModal: false,
|
showEditModal: false,
|
||||||
inserting: false,
|
inserting: false,
|
||||||
record: {}
|
record: {}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
async onEditFinish(values) {
|
async onEditFinish(values) {
|
||||||
console.log("Finished editing", values)
|
console.log("Finished editing", values);
|
||||||
|
|
||||||
if (this.state.inserting) { // Create new record
|
if (this.state.inserting) { // Create new record
|
||||||
var status = {}
|
var status = {};
|
||||||
await this.props.AddRecord.insert(values)
|
await this.props.AddRecord.insert(values);
|
||||||
} else { // Edit existing record, capable of doing sparse updates
|
} else { // Edit existing record, capable of doing sparse updates
|
||||||
var status = {}
|
var status = {};
|
||||||
await this.props.Editable.insert(values)
|
await this.props.Editable.insert(values);
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
showEditModal: false,
|
showEditModal: false,
|
||||||
inserting: false,
|
inserting: false,
|
||||||
record: {},
|
record: {},
|
||||||
})
|
});
|
||||||
// Force refresh of data
|
// Force refresh of data
|
||||||
this.getData()
|
this.getData();
|
||||||
}
|
}
|
||||||
async deleteRecord(record) {
|
async deleteRecord(record) {
|
||||||
delete record.key
|
delete record.key;
|
||||||
// Delete "null" values as they seem to cause deletes to fail silently when the value is null and field type is float
|
// Delete "null" values as they seem to cause deletes to fail silently when the value is null and field type is float
|
||||||
for (let key in record) {
|
for (let key in record) {
|
||||||
if (record[key] === null) delete record[key]
|
if (record[key] === null) delete record[key];
|
||||||
}
|
}
|
||||||
var status = {}
|
var status = {};
|
||||||
// await fetchApi(`/api/${this.props.Server}/tableData/record`, "delete", {
|
// await fetchApi(`/api/${this.props.Server}/tableData/record`, "delete", {
|
||||||
// database: this.props.Database,
|
// database: this.props.Database,
|
||||||
// table: this.props.Table,
|
// table: this.props.Table,
|
||||||
@@ -122,13 +122,13 @@ class DataTable extends Component {
|
|||||||
// record,
|
// record,
|
||||||
// }, undefined, true)
|
// }, undefined, true)
|
||||||
|
|
||||||
console.log("Deleted record", status)
|
console.log("Deleted record", status);
|
||||||
|
|
||||||
if (status.ok) notify("success", status.msg, "success")
|
if (status.ok) notify("success", status.msg, "success");
|
||||||
if (!status.ok) notify("error", status.msg, "error")
|
if (!status.ok) notify("error", status.msg, "error");
|
||||||
|
|
||||||
// Force refresh of data
|
// Force refresh of data
|
||||||
this.getData()
|
this.getData();
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
let tableProps = {
|
let tableProps = {
|
||||||
@@ -141,31 +141,31 @@ class DataTable extends Component {
|
|||||||
*/
|
*/
|
||||||
let externalOnRow = {
|
let externalOnRow = {
|
||||||
...(this.props.TableProps && this.props.TableProps.onRow && this.props.TableProps.onRow(record, rowIndex)),
|
...(this.props.TableProps && this.props.TableProps.onRow && this.props.TableProps.onRow(record, rowIndex)),
|
||||||
}
|
};
|
||||||
return {
|
return {
|
||||||
onClick: event => {
|
onClick: event => {
|
||||||
if (event.target.type !== "button") {
|
if (event.target.type !== "button") {
|
||||||
console.log("onRow", record, rowIndex)
|
console.log("onRow", record, rowIndex);
|
||||||
if (this.props.Editable) this.showEditModal(record, rowIndex)
|
if (this.props.Editable) this.showEditModal(record, rowIndex);
|
||||||
if (externalOnRow.onClick) externalOnRow.onClick(event)
|
if (externalOnRow.onClick) externalOnRow.onClick(event);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onDoubleClick: event => {
|
onDoubleClick: event => {
|
||||||
if (externalOnRow.onDoubleClick) externalOnRow.onDoubleClick(event)
|
if (externalOnRow.onDoubleClick) externalOnRow.onDoubleClick(event);
|
||||||
},
|
},
|
||||||
onContextMenu: event => {
|
onContextMenu: event => {
|
||||||
if (externalOnRow.onContextMenu) externalOnRow.onContextMenu(event)
|
if (externalOnRow.onContextMenu) externalOnRow.onContextMenu(event);
|
||||||
},
|
},
|
||||||
onMouseEnter: event => {
|
onMouseEnter: event => {
|
||||||
if (externalOnRow.onMouseEnter) externalOnRow.onMouseEnter(event)
|
if (externalOnRow.onMouseEnter) externalOnRow.onMouseEnter(event);
|
||||||
},
|
},
|
||||||
onMouseLeave: event => {
|
onMouseLeave: event => {
|
||||||
if (externalOnRow.onMouseLeave) externalOnRow.onMouseLeave(event)
|
if (externalOnRow.onMouseLeave) externalOnRow.onMouseLeave(event);
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
let columns = this.props.columns || this.inferColumns(this.state.tableData)
|
let columns = this.props.columns || this.inferColumns(this.state.tableData);
|
||||||
if (this.props.DeleteRecord && !columns.find(x => x.dataIndex === "notInUse")) columns.push({
|
if (this.props.DeleteRecord && !columns.find(x => x.dataIndex === "notInUse")) columns.push({
|
||||||
// Add delete button on the right
|
// Add delete button on the right
|
||||||
dataIndex: "notInUse",
|
dataIndex: "notInUse",
|
||||||
@@ -176,7 +176,7 @@ class DataTable extends Component {
|
|||||||
type="primary"
|
type="primary"
|
||||||
danger
|
danger
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
this.deleteRecord(record)
|
this.deleteRecord(record);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Slett permanent
|
Slett permanent
|
||||||
@@ -188,7 +188,7 @@ class DataTable extends Component {
|
|||||||
<DeleteOutlined />
|
<DeleteOutlined />
|
||||||
</Button>
|
</Button>
|
||||||
</Popover>
|
</Popover>
|
||||||
})
|
});
|
||||||
|
|
||||||
return <>
|
return <>
|
||||||
<Row>
|
<Row>
|
||||||
@@ -207,7 +207,7 @@ class DataTable extends Component {
|
|||||||
return {
|
return {
|
||||||
...x, // Add a 4th parameter to the stock render function with all of our table data
|
...x, // Add a 4th parameter to the stock render function with all of our table data
|
||||||
render: x.render ? (...originalParams) => x.render(...originalParams, this.state.tableData) : undefined
|
render: x.render ? (...originalParams) => x.render(...originalParams, this.state.tableData) : undefined
|
||||||
}
|
};
|
||||||
})}
|
})}
|
||||||
dataSource={this.state.tableData}
|
dataSource={this.state.tableData}
|
||||||
pagination={this.state.pagination.total > 10 ? this.state.pagination : false}
|
pagination={this.state.pagination.total > 10 ? this.state.pagination : false}
|
||||||
@@ -245,12 +245,12 @@ class DataTable extends Component {
|
|||||||
(this.state.inserting && this.props.AddRecord && this.props.AddRecord.fields) // Use externally supplied form input fields
|
(this.state.inserting && this.props.AddRecord && this.props.AddRecord.fields) // Use externally supplied form input fields
|
||||||
|| this.props.columns.filter && this.props.columns.filter(x => x.dataIndex !== "notInUse") // Generate input fields from external columns
|
|| this.props.columns.filter && this.props.columns.filter(x => x.dataIndex !== "notInUse") // Generate input fields from external columns
|
||||||
|| this.inferColumns(this.state.tableData)).map(col => { // Generate input fields from autogenerated columns (only works with existing data)
|
|| this.inferColumns(this.state.tableData)).map(col => { // Generate input fields from autogenerated columns (only works with existing data)
|
||||||
console.log(this.state.record)
|
console.log(this.state.record);
|
||||||
return <Form.Item key={col.dataIndex} label={col.title} name={col.dataIndex}>
|
return <Form.Item key={col.dataIndex} label={col.title} name={col.dataIndex}>
|
||||||
{col.renderEdit && col.renderEdit(this.state.record[col.dataIndex], this.state.record, undefined /* Non spec compliant, is supposed to be index of record */, this.state.tableData) || <Input
|
{col.renderEdit && col.renderEdit(this.state.record[col.dataIndex], this.state.record, undefined /* Non spec compliant, is supposed to be index of record */, this.state.tableData) || <Input
|
||||||
placeholder={this.state.record[col.dataIndex]}
|
placeholder={this.state.record[col.dataIndex]}
|
||||||
/>}
|
/>}
|
||||||
</Form.Item>
|
</Form.Item>;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
<Form.Item>
|
<Form.Item>
|
||||||
@@ -261,24 +261,24 @@ class DataTable extends Component {
|
|||||||
</Form>}
|
</Form>}
|
||||||
</Modal>
|
</Modal>
|
||||||
</Row>
|
</Row>
|
||||||
</>
|
</>;
|
||||||
}
|
}
|
||||||
inferColumns(data) {
|
inferColumns(data) {
|
||||||
// Look at the data and find columns and how to display them. Can be overridden by props.Columns if more customization is needed
|
// Look at the data and find columns and how to display them. Can be overridden by props.Columns if more customization is needed
|
||||||
let columns = []
|
let columns = [];
|
||||||
data.forEach(row => {
|
data.forEach(row => {
|
||||||
Object.keys(row).filter(x => x !== "key").forEach(key => {
|
Object.keys(row).filter(x => x !== "key").forEach(key => {
|
||||||
let existing = columns.find(col => col.key === key)
|
let existing = columns.find(col => col.key === key);
|
||||||
if (!existing) {
|
if (!existing) {
|
||||||
columns.push({
|
columns.push({
|
||||||
key: key,
|
key: key,
|
||||||
title: key,
|
title: key,
|
||||||
dataIndex: key,
|
dataIndex: key,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
})
|
});
|
||||||
return columns
|
return columns;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import "./index.css"
|
import "./index.css";
|
||||||
|
|
||||||
import React from "react"
|
import React from "react";
|
||||||
import ReactDOM from "react-dom"
|
import ReactDOM from "react-dom";
|
||||||
|
|
||||||
import App from "./components/App";
|
import App from "./components/App";
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { Route, Link, withRouter } from "react-router-dom";
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Dashboard } from "../pages/dashboard";
|
import { Dashboard } from "../pages/dashboard";
|
||||||
import { InstancesTable } from "../pages/instances/instancesTable";
|
import { InstancesTable } from "../pages/instances/instancesTable";
|
||||||
import { SlavesTable } from "../pages/slaves/slavesTable"
|
import { SlavesTable } from "../pages/slaves/slavesTable";
|
||||||
import { UsersTable } from "../pages/users/usersTable";
|
import { UsersTable } from "../pages/users/usersTable";
|
||||||
import { RolesTable } from "../pages/roles/rolesTable";
|
import { RolesTable } from "../pages/roles/rolesTable";
|
||||||
import { PermissionsTable } from "../pages/permissions/permissionsTable";
|
import { PermissionsTable } from "../pages/permissions/permissionsTable";
|
||||||
@@ -35,7 +35,7 @@ class SiteLayout extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onCollapse() {
|
onCollapse() {
|
||||||
this.setState({ collapsed: !this.state.collapsed })
|
this.setState({ collapsed: !this.state.collapsed });
|
||||||
}
|
}
|
||||||
|
|
||||||
titleCase(text) {
|
titleCase(text) {
|
||||||
@@ -44,10 +44,10 @@ class SiteLayout extends Component {
|
|||||||
|
|
||||||
replaceParametersInUrl({ endpoint, params }) {
|
replaceParametersInUrl({ endpoint, params }) {
|
||||||
let path = endpoint;
|
let path = endpoint;
|
||||||
console.log("endpoint", params)
|
console.log("endpoint", params);
|
||||||
Object.keys(params).forEach(key => {
|
Object.keys(params).forEach(key => {
|
||||||
path = path.replace(":" + key, params[key])
|
path = path.replace(":" + key, params[key]);
|
||||||
})
|
});
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, {Component} from "react"
|
import React, {Component} from "react";
|
||||||
|
|
||||||
export class Dashboard extends Component {
|
export class Dashboard extends Component {
|
||||||
constructor(props){
|
constructor(props){
|
||||||
super(props)
|
super(props);
|
||||||
}
|
}
|
||||||
render(){
|
render(){
|
||||||
return <h2>Dashboard</h2>
|
return <h2>Dashboard</h2>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
import { Card, Button, Popover, Select, Divider, Input, Form, Col, Row, Checkbox, Space } from "antd"
|
import { Card, Button, Popover, Select, Divider, Input, Form, Col, Row, Checkbox, Space } from "antd";
|
||||||
import {
|
import {
|
||||||
listSlaves,
|
listSlaves,
|
||||||
listInstances,
|
listInstances,
|
||||||
@@ -12,146 +12,146 @@ import {
|
|||||||
getInstanceConfig,
|
getInstanceConfig,
|
||||||
setInstanceConfigField,
|
setInstanceConfigField,
|
||||||
sendRcon,
|
sendRcon,
|
||||||
} from "../../util/wslink"
|
} from "../../util/wslink";
|
||||||
import DataTable from "../../components/data-table"
|
import DataTable from "../../components/data-table";
|
||||||
import notify from "../../util/notify"
|
import notify from "../../util/notify";
|
||||||
import DeleteOutlined from "@ant-design/icons/DeleteOutlined"
|
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
||||||
import EditOutlined from "@ant-design/icons/EditOutlined"
|
import EditOutlined from "@ant-design/icons/EditOutlined";
|
||||||
import PlusOutlined from "@ant-design/icons/PlusOutlined"
|
import PlusOutlined from "@ant-design/icons/PlusOutlined";
|
||||||
|
|
||||||
const { Option } = Select
|
const { Option } = Select;
|
||||||
|
|
||||||
export class InstanceView extends Component {
|
export class InstanceView extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
instance: {},
|
instance: {},
|
||||||
slaves: [],
|
slaves: [],
|
||||||
logLines: [{ message: "Logviewer. Follows the latest logs if you scroll to the bottom. Does not store logs past the lifetime of this tab" }],
|
logLines: [{ message: "Logviewer. Follows the latest logs if you scroll to the bottom. Does not store logs past the lifetime of this tab" }],
|
||||||
}
|
};
|
||||||
this.messagesEndRef = React.createRef()
|
this.messagesEndRef = React.createRef();
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
}
|
}
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
let id = this.props.match.params.id
|
let id = this.props.match.params.id;
|
||||||
|
|
||||||
await this.getData()
|
await this.getData();
|
||||||
|
|
||||||
await setInstanceOutputSubscriptions({
|
await setInstanceOutputSubscriptions({
|
||||||
instance_id: Number(id),
|
instance_id: Number(id),
|
||||||
})
|
});
|
||||||
window.instanceOutputEventHandler = ({ instance_id, output }) => {
|
window.instanceOutputEventHandler = ({ instance_id, output }) => {
|
||||||
if (instance_id === Number(id)) {
|
if (instance_id === Number(id)) {
|
||||||
this.setState({
|
this.setState({
|
||||||
logLines: [...this.state.logLines, output],
|
logLines: [...this.state.logLines, output],
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
// Automatically scroll to bottom on new line.
|
// Automatically scroll to bottom on new line.
|
||||||
// this.messagesEndRef.current.scrollIntoView({ behavior: 'smooth' })
|
// this.messagesEndRef.current.scrollIntoView({ behavior: 'smooth' })
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
async getData() {
|
async getData() {
|
||||||
let id = this.props.match.params.id
|
let id = this.props.match.params.id;
|
||||||
|
|
||||||
let instances = await listInstances()
|
let instances = await listInstances();
|
||||||
let slaves = await listSlaves()
|
let slaves = await listSlaves();
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
instance: instances.find(x => x.id === Number(id)),
|
instance: instances.find(x => x.id === Number(id)),
|
||||||
slaves,
|
slaves,
|
||||||
})
|
});
|
||||||
|
|
||||||
let config = await getInstanceConfig({ instance_id: Number(id) })
|
let config = await getInstanceConfig({ instance_id: Number(id) });
|
||||||
console.log(config)
|
console.log(config);
|
||||||
this.setState({
|
this.setState({
|
||||||
config
|
config
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
async start() {
|
async start() {
|
||||||
this.setState({
|
this.setState({
|
||||||
starting: true,
|
starting: true,
|
||||||
})
|
});
|
||||||
try {
|
try {
|
||||||
await startInstance({
|
await startInstance({
|
||||||
instance_id: this.state.instance.id,
|
instance_id: this.state.instance.id,
|
||||||
save: null,
|
save: null,
|
||||||
})
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify("Error starting instance", "error", e.message)
|
notify("Error starting instance", "error", e.message);
|
||||||
return this.setState({
|
return this.setState({
|
||||||
starting: false,
|
starting: false,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
notify("Instance started")
|
notify("Instance started");
|
||||||
this.setState({
|
this.setState({
|
||||||
starting: false,
|
starting: false,
|
||||||
})
|
});
|
||||||
this.getData()
|
this.getData();
|
||||||
}
|
}
|
||||||
async stop() {
|
async stop() {
|
||||||
this.setState({
|
this.setState({
|
||||||
stopping: true,
|
stopping: true,
|
||||||
})
|
});
|
||||||
try {
|
try {
|
||||||
await stopInstance({
|
await stopInstance({
|
||||||
instance_id: this.state.instance.id,
|
instance_id: this.state.instance.id,
|
||||||
})
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify("Error stopping instance", "error", e.message)
|
notify("Error stopping instance", "error", e.message);
|
||||||
return this.setState({
|
return this.setState({
|
||||||
stopping: false,
|
stopping: false,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
notify("Instance stopped")
|
notify("Instance stopped");
|
||||||
this.setState({
|
this.setState({
|
||||||
stopping: false,
|
stopping: false,
|
||||||
})
|
});
|
||||||
this.getData()
|
this.getData();
|
||||||
}
|
}
|
||||||
async createSave() {
|
async createSave() {
|
||||||
this.setState({
|
this.setState({
|
||||||
creatingSave: true,
|
creatingSave: true,
|
||||||
})
|
});
|
||||||
try {
|
try {
|
||||||
await createSave({
|
await createSave({
|
||||||
instance_id: this.state.instance.id,
|
instance_id: this.state.instance.id,
|
||||||
})
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
notify("Error creating save", "error", e.message)
|
notify("Error creating save", "error", e.message);
|
||||||
return this.setState({
|
return this.setState({
|
||||||
creatingSave: false,
|
creatingSave: false,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
notify("Save created", "success")
|
notify("Save created", "success");
|
||||||
this.setState({
|
this.setState({
|
||||||
creatingSave: false,
|
creatingSave: false,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
async onConfigEditFinish(values) {
|
async onConfigEditFinish(values) {
|
||||||
console.log("Completed config edit with", values)
|
console.log("Completed config edit with", values);
|
||||||
for (let k in values) {
|
for (let k in values) {
|
||||||
if (values[k] !== this.getInstanceConfigAsKvObject(this.state.config)[k]) {
|
if (values[k] !== this.getInstanceConfigAsKvObject(this.state.config)[k]) {
|
||||||
let value = values[k]
|
let value = values[k];
|
||||||
if (typeof value === "boolean") value = value.toString()
|
if (typeof value === "boolean") value = value.toString();
|
||||||
console.log("Setting", k, value)
|
console.log("Setting", k, value);
|
||||||
await setInstanceConfigField({
|
await setInstanceConfigField({
|
||||||
instance_id: this.state.instance.id,
|
instance_id: this.state.instance.id,
|
||||||
field: k,
|
field: k,
|
||||||
value: value,
|
value: value,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
notify("Set configuration fields", "success")
|
notify("Set configuration fields", "success");
|
||||||
this.setState({
|
this.setState({
|
||||||
editingConfig: false
|
editingConfig: false
|
||||||
})
|
});
|
||||||
this.getData()
|
this.getData();
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
console.log(this.state)
|
console.log(this.state);
|
||||||
let { instance, slaves } = this.state
|
let { instance, slaves } = this.state;
|
||||||
let slave = slaves && slaves.find(x => x.id === instance.assigned_slave);
|
let slave = slaves && slaves.find(x => x.id === instance.assigned_slave);
|
||||||
return <Card>
|
return <Card>
|
||||||
<h2>{instance.name}</h2>
|
<h2>{instance.name}</h2>
|
||||||
@@ -184,9 +184,9 @@ export class InstanceView extends Component {
|
|||||||
width: "200px"
|
width: "200px"
|
||||||
}}
|
}}
|
||||||
onChange={async newSlaveId => {
|
onChange={async newSlaveId => {
|
||||||
let result = await assignInstance({ instance_id: instance.id, slave_id: newSlaveId })
|
let result = await assignInstance({ instance_id: instance.id, slave_id: newSlaveId });
|
||||||
notify("Assigned to slave", "success")
|
notify("Assigned to slave", "success");
|
||||||
this.getData()
|
this.getData();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{this.state.slaves.map(slave => <Option defaultValue={instance.assigned_slave} value={slave.id} key={slave.id}>
|
{this.state.slaves.map(slave => <Option defaultValue={instance.assigned_slave} value={slave.id} key={slave.id}>
|
||||||
@@ -208,8 +208,8 @@ export class InstanceView extends Component {
|
|||||||
danger
|
danger
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await deleteInstance({ instance_id: instance.id });
|
await deleteInstance({ instance_id: instance.id });
|
||||||
notify("Deleted instance " + instance.id, "success")
|
notify("Deleted instance " + instance.id, "success");
|
||||||
this.navigate("/instances")
|
this.navigate("/instances");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Delete this instance permanently
|
Delete this instance permanently
|
||||||
@@ -245,7 +245,7 @@ export class InstanceView extends Component {
|
|||||||
{/* rcon input field */}
|
{/* rcon input field */}
|
||||||
<Form
|
<Form
|
||||||
onFinish={async values => {
|
onFinish={async values => {
|
||||||
await sendRcon({ instance_id: instance.id, command: values.command })
|
await sendRcon({ instance_id: instance.id, command: values.command });
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
@@ -256,16 +256,16 @@ export class InstanceView extends Component {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
{this.state.config && this.renderConfig(this.state.config)}
|
{this.state.config && this.renderConfig(this.state.config)}
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
getInstanceConfigAsKvObject(config) {
|
getInstanceConfigAsKvObject(config) {
|
||||||
let object = {}
|
let object = {};
|
||||||
for (let group of config.serialized_config.groups) {
|
for (let group of config.serialized_config.groups) {
|
||||||
for (let fieldName in group.fields) {
|
for (let fieldName in group.fields) {
|
||||||
object[group.name + "." + fieldName] = group.fields[fieldName]
|
object[group.name + "." + fieldName] = group.fields[fieldName];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return object
|
return object;
|
||||||
}
|
}
|
||||||
renderConfig(config) {
|
renderConfig(config) {
|
||||||
const layout = {
|
const layout = {
|
||||||
@@ -316,33 +316,33 @@ export class InstanceView extends Component {
|
|||||||
</>)}
|
</>)}
|
||||||
</Row>
|
</Row>
|
||||||
</Form>
|
</Form>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderDisplayField(value) {
|
function renderDisplayField(value) {
|
||||||
if (typeof value === "object") {
|
if (typeof value === "object") {
|
||||||
return JSON.stringify(value)
|
return JSON.stringify(value);
|
||||||
}
|
}
|
||||||
if (typeof value === "boolean") {
|
if (typeof value === "boolean") {
|
||||||
return <Checkbox />
|
return <Checkbox />;
|
||||||
}
|
}
|
||||||
return value.toString()
|
return value.toString();
|
||||||
}
|
}
|
||||||
function renderFormField(value) {
|
function renderFormField(value) {
|
||||||
if (typeof value === "object") {
|
if (typeof value === "object") {
|
||||||
return <ObjectInput />
|
return <ObjectInput />;
|
||||||
}
|
}
|
||||||
if (typeof value === "boolean") {
|
if (typeof value === "boolean") {
|
||||||
return <Checkbox />
|
return <Checkbox />;
|
||||||
}
|
}
|
||||||
return <Input />
|
return <Input />;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ObjectInput extends Component {
|
class ObjectInput extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
console.log(this.props)
|
console.log(this.props);
|
||||||
/*
|
/*
|
||||||
value: {
|
value: {
|
||||||
auto_pause: false,
|
auto_pause: false,
|
||||||
@@ -351,26 +351,26 @@ class ObjectInput extends Component {
|
|||||||
id: "factorio.settings",
|
id: "factorio.settings",
|
||||||
onChange: f()
|
onChange: f()
|
||||||
*/
|
*/
|
||||||
this.state = {}
|
this.state = {};
|
||||||
}
|
}
|
||||||
onChange(e, key) {
|
onChange(e, key) {
|
||||||
if (e.target.type === "checkbox") {
|
if (e.target.type === "checkbox") {
|
||||||
// if (e.target.checked !== undefined) {
|
// if (e.target.checked !== undefined) {
|
||||||
// Its a checkbox, set value to true/false
|
// Its a checkbox, set value to true/false
|
||||||
let value = { ...this.props.value }
|
let value = { ...this.props.value };
|
||||||
value[key] = e.target.checked || false
|
value[key] = e.target.checked || false;
|
||||||
this.props.onChange(value)
|
this.props.onChange(value);
|
||||||
} else if (e.target.type === "text") {
|
} else if (e.target.type === "text") {
|
||||||
// } else if (e.target.value !== undefined) {
|
// } else if (e.target.value !== undefined) {
|
||||||
// its probably a text input
|
// its probably a text input
|
||||||
let value = { ...this.props.value }
|
let value = { ...this.props.value };
|
||||||
value[key] = e.target.value || ""
|
value[key] = e.target.value || "";
|
||||||
this.props.onChange(value)
|
this.props.onChange(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
let { value } = this.props
|
let { value } = this.props;
|
||||||
let ret = []
|
let ret = [];
|
||||||
for (let key in value) {
|
for (let key in value) {
|
||||||
if (typeof value[key] === "boolean") {
|
if (typeof value[key] === "boolean") {
|
||||||
ret.push(<Checkbox
|
ret.push(<Checkbox
|
||||||
@@ -380,7 +380,7 @@ class ObjectInput extends Component {
|
|||||||
>
|
>
|
||||||
{key}
|
{key}
|
||||||
</Checkbox>
|
</Checkbox>
|
||||||
)
|
);
|
||||||
} else if (typeof value[key] === "string") {
|
} else if (typeof value[key] === "string") {
|
||||||
ret.push(<div
|
ret.push(<div
|
||||||
key={key}
|
key={key}
|
||||||
@@ -388,7 +388,7 @@ class ObjectInput extends Component {
|
|||||||
value={value[key]}
|
value={value[key]}
|
||||||
onChange={e => this.onChange(e, key)}
|
onChange={e => this.onChange(e, key)}
|
||||||
/></div>
|
/></div>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ret.push(<Popover
|
ret.push(<Popover
|
||||||
@@ -397,11 +397,11 @@ class ObjectInput extends Component {
|
|||||||
<Input onChange={e => this.setState({ newInput: e.target.value })} />
|
<Input onChange={e => this.setState({ newInput: e.target.value })} />
|
||||||
<Button
|
<Button
|
||||||
onClick={e => {
|
onClick={e => {
|
||||||
this.onChange({ target: { value: "", type: "text" } }, this.state.newInput)
|
this.onChange({ target: { value: "", type: "text" } }, this.state.newInput);
|
||||||
this.setState({
|
this.setState({
|
||||||
newInput: undefined,
|
newInput: undefined,
|
||||||
addPopoverVisible: false,
|
addPopoverVisible: false,
|
||||||
})
|
});
|
||||||
}}
|
}}
|
||||||
><PlusOutlined />Add property</Button>
|
><PlusOutlined />Add property</Button>
|
||||||
</>}
|
</>}
|
||||||
@@ -414,16 +414,16 @@ class ObjectInput extends Component {
|
|||||||
>
|
>
|
||||||
<PlusOutlined />Add property
|
<PlusOutlined />Add property
|
||||||
</Button>
|
</Button>
|
||||||
</Popover>)
|
</Popover>);
|
||||||
return <Space direction="vertical">{ret}</Space>
|
return <Space direction="vertical">{ret}</Space>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class ConfigFormItem extends Component {
|
class ConfigFormItem extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
let { field, group, editingConfig } = this.props
|
let { field, group, editingConfig } = this.props;
|
||||||
return <Form.Item
|
return <Form.Item
|
||||||
label={field}
|
label={field}
|
||||||
name={group.name + "." + field}
|
name={group.name + "." + field}
|
||||||
@@ -434,6 +434,6 @@ class ConfigFormItem extends Component {
|
|||||||
:
|
:
|
||||||
renderDisplayField(group.fields[field])
|
renderDisplayField(group.fields[field])
|
||||||
}
|
}
|
||||||
</Form.Item>
|
</Form.Item>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
import { Card } from "antd"
|
import { Card } from "antd";
|
||||||
import { listSlaves, listInstances, createInstance } from "../../util/wslink"
|
import { listSlaves, listInstances, createInstance } from "../../util/wslink";
|
||||||
import DataTable from "../../components/data-table"
|
import DataTable from "../../components/data-table";
|
||||||
const config = require("@clusterio/lib/config")
|
const config = require("@clusterio/lib/config");
|
||||||
|
|
||||||
export class InstancesTable extends Component {
|
export class InstancesTable extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
@@ -23,11 +23,11 @@ export class InstancesTable extends Component {
|
|||||||
insert: async args => {
|
insert: async args => {
|
||||||
let instanceConfig = new config.InstanceConfig();
|
let instanceConfig = new config.InstanceConfig();
|
||||||
await instanceConfig.init();
|
await instanceConfig.init();
|
||||||
console.log("Base config", instanceConfig)
|
console.log("Base config", instanceConfig);
|
||||||
instanceConfig.set("instance.name", args.name);
|
instanceConfig.set("instance.name", args.name);
|
||||||
let serialized_config = instanceConfig.serialize();
|
let serialized_config = instanceConfig.serialize();
|
||||||
let response = await createInstance(serialized_config)
|
let response = await createInstance(serialized_config);
|
||||||
console.log("Created instance", response)
|
console.log("Created instance", response);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
DataFunction={listInstances}
|
DataFunction={listInstances}
|
||||||
@@ -35,12 +35,12 @@ export class InstancesTable extends Component {
|
|||||||
onRow: (record, rowIndex) => {
|
onRow: (record, rowIndex) => {
|
||||||
return {
|
return {
|
||||||
onClick: event => {
|
onClick: event => {
|
||||||
this.navigate(`/instances/${record.id}/view`)
|
this.navigate(`/instances/${record.id}/view`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
import { Card } from "antd"
|
import { Card } from "antd";
|
||||||
import { listSlaves, listInstances, listPermissions } from "../../util/wslink"
|
import { listSlaves, listInstances, listPermissions } from "../../util/wslink";
|
||||||
import DataTable from "../../components/data-table"
|
import DataTable from "../../components/data-table";
|
||||||
|
|
||||||
export class PermissionsTable extends Component {
|
export class PermissionsTable extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
@@ -19,12 +19,12 @@ export class PermissionsTable extends Component {
|
|||||||
onRow: (record, rowIndex) => {
|
onRow: (record, rowIndex) => {
|
||||||
return {
|
return {
|
||||||
onClick: event => {
|
onClick: event => {
|
||||||
this.navigate(`/permissions/${record.id}/view`)
|
this.navigate(`/permissions/${record.id}/view`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
|
|
||||||
import { Card, Button, Popover, Select, Transfer } from "antd"
|
import { Card, Button, Popover, Select, Transfer } from "antd";
|
||||||
import DeleteOutlined from "@ant-design/icons/DeleteOutlined"
|
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
||||||
|
|
||||||
import {
|
import {
|
||||||
listSlaves,
|
listSlaves,
|
||||||
@@ -21,36 +21,36 @@ import {
|
|||||||
setRoles,
|
setRoles,
|
||||||
listPermissions,
|
listPermissions,
|
||||||
updateRole,
|
updateRole,
|
||||||
} from "../../util/wslink"
|
} from "../../util/wslink";
|
||||||
import DataTable from "../../components/data-table"
|
import DataTable from "../../components/data-table";
|
||||||
import notify from "../../util/notify"
|
import notify from "../../util/notify";
|
||||||
|
|
||||||
const { Option } = Select
|
const { Option } = Select;
|
||||||
|
|
||||||
export class RoleView extends Component {
|
export class RoleView extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
role: {}
|
role: {}
|
||||||
}
|
};
|
||||||
this.messagesEndRef = React.createRef()
|
this.messagesEndRef = React.createRef();
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
}
|
}
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
await this.getData()
|
await this.getData();
|
||||||
}
|
}
|
||||||
async getData() {
|
async getData() {
|
||||||
let id = this.props.match.params.id
|
let id = this.props.match.params.id;
|
||||||
|
|
||||||
let roles = await listRoles()
|
let roles = await listRoles();
|
||||||
let permissions = await listPermissions()
|
let permissions = await listPermissions();
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
role: roles.find(x => x.id === Number(id)),
|
role: roles.find(x => x.id === Number(id)),
|
||||||
permissions,
|
permissions,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
async handleChange(targetKeys) {
|
async handleChange(targetKeys) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -62,12 +62,12 @@ export class RoleView extends Component {
|
|||||||
let response = await updateRole({
|
let response = await updateRole({
|
||||||
...this.state.role,
|
...this.state.role,
|
||||||
permissions: targetKeys,
|
permissions: targetKeys,
|
||||||
})
|
});
|
||||||
console.log("Updated user roles", response)
|
console.log("Updated user roles", response);
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
console.log(this.state)
|
console.log(this.state);
|
||||||
let { role, permissions } = this.state
|
let { role, permissions } = this.state;
|
||||||
return <Card>
|
return <Card>
|
||||||
<Popover
|
<Popover
|
||||||
content={
|
content={
|
||||||
@@ -75,9 +75,9 @@ export class RoleView extends Component {
|
|||||||
type="primary"
|
type="primary"
|
||||||
danger
|
danger
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await deleteUser({ role: role.name })
|
await deleteUser({ role: role.name });
|
||||||
notify("Deleted role " + role.name, "success")
|
notify("Deleted role " + role.name, "success");
|
||||||
this.navigate("/roles")
|
this.navigate("/roles");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Delete this role permanently
|
Delete this role permanently
|
||||||
@@ -108,6 +108,6 @@ export class RoleView extends Component {
|
|||||||
onChange={this.handleChange.bind(this)}
|
onChange={this.handleChange.bind(this)}
|
||||||
render={item => item.name}
|
render={item => item.name}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
import { Card } from "antd"
|
import { Card } from "antd";
|
||||||
import { listSlaves, listInstances, listRoles, createRole } from "../../util/wslink"
|
import { listSlaves, listInstances, listRoles, createRole } from "../../util/wslink";
|
||||||
import DataTable from "../../components/data-table"
|
import DataTable from "../../components/data-table";
|
||||||
|
|
||||||
export class RolesTable extends Component {
|
export class RolesTable extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
@@ -23,8 +23,8 @@ export class RolesTable extends Component {
|
|||||||
title: "Description"
|
title: "Description"
|
||||||
}],
|
}],
|
||||||
insert: async args => {
|
insert: async args => {
|
||||||
let response = await createRole({name: args.name, description: args.description})
|
let response = await createRole({name: args.name, description: args.description});
|
||||||
console.log("Created role",response)
|
console.log("Created role",response);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
DataFunction={listRoles}
|
DataFunction={listRoles}
|
||||||
@@ -32,12 +32,12 @@ export class RolesTable extends Component {
|
|||||||
onRow: (record, rowIndex) => {
|
onRow: (record, rowIndex) => {
|
||||||
return {
|
return {
|
||||||
onClick: event => {
|
onClick: event => {
|
||||||
this.navigate(`/roles/${record.id}/view`)
|
this.navigate(`/roles/${record.id}/view`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
import { Card, Button, Input, Form } from "antd"
|
import { Card, Button, Input, Form } from "antd";
|
||||||
|
|
||||||
const layout = {
|
const layout = {
|
||||||
labelCol: {
|
labelCol: {
|
||||||
@@ -18,16 +18,16 @@ const tailLayout = {
|
|||||||
|
|
||||||
export class Settings extends Component {
|
export class Settings extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
role: {}
|
role: {}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
}
|
}
|
||||||
render() {
|
render() {
|
||||||
console.log(this.state)
|
console.log(this.state);
|
||||||
return <Card>
|
return <Card>
|
||||||
<h2>Web interface settings</h2>
|
<h2>Web interface settings</h2>
|
||||||
<Form
|
<Form
|
||||||
@@ -38,12 +38,12 @@ export class Settings extends Component {
|
|||||||
master_token: localStorage.getItem("master_token"),
|
master_token: localStorage.getItem("master_token"),
|
||||||
}}
|
}}
|
||||||
onFinish={values => {
|
onFinish={values => {
|
||||||
console.log("Saving settings",values)
|
console.log("Saving settings",values);
|
||||||
for(let key of Object.keys(values)){
|
for(let key of Object.keys(values)){
|
||||||
localStorage.setItem(key, values[key].replace("https://", "wss://").replace("http://", "ws://"))
|
localStorage.setItem(key, values[key].replace("https://", "wss://").replace("http://", "ws://"));
|
||||||
}
|
}
|
||||||
// Force refresh to apply changes
|
// Force refresh to apply changes
|
||||||
document.location = document.location
|
document.location = document.location;
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Form.Item
|
<Form.Item
|
||||||
@@ -76,6 +76,6 @@ export class Settings extends Component {
|
|||||||
</Button>
|
</Button>
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
</Form>
|
</Form>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
import { Card } from "antd";
|
import { Card } from "antd";
|
||||||
import { listSlaves, listInstances } from "../../util/wslink"
|
import { listSlaves, listInstances } from "../../util/wslink";
|
||||||
import DataTable from "../../components/data-table"
|
import DataTable from "../../components/data-table";
|
||||||
|
|
||||||
export class SlavesTable extends Component {
|
export class SlavesTable extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
@@ -19,12 +19,12 @@ export class SlavesTable extends Component {
|
|||||||
onRow: (record, rowIndex) => {
|
onRow: (record, rowIndex) => {
|
||||||
return {
|
return {
|
||||||
onClick: event => {
|
onClick: event => {
|
||||||
this.navigate(`/slaves/${record.id}/view`)
|
this.navigate(`/slaves/${record.id}/view`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,41 +1,41 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
import { Card, Button, Popover, Select, Transfer } from "antd";
|
import { Card, Button, Popover, Select, Transfer } from "antd";
|
||||||
import {
|
import {
|
||||||
deleteUser,
|
deleteUser,
|
||||||
listUsers,
|
listUsers,
|
||||||
listRoles,
|
listRoles,
|
||||||
setRoles,
|
setRoles,
|
||||||
} from "../../util/wslink"
|
} from "../../util/wslink";
|
||||||
import DataTable from "../../components/data-table"
|
import DataTable from "../../components/data-table";
|
||||||
import notify from "../../util/notify"
|
import notify from "../../util/notify";
|
||||||
import DeleteOutlined from "@ant-design/icons/DeleteOutlined"
|
import DeleteOutlined from "@ant-design/icons/DeleteOutlined";
|
||||||
|
|
||||||
const { Option } = Select
|
const { Option } = Select;
|
||||||
|
|
||||||
export class UserView extends Component {
|
export class UserView extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
user: {}
|
user: {}
|
||||||
}
|
};
|
||||||
this.messagesEndRef = React.createRef();
|
this.messagesEndRef = React.createRef();
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
}
|
}
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
await this.getData()
|
await this.getData();
|
||||||
}
|
}
|
||||||
async getData() {
|
async getData() {
|
||||||
let name = this.props.match.params.id
|
let name = this.props.match.params.id;
|
||||||
|
|
||||||
let users = await listUsers()
|
let users = await listUsers();
|
||||||
let roles = await listRoles()
|
let roles = await listRoles();
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
user: users.find(x => x.name === name),
|
user: users.find(x => x.name === name),
|
||||||
roles,
|
roles,
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
async handleChange(targetKeys) {
|
async handleChange(targetKeys) {
|
||||||
this.setState({
|
this.setState({
|
||||||
@@ -47,12 +47,12 @@ export class UserView extends Component {
|
|||||||
let response = await setRoles({
|
let response = await setRoles({
|
||||||
name: this.state.user.name,
|
name: this.state.user.name,
|
||||||
roles: targetKeys,
|
roles: targetKeys,
|
||||||
})
|
});
|
||||||
console.log("Updated user roles",response)
|
console.log("Updated user roles",response);
|
||||||
};
|
};
|
||||||
render() {
|
render() {
|
||||||
console.log(this.state)
|
console.log(this.state);
|
||||||
let { user, roles } = this.state
|
let { user, roles } = this.state;
|
||||||
return <Card>
|
return <Card>
|
||||||
<h2>{user.name}</h2>
|
<h2>{user.name}</h2>
|
||||||
<h3>Assign roles</h3>
|
<h3>Assign roles</h3>
|
||||||
@@ -71,9 +71,9 @@ export class UserView extends Component {
|
|||||||
type="primary"
|
type="primary"
|
||||||
danger
|
danger
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
await deleteUser({ name: user.name })
|
await deleteUser({ name: user.name });
|
||||||
notify("Deleted user " + user.name, "success")
|
notify("Deleted user " + user.name, "success");
|
||||||
this.navigate("/users")
|
this.navigate("/users");
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Delete this user from the cluster
|
Delete this user from the cluster
|
||||||
@@ -85,6 +85,6 @@ export class UserView extends Component {
|
|||||||
<DeleteOutlined />
|
<DeleteOutlined />
|
||||||
</Button>
|
</Button>
|
||||||
</Popover>
|
</Popover>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { Component } from "react"
|
import React, { Component } from "react";
|
||||||
import { Card } from "antd"
|
import { Card } from "antd";
|
||||||
import { listSlaves, listInstances, listUsers, createUser } from "../../util/wslink"
|
import { listSlaves, listInstances, listUsers, createUser } from "../../util/wslink";
|
||||||
import DataTable from "../../components/data-table"
|
import DataTable from "../../components/data-table";
|
||||||
|
|
||||||
export class UsersTable extends Component {
|
export class UsersTable extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props);
|
||||||
}
|
}
|
||||||
navigate(url) {
|
navigate(url) {
|
||||||
this.props.history.push(url);
|
this.props.history.push(url);
|
||||||
@@ -20,8 +20,8 @@ export class UsersTable extends Component {
|
|||||||
title: "Name"
|
title: "Name"
|
||||||
}],
|
}],
|
||||||
insert: async args => {
|
insert: async args => {
|
||||||
let response = await createUser({name: args.name})
|
let response = await createUser({name: args.name});
|
||||||
console.log("Created user",response)
|
console.log("Created user",response);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
DataFunction={listUsers}
|
DataFunction={listUsers}
|
||||||
@@ -29,12 +29,12 @@ export class UsersTable extends Component {
|
|||||||
onRow: (record, rowIndex) => {
|
onRow: (record, rowIndex) => {
|
||||||
return {
|
return {
|
||||||
onClick: event => {
|
onClick: event => {
|
||||||
this.navigate(`/users/${record.name}/view`)
|
this.navigate(`/users/${record.name}/view`);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Card>
|
</Card>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,5 +11,5 @@ export default function notify(message, type = "info", description) {
|
|||||||
description,
|
description,
|
||||||
placement: "bottomRight",
|
placement: "bottomRight",
|
||||||
});
|
});
|
||||||
if (typeof message !== "string") console.error(message)
|
if (typeof message !== "string") console.error(message);
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ export class Control extends link.Link {
|
|||||||
async instanceOutputEventHandler(message) {
|
async instanceOutputEventHandler(message) {
|
||||||
let { instance_id, output } = message.data;
|
let { instance_id, output } = message.data;
|
||||||
console.log(formatOutput(output));
|
console.log(formatOutput(output));
|
||||||
window.instanceOutputEventHandler && window.instanceOutputEventHandler({instance_id, output})
|
window.instanceOutputEventHandler && window.instanceOutputEventHandler({instance_id, output});
|
||||||
}
|
}
|
||||||
|
|
||||||
async debugWsMessageEventHandler(message) {
|
async debugWsMessageEventHandler(message) {
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { Control, ControlConnector } from "./../util/websocket"
|
import { Control, ControlConnector } from "./../util/websocket";
|
||||||
import * as errors from "@clusterio/lib/errors"
|
import * as errors from "@clusterio/lib/errors";
|
||||||
import * as link from "@clusterio/lib/link"
|
import * as link from "@clusterio/lib/link";
|
||||||
import config from "@clusterio/lib/config"
|
import config from "@clusterio/lib/config";
|
||||||
|
|
||||||
let control, controlConnector
|
let control, controlConnector;
|
||||||
|
|
||||||
// Create WS connection to master. Used by all components through the interface exported here.
|
// Create WS connection to master. Used by all components through the interface exported here.
|
||||||
(async () => {
|
(async () => {
|
||||||
@@ -17,47 +17,47 @@ let control, controlConnector
|
|||||||
try {
|
try {
|
||||||
await controlConnector.connect();
|
await controlConnector.connect();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log(err)
|
console.log(err);
|
||||||
}
|
}
|
||||||
})()
|
})();
|
||||||
|
|
||||||
let listSlaves = createListFunction("listSlaves")
|
let listSlaves = createListFunction("listSlaves");
|
||||||
let listInstances = createListFunction("listInstances")
|
let listInstances = createListFunction("listInstances");
|
||||||
let listUsers = createListFunction("listUsers", "name")
|
let listUsers = createListFunction("listUsers", "name");
|
||||||
let listRoles = createListFunction("listRoles")
|
let listRoles = createListFunction("listRoles");
|
||||||
let listPermissions = createListFunction("listPermissions", "name")
|
let listPermissions = createListFunction("listPermissions", "name");
|
||||||
|
|
||||||
let startInstance = async function ({ instance_id, save = null }) {
|
let startInstance = async function ({ instance_id, save = null }) {
|
||||||
return await link.messages.startInstance.send(control, { instance_id, save })
|
return await link.messages.startInstance.send(control, { instance_id, save });
|
||||||
}
|
};
|
||||||
let stopInstance = async function ({ instance_id }) {
|
let stopInstance = async function ({ instance_id }) {
|
||||||
return await link.messages.stopInstance.send(control, { instance_id })
|
return await link.messages.stopInstance.send(control, { instance_id });
|
||||||
}
|
};
|
||||||
let createInstance = async function (serialized_config) {
|
let createInstance = async function (serialized_config) {
|
||||||
return await link.messages.createInstance.send(control, { serialized_config });
|
return await link.messages.createInstance.send(control, { serialized_config });
|
||||||
}
|
};
|
||||||
let deleteInstance = async function ({ instance_id }) {
|
let deleteInstance = async function ({ instance_id }) {
|
||||||
return await link.messages.deleteInstance.send(control, { instance_id });
|
return await link.messages.deleteInstance.send(control, { instance_id });
|
||||||
}
|
};
|
||||||
let assignInstance = async function ({ instance_id, slave_id }) {
|
let assignInstance = async function ({ instance_id, slave_id }) {
|
||||||
return await link.messages.assignInstanceCommand.send(control, {
|
return await link.messages.assignInstanceCommand.send(control, {
|
||||||
instance_id,
|
instance_id,
|
||||||
slave_id,
|
slave_id,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
let createSave = async function ({ instance_id }) {
|
let createSave = async function ({ instance_id }) {
|
||||||
return await link.messages.createSave.send(control, { instance_id });
|
return await link.messages.createSave.send(control, { instance_id });
|
||||||
}
|
};
|
||||||
let getInstanceConfig = async function ({ instance_id }) {
|
let getInstanceConfig = async function ({ instance_id }) {
|
||||||
return await link.messages.getInstanceConfig.send(control, { instance_id });
|
return await link.messages.getInstanceConfig.send(control, { instance_id });
|
||||||
}
|
};
|
||||||
let setInstanceConfigField = async function ({ instance_id, field, value }) {
|
let setInstanceConfigField = async function ({ instance_id, field, value }) {
|
||||||
return await link.messages.setInstanceConfigField.send(control, {
|
return await link.messages.setInstanceConfigField.send(control, {
|
||||||
instance_id,
|
instance_id,
|
||||||
field,
|
field,
|
||||||
value: typeof value === "object" ? JSON.stringify(value) : value,
|
value: typeof value === "object" ? JSON.stringify(value) : value,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
let setInstanceConfigProp = async function ({ instance_id, field, prop, value }) {
|
let setInstanceConfigProp = async function ({ instance_id, field, prop, value }) {
|
||||||
return await link.messages.setInstanceConfigProp.send(control, {
|
return await link.messages.setInstanceConfigProp.send(control, {
|
||||||
instance_id,
|
instance_id,
|
||||||
@@ -65,35 +65,35 @@ let setInstanceConfigProp = async function ({ instance_id, field, prop, value })
|
|||||||
prop,
|
prop,
|
||||||
value, // JSON Object
|
value, // JSON Object
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
let sendRcon = async function ({ instance_id, command }) {
|
let sendRcon = async function ({ instance_id, command }) {
|
||||||
return await link.messages.sendRcon.send(control, { instance_id, command })
|
return await link.messages.sendRcon.send(control, { instance_id, command });
|
||||||
}
|
};
|
||||||
let setInstanceOutputSubscriptions = async function ({ instance_id }) {
|
let setInstanceOutputSubscriptions = async function ({ instance_id }) {
|
||||||
return await link.messages.setInstanceOutputSubscriptions.send(control, { instance_ids: [instance_id] })
|
return await link.messages.setInstanceOutputSubscriptions.send(control, { instance_ids: [instance_id] });
|
||||||
}
|
};
|
||||||
|
|
||||||
let createUser = async function ({ name }) {
|
let createUser = async function ({ name }) {
|
||||||
return await link.messages.createUser.send(control, { name })
|
return await link.messages.createUser.send(control, { name });
|
||||||
}
|
};
|
||||||
let deleteUser = async function ({ name }) {
|
let deleteUser = async function ({ name }) {
|
||||||
return await link.messages.deleteUser.send(control, { name })
|
return await link.messages.deleteUser.send(control, { name });
|
||||||
}
|
};
|
||||||
let setRoles = async function ({ name, roles }) {
|
let setRoles = async function ({ name, roles }) {
|
||||||
return await link.messages.updateUserRoles.send(control, {
|
return await link.messages.updateUserRoles.send(control, {
|
||||||
name,
|
name,
|
||||||
roles,
|
roles,
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
let createRole = async function ({ name, description, permissions = [] }) {
|
let createRole = async function ({ name, description, permissions = [] }) {
|
||||||
return await link.messages.createRole.send(control, { name, description, permissions })
|
return await link.messages.createRole.send(control, { name, description, permissions });
|
||||||
}
|
};
|
||||||
let updateRole = async function ({ id, name, description, permissions }) {
|
let updateRole = async function ({ id, name, description, permissions }) {
|
||||||
return await link.messages.updateRole.send(control, {
|
return await link.messages.updateRole.send(control, {
|
||||||
id, name, description, permissions
|
id, name, description, permissions
|
||||||
})
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
listSlaves,
|
listSlaves,
|
||||||
@@ -117,18 +117,18 @@ export {
|
|||||||
setInstanceConfigProp,
|
setInstanceConfigProp,
|
||||||
sendRcon,
|
sendRcon,
|
||||||
setInstanceOutputSubscriptions,
|
setInstanceOutputSubscriptions,
|
||||||
}
|
};
|
||||||
|
|
||||||
function createListFunction(name, key) {
|
function createListFunction(name, key) {
|
||||||
return async () => {
|
return async () => {
|
||||||
return (await link.messages[name].send(control)).list.map(addKey(key || "id"));
|
return (await link.messages[name].send(control)).list.map(addKey(key || "id"));
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
function addKey(key) {
|
function addKey(key) {
|
||||||
return function (el) {
|
return function (el) {
|
||||||
return {
|
return {
|
||||||
...el,
|
...el,
|
||||||
key: el[key]
|
key: el[key]
|
||||||
}
|
};
|
||||||
}
|
};
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user