refs #100 Swap backward a account in preferences

This commit is contained in:
AkiraFukushima 2018-04-02 22:17:08 +09:00
parent f39b881722
commit cdea89e8ac
3 changed files with 40 additions and 2 deletions

View File

@ -111,10 +111,27 @@ export default class Account {
}
)
await this.updateAccount(backwarded._id, Object.assign(backwarded, { order: (backwarded.order + 1) }))
// Forward account order.
// Forward account order
const updated = await this.updateAccount(ac._id, Object.assign(ac, { order: (ac.order - 1) }))
return updated
}
async backwardAccount (ac) {
const length = await this.countAuthorizedAccounts()
if (ac.order >= length) {
return ac.order
}
// Find account which is forwarded
const forwarded = await this.searchAccount(
{
order: ac.order + 1
}
)
await this.updateAccount(forwarded._id, Object.assign(forwarded, { order: (forwarded.order - 1) }))
// Backward account order
const updated = await this.updateAccount(ac._id, Object.assign(ac, { order: (ac.order + 1) }))
return updated
}
}
class EmptyRecordError {

View File

@ -320,6 +320,17 @@ ipcMain.on('forward-account', (event, acct) => {
})
})
ipcMain.on('backward-account', (event, acct) => {
const account = new Account(db)
account.backwardAccount(acct)
.then(() => {
event.sender.send('response-backward-account')
})
.catch((err) => {
event.sender.send('error-backward-account', err)
})
})
// streaming
let userStreaming = null

View File

@ -56,7 +56,17 @@ const Account = {
})
},
backwardAccount ({ commit }, account) {
return new Promise((resolve, reject) => {
ipcRenderer.send('backward-account', account)
ipcRenderer.once('error-backward-account', (event, err) => {
ipcRenderer.removeAllListeners('response-forward-account')
reject(err)
})
ipcRenderer.once('response-backward-account', (event) => {
ipcRenderer.removeAllListeners('error-backward-account')
resolve()
})
})
}
}
}