Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 1 | <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" |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 33 | responsive |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 34 | selectable |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 35 | show-empty |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 36 | no-select-on-click |
Sukanya Pandey | fde429e | 2020-09-14 20:48:39 +0530 | [diff] [blame] | 37 | hover |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 38 | no-sort-reset |
| 39 | sort-icon-left |
| 40 | :items="tableItems" |
| 41 | :fields="fields" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 42 | :empty-text="$t('global.table.emptyMessage')" |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 43 | @row-selected="onRowSelected($event, tableItems.length)" |
| 44 | > |
| 45 | <!-- Checkbox column --> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 46 | <template #head(checkbox)> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 47 | <b-form-checkbox |
| 48 | v-model="tableHeaderCheckboxModel" |
| 49 | :indeterminate="tableHeaderCheckboxIndeterminate" |
| 50 | :disabled="!isServiceEnabled" |
| 51 | @change="onChangeHeaderCheckbox($refs.table)" |
| 52 | /> |
| 53 | </template> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 54 | <template #cell(checkbox)="row"> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 55 | <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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 63 | <template #cell(actions)="{ item }"> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 64 | <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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 72 | <template #icon> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 73 | <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> |
| 90 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 91 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 92 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 93 | import { mapGetters } from 'vuex'; |
| 94 | |
| 95 | import Alert from '@/components/Global/Alert'; |
| 96 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 97 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 98 | import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin'; |
| 99 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 100 | import ModalAddRoleGroup from './ModalAddRoleGroup'; |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 101 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 102 | |
| 103 | export default { |
| 104 | components: { |
| 105 | Alert, |
| 106 | IconAdd, |
| 107 | IconEdit, |
| 108 | IconTrashcan, |
| 109 | ModalAddRoleGroup, |
| 110 | TableRowAction, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 111 | TableToolbar, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 112 | }, |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 113 | mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin], |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 114 | data() { |
| 115 | return { |
| 116 | activeRoleGroup: null, |
| 117 | fields: [ |
| 118 | { |
| 119 | key: 'checkbox', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 120 | sortable: false, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 121 | }, |
| 122 | { |
| 123 | key: 'groupName', |
| 124 | sortable: true, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 125 | label: this.$t('pageLdap.tableRoleGroups.groupName'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 126 | }, |
| 127 | { |
| 128 | key: 'groupPrivilege', |
| 129 | sortable: true, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 130 | label: this.$t('pageLdap.tableRoleGroups.groupPrivilege'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 131 | }, |
| 132 | { |
| 133 | key: 'actions', |
| 134 | sortable: false, |
| 135 | label: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 136 | tdClass: 'text-right', |
| 137 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 138 | ], |
| 139 | batchActions: [ |
| 140 | { |
| 141 | value: 'delete', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 142 | label: this.$t('global.action.delete'), |
| 143 | }, |
| 144 | ], |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 145 | }; |
| 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 158 | enabled: this.isServiceEnabled, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 159 | }, |
| 160 | { |
| 161 | value: 'delete', |
| 162 | title: this.$t('global.action.delete'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 163 | enabled: this.isServiceEnabled, |
| 164 | }, |
| 165 | ], |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 166 | }; |
| 167 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 168 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 169 | }, |
| 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 183 | okTitle: this.$t('global.action.delete'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 184 | } |
| 185 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 186 | .then((deleteConfirmed) => { |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 187 | if (deleteConfirmed) { |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 188 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 189 | this.$store |
| 190 | .dispatch('ldap/deleteRoleGroup', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 191 | roleGroups: this.selectedRows, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 192 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 193 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 194 | .catch(({ message }) => this.errorToast(message)) |
| 195 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 196 | } |
| 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 Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 208 | groupName: row.groupName, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 209 | }), |
| 210 | { |
| 211 | title: this.$t('pageLdap.modal.deleteRoleGroup'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 212 | okTitle: this.$t('global.action.delete'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 213 | } |
| 214 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 215 | .then((deleteConfirmed) => { |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 216 | if (deleteConfirmed) { |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 217 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 218 | this.$store |
| 219 | .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 220 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 221 | .catch(({ message }) => this.errorToast(message)) |
| 222 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 223 | } |
| 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 Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 235 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 236 | if (addNew) { |
| 237 | this.$store |
| 238 | .dispatch('ldap/addNewRoleGroup', data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 239 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 240 | .catch(({ message }) => this.errorToast(message)) |
| 241 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 242 | } else { |
| 243 | this.$store |
| 244 | .dispatch('ldap/saveRoleGroup', data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 245 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 246 | .catch(({ message }) => this.errorToast(message)) |
| 247 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 248 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 249 | }, |
| 250 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 251 | }; |
| 252 | </script> |