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