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