blob: c09d1661e2be07dc2e50aaec6395f0cfe21fe6f4 [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
35 no-select-on-click
36 no-sort-reset
37 sort-icon-left
38 :items="tableItems"
39 :fields="fields"
40 @row-selected="onRowSelected($event, tableItems.length)"
41 >
42 <!-- Checkbox column -->
43 <template v-slot:head(checkbox)>
44 <b-form-checkbox
45 v-model="tableHeaderCheckboxModel"
46 :indeterminate="tableHeaderCheckboxIndeterminate"
47 :disabled="!isServiceEnabled"
48 @change="onChangeHeaderCheckbox($refs.table)"
49 />
50 </template>
51 <template v-slot:cell(checkbox)="row">
52 <b-form-checkbox
53 v-model="row.rowSelected"
54 :disabled="!isServiceEnabled"
55 @change="toggleSelectRow($refs.table, row.index)"
56 />
57 </template>
58
59 <!-- table actions column -->
60 <template v-slot:cell(actions)="{ item }">
61 <table-row-action
62 v-for="(action, index) in item.actions"
63 :key="index"
64 :value="action.value"
65 :enabled="action.enabled"
66 :title="action.title"
67 @click:tableAction="onTableRowAction($event, item)"
68 >
69 <template v-slot:icon>
70 <icon-edit v-if="action.value === 'edit'" />
71 <icon-trashcan v-if="action.value === 'delete'" />
72 </template>
73 </table-row-action>
74 </template>
75 </b-table>
76 </b-col>
77 </b-row>
78 <modal-add-role-group
79 :role-group="activeRoleGroup"
80 @ok="saveRoleGroup"
81 @hidden="activeRoleGroup = null"
82 />
83 </div>
84</template>
85
86<script>
87import IconEdit from '@carbon/icons-vue/es/edit/20';
88import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
89import IconAdd from '@carbon/icons-vue/es/add--alt/20';
90import { mapGetters } from 'vuex';
91
92import Alert from '@/components/Global/Alert';
93import TableToolbar from '@/components/Global/TableToolbar';
94import TableRowAction from '@/components/Global/TableRowAction';
95import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
96import BVToastMixin from '@/components/Mixins/BVToastMixin';
97import ModalAddRoleGroup from './ModalAddRoleGroup';
Yoshie Muranakae9a59c72020-04-30 12:16:30 -070098import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Yoshie Muranakadc3d5412020-04-17 09:39:41 -070099
100export default {
101 components: {
102 Alert,
103 IconAdd,
104 IconEdit,
105 IconTrashcan,
106 ModalAddRoleGroup,
107 TableRowAction,
108 TableToolbar
109 },
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700110 mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin],
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700111 data() {
112 return {
113 activeRoleGroup: null,
114 fields: [
115 {
116 key: 'checkbox',
117 sortable: false
118 },
119 {
120 key: 'groupName',
121 sortable: true,
122 label: this.$t('pageLdap.tableRoleGroups.groupName')
123 },
124 {
125 key: 'groupPrivilege',
126 sortable: true,
127 label: this.$t('pageLdap.tableRoleGroups.groupPrivilege')
128 },
129 {
130 key: 'actions',
131 sortable: false,
132 label: '',
133 tdClass: 'text-right'
134 }
135 ],
136 batchActions: [
137 {
138 value: 'delete',
139 label: this.$t('global.action.delete')
140 }
141 ]
142 };
143 },
144 computed: {
145 ...mapGetters('ldap', ['isServiceEnabled', 'enabledRoleGroups']),
146 tableItems() {
147 return this.enabledRoleGroups.map(({ LocalRole, RemoteGroup }) => {
148 return {
149 groupName: RemoteGroup,
150 groupPrivilege: LocalRole,
151 actions: [
152 {
153 value: 'edit',
154 title: this.$t('global.action.edit'),
155 enabled: this.isServiceEnabled
156 },
157 {
158 value: 'delete',
159 title: this.$t('global.action.delete'),
160 enabled: this.isServiceEnabled
161 }
162 ]
163 };
164 });
165 }
166 },
167 created() {
168 this.$store.dispatch('localUsers/getAccountRoles');
169 },
170 methods: {
171 onBatchAction() {
172 this.$bvModal
173 .msgBoxConfirm(
174 this.$tc(
175 'pageLdap.modal.deleteRoleGroupBatchConfirmMessage',
176 this.selectedRows.length
177 ),
178 {
179 title: this.$t('pageLdap.modal.deleteRoleGroup'),
180 okTitle: this.$t('global.action.delete')
181 }
182 )
183 .then(deleteConfirmed => {
184 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700185 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700186 this.$store
187 .dispatch('ldap/deleteRoleGroup', {
188 roleGroups: this.selectedRows
189 })
190 .then(success => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700191 .catch(({ message }) => this.errorToast(message))
192 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700193 }
194 });
195 },
196 onTableRowAction(action, row) {
197 switch (action) {
198 case 'edit':
199 this.initRoleGroupModal(row);
200 break;
201 case 'delete':
202 this.$bvModal
203 .msgBoxConfirm(
204 this.$t('pageLdap.modal.deleteRoleGroupConfirmMessage', {
205 groupName: row.groupName
206 }),
207 {
208 title: this.$t('pageLdap.modal.deleteRoleGroup'),
209 okTitle: this.$t('global.action.delete')
210 }
211 )
212 .then(deleteConfirmed => {
213 if (deleteConfirmed) {
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700214 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700215 this.$store
216 .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] })
217 .then(success => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700218 .catch(({ message }) => this.errorToast(message))
219 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700220 }
221 });
222 break;
223 }
224 },
225 initRoleGroupModal(roleGroup) {
226 this.activeRoleGroup = roleGroup;
227 this.$bvModal.show('modal-role-group');
228 },
229 saveRoleGroup({ addNew, groupName, groupPrivilege }) {
230 this.activeRoleGroup = null;
231 const data = { groupName, groupPrivilege };
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700232 this.startLoader();
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700233 if (addNew) {
234 this.$store
235 .dispatch('ldap/addNewRoleGroup', data)
236 .then(success => this.successToast(success))
Yoshie Muranakae9a59c72020-04-30 12:16:30 -0700237 .catch(({ message }) => this.errorToast(message))
238 .finally(() => this.endLoader());
Yoshie Muranakadc3d5412020-04-17 09:39:41 -0700239 } else {
240 this.$store
241 .dispatch('ldap/saveRoleGroup', data)
242 .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 }
248};
249</script>