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