blob: b14c97a7fa22aee1d50266cc59a2aab9e7bc951c [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
40 :items="tableItems"
41 :fields="fields"
SurenNeware307382e2020-07-27 20:45:14 +053042 :empty-text="$t('global.table.emptyMessage')"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070043 @row-selected="onRowSelected($event, tableItems.length)"
44 >
45 <!-- Checkbox column -->
Derick Montague602e98a2020-10-21 16:20:00 -050046 <template #head(checkbox)>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070047 <b-form-checkbox
48 v-model="tableHeaderCheckboxModel"
49 :indeterminate="tableHeaderCheckboxIndeterminate"
50 :disabled="!isServiceEnabled"
51 @change="onChangeHeaderCheckbox($refs.table)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060052 >
53 <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
54 </b-form-checkbox>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070055 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050056 <template #cell(checkbox)="row">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070057 <b-form-checkbox
58 v-model="row.rowSelected"
59 :disabled="!isServiceEnabled"
60 @change="toggleSelectRow($refs.table, row.index)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060061 >
62 <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
63 </b-form-checkbox>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070064 </template>
65
66 <!-- table actions column -->
Derick Montague602e98a2020-10-21 16:20:00 -050067 <template #cell(actions)="{ item }">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070068 <table-row-action
69 v-for="(action, index) in item.actions"
70 :key="index"
71 :value="action.value"
72 :enabled="action.enabled"
73 :title="action.title"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053074 @click-table-action="onTableRowAction($event, item)"
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070075 >
Derick Montague602e98a2020-10-21 16:20:00 -050076 <template #icon>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070077 <icon-edit v-if="action.value === 'edit'" />
78 <icon-trashcan v-if="action.value === 'delete'" />
79 </template>
80 </table-row-action>
81 </template>
82 </b-table>
83 </b-col>
84 </b-row>
85 <modal-add-role-group
86 :role-group="activeRoleGroup"
87 @ok="saveRoleGroup"
88 @hidden="activeRoleGroup = null"
89 />
90 </div>
91</template>
92
93<script>
94import IconEdit from '@carbon/icons-vue/es/edit/20';
95import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
96import IconAdd from '@carbon/icons-vue/es/add--alt/20';
97import { mapGetters } from 'vuex';
98
99import Alert from '@/components/Global/Alert';
100import TableToolbar from '@/components/Global/TableToolbar';
101import TableRowAction from '@/components/Global/TableRowAction';
SurenNewareba91c492020-10-27 14:18:54 +0530102import BVTableSelectableMixin, {
103 selectedRows,
104 tableHeaderCheckboxModel,
105 tableHeaderCheckboxIndeterminate,
106} from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700107import BVToastMixin from '@/components/Mixins/BVToastMixin';
108import ModalAddRoleGroup from './ModalAddRoleGroup';
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700109import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700110
111export default {
112 components: {
113 Alert,
114 IconAdd,
115 IconEdit,
116 IconTrashcan,
117 ModalAddRoleGroup,
118 TableRowAction,
Derick Montague602e98a2020-10-21 16:20:00 -0500119 TableToolbar,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700120 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700121 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700122 data() {
123 return {
124 activeRoleGroup: null,
125 fields: [
126 {
127 key: 'checkbox',
Derick Montague602e98a2020-10-21 16:20:00 -0500128 sortable: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700129 },
130 {
131 key: 'groupName',
132 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500133 label: this.$t('pageLdap.tableRoleGroups.groupName'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700134 },
135 {
136 key: 'groupPrivilege',
137 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500138 label: this.$t('pageLdap.tableRoleGroups.groupPrivilege'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700139 },
140 {
141 key: 'actions',
142 sortable: false,
143 label: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500144 tdClass: 'text-right',
145 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700146 ],
147 batchActions: [
148 {
149 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500150 label: this.$t('global.action.delete'),
151 },
152 ],
SurenNewareba91c492020-10-27 14:18:54 +0530153 selectedRows: selectedRows,
154 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
155 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700156 };
157 },
158 computed: {
159 ...mapGetters('ldap', ['isServiceEnabled', 'enabledRoleGroups']),
160 tableItems() {
161 return this.enabledRoleGroups.map(({ LocalRole, RemoteGroup }) => {
162 return {
163 groupName: RemoteGroup,
164 groupPrivilege: LocalRole,
165 actions: [
166 {
167 value: 'edit',
168 title: this.$t('global.action.edit'),
Derick Montague602e98a2020-10-21 16:20:00 -0500169 enabled: this.isServiceEnabled,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700170 },
171 {
172 value: 'delete',
173 title: this.$t('global.action.delete'),
Derick Montague602e98a2020-10-21 16:20:00 -0500174 enabled: this.isServiceEnabled,
175 },
176 ],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700177 };
178 });
Derick Montague602e98a2020-10-21 16:20:00 -0500179 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700180 },
181 created() {
182 this.$store.dispatch('localUsers/getAccountRoles');
183 },
184 methods: {
185 onBatchAction() {
186 this.$bvModal
187 .msgBoxConfirm(
188 this.$tc(
189 'pageLdap.modal.deleteRoleGroupBatchConfirmMessage',
190 this.selectedRows.length
191 ),
192 {
193 title: this.$t('pageLdap.modal.deleteRoleGroup'),
Derick Montague602e98a2020-10-21 16:20:00 -0500194 okTitle: this.$t('global.action.delete'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700195 }
196 )
Derick Montague602e98a2020-10-21 16:20:00 -0500197 .then((deleteConfirmed) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700198 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700199 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700200 this.$store
201 .dispatch('ldap/deleteRoleGroup', {
Derick Montague602e98a2020-10-21 16:20:00 -0500202 roleGroups: this.selectedRows,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700203 })
Derick Montague602e98a2020-10-21 16:20:00 -0500204 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700205 .catch(({ message }) => this.errorToast(message))
206 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700207 }
208 });
209 },
210 onTableRowAction(action, row) {
211 switch (action) {
212 case 'edit':
213 this.initRoleGroupModal(row);
214 break;
215 case 'delete':
216 this.$bvModal
217 .msgBoxConfirm(
218 this.$t('pageLdap.modal.deleteRoleGroupConfirmMessage', {
Derick Montague602e98a2020-10-21 16:20:00 -0500219 groupName: row.groupName,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700220 }),
221 {
222 title: this.$t('pageLdap.modal.deleteRoleGroup'),
Derick Montague602e98a2020-10-21 16:20:00 -0500223 okTitle: this.$t('global.action.delete'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700224 }
225 )
Derick Montague602e98a2020-10-21 16:20:00 -0500226 .then((deleteConfirmed) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700227 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700228 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700229 this.$store
230 .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] })
Derick Montague602e98a2020-10-21 16:20:00 -0500231 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700232 .catch(({ message }) => this.errorToast(message))
233 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700234 }
235 });
236 break;
237 }
238 },
239 initRoleGroupModal(roleGroup) {
240 this.activeRoleGroup = roleGroup;
241 this.$bvModal.show('modal-role-group');
242 },
243 saveRoleGroup({ addNew, groupName, groupPrivilege }) {
244 this.activeRoleGroup = null;
245 const data = { groupName, groupPrivilege };
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700246 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700247 if (addNew) {
248 this.$store
249 .dispatch('ldap/addNewRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500250 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700251 .catch(({ message }) => this.errorToast(message))
252 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700253 } else {
254 this.$store
255 .dispatch('ldap/saveRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500256 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700257 .catch(({ message }) => this.errorToast(message))
258 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700259 }
Derick Montague602e98a2020-10-21 16:20:00 -0500260 },
261 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700262};
263</script>