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