blob: 44a24859cf22db41e92b8fe0b59e085061c74e48 [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"
52 :indeterminate="tableHeaderCheckboxIndeterminate"
53 @change="onChangeHeaderCheckbox($refs.table)"
54 />
55 </template>
56 <template v-slot:cell(checkbox)="row">
57 <b-form-checkbox
58 v-model="row.rowSelected"
59 @change="toggleSelectRow($refs.table, row.index)"
60 />
61 </template>
62
63 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070064 <template v-slot:cell(severity)="{ value }">
65 <status-icon :status="getStatus(value)" />
66 {{ value }}
67 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070068
69 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070070 <template v-slot:cell(date)="{ value }">
71 {{ value | formatDate }} {{ value | formatTime }}
72 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070073
74 <!-- Actions column -->
75 <template v-slot:cell(actions)="{ item }">
76 <table-row-action
77 v-for="(action, index) in item.actions"
78 :key="index"
79 :value="action.value"
80 :title="action.title"
81 :row-data="item"
82 :export-name="item.id"
83 @click:tableAction="onTableRowAction($event, item)"
84 >
85 <template v-slot:icon>
86 <icon-export v-if="action.value === 'export'" />
87 <icon-trashcan v-if="action.value === 'delete'" />
88 </template>
89 </table-row-action>
90 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070091 </b-table>
92 </b-col>
93 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070094
95 <!-- Table pagination -->
96 <b-row>
97 <b-col class="d-md-flex justify-content-between">
98 <b-form-group
99 class="table-pagination-select"
100 :label="$t('global.table.itemsPerPage')"
101 label-for="pagination-items-per-page"
102 >
103 <b-form-select
104 id="pagination-items-per-page"
105 v-model="perPage"
106 :options="itemsPerPageOptions"
107 />
108 </b-form-group>
109 <b-pagination
110 v-model="currentPage"
111 first-number
112 last-number
113 :per-page="perPage"
114 :total-rows="getTotalRowCount(filteredLogs.length)"
115 aria-controls="table-event-logs"
116 />
117 </b-col>
118 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700119 </b-container>
120</template>
121
122<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700123import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
124import IconExport from '@carbon/icons-vue/es/export/20';
125import { omit } from 'lodash';
126
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700127import PageTitle from '@/components/Global/PageTitle';
128import StatusIcon from '@/components/Global/StatusIcon';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700129import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700130import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700131import TableRowAction from '@/components/Global/TableRowAction';
132import TableToolbar from '@/components/Global/TableToolbar';
133import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700134
135import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
136import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700137import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700138import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
139import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700140
141const SEVERITY = ['OK', 'Warning', 'Critical'];
142
143export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700144 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700145 IconExport,
146 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700147 PageTitle,
148 StatusIcon,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700149 TableFilter,
150 TableRowAction,
151 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700152 TableToolbarExport,
153 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700154 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700155 mixins: [
156 BVPaginationMixin,
157 BVTableSelectableMixin,
158 BVToastMixin,
159 LoadingBarMixin,
160 TableFilterMixin
161 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700162 data() {
163 return {
164 fields: [
165 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700166 key: 'checkbox',
167 sortable: false
168 },
169 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700170 key: 'id',
171 label: this.$t('pageEventLogs.table.id'),
172 sortable: true
173 },
174 {
175 key: 'severity',
176 label: this.$t('pageEventLogs.table.severity'),
177 sortable: true
178 },
179 {
180 key: 'type',
181 label: this.$t('pageEventLogs.table.type'),
182 sortable: true
183 },
184 {
185 key: 'date',
186 label: this.$t('pageEventLogs.table.date'),
187 sortable: true
188 },
189 {
190 key: 'description',
191 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700192 },
193 {
194 key: 'actions',
195 sortable: false,
196 label: '',
197 tdClass: 'text-right'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700198 }
199 ],
200 tableFilters: [
201 {
202 label: this.$t('pageEventLogs.table.severity'),
203 values: SEVERITY
204 }
205 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700206 activeFilters: [],
207 batchActions: [
208 {
209 value: 'delete',
210 label: this.$t('global.action.delete')
211 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700212 ],
213 filterStartDate: null,
214 filterEndDate: null
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700215 };
216 },
217 computed: {
218 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700219 return this.$store.getters['eventLog/allEvents'].map(event => {
220 return {
221 ...event,
222 actions: [
223 {
224 value: 'export',
225 title: this.$t('global.action.export')
226 },
227 {
228 value: 'delete',
229 title: this.$t('global.action.delete')
230 }
231 ]
232 };
233 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700234 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700235 batchExportData() {
236 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700237 },
238 filteredLogsByDate() {
239 return this.getFilteredTableDataByDate(
240 this.allLogs,
241 this.filterStartDate,
242 this.filterEndDate
243 );
244 },
245 filteredLogs() {
246 return this.getFilteredTableData(
247 this.filteredLogsByDate,
248 this.activeFilters
249 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700250 }
251 },
252 created() {
253 this.startLoader();
254 this.$store
255 .dispatch('eventLog/getEventLogData')
256 .finally(() => this.endLoader());
257 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700258 beforeRouteLeave(to, from, next) {
259 // Hide loader if the user navigates to another page
260 // before request is fulfilled.
261 this.hideLoader();
262 next();
263 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700264 methods: {
265 getStatus(serverity) {
266 switch (serverity) {
267 case SEVERITY[2]:
268 return 'danger';
269 case SEVERITY[1]:
270 return 'warning';
271 case SEVERITY[0]:
272 return 'success';
273 default:
274 return '';
275 }
276 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700277 deleteLogs(uris) {
278 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
279 messages.forEach(({ type, message }) => {
280 if (type === 'success') {
281 this.successToast(message);
282 } else if (type === 'error') {
283 this.errorToast(message);
284 }
285 });
286 });
287 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700288 onFilterChange({ activeFilters }) {
289 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700290 },
291 onSortCompare(a, b, key) {
292 if (key === 'severity') {
293 return SEVERITY.indexOf(a.status) - SEVERITY.indexOf(b.status);
294 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700295 },
296 onTableRowAction(action, { uri }) {
297 if (action === 'delete') {
298 this.$bvModal
299 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
300 title: this.$tc('pageEventLogs.modal.deleteTitle'),
301 okTitle: this.$t('global.action.delete')
302 })
303 .then(deleteConfirmed => {
304 if (deleteConfirmed) this.deleteLogs([uri]);
305 });
306 }
307 },
308 onBatchAction(action) {
309 if (action === 'delete') {
310 const uris = this.selectedRows.map(row => row.uri);
311 this.$bvModal
312 .msgBoxConfirm(
313 this.$tc(
314 'pageEventLogs.modal.deleteMessage',
315 this.selectedRows.length
316 ),
317 {
318 title: this.$tc(
319 'pageEventLogs.modal.deleteTitle',
320 this.selectedRows.length
321 ),
322 okTitle: this.$t('global.action.delete')
323 }
324 )
325 .then(deleteConfirmed => {
326 if (deleteConfirmed) this.deleteLogs(uris);
327 });
328 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700329 },
330 onChangeDateTimeFilter({ fromDate, toDate }) {
331 this.filterStartDate = fromDate;
332 this.filterEndDate = toDate;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700333 }
334 }
335};
336</script>