From 7cd554bf4133a00734828fb6928fe4928293f32e Mon Sep 17 00:00:00 2001 From: Lukas Hirt Date: Mon, 7 Sep 2020 17:49:35 +0200 Subject: [PATCH] Refactor --- ui/components/App.vue | 29 ++++++---- ui/components/accounts/AccountsList.vue | 8 +-- ui/store/index.js | 70 +++++-------------------- 3 files changed, 34 insertions(+), 73 deletions(-) diff --git a/ui/components/App.vue b/ui/components/App.vue index d0afce5bc0..c77b087db8 100644 --- a/ui/components/App.vue +++ b/ui/components/App.vue @@ -2,8 +2,12 @@

- + + | +
+ +
diff --git a/ui/components/accounts/AccountsList.vue b/ui/components/accounts/AccountsList.vue index 8d7c765ed4..d8ef723030 100644 --- a/ui/components/accounts/AccountsList.vue +++ b/ui/components/accounts/AccountsList.vue @@ -8,7 +8,7 @@ :value="areAllAccountsSelected" :label="$gettext('Select all users')" hide-label - @change="toggleAllAccountsSelection" + @change="toggleSelectionAll" /> @@ -51,11 +51,7 @@ export default { ...mapGetters('Accounts', ['areAllAccountsSelected']) }, methods: { - ...mapActions('Accounts', ['toggleSelectionAll']), - - toggleAllAccountsSelection () { - this.toggleSelectionAll() - } + ...mapActions('Accounts', ['toggleSelectionAll']) } } diff --git a/ui/store/index.js b/ui/store/index.js index 0a2517df5c..aa2ccc0129 100644 --- a/ui/store/index.js +++ b/ui/store/index.js @@ -110,15 +110,15 @@ const actions = { }, toggleSelectionAll ({ commit, getters, state }) { - getters.areAllAccountsSelected ? commit('SET_SELECTED_ACCOUNTS', []) : commit('SET_SELECTED_ACCOUNTS', [...state.accounts]) + getters.areAllAccountsSelected ? commit('RESET_ACCOUNTS_SELECTION') : commit('SET_SELECTED_ACCOUNTS', [...state.accounts]) }, - async enableAccounts ({ commit, dispatch, state, rootGetters }) { + async toggleAccountStatus ({ commit, dispatch, state, rootGetters }, status) { const failedAccounts = [] injectAuthToken(rootGetters.user.token) for (const account of state.selectedAccounts) { - if (account.accountEnabled) { + if (account.accountEnabled === status) { continue } @@ -127,7 +127,7 @@ const actions = { body: { account: { id: account.id, - accountEnabled: true + accountEnabled: status }, update_mask: { paths: ['AccountEnabled'] @@ -136,73 +136,29 @@ const actions = { }) if (response.status === 201) { - console.log('Going to update') - commit('UPDATE_ACCOUNT', { ...account, accountEnabled: true }) + commit('UPDATE_ACCOUNT', { ...account, accountEnabled: status }) } else { failedAccounts.push({ account: account.diisplayName, statusText: response.statusText }) } } if (failedAccounts.length === 1) { + const failedMessageTitle = status ? 'Failed to enable account.' : 'Failed to disable account.' + dispatch('showMessage', { - title: 'Failed to enable account.', + title: failedMessageTitle, desc: failedAccounts[0].statusText, status: 'danger' }, { root: true }) } if (failedAccounts.length > 1) { + const failedMessageTitle = status ? 'Failed to enable accounts.' : 'Failed to disable accounts.' + const failedMessageDesc = status ? 'Could not enable multiple accounts.' : 'Could not disable multiple accounts.' + dispatch('showMessage', { - title: 'Failed to enable accounts.', - desc: 'Could not enable multiple accounts', - status: 'danger' - }, { root: true }) - } - - commit('RESET_ACCOUNTS_SELECTION') - }, - - async disableAccounts ({ commit, dispatch, state, rootGetters }) { - const failedAccounts = [] - injectAuthToken(rootGetters.user.token) - - for (const account of state.selectedAccounts) { - if (!account.accountEnabled) { - continue - } - - const response = await AccountsService_UpdateAccount({ - $domain: rootGetters.configuration.server, - body: { - account: { - id: account.id, - accountEnabled: false - }, - update_mask: { - paths: ['AccountEnabled'] - } - } - }) - - if (response.status === 201) { - commit('UPDATE_ACCOUNT', { ...account, accountEnabled: false }) - } else { - failedAccounts.push({ account: account.diisplayName, statusText: response.statusText }) - } - } - - if (failedAccounts.length === 1) { - dispatch('showMessage', { - title: 'Failed to disable account.', - desc: failedAccounts[0].statusText, - status: 'danger' - }, { root: true }) - } - - if (failedAccounts.length > 1) { - dispatch('showMessage', { - title: 'Failed to disable accounts.', - desc: 'Could not disable multiple accounts', + title: failedMessageTitle, + desc: failedMessageDesc, status: 'danger' }, { root: true }) }