Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 1 | <template> |
| 2 | <div> |
| 3 | <b-row> |
| 4 | <b-col md="9"> |
| 5 | <alert :show="isServiceEnabled === false" variant="info"> |
| 6 | {{ $t('pageLdap.tableRoleGroups.alertContent') }} |
| 7 | </alert> |
| 8 | </b-col> |
| 9 | </b-row> |
| 10 | <b-row> |
| 11 | <b-col class="text-right" md="9"> |
| 12 | <b-btn |
| 13 | variant="primary" |
| 14 | :disabled="!isServiceEnabled" |
| 15 | @click="initRoleGroupModal(null)" |
| 16 | > |
| 17 | <icon-add /> |
| 18 | {{ $t('pageLdap.addRoleGroup') }} |
| 19 | </b-btn> |
| 20 | </b-col> |
| 21 | </b-row> |
| 22 | <b-row> |
| 23 | <b-col md="9"> |
| 24 | <table-toolbar |
| 25 | ref="toolbar" |
| 26 | :selected-items-count="selectedRows.length" |
| 27 | :actions="batchActions" |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 28 | @clear-selected="clearSelectedRows($refs.table)" |
| 29 | @batch-action="onBatchAction" |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 30 | /> |
| 31 | <b-table |
| 32 | ref="table" |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 33 | responsive |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 34 | selectable |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 35 | show-empty |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 36 | no-select-on-click |
Sukanya Pandey | fde429e | 2020-09-14 20:48:39 +0530 | [diff] [blame] | 37 | hover |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 38 | no-sort-reset |
| 39 | sort-icon-left |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 40 | :busy="isBusy" |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 41 | :items="tableItems" |
| 42 | :fields="fields" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 43 | :empty-text="$t('global.table.emptyMessage')" |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 44 | @row-selected="onRowSelected($event, tableItems.length)" |
| 45 | > |
| 46 | <!-- Checkbox column --> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 47 | <template #head(checkbox)> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 48 | <b-form-checkbox |
| 49 | v-model="tableHeaderCheckboxModel" |
| 50 | :indeterminate="tableHeaderCheckboxIndeterminate" |
| 51 | :disabled="!isServiceEnabled" |
| 52 | @change="onChangeHeaderCheckbox($refs.table)" |
Dixsie Wolmers | c42ad71 | 2020-11-19 17:29:24 -0600 | [diff] [blame] | 53 | > |
| 54 | <span class="sr-only">{{ $t('global.table.selectAll') }}</span> |
| 55 | </b-form-checkbox> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 56 | </template> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 57 | <template #cell(checkbox)="row"> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 58 | <b-form-checkbox |
| 59 | v-model="row.rowSelected" |
| 60 | :disabled="!isServiceEnabled" |
| 61 | @change="toggleSelectRow($refs.table, row.index)" |
Dixsie Wolmers | c42ad71 | 2020-11-19 17:29:24 -0600 | [diff] [blame] | 62 | > |
| 63 | <span class="sr-only">{{ $t('global.table.selectItem') }}</span> |
| 64 | </b-form-checkbox> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 65 | </template> |
| 66 | |
| 67 | <!-- table actions column --> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 68 | <template #cell(actions)="{ item }"> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 69 | <table-row-action |
| 70 | v-for="(action, index) in item.actions" |
| 71 | :key="index" |
| 72 | :value="action.value" |
| 73 | :enabled="action.enabled" |
| 74 | :title="action.title" |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 75 | @click-table-action="onTableRowAction($event, item)" |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 76 | > |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 77 | <template #icon> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 78 | <icon-edit v-if="action.value === 'edit'" /> |
| 79 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 80 | </template> |
| 81 | </table-row-action> |
| 82 | </template> |
| 83 | </b-table> |
| 84 | </b-col> |
| 85 | </b-row> |
| 86 | <modal-add-role-group |
| 87 | :role-group="activeRoleGroup" |
| 88 | @ok="saveRoleGroup" |
| 89 | @hidden="activeRoleGroup = null" |
| 90 | /> |
| 91 | </div> |
| 92 | </template> |
| 93 | |
| 94 | <script> |
| 95 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 96 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 97 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 98 | import { mapGetters } from 'vuex'; |
| 99 | |
| 100 | import Alert from '@/components/Global/Alert'; |
| 101 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 102 | import TableRowAction from '@/components/Global/TableRowAction'; |
SurenNeware | ba91c49 | 2020-10-27 14:18:54 +0530 | [diff] [blame] | 103 | import BVTableSelectableMixin, { |
| 104 | selectedRows, |
| 105 | tableHeaderCheckboxModel, |
| 106 | tableHeaderCheckboxIndeterminate, |
| 107 | } from '@/components/Mixins/BVTableSelectableMixin'; |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 108 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 109 | import ModalAddRoleGroup from './ModalAddRoleGroup'; |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 110 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 111 | |
| 112 | export default { |
| 113 | components: { |
| 114 | Alert, |
| 115 | IconAdd, |
| 116 | IconEdit, |
| 117 | IconTrashcan, |
| 118 | ModalAddRoleGroup, |
| 119 | TableRowAction, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 120 | TableToolbar, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 121 | }, |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 122 | mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin], |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 123 | data() { |
| 124 | return { |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 125 | isBusy: true, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 126 | activeRoleGroup: null, |
| 127 | fields: [ |
| 128 | { |
| 129 | key: 'checkbox', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 130 | sortable: false, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 131 | }, |
| 132 | { |
| 133 | key: 'groupName', |
| 134 | sortable: true, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 135 | label: this.$t('pageLdap.tableRoleGroups.groupName'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 136 | }, |
| 137 | { |
| 138 | key: 'groupPrivilege', |
| 139 | sortable: true, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 140 | label: this.$t('pageLdap.tableRoleGroups.groupPrivilege'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 141 | }, |
| 142 | { |
| 143 | key: 'actions', |
| 144 | sortable: false, |
| 145 | label: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 146 | tdClass: 'text-right', |
| 147 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 148 | ], |
| 149 | batchActions: [ |
| 150 | { |
| 151 | value: 'delete', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 152 | label: this.$t('global.action.delete'), |
| 153 | }, |
| 154 | ], |
SurenNeware | ba91c49 | 2020-10-27 14:18:54 +0530 | [diff] [blame] | 155 | selectedRows: selectedRows, |
| 156 | tableHeaderCheckboxModel: tableHeaderCheckboxModel, |
| 157 | tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 158 | }; |
| 159 | }, |
| 160 | computed: { |
| 161 | ...mapGetters('ldap', ['isServiceEnabled', 'enabledRoleGroups']), |
| 162 | tableItems() { |
| 163 | return this.enabledRoleGroups.map(({ LocalRole, RemoteGroup }) => { |
| 164 | return { |
| 165 | groupName: RemoteGroup, |
| 166 | groupPrivilege: LocalRole, |
| 167 | actions: [ |
| 168 | { |
| 169 | value: 'edit', |
| 170 | title: this.$t('global.action.edit'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 171 | enabled: this.isServiceEnabled, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 172 | }, |
| 173 | { |
| 174 | value: 'delete', |
| 175 | title: this.$t('global.action.delete'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 176 | enabled: this.isServiceEnabled, |
| 177 | }, |
| 178 | ], |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 179 | }; |
| 180 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 181 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 182 | }, |
| 183 | created() { |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 184 | this.$store.dispatch('userManagement/getAccountRoles').finally(() => { |
| 185 | this.isBusy = false; |
| 186 | }); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 187 | }, |
| 188 | methods: { |
| 189 | onBatchAction() { |
| 190 | this.$bvModal |
| 191 | .msgBoxConfirm( |
| 192 | this.$tc( |
| 193 | 'pageLdap.modal.deleteRoleGroupBatchConfirmMessage', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 194 | this.selectedRows.length, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 195 | ), |
| 196 | { |
| 197 | title: this.$t('pageLdap.modal.deleteRoleGroup'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 198 | okTitle: this.$t('global.action.delete'), |
Sukanya Pandey | 3835713 | 2020-12-22 13:40:59 +0530 | [diff] [blame] | 199 | cancelTitle: this.$t('global.action.cancel'), |
Paul Fertser | d1ef18e | 2024-04-06 08:04:14 +0000 | [diff] [blame] | 200 | autoFocusButton: 'ok', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 201 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 202 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 203 | .then((deleteConfirmed) => { |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 204 | if (deleteConfirmed) { |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 205 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 206 | this.$store |
| 207 | .dispatch('ldap/deleteRoleGroup', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 208 | roleGroups: this.selectedRows, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 209 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 210 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 211 | .catch(({ message }) => this.errorToast(message)) |
| 212 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 213 | } |
| 214 | }); |
| 215 | }, |
| 216 | onTableRowAction(action, row) { |
| 217 | switch (action) { |
| 218 | case 'edit': |
| 219 | this.initRoleGroupModal(row); |
| 220 | break; |
| 221 | case 'delete': |
| 222 | this.$bvModal |
| 223 | .msgBoxConfirm( |
| 224 | this.$t('pageLdap.modal.deleteRoleGroupConfirmMessage', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 225 | groupName: row.groupName, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 226 | }), |
| 227 | { |
| 228 | title: this.$t('pageLdap.modal.deleteRoleGroup'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 229 | okTitle: this.$t('global.action.delete'), |
Sukanya Pandey | 3835713 | 2020-12-22 13:40:59 +0530 | [diff] [blame] | 230 | cancelTitle: this.$t('global.action.cancel'), |
Paul Fertser | d1ef18e | 2024-04-06 08:04:14 +0000 | [diff] [blame] | 231 | autoFocusButton: 'ok', |
Ed Tanous | 8132399 | 2024-02-27 11:26:24 -0800 | [diff] [blame] | 232 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 233 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 234 | .then((deleteConfirmed) => { |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 235 | if (deleteConfirmed) { |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 236 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 237 | this.$store |
| 238 | .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 239 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 240 | .catch(({ message }) => this.errorToast(message)) |
| 241 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 242 | } |
| 243 | }); |
| 244 | break; |
| 245 | } |
| 246 | }, |
| 247 | initRoleGroupModal(roleGroup) { |
| 248 | this.activeRoleGroup = roleGroup; |
| 249 | this.$bvModal.show('modal-role-group'); |
| 250 | }, |
| 251 | saveRoleGroup({ addNew, groupName, groupPrivilege }) { |
| 252 | this.activeRoleGroup = null; |
| 253 | const data = { groupName, groupPrivilege }; |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 254 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 255 | if (addNew) { |
| 256 | this.$store |
| 257 | .dispatch('ldap/addNewRoleGroup', data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 258 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 259 | .catch(({ message }) => this.errorToast(message)) |
| 260 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 261 | } else { |
| 262 | this.$store |
| 263 | .dispatch('ldap/saveRoleGroup', data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 264 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 265 | .catch(({ message }) => this.errorToast(message)) |
| 266 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 267 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 268 | }, |
| 269 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 270 | }; |
| 271 | </script> |