blob: cf5d4787a7339cbc14a7a5f0792b76ab6927f936 [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
50 no-sort-reset
51 sort-desc
52 show-empty
Derick Montague6b140ba2020-09-03 16:26:33 -050053 sort-by="id"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070054 :fields="fields"
55 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070056 :sort-compare="onSortCompare"
SurenNeware307382e2020-07-27 20:45:14 +053057 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053058 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070059 :per-page="perPage"
60 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070061 :filter="searchFilter"
Sukanya Pandey99010962020-07-27 21:44:47 +053062 @filtered="onFiltered"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070063 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070064 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070065 <!-- Checkbox column -->
66 <template v-slot:head(checkbox)>
67 <b-form-checkbox
68 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070069 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070070 :indeterminate="tableHeaderCheckboxIndeterminate"
71 @change="onChangeHeaderCheckbox($refs.table)"
72 />
73 </template>
74 <template v-slot:cell(checkbox)="row">
75 <b-form-checkbox
76 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070077 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070078 @change="toggleSelectRow($refs.table, row.index)"
79 />
80 </template>
81
82 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070083 <template v-slot:cell(severity)="{ value }">
Mateusz Gapskib1f12532020-07-24 08:15:23 +020084 <status-icon v-if="value" :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070085 {{ value }}
86 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070087
88 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070089 <template v-slot:cell(date)="{ value }">
Dixsie Wolmers949cdd52020-08-24 21:36:37 -050090 <p class="mb-0">{{ value | formatDate }}</p>
91 <p class="mb-0">{{ value | formatTime }}</p>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070092 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070093
94 <!-- Actions column -->
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070095 <template v-slot:cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070096 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070097 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070098 :key="index"
99 :value="action.value"
100 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700101 :row-data="row.item"
SurenNeware96ebb0d2020-09-08 17:42:39 +0530102 :export-name="exportFileNameByDate()"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700103 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
104 @click:tableAction="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700105 >
106 <template v-slot:icon>
107 <icon-export v-if="action.value === 'export'" />
108 <icon-trashcan v-if="action.value === 'delete'" />
109 </template>
110 </table-row-action>
111 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700112 </b-table>
113 </b-col>
114 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700115
116 <!-- Table pagination -->
117 <b-row>
118 <b-col class="d-md-flex justify-content-between">
119 <b-form-group
120 class="table-pagination-select"
121 :label="$t('global.table.itemsPerPage')"
122 label-for="pagination-items-per-page"
123 >
124 <b-form-select
125 id="pagination-items-per-page"
126 v-model="perPage"
127 :options="itemsPerPageOptions"
128 />
129 </b-form-group>
130 <b-pagination
131 v-model="currentPage"
132 first-number
133 last-number
134 :per-page="perPage"
135 :total-rows="getTotalRowCount(filteredLogs.length)"
136 aria-controls="table-event-logs"
137 />
138 </b-col>
139 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700140 </b-container>
141</template>
142
143<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700144import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530145import IconExport from '@carbon/icons-vue/es/document--export/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700146import { omit } from 'lodash';
147
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700148import PageTitle from '@/components/Global/PageTitle';
149import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500150import Search from '@/components/Global/Search';
Sukanya Pandey99010962020-07-27 21:44:47 +0530151import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700152import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700153import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700154import TableRowAction from '@/components/Global/TableRowAction';
155import TableToolbar from '@/components/Global/TableToolbar';
156import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700157
158import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
159import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700160import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700161import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
162import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700163import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
164import TableSortMixin from '@/components/Mixins/TableSortMixin';
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500165import SearchFilterMixin from '@/components/Mixins/SearchFilterMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700166
167export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700168 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700169 IconExport,
170 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700171 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700172 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700173 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530174 TableCellCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700175 TableFilter,
176 TableRowAction,
177 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700178 TableToolbarExport,
179 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700180 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700181 mixins: [
182 BVPaginationMixin,
183 BVTableSelectableMixin,
184 BVToastMixin,
185 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700186 TableFilterMixin,
187 TableDataFormatterMixin,
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500188 TableSortMixin,
189 SearchFilterMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700190 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700191 data() {
192 return {
193 fields: [
194 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700195 key: 'checkbox',
196 sortable: false
197 },
198 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700199 key: 'id',
200 label: this.$t('pageEventLogs.table.id'),
201 sortable: true
202 },
203 {
204 key: 'severity',
205 label: this.$t('pageEventLogs.table.severity'),
206 sortable: true
207 },
208 {
209 key: 'type',
210 label: this.$t('pageEventLogs.table.type'),
211 sortable: true
212 },
213 {
214 key: 'date',
215 label: this.$t('pageEventLogs.table.date'),
216 sortable: true
217 },
218 {
219 key: 'description',
220 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700221 },
222 {
223 key: 'actions',
224 sortable: false,
225 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530226 tdClass: 'text-right text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700227 }
228 ],
229 tableFilters: [
230 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700231 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700232 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700233 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700234 }
235 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700236 activeFilters: [],
237 batchActions: [
238 {
239 value: 'delete',
240 label: this.$t('global.action.delete')
241 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700242 ],
243 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700244 filterEndDate: null,
Sukanya Pandey99010962020-07-27 21:44:47 +0530245 searchTotalFilteredRows: 0
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700246 };
247 },
248 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530249 filteredRows() {
250 return this.searchFilter
251 ? this.searchTotalFilteredRows
252 : this.filteredLogs.length;
253 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700254 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700255 return this.$store.getters['eventLog/allEvents'].map(event => {
256 return {
257 ...event,
258 actions: [
259 {
260 value: 'export',
261 title: this.$t('global.action.export')
262 },
263 {
264 value: 'delete',
265 title: this.$t('global.action.delete')
266 }
267 ]
268 };
269 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700270 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700271 batchExportData() {
272 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700273 },
274 filteredLogsByDate() {
275 return this.getFilteredTableDataByDate(
276 this.allLogs,
277 this.filterStartDate,
278 this.filterEndDate
279 );
280 },
281 filteredLogs() {
282 return this.getFilteredTableData(
283 this.filteredLogsByDate,
284 this.activeFilters
285 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700286 }
287 },
288 created() {
289 this.startLoader();
290 this.$store
291 .dispatch('eventLog/getEventLogData')
292 .finally(() => this.endLoader());
293 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700294 beforeRouteLeave(to, from, next) {
295 // Hide loader if the user navigates to another page
296 // before request is fulfilled.
297 this.hideLoader();
298 next();
299 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700300 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700301 deleteLogs(uris) {
302 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
303 messages.forEach(({ type, message }) => {
304 if (type === 'success') {
305 this.successToast(message);
306 } else if (type === 'error') {
307 this.errorToast(message);
308 }
309 });
310 });
311 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700312 onFilterChange({ activeFilters }) {
313 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700314 },
315 onSortCompare(a, b, key) {
316 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700317 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700318 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700319 },
320 onTableRowAction(action, { uri }) {
321 if (action === 'delete') {
322 this.$bvModal
323 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
324 title: this.$tc('pageEventLogs.modal.deleteTitle'),
325 okTitle: this.$t('global.action.delete')
326 })
327 .then(deleteConfirmed => {
328 if (deleteConfirmed) this.deleteLogs([uri]);
329 });
330 }
331 },
332 onBatchAction(action) {
333 if (action === 'delete') {
334 const uris = this.selectedRows.map(row => row.uri);
335 this.$bvModal
336 .msgBoxConfirm(
337 this.$tc(
338 'pageEventLogs.modal.deleteMessage',
339 this.selectedRows.length
340 ),
341 {
342 title: this.$tc(
343 'pageEventLogs.modal.deleteTitle',
344 this.selectedRows.length
345 ),
346 okTitle: this.$t('global.action.delete')
347 }
348 )
349 .then(deleteConfirmed => {
350 if (deleteConfirmed) this.deleteLogs(uris);
351 });
352 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700353 },
354 onChangeDateTimeFilter({ fromDate, toDate }) {
355 this.filterStartDate = fromDate;
356 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700357 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530358 onFiltered(filteredItems) {
359 this.searchTotalFilteredRows = filteredItems.length;
360 },
SurenNeware96ebb0d2020-09-08 17:42:39 +0530361 // Create export file name based on date
362 exportFileNameByDate() {
363 let date = new Date();
364 date =
365 date.toISOString().slice(0, 10) +
366 '_' +
367 date
368 .toString()
369 .split(':')
370 .join('-')
371 .split(' ')[4];
372 return this.$t('pageEventLogs.exportFilePrefix') + date;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700373 }
374 }
375};
376</script>