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