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" |
| 52 | :indeterminate="tableHeaderCheckboxIndeterminate" |
| 53 | @change="onChangeHeaderCheckbox($refs.table)" |
| 54 | /> |
| 55 | </template> |
| 56 | <template v-slot:cell(checkbox)="row"> |
| 57 | <b-form-checkbox |
| 58 | v-model="row.rowSelected" |
| 59 | @change="toggleSelectRow($refs.table, row.index)" |
| 60 | /> |
| 61 | </template> |
| 62 | |
| 63 | <!-- Severity column --> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 64 | <template v-slot:cell(severity)="{ value }"> |
Yoshie Muranaka | 73e419a | 2020-06-18 13:08:19 -0700 | [diff] [blame^] | 65 | <status-icon :status="statusIcon(value)" /> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 66 | {{ value }} |
| 67 | </template> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 68 | |
| 69 | <!-- Date column --> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 70 | <template v-slot:cell(date)="{ value }"> |
| 71 | {{ value | formatDate }} {{ value | formatTime }} |
| 72 | </template> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 73 | |
| 74 | <!-- Actions column --> |
| 75 | <template v-slot:cell(actions)="{ item }"> |
| 76 | <table-row-action |
| 77 | v-for="(action, index) in item.actions" |
| 78 | :key="index" |
| 79 | :value="action.value" |
| 80 | :title="action.title" |
| 81 | :row-data="item" |
| 82 | :export-name="item.id" |
| 83 | @click:tableAction="onTableRowAction($event, item)" |
| 84 | > |
| 85 | <template v-slot:icon> |
| 86 | <icon-export v-if="action.value === 'export'" /> |
| 87 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 88 | </template> |
| 89 | </table-row-action> |
| 90 | </template> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 91 | </b-table> |
| 92 | </b-col> |
| 93 | </b-row> |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 94 | |
| 95 | <!-- Table pagination --> |
| 96 | <b-row> |
| 97 | <b-col class="d-md-flex justify-content-between"> |
| 98 | <b-form-group |
| 99 | class="table-pagination-select" |
| 100 | :label="$t('global.table.itemsPerPage')" |
| 101 | label-for="pagination-items-per-page" |
| 102 | > |
| 103 | <b-form-select |
| 104 | id="pagination-items-per-page" |
| 105 | v-model="perPage" |
| 106 | :options="itemsPerPageOptions" |
| 107 | /> |
| 108 | </b-form-group> |
| 109 | <b-pagination |
| 110 | v-model="currentPage" |
| 111 | first-number |
| 112 | last-number |
| 113 | :per-page="perPage" |
| 114 | :total-rows="getTotalRowCount(filteredLogs.length)" |
| 115 | aria-controls="table-event-logs" |
| 116 | /> |
| 117 | </b-col> |
| 118 | </b-row> |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 119 | </b-container> |
| 120 | </template> |
| 121 | |
| 122 | <script> |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 123 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 124 | import IconExport from '@carbon/icons-vue/es/export/20'; |
| 125 | import { omit } from 'lodash'; |
| 126 | |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 127 | import PageTitle from '@/components/Global/PageTitle'; |
| 128 | import StatusIcon from '@/components/Global/StatusIcon'; |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 129 | import TableDateFilter from '@/components/Global/TableDateFilter'; |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 130 | import TableFilter from '@/components/Global/TableFilter'; |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 131 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 132 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 133 | import TableToolbarExport from '@/components/Global/TableToolbarExport'; |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 134 | |
| 135 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| 136 | import TableFilterMixin from '@/components/Mixins/TableFilterMixin'; |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 137 | import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin'; |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 138 | import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin'; |
| 139 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Yoshie Muranaka | 73e419a | 2020-06-18 13:08:19 -0700 | [diff] [blame^] | 140 | import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin'; |
| 141 | import TableSortMixin from '@/components/Mixins/TableSortMixin'; |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 142 | |
| 143 | export default { |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 144 | components: { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 145 | IconExport, |
| 146 | IconTrashcan, |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 147 | PageTitle, |
| 148 | StatusIcon, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 149 | TableFilter, |
| 150 | TableRowAction, |
| 151 | TableToolbar, |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 152 | TableToolbarExport, |
| 153 | TableDateFilter |
Yoshie Muranaka | f9832b0 | 2020-05-12 12:04:46 -0700 | [diff] [blame] | 154 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 155 | mixins: [ |
| 156 | BVPaginationMixin, |
| 157 | BVTableSelectableMixin, |
| 158 | BVToastMixin, |
| 159 | LoadingBarMixin, |
Yoshie Muranaka | 73e419a | 2020-06-18 13:08:19 -0700 | [diff] [blame^] | 160 | TableFilterMixin, |
| 161 | TableDataFormatterMixin, |
| 162 | TableSortMixin |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 163 | ], |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 164 | data() { |
| 165 | return { |
| 166 | fields: [ |
| 167 | { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 168 | key: 'checkbox', |
| 169 | sortable: false |
| 170 | }, |
| 171 | { |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 172 | key: 'id', |
| 173 | label: this.$t('pageEventLogs.table.id'), |
| 174 | sortable: true |
| 175 | }, |
| 176 | { |
| 177 | key: 'severity', |
| 178 | label: this.$t('pageEventLogs.table.severity'), |
| 179 | sortable: true |
| 180 | }, |
| 181 | { |
| 182 | key: 'type', |
| 183 | label: this.$t('pageEventLogs.table.type'), |
| 184 | sortable: true |
| 185 | }, |
| 186 | { |
| 187 | key: 'date', |
| 188 | label: this.$t('pageEventLogs.table.date'), |
| 189 | sortable: true |
| 190 | }, |
| 191 | { |
| 192 | key: 'description', |
| 193 | label: this.$t('pageEventLogs.table.description') |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 194 | }, |
| 195 | { |
| 196 | key: 'actions', |
| 197 | sortable: false, |
| 198 | label: '', |
| 199 | tdClass: 'text-right' |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 200 | } |
| 201 | ], |
| 202 | tableFilters: [ |
| 203 | { |
| 204 | label: this.$t('pageEventLogs.table.severity'), |
Yoshie Muranaka | 73e419a | 2020-06-18 13:08:19 -0700 | [diff] [blame^] | 205 | values: ['OK', 'Warning', 'Critical'] |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 206 | } |
| 207 | ], |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 208 | activeFilters: [], |
| 209 | batchActions: [ |
| 210 | { |
| 211 | value: 'delete', |
| 212 | label: this.$t('global.action.delete') |
| 213 | } |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 214 | ], |
| 215 | filterStartDate: null, |
| 216 | filterEndDate: null |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 217 | }; |
| 218 | }, |
| 219 | computed: { |
| 220 | allLogs() { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 221 | return this.$store.getters['eventLog/allEvents'].map(event => { |
| 222 | return { |
| 223 | ...event, |
| 224 | actions: [ |
| 225 | { |
| 226 | value: 'export', |
| 227 | title: this.$t('global.action.export') |
| 228 | }, |
| 229 | { |
| 230 | value: 'delete', |
| 231 | title: this.$t('global.action.delete') |
| 232 | } |
| 233 | ] |
| 234 | }; |
| 235 | }); |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 236 | }, |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 237 | batchExportData() { |
| 238 | return this.selectedRows.map(row => omit(row, 'actions')); |
Yoshie Muranaka | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 239 | }, |
| 240 | filteredLogsByDate() { |
| 241 | return this.getFilteredTableDataByDate( |
| 242 | this.allLogs, |
| 243 | this.filterStartDate, |
| 244 | this.filterEndDate |
| 245 | ); |
| 246 | }, |
| 247 | filteredLogs() { |
| 248 | return this.getFilteredTableData( |
| 249 | this.filteredLogsByDate, |
| 250 | this.activeFilters |
| 251 | ); |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 252 | } |
| 253 | }, |
| 254 | created() { |
| 255 | this.startLoader(); |
| 256 | this.$store |
| 257 | .dispatch('eventLog/getEventLogData') |
| 258 | .finally(() => this.endLoader()); |
| 259 | }, |
Yoshie Muranaka | e3a8d69 | 2020-05-28 13:30:40 -0700 | [diff] [blame] | 260 | beforeRouteLeave(to, from, next) { |
| 261 | // Hide loader if the user navigates to another page |
| 262 | // before request is fulfilled. |
| 263 | this.hideLoader(); |
| 264 | next(); |
| 265 | }, |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 266 | methods: { |
Yoshie Muranaka | be3af33 | 2020-05-11 08:23:04 -0700 | [diff] [blame] | 267 | deleteLogs(uris) { |
| 268 | this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => { |
| 269 | messages.forEach(({ type, message }) => { |
| 270 | if (type === 'success') { |
| 271 | this.successToast(message); |
| 272 | } else if (type === 'error') { |
| 273 | this.errorToast(message); |
| 274 | } |
| 275 | }); |
| 276 | }); |
| 277 | }, |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 278 | onFilterChange({ activeFilters }) { |
| 279 | this.activeFilters = activeFilters; |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 280 | }, |
| 281 | onSortCompare(a, b, key) { |
| 282 | if (key === 'severity') { |
Yoshie Muranaka | 73e419a | 2020-06-18 13:08:19 -0700 | [diff] [blame^] | 283 | return this.sortStatus(a, b, key); |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 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 | 68bbba2 | 2020-05-18 09:49:37 -0700 | [diff] [blame] | 319 | }, |
| 320 | onChangeDateTimeFilter({ fromDate, toDate }) { |
| 321 | this.filterStartDate = fromDate; |
| 322 | this.filterEndDate = toDate; |
Yoshie Muranaka | 6f10234 | 2020-05-05 09:45:39 -0700 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | }; |
| 326 | </script> |