Logger is half functional

This commit is contained in:
Tamius Han 2020-02-05 00:39:16 +01:00
parent 179614bd85
commit 435f2890c4

View File

@ -24,29 +24,41 @@
<!-- LOGGER SETTINGS PANEL --> <!-- LOGGER SETTINGS PANEL -->
<div class="settings-panel flex flex-noshrink flex-column"> <div class="settings-panel flex flex-noshrink flex-column">
<div class="panel-top"> <div class="panel-top flex-nogrow">
<h2>Logger configuration</h2> <h2>Logger configuration</h2>
<p>Paste logger configuration in this box</p> <p>Paste logger configuration in this box</p>
</div> </div>
<div class="panel-middle"> <div class="panel-middle scrollable flex-grow p-t-025em">
<div ref="settingsEditArea" <div ref="settingsEditArea"
style="white-space: pre-wrap; border: 1px solid orange; padding: 10px;" style="white-space: pre-wrap; border: 1px solid orange; padding: 10px;"
class="monospace" class="monospace h100"
:class="{'jsonbg': !confHasError, 'jsonbg-error': confHasError}" :class="{'jsonbg': !confHasError, 'jsonbg-error': confHasError}"
contenteditable="true" contenteditable="true"
@input="updateSettings" @input="updateSettings"
>{{parsedSettings}}</div> >
{{parsedSettings}}
</div>
</div>
<div class="flex-noshrink flex flex-row flex-cross-center p-t-025em">
<div class="button button-bar"
@click="restoreLoggerSettings()"
>
Revert logger config
</div>
</div> </div>
</div> </div>
<!-- LOGGER OUTPUT/START LOGGING --> <!-- LOGGER OUTPUT/START LOGGING -->
<div class="results-panel flex flex-shrink flex-column overflow-hidden"> <div class="results-panel flex flex-shrink flex-column overflow-hidden">
<div class="panel-top"> <div class="panel-top flex-nogrow">
<h2>Logger results</h2> <h2>Logger results</h2>
</div> </div>
<template v-if="logStringified"> <template v-if="logStringified">
<div class="panel-middle scrollable flex-grow"> <div v-if="confHasError" class="warn">
Logger configuration contains an error. You can export current log, but you will be unable to record a new log.
</div>
<div class="panel-middle scrollable flex-grow p-t-025em">
<pre> <pre>
{{logStringified}} {{logStringified}}
</pre> </pre>
@ -146,8 +158,7 @@ export default {
this.header = headerRotation[Math.floor(+Date.now() / (3600000*24)) % headerRotation.length] || this.header; this.header = headerRotation[Math.floor(+Date.now() / (3600000*24)) % headerRotation.length] || this.header;
this.lastSettings = await Logger.getConfig() || {}; this.getLoggerSettings();
this.parsedSettings = JSON.stringify(this.lastSettings, null, 2) || '';
}, },
computed: { computed: {
...mapState([ ...mapState([
@ -165,21 +176,30 @@ export default {
async showLogger(newValue) { async showLogger(newValue) {
this.showLoggerUi = newValue; this.showLoggerUi = newValue;
// update logger settings // update logger settings (they could have changed while the popup was closed)
if (newValue) { if (newValue) {
this.lastSettings = await Logger.getConfig() || {}; this.getLoggerSettings();
} }
} }
}, },
methods: { methods: {
async getLoggerSettings() {
this.lastSettings = await Logger.getConfig() || {};
this.parsedSettings = JSON.stringify(this.lastSettings, null, 2) || '';
},
updateSettings(val) { updateSettings(val) {
try { try {
// this.settings.active = JSON.parse(val.target.textContent); this.parsedSettings = JSON.stringify(JSON.parse(val.target.textContent.trim()), null, 2);
// this.lastSettings = JSON.parse(val.target.textContent.trim());
this.confHasError = false; this.confHasError = false;
} catch (e) { } catch (e) {
this.confHasError = true; this.confHasError = true;
} }
}, },
restoreLoggerSettings() {
this.parsedSettings = JSON.stringify(this.lastSettings, null, 2);
this.confHasError = false;
},
async startLogging(){ async startLogging(){
this.logStringified = undefined; this.logStringified = undefined;
await Logger.saveConfig({...this.lastSettings, allowLogging: true}); await Logger.saveConfig({...this.lastSettings, allowLogging: true});
@ -200,6 +220,7 @@ export default {
}, },
stopLogging() { stopLogging() {
Logger.saveConfig({...this.lastSettings, allowLogging: false}); Logger.saveConfig({...this.lastSettings, allowLogging: false});
this.lastSettings.allowLogging = false;
}, },
exportLog() { exportLog() {
IO.csStringToFile(this.logStringified); IO.csStringToFile(this.logStringified);
@ -337,4 +358,11 @@ pre {
padding-right: 1em; padding-right: 1em;
} }
.jsonbg {
background-color: #131313;
}
.jsonbg-error {
background-color: #884420;
}
</style> </style>