feat: display version in UI

closes #42
This commit is contained in:
Gauthier Roebroeck 2020-01-06 14:11:43 +08:00
parent 1f9b7cf947
commit 4085f1fdaa
5 changed files with 81 additions and 1 deletions

View file

@ -5,6 +5,7 @@ import * as lineClamp from 'vue-line-clamp'
import Vuelidate from 'vuelidate'
import { sync } from 'vuex-router-sync'
import App from './App.vue'
import actuator from './plugins/actuator.plugin'
import httpPlugin from './plugins/http.plugin'
import komgaBooks from './plugins/komga-books.plugin'
import komgaFileSystem from './plugins/komga-filesystem.plugin'
@ -24,6 +25,7 @@ Vue.use(komgaSeries, { http: Vue.prototype.$http })
Vue.use(komgaBooks, { http: Vue.prototype.$http })
Vue.use(komgaUsers, { store: store, http: Vue.prototype.$http })
Vue.use(komgaLibraries, { store: store, http: Vue.prototype.$http })
Vue.use(actuator, { http: Vue.prototype.$http })
Vue.prototype.$_ = _

View file

@ -0,0 +1,17 @@
import ActuatorService from '@/services/actuator.service'
import { AxiosInstance } from 'axios'
import _Vue from 'vue'
export default {
install (
Vue: typeof _Vue,
{ http }: { http: AxiosInstance }) {
Vue.prototype.$actuator = new ActuatorService(http)
}
}
declare module 'vue/types/vue' {
interface Vue {
$actuator: ActuatorService;
}
}

View file

@ -0,0 +1,23 @@
import { AxiosInstance } from 'axios'
const API_ACTUATOR = '/actuator'
export default class ActuatorService {
private http: AxiosInstance;
constructor (http: AxiosInstance) {
this.http = http
}
async getInfo (): Promise<ActuatorInfo> {
try {
return (await this.http.get(`${API_ACTUATOR}/info`)).data
} catch (e) {
let msg = 'An error occurred while trying to retrieve actuator info'
if (e.response.data.message) {
msg += `: ${e.response.data.message}`
}
throw new Error(msg)
}
}
}

View file

@ -0,0 +1,22 @@
interface ActuatorInfo {
git: ActuatorGit,
build: ActuatorBuild
}
interface ActuatorGit {
commit: ActuatorGitCommit,
branch: string
}
interface ActuatorGitCommit {
time: Date,
id: string
}
interface ActuatorBuild {
version: string,
artifact: string,
name: string,
group: string,
time: Date
}

View file

@ -96,6 +96,16 @@
</v-list-item-content>
</v-list-item>
</v-list>
<v-spacer/>
<template v-slot:append>
<div v-if="isAdmin && !$_.isEmpty(info)"
class="pa-2 pb-6 caption"
>
<div>v{{ info.build.version }}-{{ info.git.branch }}</div>
</div>
</template>
</v-navigation-drawer>
<v-content>
@ -115,7 +125,13 @@ export default Vue.extend({
data: function () {
return {
drawerVisible: this.$vuetify.breakpoint.lgAndUp,
modalAddLibrary: false
modalAddLibrary: false,
info: {} as ActuatorInfo
}
},
async created () {
if (this.isAdmin) {
this.info = await this.$actuator.getInfo()
}
},
computed: {