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