blob: 22a62837419b96ad24078b45023fbd81f16c2099 [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>
SurenNewarea35b5a12020-10-13 17:08:20 +0530119 <b-col sm="6">
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700120 <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>
SurenNewarea35b5a12020-10-13 17:08:20 +0530131 </b-col>
132 <b-col sm="6">
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700133 <b-pagination
134 v-model="currentPage"
135 first-number
136 last-number
137 :per-page="perPage"
138 :total-rows="getTotalRowCount(filteredLogs.length)"
139 aria-controls="table-event-logs"
140 />
141 </b-col>
142 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700143 </b-container>
144</template>
145
146<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700147import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530148import IconExport from '@carbon/icons-vue/es/document--export/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700149import { omit } from 'lodash';
150
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700151import PageTitle from '@/components/Global/PageTitle';
152import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500153import Search from '@/components/Global/Search';
Sukanya Pandey99010962020-07-27 21:44:47 +0530154import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700155import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700156import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700157import TableRowAction from '@/components/Global/TableRowAction';
158import TableToolbar from '@/components/Global/TableToolbar';
159import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700160
161import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
162import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700163import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700164import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
165import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700166import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
167import TableSortMixin from '@/components/Mixins/TableSortMixin';
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500168import SearchFilterMixin from '@/components/Mixins/SearchFilterMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700169
170export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700171 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700172 IconExport,
173 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700174 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700175 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700176 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530177 TableCellCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700178 TableFilter,
179 TableRowAction,
180 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700181 TableToolbarExport,
182 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700183 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700184 mixins: [
185 BVPaginationMixin,
186 BVTableSelectableMixin,
187 BVToastMixin,
188 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700189 TableFilterMixin,
190 TableDataFormatterMixin,
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500191 TableSortMixin,
192 SearchFilterMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700193 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700194 data() {
195 return {
196 fields: [
197 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700198 key: 'checkbox',
199 sortable: false
200 },
201 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700202 key: 'id',
203 label: this.$t('pageEventLogs.table.id'),
204 sortable: true
205 },
206 {
207 key: 'severity',
208 label: this.$t('pageEventLogs.table.severity'),
209 sortable: true
210 },
211 {
212 key: 'type',
213 label: this.$t('pageEventLogs.table.type'),
214 sortable: true
215 },
216 {
217 key: 'date',
218 label: this.$t('pageEventLogs.table.date'),
219 sortable: true
220 },
221 {
222 key: 'description',
223 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700224 },
225 {
226 key: 'actions',
227 sortable: false,
228 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530229 tdClass: 'text-right text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700230 }
231 ],
232 tableFilters: [
233 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700234 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700235 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700236 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700237 }
238 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700239 activeFilters: [],
240 batchActions: [
241 {
242 value: 'delete',
243 label: this.$t('global.action.delete')
244 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700245 ],
246 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700247 filterEndDate: null,
Sukanya Pandey99010962020-07-27 21:44:47 +0530248 searchTotalFilteredRows: 0
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700249 };
250 },
251 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530252 filteredRows() {
253 return this.searchFilter
254 ? this.searchTotalFilteredRows
255 : this.filteredLogs.length;
256 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700257 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700258 return this.$store.getters['eventLog/allEvents'].map(event => {
259 return {
260 ...event,
261 actions: [
262 {
263 value: 'export',
264 title: this.$t('global.action.export')
265 },
266 {
267 value: 'delete',
268 title: this.$t('global.action.delete')
269 }
270 ]
271 };
272 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700273 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700274 batchExportData() {
275 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700276 },
277 filteredLogsByDate() {
278 return this.getFilteredTableDataByDate(
279 this.allLogs,
280 this.filterStartDate,
281 this.filterEndDate
282 );
283 },
284 filteredLogs() {
285 return this.getFilteredTableData(
286 this.filteredLogsByDate,
287 this.activeFilters
288 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700289 }
290 },
291 created() {
292 this.startLoader();
293 this.$store
294 .dispatch('eventLog/getEventLogData')
295 .finally(() => this.endLoader());
296 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700297 beforeRouteLeave(to, from, next) {
298 // Hide loader if the user navigates to another page
299 // before request is fulfilled.
300 this.hideLoader();
301 next();
302 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700303 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700304 deleteLogs(uris) {
305 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
306 messages.forEach(({ type, message }) => {
307 if (type === 'success') {
308 this.successToast(message);
309 } else if (type === 'error') {
310 this.errorToast(message);
311 }
312 });
313 });
314 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700315 onFilterChange({ activeFilters }) {
316 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700317 },
318 onSortCompare(a, b, key) {
319 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700320 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700321 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700322 },
323 onTableRowAction(action, { uri }) {
324 if (action === 'delete') {
325 this.$bvModal
326 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
327 title: this.$tc('pageEventLogs.modal.deleteTitle'),
328 okTitle: this.$t('global.action.delete')
329 })
330 .then(deleteConfirmed => {
331 if (deleteConfirmed) this.deleteLogs([uri]);
332 });
333 }
334 },
335 onBatchAction(action) {
336 if (action === 'delete') {
337 const uris = this.selectedRows.map(row => row.uri);
338 this.$bvModal
339 .msgBoxConfirm(
340 this.$tc(
341 'pageEventLogs.modal.deleteMessage',
342 this.selectedRows.length
343 ),
344 {
345 title: this.$tc(
346 'pageEventLogs.modal.deleteTitle',
347 this.selectedRows.length
348 ),
349 okTitle: this.$t('global.action.delete')
350 }
351 )
352 .then(deleteConfirmed => {
353 if (deleteConfirmed) this.deleteLogs(uris);
354 });
355 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700356 },
357 onChangeDateTimeFilter({ fromDate, toDate }) {
358 this.filterStartDate = fromDate;
359 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700360 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530361 onFiltered(filteredItems) {
362 this.searchTotalFilteredRows = filteredItems.length;
363 },
SurenNeware96ebb0d2020-09-08 17:42:39 +0530364 // Create export file name based on date
365 exportFileNameByDate() {
366 let date = new Date();
367 date =
368 date.toISOString().slice(0, 10) +
369 '_' +
370 date
371 .toString()
372 .split(':')
373 .join('-')
374 .split(' ')[4];
375 return this.$t('pageEventLogs.exportFilePrefix') + date;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700376 }
377 }
378};
379</script>