blob: e7d4895a8988e9a5e33ac0005af7e003c9befeef [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"
9 />
10 </b-col>
Sukanya Pandey99010962020-07-27 21:44:47 +053011 <b-col sm="3" class="d-flex flex-column justify-content-end">
12 <table-cell-count
13 :filtered-items-count="filteredRows"
14 :total-number-of-cells="allLogs.length"
15 ></table-cell-count>
16 </b-col>
17 <b-col sm="8" md="7" xl="5">
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070018 <table-date-filter @change="onChangeDateTimeFilter" />
19 </b-col>
20 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070021 <b-row>
22 <b-col class="text-right">
23 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
24 </b-col>
25 </b-row>
26 <b-row>
27 <b-col>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070028 <table-toolbar
29 ref="toolbar"
30 :selected-items-count="selectedRows.length"
31 :actions="batchActions"
32 @clearSelected="clearSelectedRows($refs.table)"
33 @batchAction="onBatchAction"
34 >
35 <template v-slot:export>
36 <table-toolbar-export
37 :data="batchExportData"
SurenNeware96ebb0d2020-09-08 17:42:39 +053038 :file-name="exportFileNameByDate()"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070039 />
40 </template>
41 </table-toolbar>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070042 <b-table
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070043 id="table-event-logs"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070044 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053045 responsive="md"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070046 selectable
47 no-select-on-click
Yoshie Muranaka6f102342020-05-05 09:45:39 -070048 sort-icon-left
49 no-sort-reset
50 sort-desc
51 show-empty
Derick Montague6b140ba2020-09-03 16:26:33 -050052 sort-by="id"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070053 :fields="fields"
54 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070055 :sort-compare="onSortCompare"
SurenNeware307382e2020-07-27 20:45:14 +053056 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053057 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070058 :per-page="perPage"
59 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070060 :filter="searchFilter"
Sukanya Pandey99010962020-07-27 21:44:47 +053061 @filtered="onFiltered"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070062 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070063 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070064 <!-- Checkbox column -->
65 <template v-slot:head(checkbox)>
66 <b-form-checkbox
67 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070068 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070069 :indeterminate="tableHeaderCheckboxIndeterminate"
70 @change="onChangeHeaderCheckbox($refs.table)"
71 />
72 </template>
73 <template v-slot:cell(checkbox)="row">
74 <b-form-checkbox
75 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070076 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070077 @change="toggleSelectRow($refs.table, row.index)"
78 />
79 </template>
80
81 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070082 <template v-slot:cell(severity)="{ value }">
Mateusz Gapskib1f12532020-07-24 08:15:23 +020083 <status-icon v-if="value" :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070084 {{ value }}
85 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070086
87 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070088 <template v-slot:cell(date)="{ value }">
Dixsie Wolmers949cdd52020-08-24 21:36:37 -050089 <p class="mb-0">{{ value | formatDate }}</p>
90 <p class="mb-0">{{ value | formatTime }}</p>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070091 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070092
93 <!-- Actions column -->
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070094 <template v-slot:cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070095 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070096 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070097 :key="index"
98 :value="action.value"
99 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700100 :row-data="row.item"
SurenNeware96ebb0d2020-09-08 17:42:39 +0530101 :export-name="exportFileNameByDate()"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700102 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
103 @click:tableAction="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700104 >
105 <template v-slot:icon>
106 <icon-export v-if="action.value === 'export'" />
107 <icon-trashcan v-if="action.value === 'delete'" />
108 </template>
109 </table-row-action>
110 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700111 </b-table>
112 </b-col>
113 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700114
115 <!-- Table pagination -->
116 <b-row>
117 <b-col class="d-md-flex justify-content-between">
118 <b-form-group
119 class="table-pagination-select"
120 :label="$t('global.table.itemsPerPage')"
121 label-for="pagination-items-per-page"
122 >
123 <b-form-select
124 id="pagination-items-per-page"
125 v-model="perPage"
126 :options="itemsPerPageOptions"
127 />
128 </b-form-group>
129 <b-pagination
130 v-model="currentPage"
131 first-number
132 last-number
133 :per-page="perPage"
134 :total-rows="getTotalRowCount(filteredLogs.length)"
135 aria-controls="table-event-logs"
136 />
137 </b-col>
138 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700139 </b-container>
140</template>
141
142<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700143import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530144import IconExport from '@carbon/icons-vue/es/document--export/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700145import { omit } from 'lodash';
146
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700147import PageTitle from '@/components/Global/PageTitle';
148import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500149import Search from '@/components/Global/Search';
Sukanya Pandey99010962020-07-27 21:44:47 +0530150import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700151import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700152import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700153import TableRowAction from '@/components/Global/TableRowAction';
154import TableToolbar from '@/components/Global/TableToolbar';
155import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700156
157import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
158import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700159import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700160import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
161import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700162import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
163import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700164
165export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700166 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700167 IconExport,
168 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700169 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700170 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700171 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530172 TableCellCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700173 TableFilter,
174 TableRowAction,
175 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700176 TableToolbarExport,
177 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700178 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700179 mixins: [
180 BVPaginationMixin,
181 BVTableSelectableMixin,
182 BVToastMixin,
183 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700184 TableFilterMixin,
185 TableDataFormatterMixin,
186 TableSortMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700187 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700188 data() {
189 return {
190 fields: [
191 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700192 key: 'checkbox',
193 sortable: false
194 },
195 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700196 key: 'id',
197 label: this.$t('pageEventLogs.table.id'),
198 sortable: true
199 },
200 {
201 key: 'severity',
202 label: this.$t('pageEventLogs.table.severity'),
203 sortable: true
204 },
205 {
206 key: 'type',
207 label: this.$t('pageEventLogs.table.type'),
208 sortable: true
209 },
210 {
211 key: 'date',
212 label: this.$t('pageEventLogs.table.date'),
213 sortable: true
214 },
215 {
216 key: 'description',
217 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700218 },
219 {
220 key: 'actions',
221 sortable: false,
222 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530223 tdClass: 'text-right text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700224 }
225 ],
226 tableFilters: [
227 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700228 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700229 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700230 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700231 }
232 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700233 activeFilters: [],
234 batchActions: [
235 {
236 value: 'delete',
237 label: this.$t('global.action.delete')
238 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700239 ],
240 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700241 filterEndDate: null,
Sukanya Pandey99010962020-07-27 21:44:47 +0530242 searchFilter: null,
243 searchTotalFilteredRows: 0
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700244 };
245 },
246 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530247 filteredRows() {
248 return this.searchFilter
249 ? this.searchTotalFilteredRows
250 : this.filteredLogs.length;
251 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700252 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700253 return this.$store.getters['eventLog/allEvents'].map(event => {
254 return {
255 ...event,
256 actions: [
257 {
258 value: 'export',
259 title: this.$t('global.action.export')
260 },
261 {
262 value: 'delete',
263 title: this.$t('global.action.delete')
264 }
265 ]
266 };
267 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700268 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700269 batchExportData() {
270 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700271 },
272 filteredLogsByDate() {
273 return this.getFilteredTableDataByDate(
274 this.allLogs,
275 this.filterStartDate,
276 this.filterEndDate
277 );
278 },
279 filteredLogs() {
280 return this.getFilteredTableData(
281 this.filteredLogsByDate,
282 this.activeFilters
283 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700284 }
285 },
286 created() {
287 this.startLoader();
288 this.$store
289 .dispatch('eventLog/getEventLogData')
290 .finally(() => this.endLoader());
291 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700292 beforeRouteLeave(to, from, next) {
293 // Hide loader if the user navigates to another page
294 // before request is fulfilled.
295 this.hideLoader();
296 next();
297 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700298 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700299 deleteLogs(uris) {
300 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
301 messages.forEach(({ type, message }) => {
302 if (type === 'success') {
303 this.successToast(message);
304 } else if (type === 'error') {
305 this.errorToast(message);
306 }
307 });
308 });
309 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700310 onFilterChange({ activeFilters }) {
311 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700312 },
313 onSortCompare(a, b, key) {
314 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700315 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700316 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700317 },
318 onTableRowAction(action, { uri }) {
319 if (action === 'delete') {
320 this.$bvModal
321 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
322 title: this.$tc('pageEventLogs.modal.deleteTitle'),
323 okTitle: this.$t('global.action.delete')
324 })
325 .then(deleteConfirmed => {
326 if (deleteConfirmed) this.deleteLogs([uri]);
327 });
328 }
329 },
330 onBatchAction(action) {
331 if (action === 'delete') {
332 const uris = this.selectedRows.map(row => row.uri);
333 this.$bvModal
334 .msgBoxConfirm(
335 this.$tc(
336 'pageEventLogs.modal.deleteMessage',
337 this.selectedRows.length
338 ),
339 {
340 title: this.$tc(
341 'pageEventLogs.modal.deleteTitle',
342 this.selectedRows.length
343 ),
344 okTitle: this.$t('global.action.delete')
345 }
346 )
347 .then(deleteConfirmed => {
348 if (deleteConfirmed) this.deleteLogs(uris);
349 });
350 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700351 },
352 onChangeDateTimeFilter({ fromDate, toDate }) {
353 this.filterStartDate = fromDate;
354 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700355 },
356 onChangeSearchInput(searchValue) {
357 this.searchFilter = searchValue;
SurenNeware96ebb0d2020-09-08 17:42:39 +0530358 },
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>