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