1
0
mirror of https://github.com/h3poteto/whalebird-desktop synced 2024-12-23 15:37:59 +01:00

refs #3 Rename instance to account in global header

This commit is contained in:
AkiraFukushima 2018-03-10 23:21:09 +09:00
parent b39c508319
commit ae4f315107
4 changed files with 29 additions and 31 deletions

View File

@ -5,15 +5,12 @@ export default class Account {
this.db = db
}
listInstances () {
listAccounts () {
return new Promise((resolve, reject) => {
this.db.find({accessToken: { $ne: '' }}, (err, doc) => {
this.db.find({accessToken: { $ne: '' }}, (err, docs) => {
if (err) return reject(err)
if (empty(doc)) return reject(new EmptyRecordError('empty'))
const instances = doc.map((e, i, array) => {
return { baseURL: e.baseURL, id: e._id }
})
resolve(instances)
if (empty(docs)) return reject(new EmptyRecordError('empty'))
resolve(docs)
})
})
}
@ -29,7 +26,7 @@ export default class Account {
if (empty(doc)) return reject(new EmptyRecordError('empty'))
const instance = {
baseURL: doc.baseURL,
id: doc.id
id: doc._id
}
resolve(instance)
}

View File

@ -102,15 +102,15 @@ ipcMain.on('get-social-token', (event, _) => {
})
// nedb
ipcMain.on('list-instances', (event, _) => {
ipcMain.on('list-accounts', (event, _) => {
const account = new Account(db)
account.listInstances()
account.listAccounts()
.catch((err) => {
console.error(err)
event.sender.send('error-list-instances', err)
event.sender.send('error-list-accounts', err)
})
.then((instances) => {
event.sender.send('response-list-instances', instances)
.then((accounts) => {
event.sender.send('response-list-accounts', accounts)
})
})

View File

@ -2,17 +2,17 @@
<div id="global_header">
<el-menu
:default-active="defaultActive"
class="el-menu-vertical instance-menu"
@open="instanceSelected"
@close="instanceClosed"
class="el-menu-vertical account-menu"
@open="accountSelected"
@close="accountClosed"
:collapse="isCollapse"
:route="true"
background-color="#4a5664"
text-color="#909399"
active-text-color="#ffffff">
<el-menu-item :index="index.toString()" v-for="(instance, index) in instances" v-bind:key="instance.id" :route="{path: `/${instance.id}/home`}">
<el-menu-item :index="index.toString()" v-for="(account, index) in accounts" v-bind:key="account.id" :route="{path: `/${account.id}/home`}">
<i class="el-icon-menu"></i>
<span slot="title">{{ instance.baseURL }}</span>
<span slot="title">{{ account.baseURL }}</span>
</el-menu-item>
</el-menu>
<div class="space">
@ -34,23 +34,23 @@ export default {
},
computed: {
...mapState({
instances: state => state.GlobalHeader.instances
accounts: state => state.GlobalHeader.accounts
})
},
created () {
this.$store.dispatch('GlobalHeader/listInstances')
.then((instances) => {
return this.$router.push({ path: `/${instances[0].id}/home` })
this.$store.dispatch('GlobalHeader/listAccounts')
.then((accounts) => {
return this.$router.push({ path: `/${accounts[0]._id}/home` })
})
.catch(() => {
return this.$router.push({ path: '/login' })
})
},
methods: {
instanceSelected (key, keyPath) {
accountSelected (key, keyPath) {
console.log(key, keyPath)
},
instanceClosed (key, keyPath) {
accountClosed (key, keyPath) {
console.log(key, keyPath)
}
}
@ -66,7 +66,7 @@ html, body, #app, #global_header {
}
#global_header {
.instance-menu {
.account-menu {
height: 100%;
position: fixed;
top: 0;

View File

@ -11,15 +11,16 @@ const GlobalHeader = {
}
},
actions: {
listInstances ({ commit }) {
listAccounts ({ commit }) {
return new Promise((resolve, reject) => {
ipcRenderer.send('list-instances', 'list')
ipcRenderer.once('error-list-instances', (event, err) => {
ipcRenderer.send('list-accounts', 'list')
ipcRenderer.once('error-list-accounts', (event, err) => {
reject(err)
})
ipcRenderer.once('response-list-instances', (event, instances) => {
commit('updateAccounts', instances)
resolve(instances)
ipcRenderer.once('response-list-accounts', (event, accounts) => {
commit('updateAccounts', accounts)
console.log(accounts)
resolve(accounts)
})
})
}