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" |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 28 | @clear-selected="clearSelectedRows($refs.table)" |
| 29 | @batch-action="onBatchAction" |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 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)" |
Dixsie Wolmers | c42ad71 | 2020-11-19 17:29:24 -0600 | [diff] [blame] | 52 | > |
| 53 | <span class="sr-only">{{ $t('global.table.selectAll') }}</span> |
| 54 | </b-form-checkbox> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 55 | </template> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 56 | <template #cell(checkbox)="row"> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 57 | <b-form-checkbox |
| 58 | v-model="row.rowSelected" |
| 59 | :disabled="!isServiceEnabled" |
| 60 | @change="toggleSelectRow($refs.table, row.index)" |
Dixsie Wolmers | c42ad71 | 2020-11-19 17:29:24 -0600 | [diff] [blame] | 61 | > |
| 62 | <span class="sr-only">{{ $t('global.table.selectItem') }}</span> |
| 63 | </b-form-checkbox> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 64 | </template> |
| 65 | |
| 66 | <!-- table actions column --> |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 67 | <template #cell(actions)="{ item }"> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 68 | <table-row-action |
| 69 | v-for="(action, index) in item.actions" |
| 70 | :key="index" |
| 71 | :value="action.value" |
| 72 | :enabled="action.enabled" |
| 73 | :title="action.title" |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 74 | @click-table-action="onTableRowAction($event, item)" |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 75 | > |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 76 | <template #icon> |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 77 | <icon-edit v-if="action.value === 'edit'" /> |
| 78 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 79 | </template> |
| 80 | </table-row-action> |
| 81 | </template> |
| 82 | </b-table> |
| 83 | </b-col> |
| 84 | </b-row> |
| 85 | <modal-add-role-group |
| 86 | :role-group="activeRoleGroup" |
| 87 | @ok="saveRoleGroup" |
| 88 | @hidden="activeRoleGroup = null" |
| 89 | /> |
| 90 | </div> |
| 91 | </template> |
| 92 | |
| 93 | <script> |
| 94 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 95 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 96 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 97 | import { mapGetters } from 'vuex'; |
| 98 | |
| 99 | import Alert from '@/components/Global/Alert'; |
| 100 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 101 | import TableRowAction from '@/components/Global/TableRowAction'; |
SurenNeware | ba91c49 | 2020-10-27 14:18:54 +0530 | [diff] [blame] | 102 | import BVTableSelectableMixin, { |
| 103 | selectedRows, |
| 104 | tableHeaderCheckboxModel, |
| 105 | tableHeaderCheckboxIndeterminate, |
| 106 | } from '@/components/Mixins/BVTableSelectableMixin'; |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 107 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 108 | import ModalAddRoleGroup from './ModalAddRoleGroup'; |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 109 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 110 | |
| 111 | export default { |
| 112 | components: { |
| 113 | Alert, |
| 114 | IconAdd, |
| 115 | IconEdit, |
| 116 | IconTrashcan, |
| 117 | ModalAddRoleGroup, |
| 118 | TableRowAction, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 119 | TableToolbar, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 120 | }, |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 121 | mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin], |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 122 | data() { |
| 123 | return { |
| 124 | activeRoleGroup: null, |
| 125 | fields: [ |
| 126 | { |
| 127 | key: 'checkbox', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 128 | sortable: false, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 129 | }, |
| 130 | { |
| 131 | key: 'groupName', |
| 132 | sortable: true, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 133 | label: this.$t('pageLdap.tableRoleGroups.groupName'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 134 | }, |
| 135 | { |
| 136 | key: 'groupPrivilege', |
| 137 | sortable: true, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 138 | label: this.$t('pageLdap.tableRoleGroups.groupPrivilege'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 139 | }, |
| 140 | { |
| 141 | key: 'actions', |
| 142 | sortable: false, |
| 143 | label: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 144 | tdClass: 'text-right', |
| 145 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 146 | ], |
| 147 | batchActions: [ |
| 148 | { |
| 149 | value: 'delete', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 150 | label: this.$t('global.action.delete'), |
| 151 | }, |
| 152 | ], |
SurenNeware | ba91c49 | 2020-10-27 14:18:54 +0530 | [diff] [blame] | 153 | selectedRows: selectedRows, |
| 154 | tableHeaderCheckboxModel: tableHeaderCheckboxModel, |
| 155 | tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 156 | }; |
| 157 | }, |
| 158 | computed: { |
| 159 | ...mapGetters('ldap', ['isServiceEnabled', 'enabledRoleGroups']), |
| 160 | tableItems() { |
| 161 | return this.enabledRoleGroups.map(({ LocalRole, RemoteGroup }) => { |
| 162 | return { |
| 163 | groupName: RemoteGroup, |
| 164 | groupPrivilege: LocalRole, |
| 165 | actions: [ |
| 166 | { |
| 167 | value: 'edit', |
| 168 | title: this.$t('global.action.edit'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 169 | enabled: this.isServiceEnabled, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 170 | }, |
| 171 | { |
| 172 | value: 'delete', |
| 173 | title: this.$t('global.action.delete'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 174 | enabled: this.isServiceEnabled, |
| 175 | }, |
| 176 | ], |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 177 | }; |
| 178 | }); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 179 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 180 | }, |
| 181 | created() { |
| 182 | this.$store.dispatch('localUsers/getAccountRoles'); |
| 183 | }, |
| 184 | methods: { |
| 185 | onBatchAction() { |
| 186 | this.$bvModal |
| 187 | .msgBoxConfirm( |
| 188 | this.$tc( |
| 189 | 'pageLdap.modal.deleteRoleGroupBatchConfirmMessage', |
| 190 | this.selectedRows.length |
| 191 | ), |
| 192 | { |
| 193 | title: this.$t('pageLdap.modal.deleteRoleGroup'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 194 | okTitle: this.$t('global.action.delete'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 195 | } |
| 196 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 197 | .then((deleteConfirmed) => { |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 198 | if (deleteConfirmed) { |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 199 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 200 | this.$store |
| 201 | .dispatch('ldap/deleteRoleGroup', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 202 | roleGroups: this.selectedRows, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 203 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 204 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 205 | .catch(({ message }) => this.errorToast(message)) |
| 206 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 207 | } |
| 208 | }); |
| 209 | }, |
| 210 | onTableRowAction(action, row) { |
| 211 | switch (action) { |
| 212 | case 'edit': |
| 213 | this.initRoleGroupModal(row); |
| 214 | break; |
| 215 | case 'delete': |
| 216 | this.$bvModal |
| 217 | .msgBoxConfirm( |
| 218 | this.$t('pageLdap.modal.deleteRoleGroupConfirmMessage', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 219 | groupName: row.groupName, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 220 | }), |
| 221 | { |
| 222 | title: this.$t('pageLdap.modal.deleteRoleGroup'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 223 | okTitle: this.$t('global.action.delete'), |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 224 | } |
| 225 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 226 | .then((deleteConfirmed) => { |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 227 | if (deleteConfirmed) { |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 228 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 229 | this.$store |
| 230 | .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 231 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 232 | .catch(({ message }) => this.errorToast(message)) |
| 233 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 234 | } |
| 235 | }); |
| 236 | break; |
| 237 | } |
| 238 | }, |
| 239 | initRoleGroupModal(roleGroup) { |
| 240 | this.activeRoleGroup = roleGroup; |
| 241 | this.$bvModal.show('modal-role-group'); |
| 242 | }, |
| 243 | saveRoleGroup({ addNew, groupName, groupPrivilege }) { |
| 244 | this.activeRoleGroup = null; |
| 245 | const data = { groupName, groupPrivilege }; |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 246 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 247 | if (addNew) { |
| 248 | this.$store |
| 249 | .dispatch('ldap/addNewRoleGroup', data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 250 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 251 | .catch(({ message }) => this.errorToast(message)) |
| 252 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 253 | } else { |
| 254 | this.$store |
| 255 | .dispatch('ldap/saveRoleGroup', data) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 256 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 257 | .catch(({ message }) => this.errorToast(message)) |
| 258 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 259 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 260 | }, |
| 261 | }, |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 262 | }; |
| 263 | </script> |