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 |
| 37 | no-sort-reset |
| 38 | sort-icon-left |
| 39 | :items="tableItems" |
| 40 | :fields="fields" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame^] | 41 | :empty-text="$t('global.table.emptyMessage')" |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 42 | @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> |
| 89 | import IconEdit from '@carbon/icons-vue/es/edit/20'; |
| 90 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 91 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 92 | import { mapGetters } from 'vuex'; |
| 93 | |
| 94 | import Alert from '@/components/Global/Alert'; |
| 95 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 96 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 97 | import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin'; |
| 98 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 99 | import ModalAddRoleGroup from './ModalAddRoleGroup'; |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 100 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 101 | |
| 102 | export default { |
| 103 | components: { |
| 104 | Alert, |
| 105 | IconAdd, |
| 106 | IconEdit, |
| 107 | IconTrashcan, |
| 108 | ModalAddRoleGroup, |
| 109 | TableRowAction, |
| 110 | TableToolbar |
| 111 | }, |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 112 | mixins: [BVTableSelectableMixin, BVToastMixin, LoadingBarMixin], |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 113 | 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 Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 187 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 188 | this.$store |
| 189 | .dispatch('ldap/deleteRoleGroup', { |
| 190 | roleGroups: this.selectedRows |
| 191 | }) |
| 192 | .then(success => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 193 | .catch(({ message }) => this.errorToast(message)) |
| 194 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 195 | } |
| 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 Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 216 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 217 | this.$store |
| 218 | .dispatch('ldap/deleteRoleGroup', { roleGroups: [row] }) |
| 219 | .then(success => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 220 | .catch(({ message }) => this.errorToast(message)) |
| 221 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 222 | } |
| 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 Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 234 | this.startLoader(); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 235 | if (addNew) { |
| 236 | this.$store |
| 237 | .dispatch('ldap/addNewRoleGroup', data) |
| 238 | .then(success => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 239 | .catch(({ message }) => this.errorToast(message)) |
| 240 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 241 | } else { |
| 242 | this.$store |
| 243 | .dispatch('ldap/saveRoleGroup', data) |
| 244 | .then(success => this.successToast(success)) |
Yoshie Muranaka | e9a59c7 | 2020-04-30 12:16:30 -0700 | [diff] [blame] | 245 | .catch(({ message }) => this.errorToast(message)) |
| 246 | .finally(() => this.endLoader()); |
Yoshie Muranaka | dc3d541 | 2020-04-17 09:39:41 -0700 | [diff] [blame] | 247 | } |
| 248 | } |
| 249 | } |
| 250 | }; |
| 251 | </script> |