blob: 8b8b3ac93dc9158bb73ac2c6d248cb8b971a56c2 [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>
jason westoverd36ac8a2025-11-03 20:58:59 -060011 <b-col class="text-end" md="9">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070012 <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 westoverd36ac8a2025-11-03 20:58:59 -060026 :selected-items-count="
27 Array.isArray(selectedRows) ? selectedRows.length : 0
28 "
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070029 :actions="batchActions"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053030 @clear-selected="clearSelectedRows($refs.table)"
31 @batch-action="onBatchAction"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070032 />
33 <b-table
34 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053035 responsive
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070036 selectable
SurenNeware307382e2020-07-27 20:45:14 +053037 show-empty
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070038 no-select-on-click
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053039 hover
jason westoverd36ac8a2025-11-03 20:58:59 -060040 must-sort
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070041 sort-icon-left
jason westoverd36ac8a2025-11-03 20:58:59 -060042 thead-class="table-light"
Kenneth Fullbright41057852021-12-27 16:19:37 -060043 :busy="isBusy"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070044 :items="tableItems"
45 :fields="fields"
SurenNeware307382e2020-07-27 20:45:14 +053046 :empty-text="$t('global.table.emptyMessage')"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070047 @row-selected="onRowSelected($event, tableItems.length)"
48 >
49 <!-- Checkbox column -->
Derick Montague602e98a2020-10-21 16:20:00 -050050 <template #head(checkbox)>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070051 <b-form-checkbox
52 v-model="tableHeaderCheckboxModel"
53 :indeterminate="tableHeaderCheckboxIndeterminate"
54 :disabled="!isServiceEnabled"
jason westoverd36ac8a2025-11-03 20:58:59 -060055 @change="onChangeHeaderCheckbox($refs.table, $event)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060056 >
jason westoverd36ac8a2025-11-03 20:58:59 -060057 <span class="visually-hidden-focusable">
58 {{ $t('global.table.selectAll') }}
59 </span>
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060060 </b-form-checkbox>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070061 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050062 <template #cell(checkbox)="row">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070063 <b-form-checkbox
64 v-model="row.rowSelected"
65 :disabled="!isServiceEnabled"
66 @change="toggleSelectRow($refs.table, row.index)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060067 >
jason westoverd36ac8a2025-11-03 20:58:59 -060068 <span class="visually-hidden-focusable">
69 {{ $t('global.table.selectItem') }}
70 </span>
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060071 </b-form-checkbox>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070072 </template>
73
74 <!-- table actions column -->
Derick Montague602e98a2020-10-21 16:20:00 -050075 <template #cell(actions)="{ item }">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070076 <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 Pandeyedb8a772020-10-29 11:33:42 +053082 @click-table-action="onTableRowAction($event, item)"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070083 >
Derick Montague602e98a2020-10-21 16:20:00 -050084 <template #icon>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070085 <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 westoverd36ac8a2025-11-03 20:58:59 -060094 v-model="showRoleGroupModal"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070095 :role-group="activeRoleGroup"
96 @ok="saveRoleGroup"
97 @hidden="activeRoleGroup = null"
98 />
99 </div>
100</template>
101
102<script>
103import IconEdit from '@carbon/icons-vue/es/edit/20';
104import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
105import IconAdd from '@carbon/icons-vue/es/add--alt/20';
106import { mapGetters } from 'vuex';
107
108import Alert from '@/components/Global/Alert';
109import TableToolbar from '@/components/Global/TableToolbar';
110import TableRowAction from '@/components/Global/TableRowAction';
SurenNewareba91c492020-10-27 14:18:54 +0530111import BVTableSelectableMixin, {
112 selectedRows,
113 tableHeaderCheckboxModel,
114 tableHeaderCheckboxIndeterminate,
115} from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700116import BVToastMixin from '@/components/Mixins/BVToastMixin';
117import ModalAddRoleGroup from './ModalAddRoleGroup';
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700118import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Surya Vde23ea22024-07-11 15:19:46 +0530119import { useI18n } from 'vue-i18n';
120import i18n from '@/i18n';
jason westoverd36ac8a2025-11-03 20:58:59 -0600121import { useModal } from 'bootstrap-vue-next';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700122
123export default {
124 components: {
125 Alert,
126 IconAdd,
127 IconEdit,
128 IconTrashcan,
129 ModalAddRoleGroup,
130 TableRowAction,
Derick Montague602e98a2020-10-21 16:20:00 -0500131 TableToolbar,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700132 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700133 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
jason westoverd36ac8a2025-11-03 20:58:59 -0600134 setup() {
135 const bvModal = useModal();
136 return { bvModal };
137 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700138 data() {
139 return {
Surya Vde23ea22024-07-11 15:19:46 +0530140 $t: useI18n().t,
Kenneth Fullbright41057852021-12-27 16:19:37 -0600141 isBusy: true,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700142 activeRoleGroup: null,
jason westoverd36ac8a2025-11-03 20:58:59 -0600143 showRoleGroupModal: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700144 fields: [
145 {
146 key: 'checkbox',
Derick Montague602e98a2020-10-21 16:20:00 -0500147 sortable: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700148 },
149 {
150 key: 'groupName',
151 sortable: true,
Surya Vde23ea22024-07-11 15:19:46 +0530152 label: i18n.global.t('pageLdap.tableRoleGroups.groupName'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700153 },
154 {
155 key: 'groupPrivilege',
156 sortable: true,
Surya Vde23ea22024-07-11 15:19:46 +0530157 label: i18n.global.t('pageLdap.tableRoleGroups.groupPrivilege'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700158 },
159 {
160 key: 'actions',
161 sortable: false,
162 label: '',
jason westoverd36ac8a2025-11-03 20:58:59 -0600163 tdClass: 'text-end',
Derick Montague602e98a2020-10-21 16:20:00 -0500164 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700165 ],
166 batchActions: [
167 {
168 value: 'delete',
Surya Vde23ea22024-07-11 15:19:46 +0530169 label: i18n.global.t('global.action.delete'),
Derick Montague602e98a2020-10-21 16:20:00 -0500170 },
171 ],
SurenNewareba91c492020-10-27 14:18:54 +0530172 selectedRows: selectedRows,
173 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
174 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700175 };
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 Vde23ea22024-07-11 15:19:46 +0530187 title: i18n.global.t('global.action.edit'),
Derick Montague602e98a2020-10-21 16:20:00 -0500188 enabled: this.isServiceEnabled,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700189 },
190 {
191 value: 'delete',
Surya Vde23ea22024-07-11 15:19:46 +0530192 title: i18n.global.t('global.action.delete'),
Derick Montague602e98a2020-10-21 16:20:00 -0500193 enabled: this.isServiceEnabled,
194 },
195 ],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700196 };
197 });
Derick Montague602e98a2020-10-21 16:20:00 -0500198 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700199 },
200 created() {
Kenneth Fullbright41057852021-12-27 16:19:37 -0600201 this.$store.dispatch('userManagement/getAccountRoles').finally(() => {
202 this.isBusy = false;
203 });
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700204 },
205 methods: {
206 onBatchAction() {
jason westoverd36ac8a2025-11-03 20:58:59 -0600207 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 Muranakadc3d5412020-04-17 09:39:41 -0700231 },
232 onTableRowAction(action, row) {
233 switch (action) {
234 case 'edit':
235 this.initRoleGroupModal(row);
236 break;
237 case 'delete':
jason westoverd36ac8a2025-11-03 20:58:59 -0600238 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 Muranakadc3d5412020-04-17 09:39:41 -0700260 break;
261 }
262 },
jason westoverd36ac8a2025-11-03 20:58:59 -0600263 confirmDialog(message, options = {}) {
264 return this.$confirm({ message, ...options });
265 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700266 initRoleGroupModal(roleGroup) {
267 this.activeRoleGroup = roleGroup;
jason westoverd36ac8a2025-11-03 20:58:59 -0600268 this.showRoleGroupModal = true;
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700269 },
270 saveRoleGroup({ addNew, groupName, groupPrivilege }) {
271 this.activeRoleGroup = null;
272 const data = { groupName, groupPrivilege };
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700273 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700274 if (addNew) {
275 this.$store
276 .dispatch('ldap/addNewRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500277 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700278 .catch(({ message }) => this.errorToast(message))
279 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700280 } else {
281 this.$store
282 .dispatch('ldap/saveRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500283 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700284 .catch(({ message }) => this.errorToast(message))
285 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700286 }
Derick Montague602e98a2020-10-21 16:20:00 -0500287 },
288 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700289};
290</script>