Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
| 3 | <page-title /> |
| 4 | <b-row> |
| 5 | <b-col class="text-right"> |
| 6 | <table-filter :filters="tableFilters" @filterChange="onFilterChange" /> |
| 7 | </b-col> |
| 8 | </b-row> |
| 9 | <b-row> |
| 10 | <b-col> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 11 | <table-toolbar |
| 12 | ref="toolbar" |
| 13 | :selected-items-count="selectedRows.length" |
| 14 | :actions="batchActions" |
| 15 | @clearSelected="clearSelectedRows($refs.table)" |
| 16 | @batchAction="onBatchAction" |
| 17 | > |
| 18 | <template v-slot:export> |
| 19 | <table-toolbar-export |
| 20 | :data="batchExportData" |
| 21 | :file-name="$t('appPageTitle.eventLogs')" |
| 22 | /> |
| 23 | </template> |
| 24 | </table-toolbar> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 25 | <b-table |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 26 | id="table-event-logs" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 27 | ref="table" |
| 28 | selectable |
| 29 | no-select-on-click |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 30 | sort-icon-left |
| 31 | no-sort-reset |
| 32 | sort-desc |
| 33 | show-empty |
| 34 | sort-by="date" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 35 | :fields="fields" |
| 36 | :items="filteredLogs" |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 37 | :sort-compare="onSortCompare" |
| 38 | :empty-text="$t('pageEventLogs.table.emptyMessage')" |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 39 | :per-page="perPage" |
| 40 | :current-page="currentPage" |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 41 | @row-selected="onRowSelected($event, filteredLogs.length)" |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 42 | > |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 43 | <!-- Checkbox column --> |
| 44 | <template v-slot:head(checkbox)> |
| 45 | <b-form-checkbox |
| 46 | v-model="tableHeaderCheckboxModel" |
| 47 | :indeterminate="tableHeaderCheckboxIndeterminate" |
| 48 | @change="onChangeHeaderCheckbox($refs.table)" |
| 49 | /> |
| 50 | </template> |
| 51 | <template v-slot:cell(checkbox)="row"> |
| 52 | <b-form-checkbox |
| 53 | v-model="row.rowSelected" |
| 54 | @change="toggleSelectRow($refs.table, row.index)" |
| 55 | /> |
| 56 | </template> |
| 57 | |
| 58 | <!-- Severity column --> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 59 | <template v-slot:cell(severity)="{ value }"> |
| 60 | <status-icon :status="getStatus(value)" /> |
| 61 | {{ value }} |
| 62 | </template> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 63 | |
| 64 | <!-- Date column --> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 65 | <template v-slot:cell(date)="{ value }"> |
| 66 | {{ value | formatDate }} {{ value | formatTime }} |
| 67 | </template> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 68 | |
| 69 | <!-- Actions column --> |
| 70 | <template v-slot:cell(actions)="{ item }"> |
| 71 | <table-row-action |
| 72 | v-for="(action, index) in item.actions" |
| 73 | :key="index" |
| 74 | :value="action.value" |
| 75 | :title="action.title" |
| 76 | :row-data="item" |
| 77 | :export-name="item.id" |
| 78 | @click:tableAction="onTableRowAction($event, item)" |
| 79 | > |
| 80 | <template v-slot:icon> |
| 81 | <icon-export v-if="action.value === 'export'" /> |
| 82 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 83 | </template> |
| 84 | </table-row-action> |
| 85 | </template> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 86 | </b-table> |
| 87 | </b-col> |
| 88 | </b-row> |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 89 | |
| 90 | <!-- Table pagination --> |
| 91 | <b-row> |
| 92 | <b-col class="d-md-flex justify-content-between"> |
| 93 | <b-form-group |
| 94 | class="table-pagination-select" |
| 95 | :label="$t('global.table.itemsPerPage')" |
| 96 | label-for="pagination-items-per-page" |
| 97 | > |
| 98 | <b-form-select |
| 99 | id="pagination-items-per-page" |
| 100 | v-model="perPage" |
| 101 | :options="itemsPerPageOptions" |
| 102 | /> |
| 103 | </b-form-group> |
| 104 | <b-pagination |
| 105 | v-model="currentPage" |
| 106 | first-number |
| 107 | last-number |
| 108 | :per-page="perPage" |
| 109 | :total-rows="getTotalRowCount(filteredLogs.length)" |
| 110 | aria-controls="table-event-logs" |
| 111 | /> |
| 112 | </b-col> |
| 113 | </b-row> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 114 | </b-container> |
| 115 | </template> |
| 116 | |
| 117 | <script> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 118 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 119 | import IconExport from '@carbon/icons-vue/es/export/20'; |
| 120 | import { omit } from 'lodash'; |
| 121 | |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 122 | import PageTitle from '@/components/Global/PageTitle'; |
| 123 | import StatusIcon from '@/components/Global/StatusIcon'; |
| 124 | import TableFilter from '@/components/Global/TableFilter'; |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 125 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 126 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 127 | import TableToolbarExport from '@/components/Global/TableToolbarExport'; |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 128 | |
| 129 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| 130 | import TableFilterMixin from '@/components/Mixins/TableFilterMixin'; |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 131 | import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin'; |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 132 | import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin'; |
| 133 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 134 | |
| 135 | const SEVERITY = ['OK', 'Warning', 'Critical']; |
| 136 | |
| 137 | export default { |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 138 | components: { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 139 | IconExport, |
| 140 | IconTrashcan, |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 141 | PageTitle, |
| 142 | StatusIcon, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 143 | TableFilter, |
| 144 | TableRowAction, |
| 145 | TableToolbar, |
| 146 | TableToolbarExport |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 147 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 148 | mixins: [ |
| 149 | BVPaginationMixin, |
| 150 | BVTableSelectableMixin, |
| 151 | BVToastMixin, |
| 152 | LoadingBarMixin, |
| 153 | TableFilterMixin |
| 154 | ], |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 155 | data() { |
| 156 | return { |
| 157 | fields: [ |
| 158 | { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 159 | key: 'checkbox', |
| 160 | sortable: false |
| 161 | }, |
| 162 | { |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 163 | key: 'id', |
| 164 | label: this.$t('pageEventLogs.table.id'), |
| 165 | sortable: true |
| 166 | }, |
| 167 | { |
| 168 | key: 'severity', |
| 169 | label: this.$t('pageEventLogs.table.severity'), |
| 170 | sortable: true |
| 171 | }, |
| 172 | { |
| 173 | key: 'type', |
| 174 | label: this.$t('pageEventLogs.table.type'), |
| 175 | sortable: true |
| 176 | }, |
| 177 | { |
| 178 | key: 'date', |
| 179 | label: this.$t('pageEventLogs.table.date'), |
| 180 | sortable: true |
| 181 | }, |
| 182 | { |
| 183 | key: 'description', |
| 184 | label: this.$t('pageEventLogs.table.description') |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 185 | }, |
| 186 | { |
| 187 | key: 'actions', |
| 188 | sortable: false, |
| 189 | label: '', |
| 190 | tdClass: 'text-right' |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 191 | } |
| 192 | ], |
| 193 | tableFilters: [ |
| 194 | { |
| 195 | label: this.$t('pageEventLogs.table.severity'), |
| 196 | values: SEVERITY |
| 197 | } |
| 198 | ], |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 199 | activeFilters: [], |
| 200 | batchActions: [ |
| 201 | { |
| 202 | value: 'delete', |
| 203 | label: this.$t('global.action.delete') |
| 204 | } |
| 205 | ] |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 206 | }; |
| 207 | }, |
| 208 | computed: { |
| 209 | allLogs() { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 210 | return this.$store.getters['eventLog/allEvents'].map(event => { |
| 211 | return { |
| 212 | ...event, |
| 213 | actions: [ |
| 214 | { |
| 215 | value: 'export', |
| 216 | title: this.$t('global.action.export') |
| 217 | }, |
| 218 | { |
| 219 | value: 'delete', |
| 220 | title: this.$t('global.action.delete') |
| 221 | } |
| 222 | ] |
| 223 | }; |
| 224 | }); |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 225 | }, |
| 226 | filteredLogs: { |
| 227 | get: function() { |
| 228 | return this.getFilteredTableData(this.allLogs, this.activeFilters); |
| 229 | }, |
| 230 | set: function(newVal) { |
| 231 | return newVal; |
| 232 | } |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 233 | }, |
| 234 | batchExportData() { |
| 235 | return this.selectedRows.map(row => omit(row, 'actions')); |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 236 | } |
| 237 | }, |
| 238 | created() { |
| 239 | this.startLoader(); |
| 240 | this.$store |
| 241 | .dispatch('eventLog/getEventLogData') |
| 242 | .finally(() => this.endLoader()); |
| 243 | }, |
Yoshie Muranaka | e3a8d69 | 2020-05-28 13:30:40 -0700 | [diff] [blame] | 244 | beforeRouteLeave(to, from, next) { |
| 245 | // Hide loader if the user navigates to another page |
| 246 | // before request is fulfilled. |
| 247 | this.hideLoader(); |
| 248 | next(); |
| 249 | }, |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 250 | methods: { |
| 251 | getStatus(serverity) { |
| 252 | switch (serverity) { |
| 253 | case SEVERITY[2]: |
| 254 | return 'danger'; |
| 255 | case SEVERITY[1]: |
| 256 | return 'warning'; |
| 257 | case SEVERITY[0]: |
| 258 | return 'success'; |
| 259 | default: |
| 260 | return ''; |
| 261 | } |
| 262 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 263 | deleteLogs(uris) { |
| 264 | this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => { |
| 265 | messages.forEach(({ type, message }) => { |
| 266 | if (type === 'success') { |
| 267 | this.successToast(message); |
| 268 | } else if (type === 'error') { |
| 269 | this.errorToast(message); |
| 270 | } |
| 271 | }); |
| 272 | }); |
| 273 | }, |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 274 | onFilterChange({ activeFilters }) { |
| 275 | this.activeFilters = activeFilters; |
| 276 | this.filteredLogs = this.getFilteredTableData( |
| 277 | this.allLogs, |
| 278 | activeFilters |
| 279 | ); |
| 280 | }, |
| 281 | onSortCompare(a, b, key) { |
| 282 | if (key === 'severity') { |
| 283 | return SEVERITY.indexOf(a.status) - SEVERITY.indexOf(b.status); |
| 284 | } |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 285 | }, |
| 286 | onTableRowAction(action, { uri }) { |
| 287 | if (action === 'delete') { |
| 288 | this.$bvModal |
| 289 | .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), { |
| 290 | title: this.$tc('pageEventLogs.modal.deleteTitle'), |
| 291 | okTitle: this.$t('global.action.delete') |
| 292 | }) |
| 293 | .then(deleteConfirmed => { |
| 294 | if (deleteConfirmed) this.deleteLogs([uri]); |
| 295 | }); |
| 296 | } |
| 297 | }, |
| 298 | onBatchAction(action) { |
| 299 | if (action === 'delete') { |
| 300 | const uris = this.selectedRows.map(row => row.uri); |
| 301 | this.$bvModal |
| 302 | .msgBoxConfirm( |
| 303 | this.$tc( |
| 304 | 'pageEventLogs.modal.deleteMessage', |
| 305 | this.selectedRows.length |
| 306 | ), |
| 307 | { |
| 308 | title: this.$tc( |
| 309 | 'pageEventLogs.modal.deleteTitle', |
| 310 | this.selectedRows.length |
| 311 | ), |
| 312 | okTitle: this.$t('global.action.delete') |
| 313 | } |
| 314 | ) |
| 315 | .then(deleteConfirmed => { |
| 316 | if (deleteConfirmed) this.deleteLogs(uris); |
| 317 | }); |
| 318 | } |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 319 | } |
| 320 | } |
| 321 | }; |
| 322 | </script> |