blob: f73d927615f2524ecfbaf5cc2660045528612890 [file] [log] [blame]
Yoshie Muranakadc3d5412020-04-17 09:39:41 -07001<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 Pandeyedb8a772020-10-29 11:33:42 +053028 @clear-selected="clearSelectedRows($refs.table)"
29 @batch-action="onBatchAction"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070030 />
31 <b-table
32 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053033 responsive
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070034 selectable
SurenNeware307382e2020-07-27 20:45:14 +053035 show-empty
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070036 no-select-on-click
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053037 hover
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070038 no-sort-reset
39 sort-icon-left
Kenneth Fullbright41057852021-12-27 16:19:37 -060040 :busy="isBusy"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070041 :items="tableItems"
42 :fields="fields"
SurenNeware307382e2020-07-27 20:45:14 +053043 :empty-text="$t('global.table.emptyMessage')"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070044 @row-selected="onRowSelected($event, tableItems.length)"
45 >
46 <!-- Checkbox column -->
Derick Montague602e98a2020-10-21 16:20:00 -050047 <template #head(checkbox)>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070048 <b-form-checkbox
49 v-model="tableHeaderCheckboxModel"
50 :indeterminate="tableHeaderCheckboxIndeterminate"
51 :disabled="!isServiceEnabled"
52 @change="onChangeHeaderCheckbox($refs.table)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060053 >
54 <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
55 </b-form-checkbox>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070056 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050057 <template #cell(checkbox)="row">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070058 <b-form-checkbox
59 v-model="row.rowSelected"
60 :disabled="!isServiceEnabled"
61 @change="toggleSelectRow($refs.table, row.index)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060062 >
63 <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
64 </b-form-checkbox>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070065 </template>
66
67 <!-- table actions column -->
Derick Montague602e98a2020-10-21 16:20:00 -050068 <template #cell(actions)="{ item }">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070069 <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 Pandeyedb8a772020-10-29 11:33:42 +053075 @click-table-action="onTableRowAction($event, item)"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070076 >
Derick Montague602e98a2020-10-21 16:20:00 -050077 <template #icon>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070078 <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>
95import IconEdit from '@carbon/icons-vue/es/edit/20';
96import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
97import IconAdd from '@carbon/icons-vue/es/add--alt/20';
98import { mapGetters } from 'vuex';
99
100import Alert from '@/components/Global/Alert';
101import TableToolbar from '@/components/Global/TableToolbar';
102import TableRowAction from '@/components/Global/TableRowAction';
SurenNewareba91c492020-10-27 14:18:54 +0530103import BVTableSelectableMixin, {
104 selectedRows,
105 tableHeaderCheckboxModel,
106 tableHeaderCheckboxIndeterminate,
107} from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700108import BVToastMixin from '@/components/Mixins/BVToastMixin';
109import ModalAddRoleGroup from './ModalAddRoleGroup';
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700110import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Surya Vde23ea22024-07-11 15:19:46 +0530111import { useI18n } from 'vue-i18n';
112import i18n from '@/i18n';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700113
114export default {
115 components: {
116 Alert,
117 IconAdd,
118 IconEdit,
119 IconTrashcan,
120 ModalAddRoleGroup,
121 TableRowAction,
Derick Montague602e98a2020-10-21 16:20:00 -0500122 TableToolbar,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700123 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700124 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700125 data() {
126 return {
Surya Vde23ea22024-07-11 15:19:46 +0530127 $t: useI18n().t,
Kenneth Fullbright41057852021-12-27 16:19:37 -0600128 isBusy: true,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700129 activeRoleGroup: null,
130 fields: [
131 {
132 key: 'checkbox',
Derick Montague602e98a2020-10-21 16:20:00 -0500133 sortable: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700134 },
135 {
136 key: 'groupName',
137 sortable: true,
Surya Vde23ea22024-07-11 15:19:46 +0530138 label: i18n.global.t('pageLdap.tableRoleGroups.groupName'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700139 },
140 {
141 key: 'groupPrivilege',
142 sortable: true,
Surya Vde23ea22024-07-11 15:19:46 +0530143 label: i18n.global.t('pageLdap.tableRoleGroups.groupPrivilege'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700144 },
145 {
146 key: 'actions',
147 sortable: false,
148 label: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500149 tdClass: 'text-right',
150 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700151 ],
152 batchActions: [
153 {
154 value: 'delete',
Surya Vde23ea22024-07-11 15:19:46 +0530155 label: i18n.global.t('global.action.delete'),
Derick Montague602e98a2020-10-21 16:20:00 -0500156 },
157 ],
SurenNewareba91c492020-10-27 14:18:54 +0530158 selectedRows: selectedRows,
159 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
160 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700161 };
162 },
163 computed: {
164 ...mapGetters('ldap', ['isServiceEnabled', 'enabledRoleGroups']),
165 tableItems() {
166 return this.enabledRoleGroups.map(({ LocalRole, RemoteGroup }) => {
167 return {
168 groupName: RemoteGroup,
169 groupPrivilege: LocalRole,
170 actions: [
171 {
172 value: 'edit',
Surya Vde23ea22024-07-11 15:19:46 +0530173 title: i18n.global.t('global.action.edit'),
Derick Montague602e98a2020-10-21 16:20:00 -0500174 enabled: this.isServiceEnabled,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700175 },
176 {
177 value: 'delete',
Surya Vde23ea22024-07-11 15:19:46 +0530178 title: i18n.global.t('global.action.delete'),
Derick Montague602e98a2020-10-21 16:20:00 -0500179 enabled: this.isServiceEnabled,
180 },
181 ],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700182 };
183 });
Derick Montague602e98a2020-10-21 16:20:00 -0500184 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700185 },
186 created() {
Kenneth Fullbright41057852021-12-27 16:19:37 -0600187 this.$store.dispatch('userManagement/getAccountRoles').finally(() => {
188 this.isBusy = false;
189 });
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700190 },
191 methods: {
192 onBatchAction() {
193 this.$bvModal
194 .msgBoxConfirm(
Surya Vde23ea22024-07-11 15:19:46 +0530195 i18n.global.t(
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700196 'pageLdap.modal.deleteRoleGroupBatchConfirmMessage',
Ed Tanous81323992024-02-27 11:26:24 -0800197 this.selectedRows.length,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700198 ),
199 {
Surya Vde23ea22024-07-11 15:19:46 +0530200 title: i18n.global.t('pageLdap.modal.deleteRoleGroup'),
201 okTitle: i18n.global.t('global.action.delete'),
202 cancelTitle: i18n.global.t('global.action.cancel'),
Paul Fertserd1ef18e2024-04-06 08:04:14 +0000203 autoFocusButton: 'ok',
Ed Tanous81323992024-02-27 11:26:24 -0800204 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700205 )
Derick Montague602e98a2020-10-21 16:20:00 -0500206 .then((deleteConfirmed) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700207 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700208 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700209 this.$store
210 .dispatch('ldap/deleteRoleGroup', {
Derick Montague602e98a2020-10-21 16:20:00 -0500211 roleGroups: this.selectedRows,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700212 })
Derick Montague602e98a2020-10-21 16:20:00 -0500213 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700214 .catch(({ message }) => this.errorToast(message))
215 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700216 }
217 });
218 },
219 onTableRowAction(action, row) {
220 switch (action) {
221 case 'edit':
222 this.initRoleGroupModal(row);
223 break;
224 case 'delete':
225 this.$bvModal
226 .msgBoxConfirm(
Surya Vde23ea22024-07-11 15:19:46 +0530227 i18n.global.t('pageLdap.modal.deleteRoleGroupConfirmMessage', {
Derick Montague602e98a2020-10-21 16:20:00 -0500228 groupName: row.groupName,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700229 }),
230 {
Surya Vde23ea22024-07-11 15:19:46 +0530231 title: i18n.global.t('pageLdap.modal.deleteRoleGroup'),
232 okTitle: i18n.global.t('global.action.delete'),
233 cancelTitle: i18n.global.t('global.action.cancel'),
Paul Fertserd1ef18e2024-04-06 08:04:14 +0000234 autoFocusButton: 'ok',
Ed Tanous81323992024-02-27 11:26:24 -0800235 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700236 )
Derick Montague602e98a2020-10-21 16:20:00 -0500237 .then((deleteConfirmed) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700238 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700239 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700240 this.$store
241 .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] })
Derick Montague602e98a2020-10-21 16:20:00 -0500242 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700243 .catch(({ message }) => this.errorToast(message))
244 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700245 }
246 });
247 break;
248 }
249 },
250 initRoleGroupModal(roleGroup) {
251 this.activeRoleGroup = roleGroup;
252 this.$bvModal.show('modal-role-group');
253 },
254 saveRoleGroup({ addNew, groupName, groupPrivilege }) {
255 this.activeRoleGroup = null;
256 const data = { groupName, groupPrivilege };
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700257 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700258 if (addNew) {
259 this.$store
260 .dispatch('ldap/addNewRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500261 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700262 .catch(({ message }) => this.errorToast(message))
263 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700264 } else {
265 this.$store
266 .dispatch('ldap/saveRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500267 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700268 .catch(({ message }) => this.errorToast(message))
269 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700270 }
Derick Montague602e98a2020-10-21 16:20:00 -0500271 },
272 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700273};
274</script>