aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-11-27 13:47:12 -0600
committerGitHub <noreply@github.com>2021-11-27 13:47:12 -0600
commit8d7375bc21e0012490d95f6e06b905fe2b0a4b74 (patch)
tree41e644768a9ac08ebd5074a81e784df79b9b0cf0 /src
parent36e0fc96988d2e37fd7e6b2041c8669cac360496 (diff)
parentde76cbf2b466362cf03fda3b2c52b74d4d96dd10 (diff)
downloadslskd-8d7375bc21e0012490d95f6e06b905fe2b0a4b74.tar.gz
Merge pull request #284 from slskd/config-ui
Tweak System UI
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/API/Controllers/OptionsController.cs8
-rw-r--r--src/web/src/components/Shared/CodeEditor.js (renamed from src/web/src/components/System/Options/CodeEditor.js)0
-rw-r--r--src/web/src/components/System/Info.js27
-rw-r--r--src/web/src/components/System/Options/Edit.js24
-rw-r--r--src/web/src/components/System/Options/View.js11
-rw-r--r--src/web/src/components/System/System.css19
-rw-r--r--src/web/src/components/System/System.js7
-rw-r--r--src/web/src/lib/options.js4
8 files changed, 64 insertions, 36 deletions
diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs
index b4626cb9..60237878 100644
--- a/src/slskd/Core/API/Controllers/OptionsController.cs
+++ b/src/slskd/Core/API/Controllers/OptionsController.cs
@@ -75,6 +75,14 @@ namespace slskd.Core.API
[HttpGet]
[Authorize]
+ [Route("yaml/location")]
+ public IActionResult GetYamlFileLocation()
+ {
+ return Ok(Program.ConfigurationFile);
+ }
+
+ [HttpGet]
+ [Authorize]
[Route("yaml")]
public IActionResult GetYamlFile()
{
diff --git a/src/web/src/components/System/Options/CodeEditor.js b/src/web/src/components/Shared/CodeEditor.js
index 77867a12..77867a12 100644
--- a/src/web/src/components/System/Options/CodeEditor.js
+++ b/src/web/src/components/Shared/CodeEditor.js
diff --git a/src/web/src/components/System/Info.js b/src/web/src/components/System/Info.js
index ee132aec..8d7db123 100644
--- a/src/web/src/components/System/Info.js
+++ b/src/web/src/components/System/Info.js
@@ -1,13 +1,20 @@
-import React, { Component } from 'react';
-
-class Info extends Component {
- render = () => {
- return (
- <div>
- <pre>{JSON.stringify(this.props.state, null, 2)}</pre>
- </div>
- );
- }
+import React from 'react';
+import YAML from 'yaml';
+
+import CodeEditor from '../Shared/CodeEditor';
+
+const Info = ({ state }) => {
+ const stateAsYaml = YAML.stringify(state, { simpleKeys: true, sortMapEntries: true })
+
+ return (
+ <div className='state-code-container'>
+ <CodeEditor
+ value={stateAsYaml}
+ basicSetup={false}
+ editable={false}
+ />
+ </div>
+ );
}
export default Info; \ No newline at end of file
diff --git a/src/web/src/components/System/Options/Edit.js b/src/web/src/components/System/Options/Edit.js
index 0092279a..67739c98 100644
--- a/src/web/src/components/System/Options/Edit.js
+++ b/src/web/src/components/System/Options/Edit.js
@@ -1,14 +1,14 @@
import React, { useState, useEffect } from 'react';
import { Button, Icon, Message } from 'semantic-ui-react';
-import CodeEditor from './CodeEditor';
+import CodeEditor from '../../Shared/CodeEditor';
-import { getYaml, validateYaml, updateYaml } from '../../../lib/options';
+import { getYamlLocation, getYaml, validateYaml, updateYaml } from '../../../lib/options';
import PlaceholderSegment from '../../Shared/PlaceholderSegment';
-const Edit = ({ cancelAction }) => {
+const Edit = ({ filename, cancelAction }) => {
const [{ loading, error }, setLoading] = useState({ loading: true, error: false });
- const [{ yaml, isDirty }, setYaml] = useState({ yaml: undefined, isDirty: false });
+ const [{ location, yaml, isDirty }, setYaml] = useState({ location: undefined, yaml: undefined, isDirty: false });
const [yamlError, setYamlError] = useState();
useEffect(() => {
@@ -19,8 +19,9 @@ const Edit = ({ cancelAction }) => {
setLoading({ loading: true, error: false });
try {
- const yaml = await getYaml();
- setYaml({ yaml: yaml, isDirty: false })
+ const [location, yaml] = await Promise.all([getYamlLocation(), getYaml()]);
+
+ setYaml({ location, yaml, isDirty: false })
setLoading({ loading: false, error: false })
} catch (error) {
setLoading({ loading: false, error: error.message })
@@ -28,7 +29,7 @@ const Edit = ({ cancelAction }) => {
}
const update = async (yaml) => {
- setYaml({ yaml, isDirty: true });
+ setYaml({ location, yaml, isDirty: true });
validate(yaml);
}
@@ -56,16 +57,19 @@ const Edit = ({ cancelAction }) => {
return (
<>
+ <Message warning>
+ <Icon name='warning sign'/>Editing {location}
+ </Message>
<div
- className='code-container'
- style={{height: yamlError ? 'calc(100vh - 316px)' : undefined}}
+ {...{ className: yamlError ? 'edit-code-container-error' : 'edit-code-container' }}
+ //style={{height: yamlError ? 'calc(100vh - 316px)' : undefined}}
>
<CodeEditor
value={yaml}
onChange={(value) => update(value)}
/>
</div>
- {yamlError && <Message className='yaml-error' icon='x' negative>{yamlError}</Message>}
+ {yamlError && <Message className='yaml-error' negative><Icon name='x'/>{yamlError}</Message>}
<div className='footer-buttons'>
<Button primary disabled={!isDirty} onClick={() => save(yaml)}><Icon name='save'/>Save</Button>
<Button onClick={() => cancelAction()}><Icon name='close'/>Cancel</Button>
diff --git a/src/web/src/components/System/Options/View.js b/src/web/src/components/System/Options/View.js
index 61651f8d..83b24a88 100644
--- a/src/web/src/components/System/Options/View.js
+++ b/src/web/src/components/System/Options/View.js
@@ -1,20 +1,17 @@
import React from 'react';
-import yaml from 'yaml';
+import YAML from 'yaml';
import { Icon, Button } from 'semantic-ui-react';
-import CodeEditor from './CodeEditor';
+import CodeEditor from '../../Shared/CodeEditor';
const View = ({ options, editAction }) => {
const { remoteConfiguration } = options;
- const doc = new yaml.Document();
- doc.contents = options;
-
- const optionsAsYaml = doc.toString();
+ const optionsAsYaml = YAML.stringify(options, { simpleKeys: true, sortMapEntries: true })
return (
<>
- <div className='code-container'>
+ <div className='view-code-container'>
<CodeEditor
value={optionsAsYaml}
basicSetup={false}
diff --git a/src/web/src/components/System/System.css b/src/web/src/components/System/System.css
index 23f05221..1e9c4a5d 100644
--- a/src/web/src/components/System/System.css
+++ b/src/web/src/components/System/System.css
@@ -38,8 +38,23 @@
text-align: right;
}
-.code-container {
+.state-code-editor, .view-code-container, .edit-code-container, .edit-code-container-error {
border: 1px solid #d4d4d5;
overflow: auto;
- height: calc(100vh - 254px);
+}
+
+.state-code-container {
+ height: calc(100vh - 204px);
+}
+
+.view-code-container {
+ height: calc(100vh - 254px);
+}
+
+.edit-code-container {
+ height: calc(100vh - 316px);
+}
+
+.edit-code-container-error {
+ height: calc(100vh - 378px);
} \ No newline at end of file
diff --git a/src/web/src/components/System/System.js b/src/web/src/components/System/System.js
index 08253c7a..8b0ea4d4 100644
--- a/src/web/src/components/System/System.js
+++ b/src/web/src/components/System/System.js
@@ -6,13 +6,6 @@ import Logs from './Logs';
import Options from './Options';
class System extends Component {
- componentDidMount = () => {
- }
-
- componentWillUnmount = () => {
-
- }
-
render = () => {
return (
<div className='system'>
diff --git a/src/web/src/lib/options.js b/src/web/src/lib/options.js
index e299996d..da198bd8 100644
--- a/src/web/src/lib/options.js
+++ b/src/web/src/lib/options.js
@@ -8,6 +8,10 @@ export const getYaml = async () => {
return (await api.get('/options/yaml')).data;
};
+export const getYamlLocation = async () => {
+ return (await api.get('/options/yaml/location')).data;
+}
+
export const validateYaml = async ({ yaml }) => {
return (await api.post('/options/yaml/validate', yaml)).data;
};