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