blob: ef300ea55b6645b1ac81507ce672e600b824b41a [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"
28 @clearSelected="clearSelectedRows($refs.table)"
29 @batchAction="onBatchAction"
30 />
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)"
52 />
53 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050054 <template #cell(checkbox)="row">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070055 <b-form-checkbox
56 v-model="row.rowSelected"
57 :disabled="!isServiceEnabled"
58 @change="toggleSelectRow($refs.table, row.index)"
59 />
60 </template>
61
62 <!-- table actions column -->
Derick Montague602e98a2020-10-21 16:20:00 -050063 <template #cell(actions)="{ item }">
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070064 <table-row-action
65 v-for="(action, index) in item.actions"
66 :key="index"
67 :value="action.value"
68 :enabled="action.enabled"
69 :title="action.title"
70 @click:tableAction="onTableRowAction($event, item)"
71 >
Derick Montague602e98a2020-10-21 16:20:00 -050072 <template #icon>
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070073 <icon-edit v-if="action.value === 'edit'" />
74 <icon-trashcan v-if="action.value === 'delete'" />
75 </template>
76 </table-row-action>
77 </template>
78 </b-table>
79 </b-col>
80 </b-row>
81 <modal-add-role-group
82 :role-group="activeRoleGroup"
83 @ok="saveRoleGroup"
84 @hidden="activeRoleGroup = null"
85 />
86 </div>
87</template>
88
89<script>
90import IconEdit from '@carbon/icons-vue/es/edit/20';
91import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
92import IconAdd from '@carbon/icons-vue/es/add--alt/20';
93import { mapGetters } from 'vuex';
94
95import Alert from '@/components/Global/Alert';
96import TableToolbar from '@/components/Global/TableToolbar';
97import TableRowAction from '@/components/Global/TableRowAction';
98import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
99import BVToastMixin from '@/components/Mixins/BVToastMixin';
100import ModalAddRoleGroup from './ModalAddRoleGroup';
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700101import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700102
103export default {
104 components: {
105 Alert,
106 IconAdd,
107 IconEdit,
108 IconTrashcan,
109 ModalAddRoleGroup,
110 TableRowAction,
Derick Montague602e98a2020-10-21 16:20:00 -0500111 TableToolbar,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700112 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700113 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700114 data() {
115 return {
116 activeRoleGroup: null,
117 fields: [
118 {
119 key: 'checkbox',
Derick Montague602e98a2020-10-21 16:20:00 -0500120 sortable: false,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700121 },
122 {
123 key: 'groupName',
124 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500125 label: this.$t('pageLdap.tableRoleGroups.groupName'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700126 },
127 {
128 key: 'groupPrivilege',
129 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500130 label: this.$t('pageLdap.tableRoleGroups.groupPrivilege'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700131 },
132 {
133 key: 'actions',
134 sortable: false,
135 label: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500136 tdClass: 'text-right',
137 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700138 ],
139 batchActions: [
140 {
141 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500142 label: this.$t('global.action.delete'),
143 },
144 ],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700145 };
146 },
147 computed: {
148 ...mapGetters('ldap', ['isServiceEnabled', 'enabledRoleGroups']),
149 tableItems() {
150 return this.enabledRoleGroups.map(({ LocalRole, RemoteGroup }) => {
151 return {
152 groupName: RemoteGroup,
153 groupPrivilege: LocalRole,
154 actions: [
155 {
156 value: 'edit',
157 title: this.$t('global.action.edit'),
Derick Montague602e98a2020-10-21 16:20:00 -0500158 enabled: this.isServiceEnabled,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700159 },
160 {
161 value: 'delete',
162 title: this.$t('global.action.delete'),
Derick Montague602e98a2020-10-21 16:20:00 -0500163 enabled: this.isServiceEnabled,
164 },
165 ],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700166 };
167 });
Derick Montague602e98a2020-10-21 16:20:00 -0500168 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700169 },
170 created() {
171 this.$store.dispatch('localUsers/getAccountRoles');
172 },
173 methods: {
174 onBatchAction() {
175 this.$bvModal
176 .msgBoxConfirm(
177 this.$tc(
178 'pageLdap.modal.deleteRoleGroupBatchConfirmMessage',
179 this.selectedRows.length
180 ),
181 {
182 title: this.$t('pageLdap.modal.deleteRoleGroup'),
Derick Montague602e98a2020-10-21 16:20:00 -0500183 okTitle: this.$t('global.action.delete'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700184 }
185 )
Derick Montague602e98a2020-10-21 16:20:00 -0500186 .then((deleteConfirmed) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700187 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700188 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700189 this.$store
190 .dispatch('ldap/deleteRoleGroup', {
Derick Montague602e98a2020-10-21 16:20:00 -0500191 roleGroups: this.selectedRows,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700192 })
Derick Montague602e98a2020-10-21 16:20:00 -0500193 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700194 .catch(({ message }) => this.errorToast(message))
195 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700196 }
197 });
198 },
199 onTableRowAction(action, row) {
200 switch (action) {
201 case 'edit':
202 this.initRoleGroupModal(row);
203 break;
204 case 'delete':
205 this.$bvModal
206 .msgBoxConfirm(
207 this.$t('pageLdap.modal.deleteRoleGroupConfirmMessage', {
Derick Montague602e98a2020-10-21 16:20:00 -0500208 groupName: row.groupName,
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700209 }),
210 {
211 title: this.$t('pageLdap.modal.deleteRoleGroup'),
Derick Montague602e98a2020-10-21 16:20:00 -0500212 okTitle: this.$t('global.action.delete'),
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700213 }
214 )
Derick Montague602e98a2020-10-21 16:20:00 -0500215 .then((deleteConfirmed) => {
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700216 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700217 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700218 this.$store
219 .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] })
Derick Montague602e98a2020-10-21 16:20:00 -0500220 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700221 .catch(({ message }) => this.errorToast(message))
222 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700223 }
224 });
225 break;
226 }
227 },
228 initRoleGroupModal(roleGroup) {
229 this.activeRoleGroup = roleGroup;
230 this.$bvModal.show('modal-role-group');
231 },
232 saveRoleGroup({ addNew, groupName, groupPrivilege }) {
233 this.activeRoleGroup = null;
234 const data = { groupName, groupPrivilege };
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700235 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700236 if (addNew) {
237 this.$store
238 .dispatch('ldap/addNewRoleGroup', data)
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 } else {
243 this.$store
244 .dispatch('ldap/saveRoleGroup', data)
Derick Montague602e98a2020-10-21 16:20:00 -0500245 .then((success) => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700246 .catch(({ message }) => this.errorToast(message))
247 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700248 }
Derick Montague602e98a2020-10-21 16:20:00 -0500249 },
250 },
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700251};
252</script>