blob: 87dcad5da251ece3efdc16609a2b528d77568caa [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 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700221 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700222 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700223 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700224 }
225 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700226 activeFilters: [],
227 batchActions: [
228 {
229 value: 'delete',
230 label: this.$t('global.action.delete')
231 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700232 ],
233 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700234 filterEndDate: null,
235 searchFilter: null
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700236 };
237 },
238 computed: {
239 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700240 return this.$store.getters['eventLog/allEvents'].map(event => {
241 return {
242 ...event,
243 actions: [
244 {
245 value: 'export',
246 title: this.$t('global.action.export')
247 },
248 {
249 value: 'delete',
250 title: this.$t('global.action.delete')
251 }
252 ]
253 };
254 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700255 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700256 batchExportData() {
257 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700258 },
259 filteredLogsByDate() {
260 return this.getFilteredTableDataByDate(
261 this.allLogs,
262 this.filterStartDate,
263 this.filterEndDate
264 );
265 },
266 filteredLogs() {
267 return this.getFilteredTableData(
268 this.filteredLogsByDate,
269 this.activeFilters
270 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700271 }
272 },
273 created() {
274 this.startLoader();
275 this.$store
276 .dispatch('eventLog/getEventLogData')
277 .finally(() => this.endLoader());
278 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700279 beforeRouteLeave(to, from, next) {
280 // Hide loader if the user navigates to another page
281 // before request is fulfilled.
282 this.hideLoader();
283 next();
284 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700285 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700286 deleteLogs(uris) {
287 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
288 messages.forEach(({ type, message }) => {
289 if (type === 'success') {
290 this.successToast(message);
291 } else if (type === 'error') {
292 this.errorToast(message);
293 }
294 });
295 });
296 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700297 onFilterChange({ activeFilters }) {
298 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700299 },
300 onSortCompare(a, b, key) {
301 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700302 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700303 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700304 },
305 onTableRowAction(action, { uri }) {
306 if (action === 'delete') {
307 this.$bvModal
308 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
309 title: this.$tc('pageEventLogs.modal.deleteTitle'),
310 okTitle: this.$t('global.action.delete')
311 })
312 .then(deleteConfirmed => {
313 if (deleteConfirmed) this.deleteLogs([uri]);
314 });
315 }
316 },
317 onBatchAction(action) {
318 if (action === 'delete') {
319 const uris = this.selectedRows.map(row => row.uri);
320 this.$bvModal
321 .msgBoxConfirm(
322 this.$tc(
323 'pageEventLogs.modal.deleteMessage',
324 this.selectedRows.length
325 ),
326 {
327 title: this.$tc(
328 'pageEventLogs.modal.deleteTitle',
329 this.selectedRows.length
330 ),
331 okTitle: this.$t('global.action.delete')
332 }
333 )
334 .then(deleteConfirmed => {
335 if (deleteConfirmed) this.deleteLogs(uris);
336 });
337 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700338 },
339 onChangeDateTimeFilter({ fromDate, toDate }) {
340 this.filterStartDate = fromDate;
341 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700342 },
343 onChangeSearchInput(searchValue) {
344 this.searchFilter = searchValue;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700345 }
346 }
347};
348</script>