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