blob: 256a23803e6b011dbedd8bd473ed628e8de2a6b3 [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
51 sort-by="date"
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')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070056 :per-page="perPage"
57 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070058 :filter="searchFilter"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070059 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070060 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070061 <!-- Checkbox column -->
62 <template v-slot:head(checkbox)>
63 <b-form-checkbox
64 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070065 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070066 :indeterminate="tableHeaderCheckboxIndeterminate"
67 @change="onChangeHeaderCheckbox($refs.table)"
68 />
69 </template>
70 <template v-slot:cell(checkbox)="row">
71 <b-form-checkbox
72 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070073 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070074 @change="toggleSelectRow($refs.table, row.index)"
75 />
76 </template>
77
78 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070079 <template v-slot:cell(severity)="{ value }">
Mateusz Gapskib1f12532020-07-24 08:15:23 +020080 <status-icon v-if="value" :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070081 {{ value }}
82 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070083
84 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070085 <template v-slot:cell(date)="{ value }">
Dixsie Wolmers949cdd52020-08-24 21:36:37 -050086 <p class="mb-0">{{ value | formatDate }}</p>
87 <p class="mb-0">{{ value | formatTime }}</p>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070088 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070089
90 <!-- Actions column -->
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070091 <template v-slot:cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070092 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070093 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070094 :key="index"
95 :value="action.value"
96 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070097 :row-data="row.item"
98 :export-name="row.item.id"
99 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
100 @click:tableAction="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700101 >
102 <template v-slot:icon>
103 <icon-export v-if="action.value === 'export'" />
104 <icon-trashcan v-if="action.value === 'delete'" />
105 </template>
106 </table-row-action>
107 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700108 </b-table>
109 </b-col>
110 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700111
112 <!-- Table pagination -->
113 <b-row>
114 <b-col class="d-md-flex justify-content-between">
115 <b-form-group
116 class="table-pagination-select"
117 :label="$t('global.table.itemsPerPage')"
118 label-for="pagination-items-per-page"
119 >
120 <b-form-select
121 id="pagination-items-per-page"
122 v-model="perPage"
123 :options="itemsPerPageOptions"
124 />
125 </b-form-group>
126 <b-pagination
127 v-model="currentPage"
128 first-number
129 last-number
130 :per-page="perPage"
131 :total-rows="getTotalRowCount(filteredLogs.length)"
132 aria-controls="table-event-logs"
133 />
134 </b-col>
135 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700136 </b-container>
137</template>
138
139<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700140import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530141import IconExport from '@carbon/icons-vue/es/document--export/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700142import { omit } from 'lodash';
143
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700144import PageTitle from '@/components/Global/PageTitle';
145import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500146import Search from '@/components/Global/Search';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700147import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700148import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700149import TableRowAction from '@/components/Global/TableRowAction';
150import TableToolbar from '@/components/Global/TableToolbar';
151import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700152
153import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
154import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700155import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700156import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
157import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700158import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
159import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700160
161export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700162 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700163 IconExport,
164 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700165 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700166 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700167 StatusIcon,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700168 TableFilter,
169 TableRowAction,
170 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700171 TableToolbarExport,
172 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700173 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700174 mixins: [
175 BVPaginationMixin,
176 BVTableSelectableMixin,
177 BVToastMixin,
178 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700179 TableFilterMixin,
180 TableDataFormatterMixin,
181 TableSortMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700182 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700183 data() {
184 return {
185 fields: [
186 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700187 key: 'checkbox',
188 sortable: false
189 },
190 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700191 key: 'id',
192 label: this.$t('pageEventLogs.table.id'),
193 sortable: true
194 },
195 {
196 key: 'severity',
197 label: this.$t('pageEventLogs.table.severity'),
198 sortable: true
199 },
200 {
201 key: 'type',
202 label: this.$t('pageEventLogs.table.type'),
203 sortable: true
204 },
205 {
206 key: 'date',
207 label: this.$t('pageEventLogs.table.date'),
208 sortable: true
209 },
210 {
211 key: 'description',
212 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700213 },
214 {
215 key: 'actions',
216 sortable: false,
217 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530218 tdClass: 'text-right text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700219 }
220 ],
221 tableFilters: [
222 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700223 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700224 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700225 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700226 }
227 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700228 activeFilters: [],
229 batchActions: [
230 {
231 value: 'delete',
232 label: this.$t('global.action.delete')
233 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700234 ],
235 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700236 filterEndDate: null,
237 searchFilter: null
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700238 };
239 },
240 computed: {
241 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700242 return this.$store.getters['eventLog/allEvents'].map(event => {
243 return {
244 ...event,
245 actions: [
246 {
247 value: 'export',
248 title: this.$t('global.action.export')
249 },
250 {
251 value: 'delete',
252 title: this.$t('global.action.delete')
253 }
254 ]
255 };
256 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700257 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700258 batchExportData() {
259 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700260 },
261 filteredLogsByDate() {
262 return this.getFilteredTableDataByDate(
263 this.allLogs,
264 this.filterStartDate,
265 this.filterEndDate
266 );
267 },
268 filteredLogs() {
269 return this.getFilteredTableData(
270 this.filteredLogsByDate,
271 this.activeFilters
272 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700273 }
274 },
275 created() {
276 this.startLoader();
277 this.$store
278 .dispatch('eventLog/getEventLogData')
279 .finally(() => this.endLoader());
280 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700281 beforeRouteLeave(to, from, next) {
282 // Hide loader if the user navigates to another page
283 // before request is fulfilled.
284 this.hideLoader();
285 next();
286 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700287 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700288 deleteLogs(uris) {
289 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
290 messages.forEach(({ type, message }) => {
291 if (type === 'success') {
292 this.successToast(message);
293 } else if (type === 'error') {
294 this.errorToast(message);
295 }
296 });
297 });
298 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700299 onFilterChange({ activeFilters }) {
300 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700301 },
302 onSortCompare(a, b, key) {
303 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700304 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700305 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700306 },
307 onTableRowAction(action, { uri }) {
308 if (action === 'delete') {
309 this.$bvModal
310 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
311 title: this.$tc('pageEventLogs.modal.deleteTitle'),
312 okTitle: this.$t('global.action.delete')
313 })
314 .then(deleteConfirmed => {
315 if (deleteConfirmed) this.deleteLogs([uri]);
316 });
317 }
318 },
319 onBatchAction(action) {
320 if (action === 'delete') {
321 const uris = this.selectedRows.map(row => row.uri);
322 this.$bvModal
323 .msgBoxConfirm(
324 this.$tc(
325 'pageEventLogs.modal.deleteMessage',
326 this.selectedRows.length
327 ),
328 {
329 title: this.$tc(
330 'pageEventLogs.modal.deleteTitle',
331 this.selectedRows.length
332 ),
333 okTitle: this.$t('global.action.delete')
334 }
335 )
336 .then(deleteConfirmed => {
337 if (deleteConfirmed) this.deleteLogs(uris);
338 });
339 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700340 },
341 onChangeDateTimeFilter({ fromDate, toDate }) {
342 this.filterStartDate = fromDate;
343 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700344 },
345 onChangeSearchInput(searchValue) {
346 this.searchFilter = searchValue;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700347 }
348 }
349};
350</script>