refs #390 Remove all account associations

This commit is contained in:
AkiraFukushima 2018-06-13 22:51:41 +09:00
parent 2879244e79
commit 8a00261239
4 changed files with 65 additions and 1 deletions

View File

@ -112,6 +112,19 @@ export default class Account {
})
}
removeAll () {
return new Promise((resolve, reject) => {
this.db.remove(
{},
{ multi: true },
(err, numRemoved) => {
if (err) return reject(err)
resolve(numRemoved)
}
)
})
}
async forwardAccount (ac) {
if (ac.order <= 1) {
return ac.order

View File

@ -383,6 +383,18 @@ ipcMain.on('refresh-accounts', (event, _) => {
})
})
ipcMain.on('remove-all-accounts', (event, _) => {
const account = new Account(accountDB)
account.removeAll()
.then(() => {
event.sender.send('response-remove-all-accounts')
})
.catch((err) => {
log.error(err)
event.sender.send('error-remove-all-accounts', err)
})
})
// streaming
let userStreaming = null

View File

@ -43,6 +43,19 @@
</el-table>
</template>
</div>
<div class="reset">
<el-popover
placement="top"
width="160"
v-model="deletePopoverVisible">
<p>Are you sure to remove all associations?</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="deletePopoverVisible = false">cancel</el-button>
<el-button type="danger" size="mini" @click="removeAllAssociations">confirm</el-button>
</div>
<el-button slot="reference" type="danger">Remove all associations</el-button>
</el-popover>
</div>
</div>
</template>
@ -53,7 +66,8 @@ export default {
name: 'account',
data () {
return {
openRemoveDialog: false
openRemoveDialog: false,
deletePopoverVisible: false
}
},
computed: {
@ -103,6 +117,13 @@ export default {
.then(() => {
this.loadAccounts()
})
},
removeAllAssociations () {
this.deletePopoverVisible = false
this.$store.dispatch('Preferences/Account/removeAllAccounts')
.then(() => {
this.$router.push('/login')
})
}
}
}
@ -124,6 +145,11 @@ export default {
.el-table::before {
background-color: var(--theme-border-color);
}
.reset {
margin: 24px 12px;
text-align: right;
}
}
.allow-up {

View File

@ -67,6 +67,19 @@ const Account = {
resolve()
})
})
},
removeAllAccounts () {
return new Promise((resolve, reject) => {
ipcRenderer.send('remove-all-accounts')
ipcRenderer.once('error-remove-all-accounts', (event, err) => {
ipcRenderer.removeAllListeners('response-remove-all-accounts')
reject(err)
})
ipcRenderer.once('response-remove-all-accounts', (event) => {
ipcRenderer.removeAllListeners('error-remove-all-accounts')
resolve()
})
})
}
}
}