blob: eeebfb9b60db8a6bf04862f6a7ebfc71ac0753de [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';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700111
112export default {
113 components: {
114 Alert,
115 IconAdd,
116 IconEdit,
117 IconTrashcan,
118 ModalAddRoleGroup,
119 TableRowAction,
Derick Montague602e98a2020-10-21 16:20:00 -0500120 TableToolbar,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700121 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700122 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700123 data() {
124 return {
Kenneth Fullbright41057852021-12-27 16:19:37 -0600125 isBusy: true,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700126 activeRoleGroup: null,
127 fields: [
128 {
129 key: 'checkbox',
Derick Montague602e98a2020-10-21 16:20:00 -0500130 sortable: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700131 },
132 {
133 key: 'groupName',
134 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500135 label: this.$t('pageLdap.tableRoleGroups.groupName'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700136 },
137 {
138 key: 'groupPrivilege',
139 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500140 label: this.$t('pageLdap.tableRoleGroups.groupPrivilege'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700141 },
142 {
143 key: 'actions',
144 sortable: false,
145 label: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500146 tdClass: 'text-right',
147 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700148 ],
149 batchActions: [
150 {
151 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500152 label: this.$t('global.action.delete'),
153 },
154 ],
SurenNewareba91c492020-10-27 14:18:54 +0530155 selectedRows: selectedRows,
156 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
157 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700158 };
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 Montague602e98a2020-10-21 16:20:00 -0500171 enabled: this.isServiceEnabled,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700172 },
173 {
174 value: 'delete',
175 title: this.$t('global.action.delete'),
Derick Montague602e98a2020-10-21 16:20:00 -0500176 enabled: this.isServiceEnabled,
177 },
178 ],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700179 };
180 });
Derick Montague602e98a2020-10-21 16:20:00 -0500181 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700182 },
183 created() {
Kenneth Fullbright41057852021-12-27 16:19:37 -0600184 this.$store.dispatch('userManagement/getAccountRoles').finally(() => {
185 this.isBusy = false;
186 });
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700187 },
188 methods: {
189 onBatchAction() {
190 this.$bvModal
191 .msgBoxConfirm(
192 this.$tc(
193 'pageLdap.modal.deleteRoleGroupBatchConfirmMessage',
Ed Tanous81323992024-02-27 11:26:24 -0800194 this.selectedRows.length,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700195 ),
196 {
197 title: this.$t('pageLdap.modal.deleteRoleGroup'),
Derick Montague602e98a2020-10-21 16:20:00 -0500198 okTitle: this.$t('global.action.delete'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530199 cancelTitle: this.$t('global.action.cancel'),
Paul Fertserd1ef18e2024-04-06 08:04:14 +0000200 autoFocusButton: 'ok',
Ed Tanous81323992024-02-27 11:26:24 -0800201 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700202 )
Derick Montague602e98a2020-10-21 16:20:00 -0500203 .then((deleteConfirmed) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700204 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700205 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700206 this.$store
207 .dispatch('ldap/deleteRoleGroup', {
Derick Montague602e98a2020-10-21 16:20:00 -0500208 roleGroups: this.selectedRows,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700209 })
Derick Montague602e98a2020-10-21 16:20:00 -0500210 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700211 .catch(({ message }) => this.errorToast(message))
212 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700213 }
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 Montague602e98a2020-10-21 16:20:00 -0500225 groupName: row.groupName,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700226 }),
227 {
228 title: this.$t('pageLdap.modal.deleteRoleGroup'),
Derick Montague602e98a2020-10-21 16:20:00 -0500229 okTitle: this.$t('global.action.delete'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530230 cancelTitle: this.$t('global.action.cancel'),
Paul Fertserd1ef18e2024-04-06 08:04:14 +0000231 autoFocusButton: 'ok',
Ed Tanous81323992024-02-27 11:26:24 -0800232 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700233 )
Derick Montague602e98a2020-10-21 16:20:00 -0500234 .then((deleteConfirmed) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700235 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700236 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700237 this.$store
238 .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] })
Derick Montague602e98a2020-10-21 16:20:00 -0500239 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700240 .catch(({ message }) => this.errorToast(message))
241 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700242 }
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 Muranakae9a59c72020-04-30 12:16:30 -0700254 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700255 if (addNew) {
256 this.$store
257 .dispatch('ldap/addNewRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500258 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700259 .catch(({ message }) => this.errorToast(message))
260 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700261 } else {
262 this.$store
263 .dispatch('ldap/saveRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500264 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700265 .catch(({ message }) => this.errorToast(message))
266 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700267 }
Derick Montague602e98a2020-10-21 16:20:00 -0500268 },
269 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700270};
271</script>