refs #1 Show instance url in sidemenu

This commit is contained in:
AkiraFukushima 2018-03-09 15:48:20 +09:00
parent ac8e48cfea
commit e4e4445c35
4 changed files with 76 additions and 4 deletions

View File

@ -58,6 +58,7 @@ export default class Authentication {
})
}
// TODO: このクラスにいる必要性がない,外に出したい
listInstances () {
return new Promise((resolve, reject) => {
this.db.find({accessToken: { $ne: '' }}, (err, doc) => {

View File

@ -106,6 +106,7 @@ ipcMain.on('list-instances', (event, _) => {
})
})
// storage access
ipcMain.on('get-instance-token', (event, _) => {
storage.get('config', (err, data) => {
if (err || empty(data)) {
@ -117,6 +118,23 @@ ipcMain.on('get-instance-token', (event, _) => {
})
})
// db
ipcMain.on('get-instance', (event, id) => {
db.findOne(
{
_id: id
},
(err, doc) => {
if (err || empty(doc)) return event.sender.send('empty-instance', err)
const instance = {
baseURL: doc.baseURL,
id: doc.id
}
event.sender.send('instance', instance)
}
)
})
/**
* Auto Updater
*

View File

@ -1,5 +1,10 @@
<template>
<div id="side_menu">
<div class="profile-wrapper">
<div class="profile">
{{ instance.baseURL }}
</div>
</div>
<el-menu
default-active="1"
background-color="#373d48"
@ -32,8 +37,18 @@
</template>
<script>
import { mapState } from 'vuex'
export default {
name: 'side-menu',
computed: {
...mapState({
instance: state => state.TimelineSpace.SideMenu.instance
})
},
created () {
this.$store.dispatch('TimelineSpace/SideMenu/fetchInstance', this.$route.params.id)
},
methods: {
id () {
return this.$route.params.id
@ -44,11 +59,27 @@ export default {
<style lang="scss" scoped>
#side_menu {
.timeline-menu {
.profile-wrapper {
background-color: #373d48;
position: fixed;
top: 0;
left: 65px;
width: 144px;
height: 40px;
.profile {
color: #ffffff;
font-weight: bold;
padding: 10px 20px;
}
}
.timeline-menu {
position: fixed;
top: 40px;
left: 65px;
height: 100%;
width: 144px;
}
}
</style>

View File

@ -1,8 +1,30 @@
import { ipcRenderer } from 'electron'
const SideMenu = {
namespaced: true,
state: {},
mutations: {},
actions: {}
state: {
instance: {
baseURL: '',
id: ''
}
},
mutations: {
updateInstance (state, instance) {
state.instance = instance
}
},
actions: {
fetchInstance ({ commit }, id) {
ipcRenderer.send('get-instance', id)
ipcRenderer.on('empty-instance', (event, err) => {
// TODO: handle error
console.log(err)
})
ipcRenderer.on('instance', (event, instance) => {
commit('updateInstance', instance)
})
}
}
}
export default SideMenu