Add check config changes during WebUI
This commit is contained in:
+28
-25
@@ -29,38 +29,41 @@
|
|||||||
<br>
|
<br>
|
||||||
<div id="config"></div>
|
<div id="config"></div>
|
||||||
<script>
|
<script>
|
||||||
|
let dump;
|
||||||
|
|
||||||
ace.config.set('basePath', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.24.1/');
|
ace.config.set('basePath', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.24.1/');
|
||||||
const editor = ace.edit('config', {
|
const editor = ace.edit('config', {
|
||||||
mode: 'ace/mode/yaml',
|
mode: 'ace/mode/yaml',
|
||||||
});
|
});
|
||||||
|
|
||||||
document.getElementById('save').addEventListener('click', () => {
|
document.getElementById('save').addEventListener('click', async () => {
|
||||||
fetch('api/config', {
|
let r = await fetch('api/config', {cache: 'no-cache'});
|
||||||
method: 'POST', body: editor.getValue()
|
if (r.ok && dump !== await r.text()) {
|
||||||
}).then(r => {
|
alert('Config was changed from another place. Refresh the page and make changes again');
|
||||||
if (r.ok) {
|
return;
|
||||||
alert('OK');
|
}
|
||||||
fetch('api/exit?code=100', {method: 'POST'});
|
|
||||||
} else {
|
r = await fetch('api/config', {method: 'POST', body: editor.getValue()});
|
||||||
r.text().then(alert);
|
if (r.ok) {
|
||||||
}
|
alert('OK');
|
||||||
});
|
fetch('api/exit?code=100', {method: 'POST'});
|
||||||
|
} else {
|
||||||
|
alert(await r.text());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
window.addEventListener('load', () => {
|
window.addEventListener('load', async () => {
|
||||||
fetch('api/config', {cache: 'no-cache'}).then(r => {
|
const r = await fetch('api/config', {cache: 'no-cache'});
|
||||||
if (r.status === 410) {
|
if (r.status === 410) {
|
||||||
alert('Config file is not set');
|
alert('Config file is not set');
|
||||||
} else if (r.status === 404) {
|
} else if (r.status === 404) {
|
||||||
editor.setValue(''); // config file not exist
|
editor.setValue(''); // config file not exist
|
||||||
} else if (r.ok) {
|
} else if (r.ok) {
|
||||||
r.text().then(data => {
|
dump = await r.text();
|
||||||
editor.setValue(data);
|
editor.setValue(dump);
|
||||||
});
|
} else {
|
||||||
} else {
|
alert(`Unknown error: ${r.statusText} (${r.status})`);
|
||||||
alert(`Unknown error: ${r.statusText} (${r.status})`);
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user