blob: 810edddc7056ec4f5d76960d7290adde6edc2813 [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"
SurenNeware5e25e282020-07-08 15:57:23 +053044 responsive="md"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070045 selectable
46 no-select-on-click
Yoshie Muranaka6f102342020-05-05 09:45:39 -070047 sort-icon-left
48 no-sort-reset
49 sort-desc
50 show-empty
51 sort-by="date"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070052 :fields="fields"
53 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070054 :sort-compare="onSortCompare"
SurenNeware307382e2020-07-27 20:45:14 +053055 :empty-text="$t('global.table.emptyMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070056 :per-page="perPage"
57 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070058 :filter="searchFilter"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070059 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070060 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070061 <!-- Checkbox column -->
62 <template v-slot:head(checkbox)>
63 <b-form-checkbox
64 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070065 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070066 :indeterminate="tableHeaderCheckboxIndeterminate"
67 @change="onChangeHeaderCheckbox($refs.table)"
68 />
69 </template>
70 <template v-slot:cell(checkbox)="row">
71 <b-form-checkbox
72 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070073 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070074 @change="toggleSelectRow($refs.table, row.index)"
75 />
76 </template>
77
78 <!-- Severity column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070079 <template v-slot:cell(severity)="{ value }">
Mateusz Gapskib1f12532020-07-24 08:15:23 +020080 <status-icon v-if="value" :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070081 {{ value }}
82 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070083
84 <!-- Date column -->
Yoshie Muranaka6f102342020-05-05 09:45:39 -070085 <template v-slot:cell(date)="{ value }">
86 {{ value | formatDate }} {{ value | formatTime }}
87 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070088
89 <!-- Actions column -->
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070090 <template v-slot:cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070091 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070092 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070093 :key="index"
94 :value="action.value"
95 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070096 :row-data="row.item"
97 :export-name="row.item.id"
98 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
99 @click:tableAction="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700100 >
101 <template v-slot:icon>
102 <icon-export v-if="action.value === 'export'" />
103 <icon-trashcan v-if="action.value === 'delete'" />
104 </template>
105 </table-row-action>
106 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700107 </b-table>
108 </b-col>
109 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700110
111 <!-- Table pagination -->
112 <b-row>
113 <b-col class="d-md-flex justify-content-between">
114 <b-form-group
115 class="table-pagination-select"
116 :label="$t('global.table.itemsPerPage')"
117 label-for="pagination-items-per-page"
118 >
119 <b-form-select
120 id="pagination-items-per-page"
121 v-model="perPage"
122 :options="itemsPerPageOptions"
123 />
124 </b-form-group>
125 <b-pagination
126 v-model="currentPage"
127 first-number
128 last-number
129 :per-page="perPage"
130 :total-rows="getTotalRowCount(filteredLogs.length)"
131 aria-controls="table-event-logs"
132 />
133 </b-col>
134 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700135 </b-container>
136</template>
137
138<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700139import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530140import IconExport from '@carbon/icons-vue/es/document--export/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700141import { omit } from 'lodash';
142
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700143import PageTitle from '@/components/Global/PageTitle';
144import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500145import Search from '@/components/Global/Search';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700146import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700147import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700148import TableRowAction from '@/components/Global/TableRowAction';
149import TableToolbar from '@/components/Global/TableToolbar';
150import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700151
152import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
153import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700154import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700155import BVTableSelectableMixin from '@/components/Mixins/BVTableSelectableMixin';
156import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700157import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
158import TableSortMixin from '@/components/Mixins/TableSortMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700159
160export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700161 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700162 IconExport,
163 IconTrashcan,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700164 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700165 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700166 StatusIcon,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700167 TableFilter,
168 TableRowAction,
169 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700170 TableToolbarExport,
171 TableDateFilter
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700172 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700173 mixins: [
174 BVPaginationMixin,
175 BVTableSelectableMixin,
176 BVToastMixin,
177 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700178 TableFilterMixin,
179 TableDataFormatterMixin,
180 TableSortMixin
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700181 ],
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700182 data() {
183 return {
184 fields: [
185 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700186 key: 'checkbox',
187 sortable: false
188 },
189 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700190 key: 'id',
191 label: this.$t('pageEventLogs.table.id'),
192 sortable: true
193 },
194 {
195 key: 'severity',
196 label: this.$t('pageEventLogs.table.severity'),
197 sortable: true
198 },
199 {
200 key: 'type',
201 label: this.$t('pageEventLogs.table.type'),
202 sortable: true
203 },
204 {
205 key: 'date',
206 label: this.$t('pageEventLogs.table.date'),
207 sortable: true
208 },
209 {
210 key: 'description',
211 label: this.$t('pageEventLogs.table.description')
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700212 },
213 {
214 key: 'actions',
215 sortable: false,
216 label: '',
SurenNeware5e25e282020-07-08 15:57:23 +0530217 tdClass: 'text-right text-nowrap'
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700218 }
219 ],
220 tableFilters: [
221 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700222 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700223 label: this.$t('pageEventLogs.table.severity'),
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700224 values: ['OK', 'Warning', 'Critical']
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700225 }
226 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700227 activeFilters: [],
228 batchActions: [
229 {
230 value: 'delete',
231 label: this.$t('global.action.delete')
232 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700233 ],
234 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700235 filterEndDate: null,
236 searchFilter: null
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700237 };
238 },
239 computed: {
240 allLogs() {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700241 return this.$store.getters['eventLog/allEvents'].map(event => {
242 return {
243 ...event,
244 actions: [
245 {
246 value: 'export',
247 title: this.$t('global.action.export')
248 },
249 {
250 value: 'delete',
251 title: this.$t('global.action.delete')
252 }
253 ]
254 };
255 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700256 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700257 batchExportData() {
258 return this.selectedRows.map(row => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700259 },
260 filteredLogsByDate() {
261 return this.getFilteredTableDataByDate(
262 this.allLogs,
263 this.filterStartDate,
264 this.filterEndDate
265 );
266 },
267 filteredLogs() {
268 return this.getFilteredTableData(
269 this.filteredLogsByDate,
270 this.activeFilters
271 );
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700272 }
273 },
274 created() {
275 this.startLoader();
276 this.$store
277 .dispatch('eventLog/getEventLogData')
278 .finally(() => this.endLoader());
279 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700280 beforeRouteLeave(to, from, next) {
281 // Hide loader if the user navigates to another page
282 // before request is fulfilled.
283 this.hideLoader();
284 next();
285 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700286 methods: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700287 deleteLogs(uris) {
288 this.$store.dispatch('eventLog/deleteEventLogs', uris).then(messages => {
289 messages.forEach(({ type, message }) => {
290 if (type === 'success') {
291 this.successToast(message);
292 } else if (type === 'error') {
293 this.errorToast(message);
294 }
295 });
296 });
297 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700298 onFilterChange({ activeFilters }) {
299 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700300 },
301 onSortCompare(a, b, key) {
302 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700303 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700304 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700305 },
306 onTableRowAction(action, { uri }) {
307 if (action === 'delete') {
308 this.$bvModal
309 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
310 title: this.$tc('pageEventLogs.modal.deleteTitle'),
311 okTitle: this.$t('global.action.delete')
312 })
313 .then(deleteConfirmed => {
314 if (deleteConfirmed) this.deleteLogs([uri]);
315 });
316 }
317 },
318 onBatchAction(action) {
319 if (action === 'delete') {
320 const uris = this.selectedRows.map(row => row.uri);
321 this.$bvModal
322 .msgBoxConfirm(
323 this.$tc(
324 'pageEventLogs.modal.deleteMessage',
325 this.selectedRows.length
326 ),
327 {
328 title: this.$tc(
329 'pageEventLogs.modal.deleteTitle',
330 this.selectedRows.length
331 ),
332 okTitle: this.$t('global.action.delete')
333 }
334 )
335 .then(deleteConfirmed => {
336 if (deleteConfirmed) this.deleteLogs(uris);
337 });
338 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700339 },
340 onChangeDateTimeFilter({ fromDate, toDate }) {
341 this.filterStartDate = fromDate;
342 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700343 },
344 onChangeSearchInput(searchValue) {
345 this.searchFilter = searchValue;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700346 }
347 }
348};
349</script>