blob: c345d8fb61589367442f4314d439d64904adf5dc [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'),
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -0500209 sortable: true,
210 tdClass: 'text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700211 },
212 {
213 key: 'type',
214 label: this.$t('pageEventLogs.table.type'),
215 sortable: true
216 },
217 {
218 key: 'date',
219 label: this.$t('pageEventLogs.table.date'),
220 sortable: true
221 },
222 {
223 key: 'description',
224 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700225 },
226 {
227 key: 'actions',
228 sortable: false,
229 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530230 tdClass: 'text-right text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700231 }
232 ],
233 tableFilters: [
234 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700235 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700236 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700237 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700238 }
239 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700240 activeFilters: [],
241 batchActions: [
242 {
243 value: 'delete',
244 label: this.$t('global.action.delete')
245 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700246 ],
247 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700248 filterEndDate: null,
Sukanya Pandey99010962020-07-27 21:44:47 +0530249 searchTotalFilteredRows: 0
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700250 };
251 },
252 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530253 filteredRows() {
254 return this.searchFilter
255 ? this.searchTotalFilteredRows
256 : this.filteredLogs.length;
257 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700258 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700259 return this.$store.getters['eventLog/allEvents'].map(event => {
260 return {
261 ...event,
262 actions: [
263 {
264 value: 'export',
265 title: this.$t('global.action.export')
266 },
267 {
268 value: 'delete',
269 title: this.$t('global.action.delete')
270 }
271 ]
272 };
273 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700274 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700275 batchExportData() {
276 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700277 },
278 filteredLogsByDate() {
279 return this.getFilteredTableDataByDate(
280 this.allLogs,
281 this.filterStartDate,
282 this.filterEndDate
283 );
284 },
285 filteredLogs() {
286 return this.getFilteredTableData(
287 this.filteredLogsByDate,
288 this.activeFilters
289 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700290 }
291 },
292 created() {
293 this.startLoader();
294 this.$store
295 .dispatch('eventLog/getEventLogData')
296 .finally(() => this.endLoader());
297 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700298 beforeRouteLeave(to, from, next) {
299 // Hide loader if the user navigates to another page
300 // before request is fulfilled.
301 this.hideLoader();
302 next();
303 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700304 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700305 deleteLogs(uris) {
306 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
307 messages.forEach(({ type, message }) => {
308 if (type === 'success') {
309 this.successToast(message);
310 } else if (type === 'error') {
311 this.errorToast(message);
312 }
313 });
314 });
315 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700316 onFilterChange({ activeFilters }) {
317 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700318 },
319 onSortCompare(a, b, key) {
320 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700321 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700322 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700323 },
324 onTableRowAction(action, { uri }) {
325 if (action === 'delete') {
326 this.$bvModal
327 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
328 title: this.$tc('pageEventLogs.modal.deleteTitle'),
329 okTitle: this.$t('global.action.delete')
330 })
331 .then(deleteConfirmed => {
332 if (deleteConfirmed) this.deleteLogs([uri]);
333 });
334 }
335 },
336 onBatchAction(action) {
337 if (action === 'delete') {
338 const uris = this.selectedRows.map(row => row.uri);
339 this.$bvModal
340 .msgBoxConfirm(
341 this.$tc(
342 'pageEventLogs.modal.deleteMessage',
343 this.selectedRows.length
344 ),
345 {
346 title: this.$tc(
347 'pageEventLogs.modal.deleteTitle',
348 this.selectedRows.length
349 ),
350 okTitle: this.$t('global.action.delete')
351 }
352 )
353 .then(deleteConfirmed => {
354 if (deleteConfirmed) this.deleteLogs(uris);
355 });
356 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700357 },
358 onChangeDateTimeFilter({ fromDate, toDate }) {
359 this.filterStartDate = fromDate;
360 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700361 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530362 onFiltered(filteredItems) {
363 this.searchTotalFilteredRows = filteredItems.length;
364 },
SurenNeware96ebb0d2020-09-08 17:42:39 +0530365 // Create export file name based on date
366 exportFileNameByDate() {
367 let date = new Date();
368 date =
369 date.toISOString().slice(0, 10) +
370 '_' +
371 date
372 .toString()
373 .split(':')
374 .join('-')
375 .split(' ')[4];
376 return this.$t('pageEventLogs.exportFilePrefix') + date;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700377 }
378 }
379};
380</script>