Refactor log view UI into a component.

This commit is contained in:
Kailash Nadh 2020-10-24 11:42:28 +05:30
parent b054ed5adc
commit 966954d8f4
4 changed files with 17 additions and 22 deletions

View File

@ -438,8 +438,9 @@ section.import {
.status { .status {
padding: 60px; padding: 60px;
} }
.logs { .log-view .lines {
max-height: 240px; max-height: 240px;
text-align: left;
} }
} }
@ -607,7 +608,7 @@ section.campaign {
} }
/* Logs */ /* Logs */
.logs { .log-view {
.lines { .lines {
height: 70vh; height: 70vh;
overflow-y: scroll; overflow-y: scroll;

View File

@ -127,10 +127,9 @@
</p> </p>
<br /> <br />
<p> <div class="import-logs">
<b-input v-model="logs" id="import-log" class="logs" <log-view :lines="logs" :loading="false" />
type="textarea" readonly placeholder="Import log" /> </div>
</p>
</section> </section>
</section> </section>
</template> </template>
@ -139,10 +138,12 @@
import Vue from 'vue'; import Vue from 'vue';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import ListSelector from '../components/ListSelector.vue'; import ListSelector from '../components/ListSelector.vue';
import LogView from '../components/LogView.vue';
export default Vue.extend({ export default Vue.extend({
components: { components: {
ListSelector, ListSelector,
LogView,
}, },
props: { props: {
@ -242,7 +243,7 @@ export default Vue.extend({
getLogs() { getLogs() {
this.$api.getImportLogs().then((data) => { this.$api.getImportLogs().then((data) => {
this.logs = data; this.logs = data.split('\n');
Vue.nextTick(() => { Vue.nextTick(() => {
// vue.$refs doesn't work as the logs textarea is rendered dynamically. // vue.$refs doesn't work as the logs textarea is rendered dynamically.

View File

@ -2,38 +2,31 @@
<section class="logs content relative"> <section class="logs content relative">
<h1 class="title is-4">Logs</h1> <h1 class="title is-4">Logs</h1>
<hr /> <hr />
<b-loading :active="loading.logs" :is-full-page="false" /> <log-view :loading="loading.logs" :lines="lines"></log-view>
<pre class="lines" ref="lines">
<template v-for="(l, i) in lines"><span v-html="formatLine(l)" :key="i" class="line"></span>
</template>
</pre>
</section> </section>
</template> </template>
<script> <script>
import Vue from 'vue'; import Vue from 'vue';
import { mapState } from 'vuex'; import { mapState } from 'vuex';
import LogView from '../components/LogView.vue';
const reFormatLine = new RegExp(/^(.*) (.+?)\.go:[0-9]+:\s/g);
export default Vue.extend({ export default Vue.extend({
components: {
LogView,
},
data() { data() {
return { return {
lines: '', lines: [],
pollId: null, pollId: null,
}; };
}, },
methods: { methods: {
formatLine: (l) => l.replace(reFormatLine, '<span class="stamp">$1</span> '),
getLogs() { getLogs() {
this.$api.getLogs().then((data) => { this.$api.getLogs().then((data) => {
this.lines = data; this.lines = data;
this.$nextTick(() => {
this.$refs.lines.scrollTop = this.$refs.lines.scrollHeight;
});
}); });
}, },
}, },

View File

@ -139,7 +139,7 @@ func (im *Importer) NewSession(fName, mode string, overWrite bool, listIDs []int
s := &Session{ s := &Session{
im: im, im: im,
log: log.New(im.status.logBuf, "", log.Ldate|log.Ltime), log: log.New(im.status.logBuf, "", log.Ldate|log.Ltime|log.Lshortfile),
subQueue: make(chan SubReq, commitBatchSize), subQueue: make(chan SubReq, commitBatchSize),
mode: mode, mode: mode,
overwrite: overWrite, overwrite: overWrite,