blob: 4b1a8f7e6fec70a32cda05767b99d22b8227710e [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 }">
Yoshie Muranaka73e419a2020-06-18 13:08:19 -070065 <status-icon :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070066 {{ 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 Muranaka73e419a2020-06-18 13:08:19 -0700140import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
141import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700142
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,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700160 TableFilterMixin,
161 TableDataFormatterMixin,
162 TableSortMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700163 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700164 data() {
165 return {
166 fields: [
167 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700168 key: 'checkbox',
169 sortable: false
170 },
171 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700172 key: 'id',
173 label: this.$t('pageEventLogs.table.id'),
174 sortable: true
175 },
176 {
177 key: 'severity',
178 label: this.$t('pageEventLogs.table.severity'),
179 sortable: true
180 },
181 {
182 key: 'type',
183 label: this.$t('pageEventLogs.table.type'),
184 sortable: true
185 },
186 {
187 key: 'date',
188 label: this.$t('pageEventLogs.table.date'),
189 sortable: true
190 },
191 {
192 key: 'description',
193 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700194 },
195 {
196 key: 'actions',
197 sortable: false,
198 label: '',
199 tdClass: 'text-right'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700200 }
201 ],
202 tableFilters: [
203 {
204 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700205 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700206 }
207 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700208 activeFilters: [],
209 batchActions: [
210 {
211 value: 'delete',
212 label: this.$t('global.action.delete')
213 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700214 ],
215 filterStartDate: null,
216 filterEndDate: null
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700217 };
218 },
219 computed: {
220 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700221 return this.$store.getters['eventLog/allEvents'].map(event => {
222 return {
223 ...event,
224 actions: [
225 {
226 value: 'export',
227 title: this.$t('global.action.export')
228 },
229 {
230 value: 'delete',
231 title: this.$t('global.action.delete')
232 }
233 ]
234 };
235 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700236 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700237 batchExportData() {
238 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700239 },
240 filteredLogsByDate() {
241 return this.getFilteredTableDataByDate(
242 this.allLogs,
243 this.filterStartDate,
244 this.filterEndDate
245 );
246 },
247 filteredLogs() {
248 return this.getFilteredTableData(
249 this.filteredLogsByDate,
250 this.activeFilters
251 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700252 }
253 },
254 created() {
255 this.startLoader();
256 this.$store
257 .dispatch('eventLog/getEventLogData')
258 .finally(() => this.endLoader());
259 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700260 beforeRouteLeave(to, from, next) {
261 // Hide loader if the user navigates to another page
262 // before request is fulfilled.
263 this.hideLoader();
264 next();
265 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700266 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700267 deleteLogs(uris) {
268 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
269 messages.forEach(({ type, message }) => {
270 if (type === 'success') {
271 this.successToast(message);
272 } else if (type === 'error') {
273 this.errorToast(message);
274 }
275 });
276 });
277 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700278 onFilterChange({ activeFilters }) {
279 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700280 },
281 onSortCompare(a, b, key) {
282 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700283 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700284 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700285 },
286 onTableRowAction(action, { uri }) {
287 if (action === 'delete') {
288 this.$bvModal
289 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
290 title: this.$tc('pageEventLogs.modal.deleteTitle'),
291 okTitle: this.$t('global.action.delete')
292 })
293 .then(deleteConfirmed => {
294 if (deleteConfirmed) this.deleteLogs([uri]);
295 });
296 }
297 },
298 onBatchAction(action) {
299 if (action === 'delete') {
300 const uris = this.selectedRows.map(row => row.uri);
301 this.$bvModal
302 .msgBoxConfirm(
303 this.$tc(
304 'pageEventLogs.modal.deleteMessage',
305 this.selectedRows.length
306 ),
307 {
308 title: this.$tc(
309 'pageEventLogs.modal.deleteTitle',
310 this.selectedRows.length
311 ),
312 okTitle: this.$t('global.action.delete')
313 }
314 )
315 .then(deleteConfirmed => {
316 if (deleteConfirmed) this.deleteLogs(uris);
317 });
318 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700319 },
320 onChangeDateTimeFilter({ fromDate, toDate }) {
321 this.filterStartDate = fromDate;
322 this.filterEndDate = toDate;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700323 }
324 }
325};
326</script>