blob: 64e2adb9161582fb52d4046e4c5b4abe8cf74895 [file] [log] [blame]
Yoshie Muranaka6f102342020-05-05 09:45:39 -07001<template>
2 <b-container fluid="xl">
3 <page-title />
SurenNeware787635a2020-11-24 22:42:42 +05304 <b-row class="align-items-start">
5 <b-col sm="8" xl="6" class="d-sm-flex align-items-end">
Yoshie Muranaka193c22a2020-06-30 20:54:10 -07006 <search
7 :placeholder="$t('pageEventLogs.table.searchLogs')"
Sandeepa Singh99e20d82021-02-09 17:37:59 +05308 data-test-id="eventLogs-input-searchLogs"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +05309 @change-search="onChangeSearchInput"
10 @clear-search="onClearSearchInput"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070011 />
SurenNeware787635a2020-11-24 22:42:42 +053012 <div class="ml-sm-4">
13 <table-cell-count
14 :filtered-items-count="filteredRows"
15 :total-number-of-cells="allLogs.length"
16 ></table-cell-count>
17 </div>
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070018 </b-col>
SurenNeware787635a2020-11-24 22:42:42 +053019 <b-col sm="8" md="7" xl="6">
Yoshie Muranaka68bbba22020-05-18 09:49:37 -070020 <table-date-filter @change="onChangeDateTimeFilter" />
21 </b-col>
22 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070023 <b-row>
24 <b-col class="text-right">
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053025 <table-filter :filters="tableFilters" @filter-change="onFilterChange" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -070026 </b-col>
27 </b-row>
28 <b-row>
29 <b-col>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070030 <table-toolbar
31 ref="toolbar"
32 :selected-items-count="selectedRows.length"
33 :actions="batchActions"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053034 @clear-selected="clearSelectedRows($refs.table)"
35 @batch-action="onBatchAction"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070036 >
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050037 <template #toolbar-buttons>
38 <b-button variant="primary" @click="resolveLogs">
39 {{ $t('pageEventLogs.resolve') }}
40 </b-button>
41 <b-button variant="primary" @click="unresolveLogs">
42 {{ $t('pageEventLogs.unresolve') }}
43 </b-button>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070044 <table-toolbar-export
45 :data="batchExportData"
SurenNeware96ebb0d2020-09-08 17:42:39 +053046 :file-name="exportFileNameByDate()"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070047 />
48 </template>
49 </table-toolbar>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070050 <b-table
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070051 id="table-event-logs"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070052 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053053 responsive="md"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070054 selectable
55 no-select-on-click
Yoshie Muranaka6f102342020-05-05 09:45:39 -070056 sort-icon-left
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053057 hover
Yoshie Muranaka6f102342020-05-05 09:45:39 -070058 no-sort-reset
59 sort-desc
60 show-empty
Derick Montague6b140ba2020-09-03 16:26:33 -050061 sort-by="id"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070062 :fields="fields"
63 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070064 :sort-compare="onSortCompare"
SurenNeware307382e2020-07-27 20:45:14 +053065 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053066 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070067 :per-page="perPage"
68 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070069 :filter="searchFilter"
Sukanya Pandey99010962020-07-27 21:44:47 +053070 @filtered="onFiltered"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070071 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070072 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070073 <!-- Checkbox column -->
Derick Montague602e98a2020-10-21 16:20:00 -050074 <template #head(checkbox)>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070075 <b-form-checkbox
76 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070077 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070078 :indeterminate="tableHeaderCheckboxIndeterminate"
79 @change="onChangeHeaderCheckbox($refs.table)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060080 >
81 <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
82 </b-form-checkbox>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070083 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050084 <template #cell(checkbox)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -070085 <b-form-checkbox
86 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070087 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070088 @change="toggleSelectRow($refs.table, row.index)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060089 >
90 <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
91 </b-form-checkbox>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070092 </template>
93
Sukanya Pandey47b047c2020-12-23 13:18:55 +053094 <!-- Expand chevron icon -->
95 <template #cell(expandRow)="row">
96 <b-button
97 variant="link"
98 :aria-label="expandRowLabel"
99 :title="expandRowLabel"
100 class="btn-icon-only"
101 @click="toggleRowDetails(row)"
102 >
103 <icon-chevron />
104 </b-button>
105 </template>
106
107 <template #row-details="{ item }">
108 <b-container fluid>
109 <b-row>
110 <b-col sm="6" xl="4">
111 <dl>
112 <!-- Name -->
113 <dt>{{ $t('pageEventLogs.table.name') }}:</dt>
114 <dd>{{ tableFormatter(item.name) }}</dd>
115 </dl>
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500116 <dl>
117 <!-- Type -->
118 <dt>{{ $t('pageEventLogs.table.type') }}:</dt>
119 <dd>{{ tableFormatter(item.type) }}</dd>
120 </dl>
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530121 </b-col>
122 <b-col sm="6" xl="4">
123 <dl>
124 <!-- Modified date -->
125 <dt>{{ $t('pageEventLogs.table.modifiedDate') }}:</dt>
126 <dd v-if="item.modifiedDate">
127 {{ item.modifiedDate | formatDate }}
128 {{ item.modifiedDate | formatTime }}
129 </dd>
130 <dd v-else>--</dd>
131 </dl>
132 </b-col>
133 </b-row>
134 </b-container>
135 </template>
136
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700137 <!-- Severity column -->
Derick Montague602e98a2020-10-21 16:20:00 -0500138 <template #cell(severity)="{ value }">
Mateusz Gapskib1f12532020-07-24 08:15:23 +0200139 <status-icon v-if="value" :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700140 {{ value }}
141 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700142 <!-- Date column -->
Derick Montague602e98a2020-10-21 16:20:00 -0500143 <template #cell(date)="{ value }">
Dixsie Wolmers949cdd52020-08-24 21:36:37 -0500144 <p class="mb-0">{{ value | formatDate }}</p>
145 <p class="mb-0">{{ value | formatTime }}</p>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700146 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700147
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500148 <!-- Status column -->
149 <template #cell(status)="row">
150 <b-form-checkbox
151 v-model="row.item.status"
152 name="switch"
153 switch
154 @change="changelogStatus(row.item)"
155 >
156 <span v-if="row.item.status">
157 {{ $t('pageEventLogs.resolved') }}
158 </span>
159 <span v-else> {{ $t('pageEventLogs.unresolved') }} </span>
160 </b-form-checkbox>
161 </template>
162 <template #cell(filterByStatus)="{ value }">
163 {{ value }}
164 </template>
165
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700166 <!-- Actions column -->
Derick Montague602e98a2020-10-21 16:20:00 -0500167 <template #cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700168 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700169 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700170 :key="index"
171 :value="action.value"
172 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700173 :row-data="row.item"
SurenNeware96ebb0d2020-09-08 17:42:39 +0530174 :export-name="exportFileNameByDate()"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700175 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530176 @click-table-action="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700177 >
Derick Montague602e98a2020-10-21 16:20:00 -0500178 <template #icon>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700179 <icon-export v-if="action.value === 'export'" />
180 <icon-trashcan v-if="action.value === 'delete'" />
181 </template>
182 </table-row-action>
183 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700184 </b-table>
185 </b-col>
186 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700187
188 <!-- Table pagination -->
189 <b-row>
SurenNewarea35b5a12020-10-13 17:08:20 +0530190 <b-col sm="6">
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700191 <b-form-group
192 class="table-pagination-select"
193 :label="$t('global.table.itemsPerPage')"
194 label-for="pagination-items-per-page"
195 >
196 <b-form-select
197 id="pagination-items-per-page"
198 v-model="perPage"
199 :options="itemsPerPageOptions"
200 />
201 </b-form-group>
SurenNewarea35b5a12020-10-13 17:08:20 +0530202 </b-col>
203 <b-col sm="6">
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700204 <b-pagination
205 v-model="currentPage"
206 first-number
207 last-number
208 :per-page="perPage"
209 :total-rows="getTotalRowCount(filteredLogs.length)"
210 aria-controls="table-event-logs"
211 />
212 </b-col>
213 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700214 </b-container>
215</template>
216
217<script>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700218import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530219import IconExport from '@carbon/icons-vue/es/document--export/20';
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530220import IconChevron from '@carbon/icons-vue/es/chevron--down/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700221import { omit } from 'lodash';
222
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700223import PageTitle from '@/components/Global/PageTitle';
224import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500225import Search from '@/components/Global/Search';
Sukanya Pandey99010962020-07-27 21:44:47 +0530226import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700227import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700228import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700229import TableRowAction from '@/components/Global/TableRowAction';
230import TableToolbar from '@/components/Global/TableToolbar';
231import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700232
233import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
234import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
SurenNewareba91c492020-10-27 14:18:54 +0530235import BVPaginationMixin, {
236 currentPage,
237 perPage,
238 itemsPerPageOptions,
239} from '@/components/Mixins/BVPaginationMixin';
240import BVTableSelectableMixin, {
241 selectedRows,
242 tableHeaderCheckboxModel,
243 tableHeaderCheckboxIndeterminate,
244} from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700245import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700246import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
247import TableSortMixin from '@/components/Mixins/TableSortMixin';
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530248import TableRowExpandMixin, {
249 expandRowLabel,
250} from '@/components/Mixins/TableRowExpandMixin';
SurenNewareba91c492020-10-27 14:18:54 +0530251import SearchFilterMixin, {
252 searchFilter,
253} from '@/components/Mixins/SearchFilterMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700254
255export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700256 components: {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700257 IconExport,
258 IconTrashcan,
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530259 IconChevron,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700260 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700261 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700262 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530263 TableCellCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700264 TableFilter,
265 TableRowAction,
266 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700267 TableToolbarExport,
Derick Montague602e98a2020-10-21 16:20:00 -0500268 TableDateFilter,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700269 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700270 mixins: [
271 BVPaginationMixin,
272 BVTableSelectableMixin,
273 BVToastMixin,
274 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700275 TableFilterMixin,
276 TableDataFormatterMixin,
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500277 TableSortMixin,
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530278 TableRowExpandMixin,
Derick Montague602e98a2020-10-21 16:20:00 -0500279 SearchFilterMixin,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700280 ],
Derick Montague602e98a2020-10-21 16:20:00 -0500281 beforeRouteLeave(to, from, next) {
282 // Hide loader if the user navigates to another page
283 // before request is fulfilled.
284 this.hideLoader();
285 next();
286 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700287 data() {
288 return {
289 fields: [
290 {
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530291 key: 'expandRow',
292 label: '',
293 tdClass: 'table-row-expand',
294 },
295 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700296 key: 'checkbox',
Derick Montague602e98a2020-10-21 16:20:00 -0500297 sortable: false,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700298 },
299 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700300 key: 'id',
301 label: this.$t('pageEventLogs.table.id'),
Derick Montague602e98a2020-10-21 16:20:00 -0500302 sortable: true,
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700303 },
304 {
305 key: 'severity',
306 label: this.$t('pageEventLogs.table.severity'),
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -0500307 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500308 tdClass: 'text-nowrap',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700309 },
310 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700311 key: 'date',
312 label: this.$t('pageEventLogs.table.date'),
Derick Montague602e98a2020-10-21 16:20:00 -0500313 sortable: true,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500314 tdClass: 'text-nowrap',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700315 },
316 {
317 key: 'description',
Derick Montague602e98a2020-10-21 16:20:00 -0500318 label: this.$t('pageEventLogs.table.description'),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500319 tdClass: 'text-break',
320 },
321 {
322 key: 'status',
323 label: this.$t('pageEventLogs.table.status'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700324 },
325 {
326 key: 'actions',
327 sortable: false,
328 label: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500329 tdClass: 'text-right text-nowrap',
330 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700331 ],
332 tableFilters: [
333 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700334 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700335 label: this.$t('pageEventLogs.table.severity'),
Derick Montague602e98a2020-10-21 16:20:00 -0500336 values: ['OK', 'Warning', 'Critical'],
337 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500338 {
339 key: 'filterByStatus',
340 label: this.$t('pageEventLogs.table.status'),
341 values: ['Resolved', 'Unresolved'],
342 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700343 ],
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530344 expandRowLabel,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700345 activeFilters: [],
346 batchActions: [
347 {
348 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500349 label: this.$t('global.action.delete'),
350 },
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700351 ],
SurenNewareba91c492020-10-27 14:18:54 +0530352 currentPage: currentPage,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700353 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700354 filterEndDate: null,
SurenNewareba91c492020-10-27 14:18:54 +0530355 itemsPerPageOptions: itemsPerPageOptions,
356 perPage: perPage,
357 searchFilter: searchFilter,
Derick Montague602e98a2020-10-21 16:20:00 -0500358 searchTotalFilteredRows: 0,
SurenNewareba91c492020-10-27 14:18:54 +0530359 selectedRows: selectedRows,
360 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
361 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700362 };
363 },
364 computed: {
Sukanya Pandey99010962020-07-27 21:44:47 +0530365 filteredRows() {
366 return this.searchFilter
367 ? this.searchTotalFilteredRows
368 : this.filteredLogs.length;
369 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700370 allLogs() {
Derick Montague602e98a2020-10-21 16:20:00 -0500371 return this.$store.getters['eventLog/allEvents'].map((event) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700372 return {
373 ...event,
374 actions: [
375 {
376 value: 'export',
Derick Montague602e98a2020-10-21 16:20:00 -0500377 title: this.$t('global.action.export'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700378 },
379 {
380 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500381 title: this.$t('global.action.delete'),
382 },
383 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700384 };
385 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700386 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700387 batchExportData() {
Derick Montague602e98a2020-10-21 16:20:00 -0500388 return this.selectedRows.map((row) => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700389 },
390 filteredLogsByDate() {
391 return this.getFilteredTableDataByDate(
392 this.allLogs,
393 this.filterStartDate,
394 this.filterEndDate
395 );
396 },
397 filteredLogs() {
398 return this.getFilteredTableData(
399 this.filteredLogsByDate,
400 this.activeFilters
401 );
Derick Montague602e98a2020-10-21 16:20:00 -0500402 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700403 },
404 created() {
405 this.startLoader();
406 this.$store
407 .dispatch('eventLog/getEventLogData')
408 .finally(() => this.endLoader());
409 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700410 methods: {
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500411 changelogStatus(row) {
412 this.$store
413 .dispatch('eventLog/updateEventLogStatus', {
414 uri: row.uri,
415 status: row.status,
416 })
417 .then((success) => {
418 this.successToast(success);
419 })
420 .catch(({ message }) => this.errorToast(message));
421 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700422 deleteLogs(uris) {
Derick Montague602e98a2020-10-21 16:20:00 -0500423 this.$store
424 .dispatch('eventLog/deleteEventLogs', uris)
425 .then((messages) => {
426 messages.forEach(({ type, message }) => {
427 if (type === 'success') {
428 this.successToast(message);
429 } else if (type === 'error') {
430 this.errorToast(message);
431 }
432 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700433 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700434 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700435 onFilterChange({ activeFilters }) {
436 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700437 },
438 onSortCompare(a, b, key) {
439 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700440 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700441 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700442 },
443 onTableRowAction(action, { uri }) {
444 if (action === 'delete') {
445 this.$bvModal
446 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
447 title: this.$tc('pageEventLogs.modal.deleteTitle'),
Derick Montague602e98a2020-10-21 16:20:00 -0500448 okTitle: this.$t('global.action.delete'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530449 cancelTitle: this.$t('global.action.cancel'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700450 })
Derick Montague602e98a2020-10-21 16:20:00 -0500451 .then((deleteConfirmed) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700452 if (deleteConfirmed) this.deleteLogs([uri]);
453 });
454 }
455 },
456 onBatchAction(action) {
457 if (action === 'delete') {
Derick Montague602e98a2020-10-21 16:20:00 -0500458 const uris = this.selectedRows.map((row) => row.uri);
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700459 this.$bvModal
460 .msgBoxConfirm(
461 this.$tc(
462 'pageEventLogs.modal.deleteMessage',
463 this.selectedRows.length
464 ),
465 {
466 title: this.$tc(
467 'pageEventLogs.modal.deleteTitle',
468 this.selectedRows.length
469 ),
Derick Montague602e98a2020-10-21 16:20:00 -0500470 okTitle: this.$t('global.action.delete'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530471 cancelTitle: this.$t('global.action.cancel'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700472 }
473 )
Derick Montague602e98a2020-10-21 16:20:00 -0500474 .then((deleteConfirmed) => {
Sukanya Pandey2f6d5522020-10-28 10:38:00 +0530475 if (deleteConfirmed) {
476 if (this.selectedRows.length === this.allLogs.length) {
477 this.$store
478 .dispatch(
479 'eventLog/deleteAllEventLogs',
480 this.selectedRows.length
481 )
482 .then((message) => this.successToast(message))
483 .catch(({ message }) => this.errorToast(message));
484 } else {
485 this.deleteLogs(uris);
486 }
487 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700488 });
489 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700490 },
491 onChangeDateTimeFilter({ fromDate, toDate }) {
492 this.filterStartDate = fromDate;
493 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700494 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530495 onFiltered(filteredItems) {
496 this.searchTotalFilteredRows = filteredItems.length;
497 },
SurenNeware96ebb0d2020-09-08 17:42:39 +0530498 // Create export file name based on date
499 exportFileNameByDate() {
500 let date = new Date();
501 date =
502 date.toISOString().slice(0, 10) +
503 '_' +
Derick Montague602e98a2020-10-21 16:20:00 -0500504 date.toString().split(':').join('-').split(' ')[4];
SurenNeware96ebb0d2020-09-08 17:42:39 +0530505 return this.$t('pageEventLogs.exportFilePrefix') + date;
Derick Montague602e98a2020-10-21 16:20:00 -0500506 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500507 resolveLogs() {
508 this.$store
509 .dispatch('eventLog/resolveEventLogs', this.selectedRows)
510 .then((messages) => {
511 messages.forEach(({ type, message }) => {
512 if (type === 'success') {
513 this.successToast(message);
514 } else if (type === 'error') {
515 this.errorToast(message);
516 }
517 });
518 });
519 },
520 unresolveLogs() {
521 this.$store
522 .dispatch('eventLog/unresolveEventLogs', this.selectedRows)
523 .then((messages) => {
524 messages.forEach(({ type, message }) => {
525 if (type === 'success') {
526 this.successToast(message);
527 } else if (type === 'error') {
528 this.errorToast(message);
529 }
530 });
531 });
532 },
Derick Montague602e98a2020-10-21 16:20:00 -0500533 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700534};
535</script>