blob: fa3f43cbdf5608ca65d7181dc8af9b762884133a [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">
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -05005 <b-col sm="8" xl="6" class="d-sm-flex align-items-end mb-4">
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" />
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -050026 <b-button
27 variant="link"
28 :disabled="allLogs.length === 0"
29 @click="deleteAllLogs"
30 >
31 <icon-delete /> {{ $t('global.action.deleteAll') }}
32 </b-button>
33 <b-button
34 variant="primary"
35 :class="{ disabled: allLogs.length === 0 }"
36 :download="exportFileNameByDate()"
37 :href="href"
38 >
39 <icon-export /> {{ $t('global.action.exportAll') }}
40 </b-button>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070041 </b-col>
42 </b-row>
43 <b-row>
44 <b-col>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070045 <table-toolbar
46 ref="toolbar"
47 :selected-items-count="selectedRows.length"
48 :actions="batchActions"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +053049 @clear-selected="clearSelectedRows($refs.table)"
50 @batch-action="onBatchAction"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070051 >
Dixsie Wolmers27d68af2021-05-02 18:20:27 -050052 <template #toolbar-buttons>
53 <b-button variant="primary" @click="resolveLogs">
54 {{ $t('pageEventLogs.resolve') }}
55 </b-button>
56 <b-button variant="primary" @click="unresolveLogs">
57 {{ $t('pageEventLogs.unresolve') }}
58 </b-button>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070059 <table-toolbar-export
60 :data="batchExportData"
SurenNeware96ebb0d2020-09-08 17:42:39 +053061 :file-name="exportFileNameByDate()"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070062 />
63 </template>
64 </table-toolbar>
Yoshie Muranaka6f102342020-05-05 09:45:39 -070065 <b-table
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070066 id="table-event-logs"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070067 ref="table"
SurenNeware5e25e282020-07-08 15:57:23 +053068 responsive="md"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070069 selectable
70 no-select-on-click
Yoshie Muranaka6f102342020-05-05 09:45:39 -070071 sort-icon-left
Sukanya Pandeyfde429e2020-09-14 20:48:39 +053072 hover
Yoshie Muranaka6f102342020-05-05 09:45:39 -070073 no-sort-reset
74 sort-desc
75 show-empty
Derick Montague6b140ba2020-09-03 16:26:33 -050076 sort-by="id"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070077 :fields="fields"
78 :items="filteredLogs"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070079 :sort-compare="onSortCompare"
SurenNeware307382e2020-07-27 20:45:14 +053080 :empty-text="$t('global.table.emptyMessage')"
SurenNeware156a0e62020-08-28 19:20:03 +053081 :empty-filtered-text="$t('global.table.emptySearchMessage')"
Yoshie Muranakaf9832b02020-05-12 12:04:46 -070082 :per-page="perPage"
83 :current-page="currentPage"
Yoshie Muranaka193c22a2020-06-30 20:54:10 -070084 :filter="searchFilter"
Sukanya Pandey99010962020-07-27 21:44:47 +053085 @filtered="onFiltered"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070086 @row-selected="onRowSelected($event, filteredLogs.length)"
Yoshie Muranaka6f102342020-05-05 09:45:39 -070087 >
Yoshie Muranakabe3af332020-05-11 08:23:04 -070088 <!-- Checkbox column -->
Derick Montague602e98a2020-10-21 16:20:00 -050089 <template #head(checkbox)>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070090 <b-form-checkbox
91 v-model="tableHeaderCheckboxModel"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -070092 data-test-id="eventLogs-checkbox-selectAll"
Yoshie Muranakabe3af332020-05-11 08:23:04 -070093 :indeterminate="tableHeaderCheckboxIndeterminate"
94 @change="onChangeHeaderCheckbox($refs.table)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -060095 >
96 <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
97 </b-form-checkbox>
Yoshie Muranakabe3af332020-05-11 08:23:04 -070098 </template>
Derick Montague602e98a2020-10-21 16:20:00 -050099 <template #cell(checkbox)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700100 <b-form-checkbox
101 v-model="row.rowSelected"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700102 :data-test-id="`eventLogs-checkbox-selectRow-${row.index}`"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700103 @change="toggleSelectRow($refs.table, row.index)"
Dixsie Wolmersc42ad712020-11-19 17:29:24 -0600104 >
105 <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
106 </b-form-checkbox>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700107 </template>
108
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530109 <!-- Expand chevron icon -->
110 <template #cell(expandRow)="row">
111 <b-button
112 variant="link"
113 :aria-label="expandRowLabel"
114 :title="expandRowLabel"
115 class="btn-icon-only"
116 @click="toggleRowDetails(row)"
117 >
118 <icon-chevron />
119 </b-button>
120 </template>
121
122 <template #row-details="{ item }">
123 <b-container fluid>
124 <b-row>
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -0500125 <b-col>
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530126 <dl>
127 <!-- Name -->
128 <dt>{{ $t('pageEventLogs.table.name') }}:</dt>
129 <dd>{{ tableFormatter(item.name) }}</dd>
130 </dl>
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500131 <dl>
132 <!-- Type -->
133 <dt>{{ $t('pageEventLogs.table.type') }}:</dt>
134 <dd>{{ tableFormatter(item.type) }}</dd>
135 </dl>
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530136 </b-col>
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -0500137 <b-col>
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530138 <dl>
139 <!-- Modified date -->
140 <dt>{{ $t('pageEventLogs.table.modifiedDate') }}:</dt>
141 <dd v-if="item.modifiedDate">
142 {{ item.modifiedDate | formatDate }}
143 {{ item.modifiedDate | formatTime }}
144 </dd>
145 <dd v-else>--</dd>
146 </dl>
147 </b-col>
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -0500148 <b-col class="text-nowrap">
149 <b-button
150 class="btn btn-secondary float-right"
151 :href="item.additionalDataUri"
152 target="_blank"
153 >
154 <icon-download />{{ $t('pageEventLogs.additionalDataUri') }}
155 </b-button>
156 </b-col>
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530157 </b-row>
158 </b-container>
159 </template>
160
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700161 <!-- Severity column -->
Derick Montague602e98a2020-10-21 16:20:00 -0500162 <template #cell(severity)="{ value }">
Mateusz Gapskib1f12532020-07-24 08:15:23 +0200163 <status-icon v-if="value" :status="statusIcon(value)" />
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700164 {{ value }}
165 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700166 <!-- Date column -->
Derick Montague602e98a2020-10-21 16:20:00 -0500167 <template #cell(date)="{ value }">
Dixsie Wolmers949cdd52020-08-24 21:36:37 -0500168 <p class="mb-0">{{ value | formatDate }}</p>
169 <p class="mb-0">{{ value | formatTime }}</p>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700170 </template>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700171
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500172 <!-- Status column -->
173 <template #cell(status)="row">
174 <b-form-checkbox
175 v-model="row.item.status"
176 name="switch"
177 switch
178 @change="changelogStatus(row.item)"
179 >
180 <span v-if="row.item.status">
181 {{ $t('pageEventLogs.resolved') }}
182 </span>
183 <span v-else> {{ $t('pageEventLogs.unresolved') }} </span>
184 </b-form-checkbox>
185 </template>
186 <template #cell(filterByStatus)="{ value }">
187 {{ value }}
188 </template>
189
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700190 <!-- Actions column -->
Derick Montague602e98a2020-10-21 16:20:00 -0500191 <template #cell(actions)="row">
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700192 <table-row-action
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700193 v-for="(action, index) in row.item.actions"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700194 :key="index"
195 :value="action.value"
196 :title="action.title"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700197 :row-data="row.item"
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500198 :export-name="exportFileNameByDate('export')"
Yoshie Muranakaed06dc12020-06-16 12:12:27 -0700199 :data-test-id="`eventLogs-button-deleteRow-${row.index}`"
Sukanya Pandeyedb8a772020-10-29 11:33:42 +0530200 @click-table-action="onTableRowAction($event, row.item)"
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700201 >
Derick Montague602e98a2020-10-21 16:20:00 -0500202 <template #icon>
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700203 <icon-export v-if="action.value === 'export'" />
204 <icon-trashcan v-if="action.value === 'delete'" />
205 </template>
206 </table-row-action>
207 </template>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700208 </b-table>
209 </b-col>
210 </b-row>
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700211
212 <!-- Table pagination -->
213 <b-row>
SurenNewarea35b5a12020-10-13 17:08:20 +0530214 <b-col sm="6">
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700215 <b-form-group
216 class="table-pagination-select"
217 :label="$t('global.table.itemsPerPage')"
218 label-for="pagination-items-per-page"
219 >
220 <b-form-select
221 id="pagination-items-per-page"
222 v-model="perPage"
223 :options="itemsPerPageOptions"
224 />
225 </b-form-group>
SurenNewarea35b5a12020-10-13 17:08:20 +0530226 </b-col>
227 <b-col sm="6">
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700228 <b-pagination
229 v-model="currentPage"
230 first-number
231 last-number
232 :per-page="perPage"
233 :total-rows="getTotalRowCount(filteredLogs.length)"
234 aria-controls="table-event-logs"
235 />
236 </b-col>
237 </b-row>
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700238 </b-container>
239</template>
240
241<script>
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500242import IconDelete from '@carbon/icons-vue/es/trash-can/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700243import IconTrashcan from '@carbon/icons-vue/es/trash-can/20';
Sukanya Pandeyb2ca0c02020-07-20 23:23:29 +0530244import IconExport from '@carbon/icons-vue/es/document--export/20';
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530245import IconChevron from '@carbon/icons-vue/es/chevron--down/20';
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -0500246import IconDownload from '@carbon/icons-vue/es/download/20';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700247import { omit } from 'lodash';
248
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700249import PageTitle from '@/components/Global/PageTitle';
250import StatusIcon from '@/components/Global/StatusIcon';
Derick Montagued853fba2020-07-16 11:24:10 -0500251import Search from '@/components/Global/Search';
Sukanya Pandey99010962020-07-27 21:44:47 +0530252import TableCellCount from '@/components/Global/TableCellCount';
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700253import TableDateFilter from '@/components/Global/TableDateFilter';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700254import TableFilter from '@/components/Global/TableFilter';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700255import TableRowAction from '@/components/Global/TableRowAction';
256import TableToolbar from '@/components/Global/TableToolbar';
257import TableToolbarExport from '@/components/Global/TableToolbarExport';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700258
259import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
260import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
SurenNewareba91c492020-10-27 14:18:54 +0530261import BVPaginationMixin, {
262 currentPage,
263 perPage,
264 itemsPerPageOptions,
265} from '@/components/Mixins/BVPaginationMixin';
266import BVTableSelectableMixin, {
267 selectedRows,
268 tableHeaderCheckboxModel,
269 tableHeaderCheckboxIndeterminate,
270} from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700271import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700272import TableDataFormatterMixin from '@/components/Mixins/TableDataFormatterMixin';
273import TableSortMixin from '@/components/Mixins/TableSortMixin';
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530274import TableRowExpandMixin, {
275 expandRowLabel,
276} from '@/components/Mixins/TableRowExpandMixin';
SurenNewareba91c492020-10-27 14:18:54 +0530277import SearchFilterMixin, {
278 searchFilter,
279} from '@/components/Mixins/SearchFilterMixin';
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700280
281export default {
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700282 components: {
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500283 IconDelete,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700284 IconExport,
285 IconTrashcan,
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530286 IconChevron,
Dixsie Wolmers8b1beff2021-06-14 11:29:44 -0500287 IconDownload,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700288 PageTitle,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700289 Search,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700290 StatusIcon,
Sukanya Pandey99010962020-07-27 21:44:47 +0530291 TableCellCount,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700292 TableFilter,
293 TableRowAction,
294 TableToolbar,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700295 TableToolbarExport,
Derick Montague602e98a2020-10-21 16:20:00 -0500296 TableDateFilter,
Yoshie Muranakaf9832b02020-05-12 12:04:46 -0700297 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700298 mixins: [
299 BVPaginationMixin,
300 BVTableSelectableMixin,
301 BVToastMixin,
302 LoadingBarMixin,
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700303 TableFilterMixin,
304 TableDataFormatterMixin,
Dixsie Wolmers9b22b492020-09-07 21:26:06 -0500305 TableSortMixin,
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530306 TableRowExpandMixin,
Derick Montague602e98a2020-10-21 16:20:00 -0500307 SearchFilterMixin,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700308 ],
Derick Montague602e98a2020-10-21 16:20:00 -0500309 beforeRouteLeave(to, from, next) {
310 // Hide loader if the user navigates to another page
311 // before request is fulfilled.
312 this.hideLoader();
313 next();
314 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700315 data() {
316 return {
317 fields: [
318 {
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530319 key: 'expandRow',
320 label: '',
321 tdClass: 'table-row-expand',
322 },
323 {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700324 key: 'checkbox',
Derick Montague602e98a2020-10-21 16:20:00 -0500325 sortable: false,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700326 },
327 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700328 key: 'id',
329 label: this.$t('pageEventLogs.table.id'),
Derick Montague602e98a2020-10-21 16:20:00 -0500330 sortable: true,
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700331 },
332 {
333 key: 'severity',
334 label: this.$t('pageEventLogs.table.severity'),
Dixsie Wolmersa04d46f2020-10-22 06:34:56 -0500335 sortable: true,
Derick Montague602e98a2020-10-21 16:20:00 -0500336 tdClass: 'text-nowrap',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700337 },
338 {
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700339 key: 'date',
340 label: this.$t('pageEventLogs.table.date'),
Derick Montague602e98a2020-10-21 16:20:00 -0500341 sortable: true,
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500342 tdClass: 'text-nowrap',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700343 },
344 {
345 key: 'description',
Derick Montague602e98a2020-10-21 16:20:00 -0500346 label: this.$t('pageEventLogs.table.description'),
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500347 tdClass: 'text-break',
348 },
349 {
350 key: 'status',
351 label: this.$t('pageEventLogs.table.status'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700352 },
353 {
354 key: 'actions',
355 sortable: false,
356 label: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500357 tdClass: 'text-right text-nowrap',
358 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700359 ],
360 tableFilters: [
361 {
Yoshie Muranaka00454002020-06-22 09:14:05 -0700362 key: 'severity',
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700363 label: this.$t('pageEventLogs.table.severity'),
Derick Montague602e98a2020-10-21 16:20:00 -0500364 values: ['OK', 'Warning', 'Critical'],
365 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500366 {
367 key: 'filterByStatus',
368 label: this.$t('pageEventLogs.table.status'),
369 values: ['Resolved', 'Unresolved'],
370 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700371 ],
Sukanya Pandey47b047c2020-12-23 13:18:55 +0530372 expandRowLabel,
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700373 activeFilters: [],
374 batchActions: [
375 {
376 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500377 label: this.$t('global.action.delete'),
378 },
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700379 ],
SurenNewareba91c492020-10-27 14:18:54 +0530380 currentPage: currentPage,
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700381 filterStartDate: null,
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700382 filterEndDate: null,
SurenNewareba91c492020-10-27 14:18:54 +0530383 itemsPerPageOptions: itemsPerPageOptions,
384 perPage: perPage,
385 searchFilter: searchFilter,
Derick Montague602e98a2020-10-21 16:20:00 -0500386 searchTotalFilteredRows: 0,
SurenNewareba91c492020-10-27 14:18:54 +0530387 selectedRows: selectedRows,
388 tableHeaderCheckboxModel: tableHeaderCheckboxModel,
389 tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate,
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700390 };
391 },
392 computed: {
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500393 href() {
394 return `data:text/json;charset=utf-8,${this.exportAllLogs()}`;
395 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530396 filteredRows() {
397 return this.searchFilter
398 ? this.searchTotalFilteredRows
399 : this.filteredLogs.length;
400 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700401 allLogs() {
Derick Montague602e98a2020-10-21 16:20:00 -0500402 return this.$store.getters['eventLog/allEvents'].map((event) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700403 return {
404 ...event,
405 actions: [
406 {
407 value: 'export',
Derick Montague602e98a2020-10-21 16:20:00 -0500408 title: this.$t('global.action.export'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700409 },
410 {
411 value: 'delete',
Derick Montague602e98a2020-10-21 16:20:00 -0500412 title: this.$t('global.action.delete'),
413 },
414 ],
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700415 };
416 });
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700417 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700418 batchExportData() {
Derick Montague602e98a2020-10-21 16:20:00 -0500419 return this.selectedRows.map((row) => omit(row, 'actions'));
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700420 },
421 filteredLogsByDate() {
422 return this.getFilteredTableDataByDate(
423 this.allLogs,
424 this.filterStartDate,
425 this.filterEndDate
426 );
427 },
428 filteredLogs() {
429 return this.getFilteredTableData(
430 this.filteredLogsByDate,
431 this.activeFilters
432 );
Derick Montague602e98a2020-10-21 16:20:00 -0500433 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700434 },
435 created() {
436 this.startLoader();
437 this.$store
438 .dispatch('eventLog/getEventLogData')
439 .finally(() => this.endLoader());
440 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700441 methods: {
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500442 changelogStatus(row) {
443 this.$store
444 .dispatch('eventLog/updateEventLogStatus', {
445 uri: row.uri,
446 status: row.status,
447 })
448 .then((success) => {
449 this.successToast(success);
450 })
451 .catch(({ message }) => this.errorToast(message));
452 },
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500453 deleteAllLogs() {
454 this.$bvModal
455 .msgBoxConfirm(this.$t('pageEventLogs.modal.deleteAllMessage'), {
456 title: this.$t('pageEventLogs.modal.deleteAllTitle'),
457 okTitle: this.$t('global.action.delete'),
458 okVariant: 'danger',
459 cancelTitle: this.$t('global.action.cancel'),
460 })
461 .then((deleteConfirmed) => {
462 if (deleteConfirmed) {
463 this.$store
464 .dispatch('eventLog/deleteAllEventLogs', this.allLogs)
465 .then((message) => this.successToast(message))
466 .catch(({ message }) => this.errorToast(message));
467 }
468 });
469 },
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700470 deleteLogs(uris) {
Derick Montague602e98a2020-10-21 16:20:00 -0500471 this.$store
472 .dispatch('eventLog/deleteEventLogs', uris)
473 .then((messages) => {
474 messages.forEach(({ type, message }) => {
475 if (type === 'success') {
476 this.successToast(message);
477 } else if (type === 'error') {
478 this.errorToast(message);
479 }
480 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700481 });
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700482 },
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500483 exportAllLogs() {
484 {
485 return this.$store.getters['eventLog/allEvents'].map((eventLogs) => {
486 const allEventLogsString = JSON.stringify(eventLogs);
487 return allEventLogsString;
488 });
489 }
490 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700491 onFilterChange({ activeFilters }) {
492 this.activeFilters = activeFilters;
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700493 },
494 onSortCompare(a, b, key) {
495 if (key === 'severity') {
Yoshie Muranaka73e419a2020-06-18 13:08:19 -0700496 return this.sortStatus(a, b, key);
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700497 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700498 },
499 onTableRowAction(action, { uri }) {
500 if (action === 'delete') {
501 this.$bvModal
502 .msgBoxConfirm(this.$tc('pageEventLogs.modal.deleteMessage'), {
503 title: this.$tc('pageEventLogs.modal.deleteTitle'),
Derick Montague602e98a2020-10-21 16:20:00 -0500504 okTitle: this.$t('global.action.delete'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530505 cancelTitle: this.$t('global.action.cancel'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700506 })
Derick Montague602e98a2020-10-21 16:20:00 -0500507 .then((deleteConfirmed) => {
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700508 if (deleteConfirmed) this.deleteLogs([uri]);
509 });
510 }
511 },
512 onBatchAction(action) {
513 if (action === 'delete') {
Derick Montague602e98a2020-10-21 16:20:00 -0500514 const uris = this.selectedRows.map((row) => row.uri);
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700515 this.$bvModal
516 .msgBoxConfirm(
517 this.$tc(
518 'pageEventLogs.modal.deleteMessage',
519 this.selectedRows.length
520 ),
521 {
522 title: this.$tc(
523 'pageEventLogs.modal.deleteTitle',
524 this.selectedRows.length
525 ),
Derick Montague602e98a2020-10-21 16:20:00 -0500526 okTitle: this.$t('global.action.delete'),
Sukanya Pandey38357132020-12-22 13:40:59 +0530527 cancelTitle: this.$t('global.action.cancel'),
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700528 }
529 )
Derick Montague602e98a2020-10-21 16:20:00 -0500530 .then((deleteConfirmed) => {
Sukanya Pandey2f6d5522020-10-28 10:38:00 +0530531 if (deleteConfirmed) {
532 if (this.selectedRows.length === this.allLogs.length) {
533 this.$store
534 .dispatch(
535 'eventLog/deleteAllEventLogs',
536 this.selectedRows.length
537 )
538 .then((message) => this.successToast(message))
539 .catch(({ message }) => this.errorToast(message));
540 } else {
541 this.deleteLogs(uris);
542 }
543 }
Yoshie Muranakabe3af332020-05-11 08:23:04 -0700544 });
545 }
Yoshie Muranaka68bbba22020-05-18 09:49:37 -0700546 },
547 onChangeDateTimeFilter({ fromDate, toDate }) {
548 this.filterStartDate = fromDate;
549 this.filterEndDate = toDate;
Yoshie Muranaka193c22a2020-06-30 20:54:10 -0700550 },
Sukanya Pandey99010962020-07-27 21:44:47 +0530551 onFiltered(filteredItems) {
552 this.searchTotalFilteredRows = filteredItems.length;
553 },
SurenNeware96ebb0d2020-09-08 17:42:39 +0530554 // Create export file name based on date
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500555 exportFileNameByDate(value) {
SurenNeware96ebb0d2020-09-08 17:42:39 +0530556 let date = new Date();
557 date =
558 date.toISOString().slice(0, 10) +
559 '_' +
Derick Montague602e98a2020-10-21 16:20:00 -0500560 date.toString().split(':').join('-').split(' ')[4];
Dixsie Wolmers7e2ba542021-06-03 07:38:12 -0500561 let fileName;
562 if (value === 'export') {
563 fileName = 'event_log_';
564 } else {
565 fileName = 'all_event_logs_';
566 }
567 return fileName + date;
Derick Montague602e98a2020-10-21 16:20:00 -0500568 },
Dixsie Wolmers27d68af2021-05-02 18:20:27 -0500569 resolveLogs() {
570 this.$store
571 .dispatch('eventLog/resolveEventLogs', this.selectedRows)
572 .then((messages) => {
573 messages.forEach(({ type, message }) => {
574 if (type === 'success') {
575 this.successToast(message);
576 } else if (type === 'error') {
577 this.errorToast(message);
578 }
579 });
580 });
581 },
582 unresolveLogs() {
583 this.$store
584 .dispatch('eventLog/unresolveEventLogs', this.selectedRows)
585 .then((messages) => {
586 messages.forEach(({ type, message }) => {
587 if (type === 'success') {
588 this.successToast(message);
589 } else if (type === 'error') {
590 this.errorToast(message);
591 }
592 });
593 });
594 },
Derick Montague602e98a2020-10-21 16:20:00 -0500595 },
Yoshie Muranaka6f102342020-05-05 09:45:39 -0700596};
597</script>