blob: af576521db817970ab27636e46b057c16285380b [file] [log] [blame]
Yoshie Muranaka6f102342020-05-05 09:45:39 -07001<template>
2 <b-container fluid="xl">
3 <page-title />
Yoshie Muranaka68bbba22020-05-18 09:49:37 -07004 <b-row class="mb-3">
Sukanya Pandey99010962020-07-27 21:44:47 +05305 <b-col sm="7" xl="4" class="d-flex flex-column justify-content-end">
Yoshie Muranaka193c22a2020-06-30 20:54:10 -07006 <search
7 :placeholder="$t('pageEventLogs.table.searchLogs')"
8 @changeSearch="onChangeSearchInput"
Dixsie Wolmers9b22b492020-09-07 21:26:06 -05009 @clearSearch="onClearSearchInput"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070010 />
11 </b-col>
Sukanya Pandey99010962020-07-27 21:44:47 +053012 <b-col sm="3" class="d-flex flex-column justify-content-end">
13 <table-cell-count
14 :filtered-items-count="filteredRows"
15 :total-number-of-cells="allLogs.length"
16 ></table-cell-count>
17 </b-col>
18 <b-col sm="8" md="7" xl="5">
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070019 <table-date-filter @change="onChangeDateTimeFilter" />
20 </b-col>
21 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070022 <b-row>
23 <b-col class="text-right">
24 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
25 </b-col>
26 </b-row>
27 <b-row>
28 <b-col>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070029 <table-toolbar
30 ref="toolbar"
31 :selected-items-count="selectedRows.length"
32 :actions="batchActions"
33 @clearSelected="clearSelectedRows($refs.table)"
34 @batchAction="onBatchAction"
35 >
36 <template v-slot:export>
37 <table-toolbar-export
38 :data="batchExportData"
SurenNeware96ebb0d2020-09-08 17:42:39 +053039 :file-name="exportFileNameByDate()"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070040 />
41 </template>
42 </table-toolbar>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070043 <b-table
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070044 id="table-event-logs"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070045 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053046 responsive="md"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070047 selectable
48 no-select-on-click
Yoshie Muranaka6f102342020-05-05 09:45:39 -070049 sort-icon-left
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053050 hover
Yoshie Muranaka6f102342020-05-05 09:45:39 -070051 no-sort-reset
52 sort-desc
53 show-empty
Derick Montague6b140ba2020-09-03 16:26:33 -050054 sort-by="id"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070055 :fields="fields"
56 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070057 :sort-compare="onSortCompare"
SurenNeware307382e2020-07-27 20:45:14 +053058 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053059 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070060 :per-page="perPage"
61 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070062 :filter="searchFilter"
Sukanya Pandey99010962020-07-27 21:44:47 +053063 @filtered="onFiltered"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070064 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070065 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070066 <!-- Checkbox column -->
67 <template v-slot:head(checkbox)>
68 <b-form-checkbox
69 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070070 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070071 :indeterminate="tableHeaderCheckboxIndeterminate"
72 @change="onChangeHeaderCheckbox($refs.table)"
73 />
74 </template>
75 <template v-slot:cell(checkbox)="row">
76 <b-form-checkbox
77 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070078 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070079 @change="toggleSelectRow($refs.table, row.index)"
80 />
81 </template>
82
83 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070084 <template v-slot:cell(severity)="{ value }">
Mateusz Gapskib1f12532020-07-24 08:15:23 +020085 <status-icon v-if="value" :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070086 {{ value }}
87 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070088
89 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070090 <template v-slot:cell(date)="{ value }">
Dixsie Wolmers949cdd52020-08-24 21:36:37 -050091 <p class="mb-0">{{ value | formatDate }}</p>
92 <p class="mb-0">{{ value | formatTime }}</p>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070093 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070094
95 <!-- Actions column -->
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070096 <template v-slot:cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070097 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070098 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070099 :key="index"
100 :value="action.value"
101 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700102 :row-data="row.item"
SurenNeware96ebb0d2020-09-08 17:42:39 +0530103 :export-name="exportFileNameByDate()"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700104 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
105 @click:tableAction="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700106 >
107 <template v-slot:icon>
108 <icon-export v-if="action.value === 'export'" />
109 <icon-trashcan v-if="action.value === 'delete'" />
110 </template>
111 </table-row-action>
112 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700113 </b-table>
114 </b-col>
115 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700116
117 <!-- Table pagination -->
118 <b-row>
119 <b-col class="d-md-flex justify-content-between">
120 <b-form-group
121 class="table-pagination-select"
122 :label="$t('global.table.itemsPerPage')"
123 label-for="pagination-items-per-page"
124 >
125 <b-form-select
126 id="pagination-items-per-page"
127 v-model="perPage"
128 :options="itemsPerPageOptions"
129 />
130 </b-form-group>
131 <b-pagination
132 v-model="currentPage"
133 first-number
134 last-number
135 :per-page="perPage"
136 :total-rows="getTotalRowCount(filteredLogs.length)"
137 aria-controls="table-event-logs"
138 />
139 </b-col>
140 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700141 </b-container>
142</template>
143
144<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700145import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530146import IconExport from '@carbon/icons-vue/es/document--export/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700147import { omit } from 'lodash';
148
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700149import PageTitle from '@/components/Global/PageTitle';
150import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500151import Search from '@/components/Global/Search';
Sukanya Pandey99010962020-07-27 21:44:47 +0530152import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700153import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700154import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700155import TableRowAction from '@/components/Global/TableRowAction';
156import TableToolbar from '@/components/Global/TableToolbar';
157import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700158
159import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
160import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700161import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700162import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
163import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700164import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
165import TableSortMixin from '@/components/Mixins/TableSortMixin';
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500166import SearchFilterMixin from '@/components/Mixins/SearchFilterMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700167
168export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700169 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700170 IconExport,
171 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700172 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700173 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700174 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530175 TableCellCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700176 TableFilter,
177 TableRowAction,
178 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700179 TableToolbarExport,
180 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700181 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700182 mixins: [
183 BVPaginationMixin,
184 BVTableSelectableMixin,
185 BVToastMixin,
186 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700187 TableFilterMixin,
188 TableDataFormatterMixin,
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500189 TableSortMixin,
190 SearchFilterMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700191 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700192 data() {
193 return {
194 fields: [
195 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700196 key: 'checkbox',
197 sortable: false
198 },
199 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700200 key: 'id',
201 label: this.$t('pageEventLogs.table.id'),
202 sortable: true
203 },
204 {
205 key: 'severity',
206 label: this.$t('pageEventLogs.table.severity'),
207 sortable: true
208 },
209 {
210 key: 'type',
211 label: this.$t('pageEventLogs.table.type'),
212 sortable: true
213 },
214 {
215 key: 'date',
216 label: this.$t('pageEventLogs.table.date'),
217 sortable: true
218 },
219 {
220 key: 'description',
221 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700222 },
223 {
224 key: 'actions',
225 sortable: false,
226 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530227 tdClass: 'text-right text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700228 }
229 ],
230 tableFilters: [
231 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700232 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700233 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700234 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700235 }
236 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700237 activeFilters: [],
238 batchActions: [
239 {
240 value: 'delete',
241 label: this.$t('global.action.delete')
242 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700243 ],
244 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700245 filterEndDate: null,
Sukanya Pandey99010962020-07-27 21:44:47 +0530246 searchTotalFilteredRows: 0
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700247 };
248 },
249 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530250 filteredRows() {
251 return this.searchFilter
252 ? this.searchTotalFilteredRows
253 : this.filteredLogs.length;
254 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700255 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700256 return this.$store.getters['eventLog/allEvents'].map(event => {
257 return {
258 ...event,
259 actions: [
260 {
261 value: 'export',
262 title: this.$t('global.action.export')
263 },
264 {
265 value: 'delete',
266 title: this.$t('global.action.delete')
267 }
268 ]
269 };
270 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700271 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700272 batchExportData() {
273 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700274 },
275 filteredLogsByDate() {
276 return this.getFilteredTableDataByDate(
277 this.allLogs,
278 this.filterStartDate,
279 this.filterEndDate
280 );
281 },
282 filteredLogs() {
283 return this.getFilteredTableData(
284 this.filteredLogsByDate,
285 this.activeFilters
286 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700287 }
288 },
289 created() {
290 this.startLoader();
291 this.$store
292 .dispatch('eventLog/getEventLogData')
293 .finally(() => this.endLoader());
294 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700295 beforeRouteLeave(to, from, next) {
296 // Hide loader if the user navigates to another page
297 // before request is fulfilled.
298 this.hideLoader();
299 next();
300 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700301 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700302 deleteLogs(uris) {
303 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
304 messages.forEach(({ type, message }) => {
305 if (type === 'success') {
306 this.successToast(message);
307 } else if (type === 'error') {
308 this.errorToast(message);
309 }
310 });
311 });
312 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700313 onFilterChange({ activeFilters }) {
314 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700315 },
316 onSortCompare(a, b, key) {
317 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700318 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700319 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700320 },
321 onTableRowAction(action, { uri }) {
322 if (action === 'delete') {
323 this.$bvModal
324 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
325 title: this.$tc('pageEventLogs.modal.deleteTitle'),
326 okTitle: this.$t('global.action.delete')
327 })
328 .then(deleteConfirmed => {
329 if (deleteConfirmed) this.deleteLogs([uri]);
330 });
331 }
332 },
333 onBatchAction(action) {
334 if (action === 'delete') {
335 const uris = this.selectedRows.map(row => row.uri);
336 this.$bvModal
337 .msgBoxConfirm(
338 this.$tc(
339 'pageEventLogs.modal.deleteMessage',
340 this.selectedRows.length
341 ),
342 {
343 title: this.$tc(
344 'pageEventLogs.modal.deleteTitle',
345 this.selectedRows.length
346 ),
347 okTitle: this.$t('global.action.delete')
348 }
349 )
350 .then(deleteConfirmed => {
351 if (deleteConfirmed) this.deleteLogs(uris);
352 });
353 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700354 },
355 onChangeDateTimeFilter({ fromDate, toDate }) {
356 this.filterStartDate = fromDate;
357 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700358 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530359 onFiltered(filteredItems) {
360 this.searchTotalFilteredRows = filteredItems.length;
361 },
SurenNeware96ebb0d2020-09-08 17:42:39 +0530362 // Create export file name based on date
363 exportFileNameByDate() {
364 let date = new Date();
365 date =
366 date.toISOString().slice(0, 10) +
367 '_' +
368 date
369 .toString()
370 .split(':')
371 .join('-')
372 .split(' ')[4];
373 return this.$t('pageEventLogs.exportFilePrefix') + date;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700374 }
375 }
376};
377</script>