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