blob: f1c761645faf01a5e32d20dcb338705febe6b220 [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"
44 selectable
45 no-select-on-click
Yoshie Muranaka6f102342020-05-05 09:45:39 -070046 sort-icon-left
47 no-sort-reset
48 sort-desc
49 show-empty
50 sort-by="date"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070051 :fields="fields"
52 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070053 :sort-compare="onSortCompare"
54 :empty-text="$t('pageEventLogs.table.emptyMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070055 :per-page="perPage"
56 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070057 :filter="searchFilter"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070058 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070059 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070060 <!-- Checkbox column -->
61 <template v-slot:head(checkbox)>
62 <b-form-checkbox
63 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070064 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070065 :indeterminate="tableHeaderCheckboxIndeterminate"
66 @change="onChangeHeaderCheckbox($refs.table)"
67 />
68 </template>
69 <template v-slot:cell(checkbox)="row">
70 <b-form-checkbox
71 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070072 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070073 @change="toggleSelectRow($refs.table, row.index)"
74 />
75 </template>
76
77 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070078 <template v-slot:cell(severity)="{ value }">
Yoshie Muranaka73e419a2020-06-18 13:08:19 -070079 <status-icon :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070080 {{ value }}
81 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070082
83 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070084 <template v-slot:cell(date)="{ value }">
85 {{ value | formatDate }} {{ value | formatTime }}
86 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070087
88 <!-- Actions column -->
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070089 <template v-slot:cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070090 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070091 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070092 :key="index"
93 :value="action.value"
94 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070095 :row-data="row.item"
96 :export-name="row.item.id"
97 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
98 @click:tableAction="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070099 >
100 <template v-slot:icon>
101 <icon-export v-if="action.value === 'export'" />
102 <icon-trashcan v-if="action.value === 'delete'" />
103 </template>
104 </table-row-action>
105 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700106 </b-table>
107 </b-col>
108 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700109
110 <!-- Table pagination -->
111 <b-row>
112 <b-col class="d-md-flex justify-content-between">
113 <b-form-group
114 class="table-pagination-select"
115 :label="$t('global.table.itemsPerPage')"
116 label-for="pagination-items-per-page"
117 >
118 <b-form-select
119 id="pagination-items-per-page"
120 v-model="perPage"
121 :options="itemsPerPageOptions"
122 />
123 </b-form-group>
124 <b-pagination
125 v-model="currentPage"
126 first-number
127 last-number
128 :per-page="perPage"
129 :total-rows="getTotalRowCount(filteredLogs.length)"
130 aria-controls="table-event-logs"
131 />
132 </b-col>
133 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700134 </b-container>
135</template>
136
137<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700138import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
139import IconExport from '@carbon/icons-vue/es/export/20';
140import { omit } from 'lodash';
141
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700142import PageTitle from '@/components/Global/PageTitle';
143import StatusIcon from '@/components/Global/StatusIcon';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700144import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700145import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700146import TableRowAction from '@/components/Global/TableRowAction';
147import TableToolbar from '@/components/Global/TableToolbar';
148import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700149
150import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
151import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700152import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700153import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
154import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700155import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
156import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700157import Search from '@/components/Global/Search';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700158
159export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700160 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700161 IconExport,
162 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700163 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700164 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700165 StatusIcon,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700166 TableFilter,
167 TableRowAction,
168 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700169 TableToolbarExport,
170 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700171 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700172 mixins: [
173 BVPaginationMixin,
174 BVTableSelectableMixin,
175 BVToastMixin,
176 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700177 TableFilterMixin,
178 TableDataFormatterMixin,
179 TableSortMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700180 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700181 data() {
182 return {
183 fields: [
184 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700185 key: 'checkbox',
186 sortable: false
187 },
188 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700189 key: 'id',
190 label: this.$t('pageEventLogs.table.id'),
191 sortable: true
192 },
193 {
194 key: 'severity',
195 label: this.$t('pageEventLogs.table.severity'),
196 sortable: true
197 },
198 {
199 key: 'type',
200 label: this.$t('pageEventLogs.table.type'),
201 sortable: true
202 },
203 {
204 key: 'date',
205 label: this.$t('pageEventLogs.table.date'),
206 sortable: true
207 },
208 {
209 key: 'description',
210 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700211 },
212 {
213 key: 'actions',
214 sortable: false,
215 label: '',
216 tdClass: 'text-right'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700217 }
218 ],
219 tableFilters: [
220 {
221 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700222 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700223 }
224 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700225 activeFilters: [],
226 batchActions: [
227 {
228 value: 'delete',
229 label: this.$t('global.action.delete')
230 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700231 ],
232 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700233 filterEndDate: null,
234 searchFilter: null
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700235 };
236 },
237 computed: {
238 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700239 return this.$store.getters['eventLog/allEvents'].map(event => {
240 return {
241 ...event,
242 actions: [
243 {
244 value: 'export',
245 title: this.$t('global.action.export')
246 },
247 {
248 value: 'delete',
249 title: this.$t('global.action.delete')
250 }
251 ]
252 };
253 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700254 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700255 batchExportData() {
256 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700257 },
258 filteredLogsByDate() {
259 return this.getFilteredTableDataByDate(
260 this.allLogs,
261 this.filterStartDate,
262 this.filterEndDate
263 );
264 },
265 filteredLogs() {
266 return this.getFilteredTableData(
267 this.filteredLogsByDate,
268 this.activeFilters
269 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700270 }
271 },
272 created() {
273 this.startLoader();
274 this.$store
275 .dispatch('eventLog/getEventLogData')
276 .finally(() => this.endLoader());
277 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700278 beforeRouteLeave(to, from, next) {
279 // Hide loader if the user navigates to another page
280 // before request is fulfilled.
281 this.hideLoader();
282 next();
283 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700284 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700285 deleteLogs(uris) {
286 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
287 messages.forEach(({ type, message }) => {
288 if (type === 'success') {
289 this.successToast(message);
290 } else if (type === 'error') {
291 this.errorToast(message);
292 }
293 });
294 });
295 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700296 onFilterChange({ activeFilters }) {
297 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700298 },
299 onSortCompare(a, b, key) {
300 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700301 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700302 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700303 },
304 onTableRowAction(action, { uri }) {
305 if (action === 'delete') {
306 this.$bvModal
307 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
308 title: this.$tc('pageEventLogs.modal.deleteTitle'),
309 okTitle: this.$t('global.action.delete')
310 })
311 .then(deleteConfirmed => {
312 if (deleteConfirmed) this.deleteLogs([uri]);
313 });
314 }
315 },
316 onBatchAction(action) {
317 if (action === 'delete') {
318 const uris = this.selectedRows.map(row => row.uri);
319 this.$bvModal
320 .msgBoxConfirm(
321 this.$tc(
322 'pageEventLogs.modal.deleteMessage',
323 this.selectedRows.length
324 ),
325 {
326 title: this.$tc(
327 'pageEventLogs.modal.deleteTitle',
328 this.selectedRows.length
329 ),
330 okTitle: this.$t('global.action.delete')
331 }
332 )
333 .then(deleteConfirmed => {
334 if (deleteConfirmed) this.deleteLogs(uris);
335 });
336 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700337 },
338 onChangeDateTimeFilter({ fromDate, toDate }) {
339 this.filterStartDate = fromDate;
340 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700341 },
342 onChangeSearchInput(searchValue) {
343 this.searchFilter = searchValue;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700344 }
345 }
346};
347</script>