Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 3111b6f | 2020-04-21 19:48:38 -0700 | [diff] [blame] | 2 | <b-container fluid="xl"> |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 3 | <page-title /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 4 | <b-row> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 5 | <b-col xl="9" class="text-right"> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 6 | <b-button variant="link" @click="initModalSettings"> |
Yoshie Muranaka | 996d2d5 | 2019-12-30 09:06:45 -0800 | [diff] [blame] | 7 | <icon-settings /> |
Yoshie Muranaka | 80735e1 | 2020-04-28 09:48:59 -0700 | [diff] [blame] | 8 | {{ $t('pageLocalUserManagement.accountPolicySettings') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 9 | </b-button> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 10 | <b-button |
| 11 | variant="primary" |
| 12 | data-test-id="localUserManagement-button-addUser" |
| 13 | @click="initModalUser(null)" |
| 14 | > |
Yoshie Muranaka | 996d2d5 | 2019-12-30 09:06:45 -0800 | [diff] [blame] | 15 | <icon-add /> |
Yoshie Muranaka | 80735e1 | 2020-04-28 09:48:59 -0700 | [diff] [blame] | 16 | {{ $t('pageLocalUserManagement.addUser') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 17 | </b-button> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 18 | </b-col> |
| 19 | </b-row> |
| 20 | <b-row> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 21 | <b-col xl="9"> |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 22 | <table-toolbar |
| 23 | ref="toolbar" |
| 24 | :selected-items-count="selectedRows.length" |
| 25 | :actions="tableToolbarActions" |
| 26 | @clearSelected="clearSelectedRows($refs.table)" |
| 27 | @batchAction="onBatchAction" |
| 28 | /> |
| 29 | <b-table |
| 30 | ref="table" |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 31 | responsive="md" |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 32 | selectable |
| 33 | no-select-on-click |
| 34 | :fields="fields" |
| 35 | :items="tableItems" |
| 36 | @row-selected="onRowSelected($event, tableItems.length)" |
| 37 | > |
| 38 | <!-- Checkbox column --> |
| 39 | <template v-slot:head(checkbox)> |
| 40 | <b-form-checkbox |
| 41 | v-model="tableHeaderCheckboxModel" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 42 | data-test-id="localUserManagement-checkbox-tableHeaderCheckbox" |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 43 | :indeterminate="tableHeaderCheckboxIndeterminate" |
| 44 | @change="onChangeHeaderCheckbox($refs.table)" |
| 45 | /> |
| 46 | </template> |
| 47 | <template v-slot:cell(checkbox)="row"> |
| 48 | <b-form-checkbox |
| 49 | v-model="row.rowSelected" |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 50 | data-test-id="localUserManagement-checkbox-toggleSelectRow" |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 51 | @change="toggleSelectRow($refs.table, row.index)" |
| 52 | /> |
| 53 | </template> |
| 54 | |
| 55 | <!-- table actions column --> |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 56 | <template v-slot:cell(actions)="{ item }"> |
| 57 | <table-row-action |
| 58 | v-for="(action, index) in item.actions" |
| 59 | :key="index" |
| 60 | :value="action.value" |
| 61 | :enabled="action.enabled" |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 62 | :title="action.title" |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 63 | @click:tableAction="onTableRowAction($event, item)" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 64 | > |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 65 | <template v-slot:icon> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 66 | <icon-edit |
| 67 | v-if="action.value === 'edit'" |
| 68 | :data-test-id=" |
| 69 | `localUserManagement-tableRowAction-edit-${index}` |
| 70 | " |
| 71 | /> |
| 72 | <icon-trashcan |
| 73 | v-if="action.value === 'delete'" |
| 74 | :data-test-id=" |
| 75 | `localUserManagement-tableRowAction-delete-${index}` |
| 76 | " |
| 77 | /> |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 78 | </template> |
| 79 | </table-row-action> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 80 | </template> |
| 81 | </b-table> |
| 82 | </b-col> |
| 83 | </b-row> |
| 84 | <b-row> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 85 | <b-col xl="8"> |
Dixsie Wolmers | fe1e658 | 2020-07-15 11:18:12 -0500 | [diff] [blame] | 86 | <b-button |
| 87 | v-b-toggle.collapse-role-table |
| 88 | data-test-id="localUserManagement-button-viewPrivilegeRoleDescriptions" |
| 89 | variant="link" |
| 90 | class="mt-3" |
| 91 | > |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 92 | <icon-chevron /> |
Yoshie Muranaka | 80735e1 | 2020-04-28 09:48:59 -0700 | [diff] [blame] | 93 | {{ $t('pageLocalUserManagement.viewPrivilegeRoleDescriptions') }} |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 94 | </b-button> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 95 | <b-collapse id="collapse-role-table" class="mt-3"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 96 | <table-roles /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 97 | </b-collapse> |
| 98 | </b-col> |
| 99 | </b-row> |
| 100 | <!-- Modals --> |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 101 | <modal-settings :settings="settings" @ok="saveAccountSettings" /> |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 102 | <modal-user |
| 103 | :user="activeUser" |
| 104 | :password-requirements="passwordRequirements" |
| 105 | @ok="saveUser" |
Yoshie Muranaka | 791622b | 2020-04-17 13:55:16 -0700 | [diff] [blame] | 106 | @hidden="activeUser = null" |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 107 | /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 108 | </b-container> |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 109 | </template> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 110 | |
| 111 | <script> |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 112 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 113 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 114 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 115 | import IconSettings from '@carbon/icons-vue/es/settings/20'; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 116 | import IconChevron from '@carbon/icons-vue/es/chevron--up/20'; |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 117 | |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 118 | import ModalUser from './ModalUser'; |
| 119 | import ModalSettings from './ModalSettings'; |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 120 | import PageTitle from '@/components/Global/PageTitle'; |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 121 | import TableRoles from './TableRoles'; |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 122 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 123 | import TableRowAction from '@/components/Global/TableRowAction'; |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 124 | |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 125 | import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin'; |
| 126 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 127 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 128 | |
| 129 | export default { |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 130 | name: 'LocalUsers', |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 131 | components: { |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 132 | IconAdd, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 133 | IconChevron, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 134 | IconEdit, |
| 135 | IconSettings, |
| 136 | IconTrashcan, |
| 137 | ModalSettings, |
| 138 | ModalUser, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 139 | PageTitle, |
Yoshie Muranaka | 8d12910 | 2019-12-19 09:51:55 -0800 | [diff] [blame] | 140 | TableRoles, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 141 | TableRowAction, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 142 | TableToolbar |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 143 | }, |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 144 | mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin], |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 145 | data() { |
| 146 | return { |
| 147 | activeUser: null, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 148 | fields: [ |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 149 | { |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 150 | key: 'checkbox' |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 151 | }, |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 152 | { |
| 153 | key: 'username', |
| 154 | label: this.$t('pageLocalUserManagement.table.username') |
| 155 | }, |
| 156 | { |
| 157 | key: 'privilege', |
| 158 | label: this.$t('pageLocalUserManagement.table.privilege') |
| 159 | }, |
| 160 | { |
| 161 | key: 'status', |
| 162 | label: this.$t('pageLocalUserManagement.table.status') |
| 163 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 164 | { |
| 165 | key: 'actions', |
| 166 | label: '', |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 167 | tdClass: 'text-right text-nowrap' |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 168 | } |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 169 | ], |
| 170 | tableToolbarActions: [ |
| 171 | { |
| 172 | value: 'delete', |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 173 | label: this.$t('global.action.delete') |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 174 | }, |
| 175 | { |
| 176 | value: 'enable', |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 177 | label: this.$t('global.action.enable') |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 178 | }, |
| 179 | { |
| 180 | value: 'disable', |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 181 | label: this.$t('global.action.disable') |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 182 | } |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 183 | ] |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 184 | }; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 185 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 186 | computed: { |
| 187 | allUsers() { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 188 | return this.$store.getters['localUsers/allUsers']; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 189 | }, |
| 190 | tableItems() { |
| 191 | // transform user data to table data |
| 192 | return this.allUsers.map(user => { |
| 193 | return { |
| 194 | username: user.UserName, |
| 195 | privilege: user.RoleId, |
| 196 | status: user.Locked |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 197 | ? 'Locked' |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 198 | : user.Enabled |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 199 | ? 'Enabled' |
| 200 | : 'Disabled', |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 201 | actions: [ |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 202 | { |
| 203 | value: 'edit', |
| 204 | enabled: true, |
| 205 | title: this.$t('pageLocalUserManagement.editUser') |
| 206 | }, |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 207 | { |
| 208 | value: 'delete', |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 209 | enabled: user.UserName === 'root' ? false : true, |
Yoshie Muranaka | 2932165 | 2020-05-04 10:52:36 -0700 | [diff] [blame] | 210 | title: this.$tc('pageLocalUserManagement.deleteUser') |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 211 | } |
| 212 | ], |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 213 | ...user |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 214 | }; |
| 215 | }); |
Yoshie Muranaka | 52b0223 | 2020-02-20 08:00:45 -0800 | [diff] [blame] | 216 | }, |
| 217 | settings() { |
| 218 | return this.$store.getters['localUsers/accountSettings']; |
| 219 | }, |
| 220 | passwordRequirements() { |
| 221 | return this.$store.getters['localUsers/accountPasswordRequirements']; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 222 | } |
| 223 | }, |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 224 | created() { |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 225 | this.startLoader(); |
| 226 | this.$store.dispatch('localUsers/getUsers').finally(() => this.endLoader()); |
Yoshie Muranaka | fb78d19 | 2020-03-03 11:55:52 -0800 | [diff] [blame] | 227 | this.$store.dispatch('localUsers/getAccountSettings'); |
Yoshie Muranaka | 038a9da | 2020-04-17 11:22:56 -0700 | [diff] [blame] | 228 | this.$store.dispatch('localUsers/getAccountRoles'); |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 229 | }, |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 230 | beforeRouteLeave(to, from, next) { |
| 231 | this.hideLoader(); |
| 232 | next(); |
| 233 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 234 | methods: { |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 235 | initModalUser(user) { |
| 236 | this.activeUser = user; |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 237 | this.$bvModal.show('modal-user'); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 238 | }, |
| 239 | initModalDelete(user) { |
| 240 | this.$bvModal |
| 241 | .msgBoxConfirm( |
Yoshie Muranaka | eaa0480 | 2020-02-28 13:21:27 -0800 | [diff] [blame] | 242 | this.$t('pageLocalUserManagement.modal.deleteConfirmMessage', { |
| 243 | user: user.username |
| 244 | }), |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 245 | { |
Yoshie Muranaka | 2932165 | 2020-05-04 10:52:36 -0700 | [diff] [blame] | 246 | title: this.$tc('pageLocalUserManagement.deleteUser'), |
| 247 | okTitle: this.$tc('pageLocalUserManagement.deleteUser') |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 248 | } |
| 249 | ) |
| 250 | .then(deleteConfirmed => { |
| 251 | if (deleteConfirmed) { |
| 252 | this.deleteUser(user); |
| 253 | } |
| 254 | }); |
| 255 | }, |
| 256 | initModalSettings() { |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 257 | this.$bvModal.show('modal-settings'); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 258 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 259 | saveUser({ isNewUser, userData }) { |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 260 | this.startLoader(); |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 261 | if (isNewUser) { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 262 | this.$store |
| 263 | .dispatch('localUsers/createUser', userData) |
| 264 | .then(success => this.successToast(success)) |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 265 | .catch(({ message }) => this.errorToast(message)) |
| 266 | .finally(() => this.endLoader()); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 267 | } else { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 268 | this.$store |
| 269 | .dispatch('localUsers/updateUser', userData) |
| 270 | .then(success => this.successToast(success)) |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 271 | .catch(({ message }) => this.errorToast(message)) |
| 272 | .finally(() => this.endLoader()); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 273 | } |
| 274 | }, |
| 275 | deleteUser({ username }) { |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 276 | this.startLoader(); |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 277 | this.$store |
| 278 | .dispatch('localUsers/deleteUser', username) |
| 279 | .then(success => this.successToast(success)) |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 280 | .catch(({ message }) => this.errorToast(message)) |
| 281 | .finally(() => this.endLoader()); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 282 | }, |
| 283 | onBatchAction(action) { |
| 284 | switch (action) { |
| 285 | case 'delete': |
Yoshie Muranaka | 2932165 | 2020-05-04 10:52:36 -0700 | [diff] [blame] | 286 | this.$bvModal |
| 287 | .msgBoxConfirm( |
| 288 | this.$tc( |
| 289 | 'pageLocalUserManagement.modal.batchDeleteConfirmMessage', |
| 290 | this.selectedRows.length |
| 291 | ), |
| 292 | { |
| 293 | title: this.$tc( |
| 294 | 'pageLocalUserManagement.deleteUser', |
| 295 | this.selectedRows.length |
| 296 | ), |
| 297 | okTitle: this.$tc( |
| 298 | 'pageLocalUserManagement.deleteUser', |
| 299 | this.selectedRows.length |
| 300 | ) |
| 301 | } |
| 302 | ) |
| 303 | .then(deleteConfirmed => { |
| 304 | if (deleteConfirmed) { |
Yoshie Muranaka | 8e4b5c3 | 2020-05-27 14:10:52 -0700 | [diff] [blame] | 305 | this.startLoader(); |
Yoshie Muranaka | 2932165 | 2020-05-04 10:52:36 -0700 | [diff] [blame] | 306 | this.$store |
| 307 | .dispatch('localUsers/deleteUsers', this.selectedRows) |
| 308 | .then(messages => { |
| 309 | messages.forEach(({ type, message }) => { |
| 310 | if (type === 'success') this.successToast(message); |
| 311 | if (type === 'error') this.errorToast(message); |
| 312 | }); |
| 313 | }) |
| 314 | .finally(() => this.endLoader()); |
| 315 | } |
| 316 | }); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 317 | break; |
| 318 | case 'enable': |
Yoshie Muranaka | 8e4b5c3 | 2020-05-27 14:10:52 -0700 | [diff] [blame] | 319 | this.startLoader(); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 320 | this.$store |
| 321 | .dispatch('localUsers/enableUsers', this.selectedRows) |
| 322 | .then(messages => { |
| 323 | messages.forEach(({ type, message }) => { |
| 324 | if (type === 'success') this.successToast(message); |
| 325 | if (type === 'error') this.errorToast(message); |
| 326 | }); |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 327 | }) |
| 328 | .finally(() => this.endLoader()); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 329 | break; |
| 330 | case 'disable': |
Yoshie Muranaka | 8e4b5c3 | 2020-05-27 14:10:52 -0700 | [diff] [blame] | 331 | this.startLoader(); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 332 | this.$store |
| 333 | .dispatch('localUsers/disableUsers', this.selectedRows) |
| 334 | .then(messages => { |
| 335 | messages.forEach(({ type, message }) => { |
| 336 | if (type === 'success') this.successToast(message); |
| 337 | if (type === 'error') this.errorToast(message); |
| 338 | }); |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 339 | }) |
| 340 | .finally(() => this.endLoader()); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 341 | break; |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 342 | } |
Yoshie Muranaka | 0e893f0 | 2020-02-18 13:39:45 -0800 | [diff] [blame] | 343 | }, |
| 344 | onTableRowAction(action, row) { |
| 345 | switch (action) { |
| 346 | case 'edit': |
| 347 | this.initModalUser(row); |
| 348 | break; |
| 349 | case 'delete': |
| 350 | this.initModalDelete(row); |
| 351 | break; |
| 352 | default: |
| 353 | break; |
| 354 | } |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 355 | }, |
| 356 | saveAccountSettings(settings) { |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 357 | this.startLoader(); |
Yoshie Muranaka | 1b1c100 | 2020-02-20 10:18:36 -0800 | [diff] [blame] | 358 | this.$store |
| 359 | .dispatch('localUsers/saveAccountSettings', settings) |
| 360 | .then(message => this.successToast(message)) |
Yoshie Muranaka | 346be2a | 2020-04-28 11:12:14 -0700 | [diff] [blame] | 361 | .catch(({ message }) => this.errorToast(message)) |
| 362 | .finally(() => this.endLoader()); |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | }; |
| 366 | </script> |
| 367 | |
| 368 | <style lang="scss" scoped> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 369 | .btn.collapsed { |
| 370 | svg { |
| 371 | transform: rotate(180deg); |
| 372 | } |
| 373 | } |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 374 | </style> |