blob: d7a64c90a87f59b160bc1a1646726cdb3eb9761a [file] [log] [blame]
Yoshie Muranaka6f102342020-05-05 09:45:39 -07001<template>
2 <b-container fluid="xl">
3 <page-title />
4 <b-row>
5 <b-col class="text-right">
6 <table-filter :filters="tableFilters" @filterChange="onFilterChange" />
7 </b-col>
8 </b-row>
9 <b-row>
10 <b-col>
11 <b-table
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070012 id="table-event-logs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070013 :fields="fields"
14 :items="filteredLogs"
15 sort-icon-left
16 no-sort-reset
17 sort-desc
18 show-empty
19 sort-by="date"
20 :sort-compare="onSortCompare"
21 :empty-text="$t('pageEventLogs.table.emptyMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070022 :per-page="perPage"
23 :current-page="currentPage"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070024 >
25 <template v-slot:cell(severity)="{ value }">
26 <status-icon :status="getStatus(value)" />
27 {{ value }}
28 </template>
29 <template v-slot:cell(date)="{ value }">
30 {{ value | formatDate }} {{ value | formatTime }}
31 </template>
32 </b-table>
33 </b-col>
34 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070035
36 <!-- Table pagination -->
37 <b-row>
38 <b-col class="d-md-flex justify-content-between">
39 <b-form-group
40 class="table-pagination-select"
41 :label="$t('global.table.itemsPerPage')"
42 label-for="pagination-items-per-page"
43 >
44 <b-form-select
45 id="pagination-items-per-page"
46 v-model="perPage"
47 :options="itemsPerPageOptions"
48 />
49 </b-form-group>
50 <b-pagination
51 v-model="currentPage"
52 first-number
53 last-number
54 :per-page="perPage"
55 :total-rows="getTotalRowCount(filteredLogs.length)"
56 aria-controls="table-event-logs"
57 />
58 </b-col>
59 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070060 </b-container>
61</template>
62
63<script>
64import PageTitle from '@/components/Global/PageTitle';
65import StatusIcon from '@/components/Global/StatusIcon';
66import TableFilter from '@/components/Global/TableFilter';
67
68import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
69import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070070import BVPaginationMixin from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -070071
72const SEVERITY = ['OK', 'Warning', 'Critical'];
73
74export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070075 components: {
76 PageTitle,
77 StatusIcon,
78 TableFilter
79 },
80 mixins: [LoadingBarMixin, TableFilterMixin, BVPaginationMixin],
Yoshie Muranaka6f102342020-05-05 09:45:39 -070081 data() {
82 return {
83 fields: [
84 {
85 key: 'id',
86 label: this.$t('pageEventLogs.table.id'),
87 sortable: true
88 },
89 {
90 key: 'severity',
91 label: this.$t('pageEventLogs.table.severity'),
92 sortable: true
93 },
94 {
95 key: 'type',
96 label: this.$t('pageEventLogs.table.type'),
97 sortable: true
98 },
99 {
100 key: 'date',
101 label: this.$t('pageEventLogs.table.date'),
102 sortable: true
103 },
104 {
105 key: 'description',
106 label: this.$t('pageEventLogs.table.description')
107 }
108 ],
109 tableFilters: [
110 {
111 label: this.$t('pageEventLogs.table.severity'),
112 values: SEVERITY
113 }
114 ],
115 activeFilters: []
116 };
117 },
118 computed: {
119 allLogs() {
120 return this.$store.getters['eventLog/allEvents'];
121 },
122 filteredLogs: {
123 get: function() {
124 return this.getFilteredTableData(this.allLogs, this.activeFilters);
125 },
126 set: function(newVal) {
127 return newVal;
128 }
129 }
130 },
131 created() {
132 this.startLoader();
133 this.$store
134 .dispatch('eventLog/getEventLogData')
135 .finally(() => this.endLoader());
136 },
Yoshie Muranakae3a8d692020-05-28 13:30:40 -0700137 beforeRouteLeave(to, from, next) {
138 // Hide loader if the user navigates to another page
139 // before request is fulfilled.
140 this.hideLoader();
141 next();
142 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700143 methods: {
144 getStatus(serverity) {
145 switch (serverity) {
146 case SEVERITY[2]:
147 return 'danger';
148 case SEVERITY[1]:
149 return 'warning';
150 case SEVERITY[0]:
151 return 'success';
152 default:
153 return '';
154 }
155 },
156 onFilterChange({ activeFilters }) {
157 this.activeFilters = activeFilters;
158 this.filteredLogs = this.getFilteredTableData(
159 this.allLogs,
160 activeFilters
161 );
162 },
163 onSortCompare(a, b, key) {
164 if (key === 'severity') {
165 return SEVERITY.indexOf(a.status) - SEVERITY.indexOf(b.status);
166 }
167 }
168 }
169};
170</script>