Add logs dialog

This commit is contained in:
CzBiX
2019-04-13 00:59:57 +08:00
parent e315a35982
commit ec7f5b787b
4 changed files with 118 additions and 18 deletions

View File

@@ -62,6 +62,10 @@ class Api {
return this.axios.post('/app/setPreferences', data);
}
public getLogs() {
return this.axios.get('/log/main').then(this.handleResponse);
}
private handleResponse(resp: AxiosResponse) {
return resp.data;
}

View File

@@ -5,7 +5,7 @@
:clipped="$vuetify.breakpoint.lgAndUp"
v-model="drawer"
>
<drawer />
<drawer v-model="drawerOptions" />
</v-navigation-drawer>
<v-toolbar
:clipped-left="$vuetify.breakpoint.lgAndUp"
@@ -34,6 +34,7 @@
<add-form />
<login-form v-if="needAuth" v-model="needAuth" />
<logs-dialog v-if="drawerOptions.showLogs" v-model="drawerOptions.showLogs" />
<v-footer
app
@@ -53,6 +54,7 @@ import Drawer from './components/Drawer.vue';
import LoginForm from './components/LoginForm.vue';
import Torrents from './components/Torrents.vue';
import AppFooter from './components/Footer.vue';
import LogsDialog from './components/LogsDialog.vue';
import { api } from './Api';
import { mapActions, mapState, mapMutations } from 'vuex';
import Axios, { AxiosError } from 'axios';
@@ -65,11 +67,15 @@ export default Vue.extend({
LoginForm,
Torrents,
AppFooter,
LogsDialog,
},
data() {
return {
needAuth: false,
drawer: true,
drawerOptions: {
showLogs: false,
},
task: 0,
};
},

View File

@@ -55,7 +55,7 @@
v-model="filter[child.select]"
/>
</template>
<v-list-tile v-else :key="item.text">
<v-list-tile v-else :key="item.text" @click="item.click ? item.click() : null">
<v-list-tile-action>
<v-icon>{{ item.icon }}</v-icon>
</v-list-tile-action>
@@ -66,16 +66,6 @@
</v-list-tile-content>
</v-list-tile>
</template>
<v-list-tile key="switch_ui" @click="switchUi">
<v-list-tile-action>
<v-icon>mdi-history</v-icon>
</v-list-tile-action>
<v-list-tile-content>
<v-list-tile-title>
Switch to old UI
</v-list-tile-title>
</v-list-tile-content>
</v-list-tile>
</v-list>
</template>
@@ -92,6 +82,10 @@ export default {
FilterGroup,
},
props: {
value: Object,
},
data() {
return {
filter: {
@@ -99,8 +93,7 @@ export default {
category: null,
site: null,
},
basicItems: [
{ icon: 'mdi-settings', text: 'Settings' },
basicItems: null,
// {
// 'icon': 'mdi-menu-up',
// 'icon-alt': 'mdi-menu-down',
@@ -118,13 +111,20 @@ export default {
// { icon: 'mdi-alert', text: 'Errored' },
// ],
// },
],
endItems: [
{ icon: 'mdi-help', text: 'Help' },
],
endItems: null,
};
},
created() {
this.basicItems = [
{ icon: 'mdi-settings', text: 'Settings', click: () => alert('TODO') },
];
this.endItems = [
{ icon: 'mdi-delta', text: 'Logs', click: () => this.updateOptions('showLogs', true) },
{ icon: 'mdi-history', text: 'Switch to old UI', click: this.switchUi },
];
},
computed: {
...mapGetters([
'isDataReady',
@@ -184,6 +184,9 @@ export default {
location.reload(true);
},
updateOptions(key: string, value: any) {
this.$emit('input', Object.assign({}, this.value, {[key]: value}));
},
},
watch: {

View File

@@ -0,0 +1,87 @@
<template>
<v-dialog :value="value" @input="$emit('input', $event)" scrollable width="50%">
<v-card>
<v-card-title
class="headline grey lighten-4"
>
<v-icon class="mr-2">mdi-delta</v-icon>
<span>Logs</span>
</v-card-title>
<v-card-text>
<v-progress-linear
:indeterminate="true"
v-if="!logs"
/>
<ol class="logs caption">
<li v-for="(row, i) in logs" :key="i" :class="row.type | typeColor">
[{{ row.type | formatType }} {{ row.timestamp / 1000 | formatTimestamp }}] {{ row.message }}
</li>
</ol>
<div ref="end" />
</v-card-text>
<v-card-actions>
<v-spacer />
<v-btn flat @click="closeDialog">Close</v-btn>
</v-card-actions>
</v-card>
</v-dialog>
</template>
<script lang="ts">
import Vue from 'vue'
import { api } from '../Api';
export default Vue.extend({
props: {
value: Boolean,
},
data() {
return {
logs: null,
};
},
filters: {
formatType(type: number) {
const map: any = {
1: 'N',
2: 'I',
4: 'W',
8: 'C',
};
return map[type];
},
typeColor(type: number) {
const map: any = {
1: 'secondary--text',
2: 'info--text',
4: 'warn--text',
8: 'error--text',
};
return map[type];
},
},
methods: {
closeDialog() {
this.$emit('input', false);
},
async getLogs() {
this.logs = await api.getLogs();
await this.$nextTick();
this.$refs.end.scrollIntoView();
},
},
async created() {
await this.getLogs();
},
});
</script>
<style lang="scss" scoped>
.logs {
font-family: monospace;
li:not(:last-child) {
line-height: 1.4em;
}
}
</style>