Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 2 | <b-container fluid> |
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 | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 7 | Account policy settings |
Yoshie Muranaka | 996d2d5 | 2019-12-30 09:06:45 -0800 | [diff] [blame] | 8 | <icon-settings /> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 9 | </b-button> |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 10 | <b-button variant="primary" @click="initModalUser(null)"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 11 | Add user |
Yoshie Muranaka | 996d2d5 | 2019-12-30 09:06:45 -0800 | [diff] [blame] | 12 | <icon-add /> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 13 | </b-button> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 14 | </b-col> |
| 15 | </b-row> |
| 16 | <b-row> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 17 | <b-col xl="9"> |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 18 | <table-toolbar |
| 19 | ref="toolbar" |
| 20 | :selected-items-count="selectedRows.length" |
| 21 | :actions="tableToolbarActions" |
| 22 | @clearSelected="clearSelectedRows($refs.table)" |
| 23 | @batchAction="onBatchAction" |
| 24 | /> |
| 25 | <b-table |
| 26 | ref="table" |
| 27 | selectable |
| 28 | no-select-on-click |
| 29 | :fields="fields" |
| 30 | :items="tableItems" |
| 31 | @row-selected="onRowSelected($event, tableItems.length)" |
| 32 | > |
| 33 | <!-- Checkbox column --> |
| 34 | <template v-slot:head(checkbox)> |
| 35 | <b-form-checkbox |
| 36 | v-model="tableHeaderCheckboxModel" |
| 37 | :indeterminate="tableHeaderCheckboxIndeterminate" |
| 38 | @change="onChangeHeaderCheckbox($refs.table)" |
| 39 | /> |
| 40 | </template> |
| 41 | <template v-slot:cell(checkbox)="row"> |
| 42 | <b-form-checkbox |
| 43 | v-model="row.rowSelected" |
| 44 | @change="toggleSelectRow($refs.table, row.index)" |
| 45 | /> |
| 46 | </template> |
| 47 | |
| 48 | <!-- table actions column --> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 49 | <template v-slot:cell(actions)="data"> |
| 50 | <b-button |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 51 | aria-label="Edit user" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 52 | title="Edit user" |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 53 | variant="link" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 54 | :disabled="!data.value.edit" |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 55 | @click="initModalUser(data.item)" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 56 | > |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 57 | <icon-edit /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 58 | </b-button> |
| 59 | <b-button |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 60 | aria-label="Delete user" |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 61 | title="Delete user" |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 62 | variant="link" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 63 | :disabled="!data.value.delete" |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 64 | @click="initModalDelete(data.item)" |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 65 | > |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 66 | <icon-trashcan /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 67 | </b-button> |
| 68 | </template> |
| 69 | </b-table> |
| 70 | </b-col> |
| 71 | </b-row> |
| 72 | <b-row> |
Yoshie Muranaka | 74f8687 | 2020-02-10 12:28:37 -0800 | [diff] [blame] | 73 | <b-col xl="8"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 74 | <b-button v-b-toggle.collapse-role-table variant="link" class="mt-3"> |
| 75 | View privilege role descriptions |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 76 | <icon-chevron /> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 77 | </b-button> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 78 | <b-collapse id="collapse-role-table" class="mt-3"> |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 79 | <table-roles /> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 80 | </b-collapse> |
| 81 | </b-col> |
| 82 | </b-row> |
| 83 | <!-- Modals --> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 84 | <modal-settings :settings="settings"></modal-settings> |
| 85 | <modal-user :user="activeUser" @ok="saveUser"></modal-user> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 86 | </b-container> |
Derick Montague | a2988f4 | 2020-01-17 13:46:30 -0600 | [diff] [blame] | 87 | </template> |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 88 | |
| 89 | <script> |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 90 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 91 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 92 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 93 | import IconSettings from '@carbon/icons-vue/es/settings/20'; |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 94 | import IconChevron from '@carbon/icons-vue/es/chevron--up/20'; |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 95 | |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 96 | import ModalUser from './ModalUser'; |
| 97 | import ModalSettings from './ModalSettings'; |
| 98 | import PageTitle from '../../../components/Global/PageTitle'; |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 99 | import TableRoles from './TableRoles'; |
| 100 | import TableToolbar from '../../../components/Global/TableToolbar'; |
| 101 | |
| 102 | import BVTableSelectableMixin from '../../../components/Mixins/BVTableSelectableMixin'; |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 103 | import BVToastMixin from '../../../components/Mixins/BVToastMixin'; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 104 | |
| 105 | export default { |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 106 | name: 'LocalUsers', |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 107 | components: { |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 108 | IconAdd, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 109 | IconChevron, |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 110 | IconEdit, |
| 111 | IconSettings, |
| 112 | IconTrashcan, |
| 113 | ModalSettings, |
| 114 | ModalUser, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 115 | PageTitle, |
Yoshie Muranaka | 8d12910 | 2019-12-19 09:51:55 -0800 | [diff] [blame] | 116 | TableRoles, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 117 | TableToolbar |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 118 | }, |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 119 | mixins: [BVTableSelectableMixin, BVToastMixin], |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 120 | data() { |
| 121 | return { |
| 122 | activeUser: null, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 123 | settings: null, |
| 124 | fields: [ |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 125 | { |
| 126 | key: 'checkbox', |
| 127 | label: '', |
| 128 | tdClass: 'table-cell__checkbox' |
| 129 | }, |
| 130 | 'checkbox', |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 131 | 'username', |
| 132 | 'privilege', |
| 133 | 'status', |
| 134 | { |
| 135 | key: 'actions', |
| 136 | label: '', |
| 137 | tdClass: 'table-cell__actions' |
| 138 | } |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 139 | ], |
| 140 | tableToolbarActions: [ |
| 141 | { |
| 142 | value: 'delete', |
| 143 | labelKey: 'localUserManagement.tableActions.delete' |
| 144 | }, |
| 145 | { |
| 146 | value: 'enable', |
| 147 | labelKey: 'localUserManagement.tableActions.enable' |
| 148 | }, |
| 149 | { |
| 150 | value: 'disable', |
| 151 | labelKey: 'localUserManagement.tableActions.disable' |
| 152 | } |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 153 | ] |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 154 | }; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 155 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 156 | computed: { |
| 157 | allUsers() { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 158 | return this.$store.getters['localUsers/allUsers']; |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 159 | }, |
| 160 | tableItems() { |
| 161 | // transform user data to table data |
| 162 | return this.allUsers.map(user => { |
| 163 | return { |
| 164 | username: user.UserName, |
| 165 | privilege: user.RoleId, |
| 166 | status: user.Locked |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 167 | ? 'Locked' |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 168 | : user.Enabled |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 169 | ? 'Enabled' |
| 170 | : 'Disabled', |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 171 | actions: { |
| 172 | edit: true, |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 173 | delete: user.UserName === 'root' ? false : true |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 174 | }, |
| 175 | ...user |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 176 | }; |
| 177 | }); |
| 178 | } |
| 179 | }, |
Derick Montague | 09e45cd | 2020-01-23 15:45:57 -0600 | [diff] [blame] | 180 | created() { |
| 181 | this.getUsers(); |
| 182 | }, |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 183 | methods: { |
| 184 | getUsers() { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 185 | this.$store.dispatch('localUsers/getUsers'); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 186 | }, |
| 187 | initModalUser(user) { |
| 188 | this.activeUser = user; |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 189 | this.$bvModal.show('modal-user'); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 190 | }, |
| 191 | initModalDelete(user) { |
| 192 | this.$bvModal |
| 193 | .msgBoxConfirm( |
| 194 | `Are you sure you want to delete user '${user.username}'? This action cannot be undone.`, |
| 195 | { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 196 | title: 'Delete user', |
| 197 | okTitle: 'Delete user' |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 198 | } |
| 199 | ) |
| 200 | .then(deleteConfirmed => { |
| 201 | if (deleteConfirmed) { |
| 202 | this.deleteUser(user); |
| 203 | } |
| 204 | }); |
| 205 | }, |
| 206 | initModalSettings() { |
| 207 | if (this.settings) { |
Derick Montague | e2fd156 | 2019-12-20 13:26:53 -0600 | [diff] [blame] | 208 | this.$bvModal.show('modal-settings'); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 209 | } else { |
| 210 | // fetch settings then show modal |
| 211 | } |
| 212 | }, |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 213 | saveUser({ isNewUser, userData }) { |
| 214 | if (isNewUser) { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 215 | this.$store |
| 216 | .dispatch('localUsers/createUser', userData) |
| 217 | .then(success => this.successToast(success)) |
| 218 | .catch(({ message }) => this.errorToast(message)); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 219 | } else { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 220 | this.$store |
| 221 | .dispatch('localUsers/updateUser', userData) |
| 222 | .then(success => this.successToast(success)) |
| 223 | .catch(({ message }) => this.errorToast(message)); |
Yoshie Muranaka | 463a570 | 2019-12-04 09:09:36 -0800 | [diff] [blame] | 224 | } |
| 225 | }, |
| 226 | deleteUser({ username }) { |
Yoshie Muranaka | 0fc91e7 | 2020-02-05 11:23:06 -0800 | [diff] [blame] | 227 | this.$store |
| 228 | .dispatch('localUsers/deleteUser', username) |
| 229 | .then(success => this.successToast(success)) |
| 230 | .catch(({ message }) => this.errorToast(message)); |
Yoshie Muranaka | 183c275 | 2020-02-12 11:30:49 -0800 | [diff] [blame] | 231 | }, |
| 232 | onBatchAction(action) { |
| 233 | switch (action) { |
| 234 | case 'delete': |
| 235 | this.$store |
| 236 | .dispatch('localUsers/deleteUsers', this.selectedRows) |
| 237 | .then(messages => { |
| 238 | messages.forEach(({ type, message }) => { |
| 239 | if (type === 'success') this.successToast(message); |
| 240 | if (type === 'error') this.errorToast(message); |
| 241 | }); |
| 242 | }); |
| 243 | break; |
| 244 | case 'enable': |
| 245 | this.$store |
| 246 | .dispatch('localUsers/enableUsers', this.selectedRows) |
| 247 | .then(messages => { |
| 248 | messages.forEach(({ type, message }) => { |
| 249 | if (type === 'success') this.successToast(message); |
| 250 | if (type === 'error') this.errorToast(message); |
| 251 | }); |
| 252 | }); |
| 253 | break; |
| 254 | case 'disable': |
| 255 | this.$store |
| 256 | .dispatch('localUsers/disableUsers', this.selectedRows) |
| 257 | .then(messages => { |
| 258 | messages.forEach(({ type, message }) => { |
| 259 | if (type === 'success') this.successToast(message); |
| 260 | if (type === 'error') this.errorToast(message); |
| 261 | }); |
| 262 | }); |
| 263 | break; |
| 264 | default: |
| 265 | break; |
| 266 | } |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | }; |
| 270 | </script> |
| 271 | |
| 272 | <style lang="scss" scoped> |
Yoshie Muranaka | 4b0fc1d | 2020-01-06 07:36:16 -0800 | [diff] [blame] | 273 | .btn.collapsed { |
| 274 | svg { |
| 275 | transform: rotate(180deg); |
| 276 | } |
| 277 | } |
Yoshie Muranaka | 35080ac | 2020-01-17 15:38:57 -0600 | [diff] [blame] | 278 | </style> |