blob: 21a0e288c162ba68f1ab298eac7d9c5b2c728189 [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">
5 <b-col md="6" lg="7" xl="5" offset-md="6" offset-lg="5" offset-xl="7">
6 <table-date-filter @change="onChangeDateTimeFilter" />
7 </b-col>
8 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -07009 <b-row>
10 <b-col class="text-right">
11 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
12 </b-col>
13 </b-row>
14 <b-row>
15 <b-col>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070016 <table-toolbar
17 ref="toolbar"
18 :selected-items-count="selectedRows.length"
19 :actions="batchActions"
20 @clearSelected="clearSelectedRows($refs.table)"
21 @batchAction="onBatchAction"
22 >
23 <template v-slot:export>
24 <table-toolbar-export
25 :data="batchExportData"
26 :file-name="$t('appPageTitle.eventLogs')"
27 />
28 </template>
29 </table-toolbar>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070030 <b-table
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070031 id="table-event-logs"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070032 ref="table"
33 selectable
34 no-select-on-click
Yoshie Muranaka6f102342020-05-05 09:45:39 -070035 sort-icon-left
36 no-sort-reset
37 sort-desc
38 show-empty
39 sort-by="date"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070040 :fields="fields"
41 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070042 :sort-compare="onSortCompare"
43 :empty-text="$t('pageEventLogs.table.emptyMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070044 :per-page="perPage"
45 :current-page="currentPage"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070046 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070047 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070048 <!-- Checkbox column -->
49 <template v-slot:head(checkbox)>
50 <b-form-checkbox
51 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070052 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070053 :indeterminate="tableHeaderCheckboxIndeterminate"
54 @change="onChangeHeaderCheckbox($refs.table)"
55 />
56 </template>
57 <template v-slot:cell(checkbox)="row">
58 <b-form-checkbox
59 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070060 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070061 @change="toggleSelectRow($refs.table, row.index)"
62 />
63 </template>
64
65 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070066 <template v-slot:cell(severity)="{ value }">
Yoshie Muranaka73e419a2020-06-18 13:08:19 -070067 <status-icon :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070068 {{ value }}
69 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070070
71 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070072 <template v-slot:cell(date)="{ value }">
73 {{ value | formatDate }} {{ value | formatTime }}
74 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070075
76 <!-- Actions column -->
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070077 <template v-slot:cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070078 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070079 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070080 :key="index"
81 :value="action.value"
82 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070083 :row-data="row.item"
84 :export-name="row.item.id"
85 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
86 @click:tableAction="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070087 >
88 <template v-slot:icon>
89 <icon-export v-if="action.value === 'export'" />
90 <icon-trashcan v-if="action.value === 'delete'" />
91 </template>
92 </table-row-action>
93 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070094 </b-table>
95 </b-col>
96 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070097
98 <!-- Table pagination -->
99 <b-row>
100 <b-col class="d-md-flex justify-content-between">
101 <b-form-group
102 class="table-pagination-select"
103 :label="$t('global.table.itemsPerPage')"
104 label-for="pagination-items-per-page"
105 >
106 <b-form-select
107 id="pagination-items-per-page"
108 v-model="perPage"
109 :options="itemsPerPageOptions"
110 />
111 </b-form-group>
112 <b-pagination
113 v-model="currentPage"
114 first-number
115 last-number
116 :per-page="perPage"
117 :total-rows="getTotalRowCount(filteredLogs.length)"
118 aria-controls="table-event-logs"
119 />
120 </b-col>
121 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700122 </b-container>
123</template>
124
125<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700126import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
127import IconExport from '@carbon/icons-vue/es/export/20';
128import { omit } from 'lodash';
129
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700130import PageTitle from '@/components/Global/PageTitle';
131import StatusIcon from '@/components/Global/StatusIcon';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700132import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700133import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700134import TableRowAction from '@/components/Global/TableRowAction';
135import TableToolbar from '@/components/Global/TableToolbar';
136import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700137
138import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
139import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700140import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700141import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
142import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700143import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
144import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700145
146export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700147 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700148 IconExport,
149 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700150 PageTitle,
151 StatusIcon,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700152 TableFilter,
153 TableRowAction,
154 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700155 TableToolbarExport,
156 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700157 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700158 mixins: [
159 BVPaginationMixin,
160 BVTableSelectableMixin,
161 BVToastMixin,
162 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700163 TableFilterMixin,
164 TableDataFormatterMixin,
165 TableSortMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700166 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700167 data() {
168 return {
169 fields: [
170 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700171 key: 'checkbox',
172 sortable: false
173 },
174 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700175 key: 'id',
176 label: this.$t('pageEventLogs.table.id'),
177 sortable: true
178 },
179 {
180 key: 'severity',
181 label: this.$t('pageEventLogs.table.severity'),
182 sortable: true
183 },
184 {
185 key: 'type',
186 label: this.$t('pageEventLogs.table.type'),
187 sortable: true
188 },
189 {
190 key: 'date',
191 label: this.$t('pageEventLogs.table.date'),
192 sortable: true
193 },
194 {
195 key: 'description',
196 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700197 },
198 {
199 key: 'actions',
200 sortable: false,
201 label: '',
202 tdClass: 'text-right'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700203 }
204 ],
205 tableFilters: [
206 {
207 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700208 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700209 }
210 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700211 activeFilters: [],
212 batchActions: [
213 {
214 value: 'delete',
215 label: this.$t('global.action.delete')
216 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700217 ],
218 filterStartDate: null,
219 filterEndDate: null
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700220 };
221 },
222 computed: {
223 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700224 return this.$store.getters['eventLog/allEvents'].map(event => {
225 return {
226 ...event,
227 actions: [
228 {
229 value: 'export',
230 title: this.$t('global.action.export')
231 },
232 {
233 value: 'delete',
234 title: this.$t('global.action.delete')
235 }
236 ]
237 };
238 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700239 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700240 batchExportData() {
241 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700242 },
243 filteredLogsByDate() {
244 return this.getFilteredTableDataByDate(
245 this.allLogs,
246 this.filterStartDate,
247 this.filterEndDate
248 );
249 },
250 filteredLogs() {
251 return this.getFilteredTableData(
252 this.filteredLogsByDate,
253 this.activeFilters
254 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700255 }
256 },
257 created() {
258 this.startLoader();
259 this.$store
260 .dispatch('eventLog/getEventLogData')
261 .finally(() => this.endLoader());
262 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700263 beforeRouteLeave(to, from, next) {
264 // Hide loader if the user navigates to another page
265 // before request is fulfilled.
266 this.hideLoader();
267 next();
268 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700269 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700270 deleteLogs(uris) {
271 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
272 messages.forEach(({ type, message }) => {
273 if (type === 'success') {
274 this.successToast(message);
275 } else if (type === 'error') {
276 this.errorToast(message);
277 }
278 });
279 });
280 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700281 onFilterChange({ activeFilters }) {
282 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700283 },
284 onSortCompare(a, b, key) {
285 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700286 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700287 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700288 },
289 onTableRowAction(action, { uri }) {
290 if (action === 'delete') {
291 this.$bvModal
292 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
293 title: this.$tc('pageEventLogs.modal.deleteTitle'),
294 okTitle: this.$t('global.action.delete')
295 })
296 .then(deleteConfirmed => {
297 if (deleteConfirmed) this.deleteLogs([uri]);
298 });
299 }
300 },
301 onBatchAction(action) {
302 if (action === 'delete') {
303 const uris = this.selectedRows.map(row => row.uri);
304 this.$bvModal
305 .msgBoxConfirm(
306 this.$tc(
307 'pageEventLogs.modal.deleteMessage',
308 this.selectedRows.length
309 ),
310 {
311 title: this.$tc(
312 'pageEventLogs.modal.deleteTitle',
313 this.selectedRows.length
314 ),
315 okTitle: this.$t('global.action.delete')
316 }
317 )
318 .then(deleteConfirmed => {
319 if (deleteConfirmed) this.deleteLogs(uris);
320 });
321 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700322 },
323 onChangeDateTimeFilter({ fromDate, toDate }) {
324 this.filterStartDate = fromDate;
325 this.filterEndDate = toDate;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700326 }
327 }
328};
329</script>