blob: 90f589a397cc7213459179cd77c0f4edf3ed38ea [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 >
Derick Montague602e98a2020-10-21 16:20:00 -050036 <template #export>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070037 <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 -->
Derick Montague602e98a2020-10-21 16:20:00 -050067 <template #head(checkbox)>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070068 <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>
Derick Montague602e98a2020-10-21 16:20:00 -050075 <template #cell(checkbox)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070076 <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 -->
Derick Montague602e98a2020-10-21 16:20:00 -050084 <template #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 -->
Derick Montague602e98a2020-10-21 16:20:00 -050090 <template #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 -->
Derick Montague602e98a2020-10-21 16:20:00 -050096 <template #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 >
Derick Montague602e98a2020-10-21 16:20:00 -0500107 <template #icon>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700108 <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,
Derick Montague602e98a2020-10-21 16:20:00 -0500182 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,
Derick Montague602e98a2020-10-21 16:20:00 -0500192 SearchFilterMixin,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700193 ],
Derick Montague602e98a2020-10-21 16:20:00 -0500194 beforeRouteLeave(to, from, next) {
195 // Hide loader if the user navigates to another page
196 // before request is fulfilled.
197 this.hideLoader();
198 next();
199 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700200 data() {
201 return {
202 fields: [
203 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700204 key: 'checkbox',
Derick Montague602e98a2020-10-21 16:20:00 -0500205 sortable: false,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700206 },
207 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700208 key: 'id',
209 label: this.$t('pageEventLogs.table.id'),
Derick Montague602e98a2020-10-21 16:20:00 -0500210 sortable: true,
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700211 },
212 {
213 key: 'severity',
214 label: this.$t('pageEventLogs.table.severity'),
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -0500215 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500216 tdClass: 'text-nowrap',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700217 },
218 {
219 key: 'type',
220 label: this.$t('pageEventLogs.table.type'),
Derick Montague602e98a2020-10-21 16:20:00 -0500221 sortable: true,
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700222 },
223 {
224 key: 'date',
225 label: this.$t('pageEventLogs.table.date'),
Derick Montague602e98a2020-10-21 16:20:00 -0500226 sortable: true,
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700227 },
228 {
229 key: 'description',
Derick Montague602e98a2020-10-21 16:20:00 -0500230 label: this.$t('pageEventLogs.table.description'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700231 },
232 {
233 key: 'actions',
234 sortable: false,
235 label: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500236 tdClass: 'text-right text-nowrap',
237 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700238 ],
239 tableFilters: [
240 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700241 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700242 label: this.$t('pageEventLogs.table.severity'),
Derick Montague602e98a2020-10-21 16:20:00 -0500243 values: ['OK', 'Warning', 'Critical'],
244 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700245 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700246 activeFilters: [],
247 batchActions: [
248 {
249 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500250 label: this.$t('global.action.delete'),
251 },
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700252 ],
253 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700254 filterEndDate: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500255 searchTotalFilteredRows: 0,
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700256 };
257 },
258 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530259 filteredRows() {
260 return this.searchFilter
261 ? this.searchTotalFilteredRows
262 : this.filteredLogs.length;
263 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700264 allLogs() {
Derick Montague602e98a2020-10-21 16:20:00 -0500265 return this.$store.getters['eventLog/allEvents'].map((event) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700266 return {
267 ...event,
268 actions: [
269 {
270 value: 'export',
Derick Montague602e98a2020-10-21 16:20:00 -0500271 title: this.$t('global.action.export'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700272 },
273 {
274 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500275 title: this.$t('global.action.delete'),
276 },
277 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700278 };
279 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700280 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700281 batchExportData() {
Derick Montague602e98a2020-10-21 16:20:00 -0500282 return this.selectedRows.map((row) => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700283 },
284 filteredLogsByDate() {
285 return this.getFilteredTableDataByDate(
286 this.allLogs,
287 this.filterStartDate,
288 this.filterEndDate
289 );
290 },
291 filteredLogs() {
292 return this.getFilteredTableData(
293 this.filteredLogsByDate,
294 this.activeFilters
295 );
Derick Montague602e98a2020-10-21 16:20:00 -0500296 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700297 },
298 created() {
299 this.startLoader();
300 this.$store
301 .dispatch('eventLog/getEventLogData')
302 .finally(() => this.endLoader());
303 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700304 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700305 deleteLogs(uris) {
Derick Montague602e98a2020-10-21 16:20:00 -0500306 this.$store
307 .dispatch('eventLog/deleteEventLogs', uris)
308 .then((messages) => {
309 messages.forEach(({ type, message }) => {
310 if (type === 'success') {
311 this.successToast(message);
312 } else if (type === 'error') {
313 this.errorToast(message);
314 }
315 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700316 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700317 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700318 onFilterChange({ activeFilters }) {
319 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700320 },
321 onSortCompare(a, b, key) {
322 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700323 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700324 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700325 },
326 onTableRowAction(action, { uri }) {
327 if (action === 'delete') {
328 this.$bvModal
329 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
330 title: this.$tc('pageEventLogs.modal.deleteTitle'),
Derick Montague602e98a2020-10-21 16:20:00 -0500331 okTitle: this.$t('global.action.delete'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700332 })
Derick Montague602e98a2020-10-21 16:20:00 -0500333 .then((deleteConfirmed) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700334 if (deleteConfirmed) this.deleteLogs([uri]);
335 });
336 }
337 },
338 onBatchAction(action) {
339 if (action === 'delete') {
Derick Montague602e98a2020-10-21 16:20:00 -0500340 const uris = this.selectedRows.map((row) => row.uri);
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700341 this.$bvModal
342 .msgBoxConfirm(
343 this.$tc(
344 'pageEventLogs.modal.deleteMessage',
345 this.selectedRows.length
346 ),
347 {
348 title: this.$tc(
349 'pageEventLogs.modal.deleteTitle',
350 this.selectedRows.length
351 ),
Derick Montague602e98a2020-10-21 16:20:00 -0500352 okTitle: this.$t('global.action.delete'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700353 }
354 )
Derick Montague602e98a2020-10-21 16:20:00 -0500355 .then((deleteConfirmed) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700356 if (deleteConfirmed) this.deleteLogs(uris);
357 });
358 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700359 },
360 onChangeDateTimeFilter({ fromDate, toDate }) {
361 this.filterStartDate = fromDate;
362 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700363 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530364 onFiltered(filteredItems) {
365 this.searchTotalFilteredRows = filteredItems.length;
366 },
SurenNeware96ebb0d2020-09-08 17:42:39 +0530367 // Create export file name based on date
368 exportFileNameByDate() {
369 let date = new Date();
370 date =
371 date.toISOString().slice(0, 10) +
372 '_' +
Derick Montague602e98a2020-10-21 16:20:00 -0500373 date.toString().split(':').join('-').split(' ')[4];
SurenNeware96ebb0d2020-09-08 17:42:39 +0530374 return this.$t('pageEventLogs.exportFilePrefix') + date;
Derick Montague602e98a2020-10-21 16:20:00 -0500375 },
376 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700377};
378</script>