blob: 0e8a54481328041b5d1731f1016c1c9b69fd6130 [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">
Yoshie Muranaka193c22a2020-06-30 20:54:10 -07005 <b-col
6 sm="8"
7 md="7"
8 xl="4"
9 class="mb-2 mb-xl-0 d-flex flex-column justify-content-end"
10 >
11 <search
12 :placeholder="$t('pageEventLogs.table.searchLogs')"
13 @changeSearch="onChangeSearchInput"
14 />
15 </b-col>
16 <b-col sm="8" md="7" xl="5" offset-xl="3">
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070017 <table-date-filter @change="onChangeDateTimeFilter" />
18 </b-col>
19 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070020 <b-row>
21 <b-col class="text-right">
22 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
23 </b-col>
24 </b-row>
25 <b-row>
26 <b-col>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070027 <table-toolbar
28 ref="toolbar"
29 :selected-items-count="selectedRows.length"
30 :actions="batchActions"
31 @clearSelected="clearSelectedRows($refs.table)"
32 @batchAction="onBatchAction"
33 >
34 <template v-slot:export>
35 <table-toolbar-export
36 :data="batchExportData"
37 :file-name="$t('appPageTitle.eventLogs')"
38 />
39 </template>
40 </table-toolbar>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070041 <b-table
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070042 id="table-event-logs"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070043 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053044 responsive="md"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070045 selectable
46 no-select-on-click
Yoshie Muranaka6f102342020-05-05 09:45:39 -070047 sort-icon-left
48 no-sort-reset
49 sort-desc
50 show-empty
Derick Montague6b140ba2020-09-03 16:26:33 -050051 sort-by="id"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070052 :fields="fields"
53 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070054 :sort-compare="onSortCompare"
SurenNeware307382e2020-07-27 20:45:14 +053055 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053056 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070057 :per-page="perPage"
58 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070059 :filter="searchFilter"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070060 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070061 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070062 <!-- Checkbox column -->
63 <template v-slot:head(checkbox)>
64 <b-form-checkbox
65 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070066 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070067 :indeterminate="tableHeaderCheckboxIndeterminate"
68 @change="onChangeHeaderCheckbox($refs.table)"
69 />
70 </template>
71 <template v-slot:cell(checkbox)="row">
72 <b-form-checkbox
73 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070074 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070075 @change="toggleSelectRow($refs.table, row.index)"
76 />
77 </template>
78
79 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070080 <template v-slot:cell(severity)="{ value }">
Mateusz Gapskib1f12532020-07-24 08:15:23 +020081 <status-icon v-if="value" :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070082 {{ value }}
83 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070084
85 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070086 <template v-slot:cell(date)="{ value }">
Dixsie Wolmers949cdd52020-08-24 21:36:37 -050087 <p class="mb-0">{{ value | formatDate }}</p>
88 <p class="mb-0">{{ value | formatTime }}</p>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070089 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070090
91 <!-- Actions column -->
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070092 <template v-slot:cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070093 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070094 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070095 :key="index"
96 :value="action.value"
97 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070098 :row-data="row.item"
99 :export-name="row.item.id"
100 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
101 @click:tableAction="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700102 >
103 <template v-slot:icon>
104 <icon-export v-if="action.value === 'export'" />
105 <icon-trashcan v-if="action.value === 'delete'" />
106 </template>
107 </table-row-action>
108 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700109 </b-table>
110 </b-col>
111 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700112
113 <!-- Table pagination -->
114 <b-row>
115 <b-col class="d-md-flex justify-content-between">
116 <b-form-group
117 class="table-pagination-select"
118 :label="$t('global.table.itemsPerPage')"
119 label-for="pagination-items-per-page"
120 >
121 <b-form-select
122 id="pagination-items-per-page"
123 v-model="perPage"
124 :options="itemsPerPageOptions"
125 />
126 </b-form-group>
127 <b-pagination
128 v-model="currentPage"
129 first-number
130 last-number
131 :per-page="perPage"
132 :total-rows="getTotalRowCount(filteredLogs.length)"
133 aria-controls="table-event-logs"
134 />
135 </b-col>
136 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700137 </b-container>
138</template>
139
140<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700141import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530142import IconExport from '@carbon/icons-vue/es/document--export/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700143import { omit } from 'lodash';
144
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700145import PageTitle from '@/components/Global/PageTitle';
146import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500147import Search from '@/components/Global/Search';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700148import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700149import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700150import TableRowAction from '@/components/Global/TableRowAction';
151import TableToolbar from '@/components/Global/TableToolbar';
152import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700153
154import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
155import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700156import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700157import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
158import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700159import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
160import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700161
162export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700163 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700164 IconExport,
165 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700166 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700167 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700168 StatusIcon,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700169 TableFilter,
170 TableRowAction,
171 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700172 TableToolbarExport,
173 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700174 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700175 mixins: [
176 BVPaginationMixin,
177 BVTableSelectableMixin,
178 BVToastMixin,
179 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700180 TableFilterMixin,
181 TableDataFormatterMixin,
182 TableSortMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700183 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700184 data() {
185 return {
186 fields: [
187 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700188 key: 'checkbox',
189 sortable: false
190 },
191 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700192 key: 'id',
193 label: this.$t('pageEventLogs.table.id'),
194 sortable: true
195 },
196 {
197 key: 'severity',
198 label: this.$t('pageEventLogs.table.severity'),
199 sortable: true
200 },
201 {
202 key: 'type',
203 label: this.$t('pageEventLogs.table.type'),
204 sortable: true
205 },
206 {
207 key: 'date',
208 label: this.$t('pageEventLogs.table.date'),
209 sortable: true
210 },
211 {
212 key: 'description',
213 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700214 },
215 {
216 key: 'actions',
217 sortable: false,
218 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530219 tdClass: 'text-right text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700220 }
221 ],
222 tableFilters: [
223 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700224 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700225 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700226 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700227 }
228 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700229 activeFilters: [],
230 batchActions: [
231 {
232 value: 'delete',
233 label: this.$t('global.action.delete')
234 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700235 ],
236 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700237 filterEndDate: null,
238 searchFilter: null
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700239 };
240 },
241 computed: {
242 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700243 return this.$store.getters['eventLog/allEvents'].map(event => {
244 return {
245 ...event,
246 actions: [
247 {
248 value: 'export',
249 title: this.$t('global.action.export')
250 },
251 {
252 value: 'delete',
253 title: this.$t('global.action.delete')
254 }
255 ]
256 };
257 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700258 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700259 batchExportData() {
260 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700261 },
262 filteredLogsByDate() {
263 return this.getFilteredTableDataByDate(
264 this.allLogs,
265 this.filterStartDate,
266 this.filterEndDate
267 );
268 },
269 filteredLogs() {
270 return this.getFilteredTableData(
271 this.filteredLogsByDate,
272 this.activeFilters
273 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700274 }
275 },
276 created() {
277 this.startLoader();
278 this.$store
279 .dispatch('eventLog/getEventLogData')
280 .finally(() => this.endLoader());
281 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700282 beforeRouteLeave(to, from, next) {
283 // Hide loader if the user navigates to another page
284 // before request is fulfilled.
285 this.hideLoader();
286 next();
287 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700288 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700289 deleteLogs(uris) {
290 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
291 messages.forEach(({ type, message }) => {
292 if (type === 'success') {
293 this.successToast(message);
294 } else if (type === 'error') {
295 this.errorToast(message);
296 }
297 });
298 });
299 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700300 onFilterChange({ activeFilters }) {
301 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700302 },
303 onSortCompare(a, b, key) {
304 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700305 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700306 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700307 },
308 onTableRowAction(action, { uri }) {
309 if (action === 'delete') {
310 this.$bvModal
311 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
312 title: this.$tc('pageEventLogs.modal.deleteTitle'),
313 okTitle: this.$t('global.action.delete')
314 })
315 .then(deleteConfirmed => {
316 if (deleteConfirmed) this.deleteLogs([uri]);
317 });
318 }
319 },
320 onBatchAction(action) {
321 if (action === 'delete') {
322 const uris = this.selectedRows.map(row => row.uri);
323 this.$bvModal
324 .msgBoxConfirm(
325 this.$tc(
326 'pageEventLogs.modal.deleteMessage',
327 this.selectedRows.length
328 ),
329 {
330 title: this.$tc(
331 'pageEventLogs.modal.deleteTitle',
332 this.selectedRows.length
333 ),
334 okTitle: this.$t('global.action.delete')
335 }
336 )
337 .then(deleteConfirmed => {
338 if (deleteConfirmed) this.deleteLogs(uris);
339 });
340 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700341 },
342 onChangeDateTimeFilter({ fromDate, toDate }) {
343 this.filterStartDate = fromDate;
344 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700345 },
346 onChangeSearchInput(searchValue) {
347 this.searchFilter = searchValue;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700348 }
349 }
350};
351</script>