浏览代码

Refactor log view UI into a component.

Kailash Nadh 4 年之前
父节点
当前提交
966954d8f4
共有 4 个文件被更改,包括 17 次插入22 次删除
  1. 3 2
      frontend/src/assets/style.scss
  2. 6 5
      frontend/src/views/Import.vue
  3. 7 14
      frontend/src/views/Logs.vue
  4. 1 1
      internal/subimporter/importer.go

+ 3 - 2
frontend/src/assets/style.scss

@@ -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;

+ 6 - 5
frontend/src/views/Import.vue

@@ -127,10 +127,9 @@
       </p>
       </p>
       <br />
       <br />
 
 
-      <p>
-        <b-input v-model="logs" id="import-log" class="logs"
-          type="textarea" readonly placeholder="Import log" />
-      </p>
+      <div class="import-logs">
+        <log-view :lines="logs" :loading="false" />
+      </div>
     </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.

+ 7 - 14
frontend/src/views/Logs.vue

@@ -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" />
-    <pre class="lines" ref="lines">
-<template v-for="(l, i) in lines"><span v-html="formatLine(l)" :key="i" class="line"></span>
-</template>
-    </pre>
+    <log-view :loading="loading.logs" :lines="lines"></log-view>
   </section>
   </section>
 </template>
 </template>
 
 
 <script>
 <script>
 import Vue from 'vue';
 import Vue from 'vue';
 import { mapState } from 'vuex';
 import { mapState } from 'vuex';
-
-const reFormatLine = new RegExp(/^(.*) (.+?)\.go:[0-9]+:\s/g);
+import LogView from '../components/LogView.vue';
 
 
 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;
-        });
       });
       });
     },
     },
   },
   },

+ 1 - 1
internal/subimporter/importer.go

@@ -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,