blob: a851a0331b8921dd2ef64bd653b2f7305952716f [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';
97
98export default {
99 components: {
100 Alert,
101 IconAdd,
102 IconEdit,
103 IconTrashcan,
104 ModalAddRoleGroup,
105 TableRowAction,
106 TableToolbar
107 },
108 mixins: [BVTableSelectableMixin, BVToastMixin],
109 data() {
110 return {
111 activeRoleGroup: null,
112 fields: [
113 {
114 key: 'checkbox',
115 sortable: false
116 },
117 {
118 key: 'groupName',
119 sortable: true,
120 label: this.$t('pageLdap.tableRoleGroups.groupName')
121 },
122 {
123 key: 'groupPrivilege',
124 sortable: true,
125 label: this.$t('pageLdap.tableRoleGroups.groupPrivilege')
126 },
127 {
128 key: 'actions',
129 sortable: false,
130 label: '',
131 tdClass: 'text-right'
132 }
133 ],
134 batchActions: [
135 {
136 value: 'delete',
137 label: this.$t('global.action.delete')
138 }
139 ]
140 };
141 },
142 computed: {
143 ...mapGetters('ldap', ['isServiceEnabled', 'enabledRoleGroups']),
144 tableItems() {
145 return this.enabledRoleGroups.map(({ LocalRole, RemoteGroup }) => {
146 return {
147 groupName: RemoteGroup,
148 groupPrivilege: LocalRole,
149 actions: [
150 {
151 value: 'edit',
152 title: this.$t('global.action.edit'),
153 enabled: this.isServiceEnabled
154 },
155 {
156 value: 'delete',
157 title: this.$t('global.action.delete'),
158 enabled: this.isServiceEnabled
159 }
160 ]
161 };
162 });
163 }
164 },
165 created() {
166 this.$store.dispatch('localUsers/getAccountRoles');
167 },
168 methods: {
169 onBatchAction() {
170 this.$bvModal
171 .msgBoxConfirm(
172 this.$tc(
173 'pageLdap.modal.deleteRoleGroupBatchConfirmMessage',
174 this.selectedRows.length
175 ),
176 {
177 title: this.$t('pageLdap.modal.deleteRoleGroup'),
178 okTitle: this.$t('global.action.delete')
179 }
180 )
181 .then(deleteConfirmed => {
182 if (deleteConfirmed) {
183 this.$store
184 .dispatch('ldap/deleteRoleGroup', {
185 roleGroups: this.selectedRows
186 })
187 .then(success => this.successToast(success))
188 .catch(({ message }) => this.errorToast(message));
189 }
190 });
191 },
192 onTableRowAction(action, row) {
193 switch (action) {
194 case 'edit':
195 this.initRoleGroupModal(row);
196 break;
197 case 'delete':
198 this.$bvModal
199 .msgBoxConfirm(
200 this.$t('pageLdap.modal.deleteRoleGroupConfirmMessage', {
201 groupName: row.groupName
202 }),
203 {
204 title: this.$t('pageLdap.modal.deleteRoleGroup'),
205 okTitle: this.$t('global.action.delete')
206 }
207 )
208 .then(deleteConfirmed => {
209 if (deleteConfirmed) {
210 this.$store
211 .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] })
212 .then(success => this.successToast(success))
213 .catch(({ message }) => this.errorToast(message));
214 }
215 });
216 break;
217 }
218 },
219 initRoleGroupModal(roleGroup) {
220 this.activeRoleGroup = roleGroup;
221 this.$bvModal.show('modal-role-group');
222 },
223 saveRoleGroup({ addNew, groupName, groupPrivilege }) {
224 this.activeRoleGroup = null;
225 const data = { groupName, groupPrivilege };
226 if (addNew) {
227 this.$store
228 .dispatch('ldap/addNewRoleGroup', data)
229 .then(success => this.successToast(success))
230 .catch(({ message }) => this.errorToast(message));
231 } else {
232 this.$store
233 .dispatch('ldap/saveRoleGroup', data)
234 .then(success => this.successToast(success))
235 .catch(({ message }) => this.errorToast(message));
236 }
237 }
238 }
239};
240</script>