blob: a6dc10f5069c71773dd0194a539b4307ac0fac7f [file] [log] [blame]
Yoshie Muranaka22d4d522020-12-03 10:58:35 -08001<template>
2 <b-container fluid="xl">
3 <page-title />
4 <b-row>
5 <b-col sm="6" lg="5" xl="4">
Yoshie Muranakaf415a082020-12-07 13:04:11 -08006 <page-section :section-title="$t('pageDumps.initiateDump')">
Yoshie Muranaka22d4d522020-12-03 10:58:35 -08007 <dumps-form />
8 </page-section>
9 </b-col>
10 </b-row>
11 <b-row>
12 <b-col xl="10">
Yoshie Muranakaf415a082020-12-07 13:04:11 -080013 <page-section :section-title="$t('pageDumps.dumpsAvailableOnBmc')">
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080014 <b-row class="align-items-start">
15 <b-col sm="8" xl="6" class="d-sm-flex align-items-end">
16 <search
17 :placeholder="$t('pageDumps.table.searchDumps')"
18 @change-search="onChangeSearchInput"
19 @clear-search="onClearSearchInput"
20 />
21 <div class="ml-sm-4">
22 <table-cell-count
23 :filtered-items-count="filteredItemCount"
24 :total-number-of-cells="tableItems.length"
25 ></table-cell-count>
26 </div>
27 </b-col>
28 <b-col sm="8" md="7" xl="6">
29 <table-date-filter @change="onChangeDateTimeFilter" />
30 </b-col>
31 </b-row>
32 <table-toolbar
33 :selected-items-count="selectedRows.length"
34 :actions="batchActions"
35 @clear-selected="clearSelectedRows($refs.table)"
36 @batch-action="onTableBatchAction"
37 />
38 <b-table
39 ref="table"
40 show-empty
41 hover
42 sort-icon-left
43 no-sort-reset
Yoshie Muranakaf415a082020-12-07 13:04:11 -080044 sort-desc
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080045 selectable
46 no-select-on-click
47 responsive="md"
48 sort-by="dateTime"
49 :fields="fields"
50 :items="filteredTableItems"
51 :empty-text="$t('global.table.emptyMessage')"
52 :empty-filtered-text="$t('global.table.emptySearchMessage')"
53 :filter="searchFilter"
54 @filtered="onChangeSearchFilter"
55 @row-selected="onRowSelected($event, filteredTableItems.length)"
56 >
57 <!-- Checkbox column -->
58 <template #head(checkbox)>
59 <b-form-checkbox
60 v-model="tableHeaderCheckboxModel"
61 :indeterminate="tableHeaderCheckboxIndeterminate"
62 @change="onChangeHeaderCheckbox($refs.table)"
63 >
64 <span class="sr-only">{{ $t('global.table.selectAll') }}</span>
65 </b-form-checkbox>
66 </template>
67 <template #cell(checkbox)="row">
68 <b-form-checkbox
69 v-model="row.rowSelected"
70 @change="toggleSelectRow($refs.table, row.index)"
71 >
72 <span class="sr-only">{{ $t('global.table.selectItem') }}</span>
73 </b-form-checkbox>
74 </template>
75
76 <!-- Date and Time column -->
77 <template #cell(dateTime)="{ value }">
78 <p class="mb-0">{{ value | formatDate }}</p>
79 <p class="mb-0">{{ value | formatTime }}</p>
80 </template>
81
82 <!-- Size column -->
83 <template #cell(size)="{ value }">
84 {{ convertBytesToMegabytes(value) }} MB
85 </template>
86
87 <!-- Actions column -->
88 <template #cell(actions)="row">
89 <table-row-action
90 v-for="(action, index) in row.item.actions"
91 :key="index"
92 :value="action.value"
93 :title="action.title"
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080094 :download-location="row.item.data"
Sneha Patel3f9cfa22021-06-04 16:06:08 -050095 :export-name="exportFileName(row)"
Yoshie Muranaka22d4d522020-12-03 10:58:35 -080096 @click-table-action="onTableRowAction($event, row.item)"
97 >
98 <template #icon>
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -080099 <icon-download v-if="action.value === 'download'" />
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800100 <icon-delete v-if="action.value === 'delete'" />
101 </template>
102 </table-row-action>
103 </template>
104 </b-table>
105 </page-section>
106 </b-col>
107 </b-row>
Sukanya Pandeyf7000cd2021-08-26 18:34:49 +0530108 <!-- Table pagination -->
109 <b-row>
110 <b-col sm="6" xl="5">
111 <b-form-group
112 class="table-pagination-select"
113 :label="$t('global.table.itemsPerPage')"
114 label-for="pagination-items-per-page"
115 >
116 <b-form-select
117 id="pagination-items-per-page"
118 v-model="perPage"
119 :options="itemsPerPageOptions"
120 />
121 </b-form-group>
122 </b-col>
123 <b-col sm="6" xl="5">
124 <b-pagination
125 v-model="currentPage"
126 first-number
127 last-number
128 :per-page="perPage"
129 :total-rows="getTotalRowCount(filteredItemCount)"
130 aria-controls="table-dump-entries"
131 />
132 </b-col>
133 </b-row>
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800134 </b-container>
135</template>
136
137<script>
138import IconDelete from '@carbon/icons-vue/es/trash-can/20';
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -0800139import IconDownload from '@carbon/icons-vue/es/download/20';
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800140
141import DumpsForm from './DumpsForm';
142import PageSection from '@/components/Global/PageSection';
143import PageTitle from '@/components/Global/PageTitle';
144import Search from '@/components/Global/Search';
145import TableCellCount from '@/components/Global/TableCellCount';
146import TableDateFilter from '@/components/Global/TableDateFilter';
147import TableRowAction from '@/components/Global/TableRowAction';
148import TableToolbar from '@/components/Global/TableToolbar';
149
150import BVTableSelectableMixin, {
151 selectedRows,
152 tableHeaderCheckboxModel,
153 tableHeaderCheckboxIndeterminate,
154} from '@/components/Mixins/BVTableSelectableMixin';
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800155import BVToastMixin from '@/components/Mixins/BVToastMixin';
Sukanya Pandeyf7000cd2021-08-26 18:34:49 +0530156import BVPaginationMixin, {
157 currentPage,
158 perPage,
159 itemsPerPageOptions,
160} from '@/components/Mixins/BVPaginationMixin';
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800161import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
162import SearchFilterMixin, {
163 searchFilter,
164} from '@/components/Mixins/SearchFilterMixin';
165import TableFilterMixin from '@/components/Mixins/TableFilterMixin';
166
167export default {
168 components: {
169 DumpsForm,
170 IconDelete,
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -0800171 IconDownload,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800172 PageSection,
173 PageTitle,
174 Search,
175 TableCellCount,
176 TableDateFilter,
177 TableRowAction,
178 TableToolbar,
179 },
180 mixins: [
181 BVTableSelectableMixin,
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800182 BVToastMixin,
Sukanya Pandeyf7000cd2021-08-26 18:34:49 +0530183 BVPaginationMixin,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800184 LoadingBarMixin,
185 SearchFilterMixin,
186 TableFilterMixin,
187 ],
188 beforeRouteLeave(to, from, next) {
189 // Hide loader if the user navigates to another page
190 // before request is fulfilled.
191 this.hideLoader();
192 next();
193 },
194 data() {
195 return {
196 fields: [
197 {
198 key: 'checkbox',
199 sortable: false,
200 },
201 {
202 key: 'dateTime',
203 label: this.$t('pageDumps.table.dateAndTime'),
204 sortable: true,
205 },
206 {
207 key: 'dumpType',
208 label: this.$t('pageDumps.table.dumpType'),
209 sortable: true,
210 },
211 {
212 key: 'id',
213 label: this.$t('pageDumps.table.id'),
214 sortable: true,
215 },
216 {
217 key: 'size',
218 label: this.$t('pageDumps.table.size'),
219 sortable: true,
220 },
221 {
222 key: 'actions',
223 sortable: false,
224 label: '',
225 tdClass: 'text-right text-nowrap',
226 },
227 ],
228 batchActions: [
229 {
230 value: 'delete',
231 label: this.$t('global.action.delete'),
232 },
233 ],
Sukanya Pandeyf7000cd2021-08-26 18:34:49 +0530234 currentPage: currentPage,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800235 filterEndDate: null,
236 filterStartDate: null,
Sukanya Pandeyf7000cd2021-08-26 18:34:49 +0530237 itemsPerPageOptions: itemsPerPageOptions,
238 perPage: perPage,
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800239 searchFilter,
240 searchFilteredItemsCount: 0,
241 selectedRows,
242 tableHeaderCheckboxIndeterminate,
243 tableHeaderCheckboxModel,
244 };
245 },
246 computed: {
247 dumps() {
Kennethc2c53aa2021-11-30 17:04:58 -0600248 return this.$store.getters['dumps/allDumps'];
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800249 },
250 tableItems() {
251 return this.dumps.map((item) => {
252 return {
253 ...item,
254 actions: [
255 {
Yoshie Muranakaa87f3e72021-01-04 14:08:04 -0800256 value: 'download',
257 title: this.$t('global.action.download'),
258 },
259 {
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800260 value: 'delete',
261 title: this.$t('global.action.delete'),
262 },
263 ],
264 };
265 });
266 },
267 filteredTableItems() {
268 return this.getFilteredTableDataByDate(
269 this.tableItems,
270 this.filterStartDate,
271 this.filterEndDate,
272 'dateTime'
273 );
274 },
275 filteredItemCount() {
276 return this.searchFilter
277 ? this.searchFilteredItemsCount
278 : this.filteredTableItems.length;
279 },
280 },
281 created() {
282 this.startLoader();
Kennethc2c53aa2021-11-30 17:04:58 -0600283 this.$store
284 .dispatch('dumps/getBmcDumpEntries')
285 .finally(() => this.endLoader());
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800286 },
287 methods: {
288 convertBytesToMegabytes(bytes) {
289 return parseFloat((bytes / 1000000).toFixed(3));
290 },
291 onChangeSearchFilter(items) {
292 this.searchFilteredItemsCount = items.length;
293 },
294 onChangeDateTimeFilter({ fromDate, toDate }) {
295 this.filterStartDate = fromDate;
296 this.filterEndDate = toDate;
297 },
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800298 onTableRowAction(action, dump) {
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800299 if (action === 'delete') {
300 this.$bvModal
301 .msgBoxConfirm(this.$tc('pageDumps.modal.deleteDumpConfirmation'), {
302 title: this.$tc('pageDumps.modal.deleteDump'),
303 okTitle: this.$tc('pageDumps.modal.deleteDump'),
304 cancelTitle: this.$t('global.action.cancel'),
305 })
306 .then((deleteConfrimed) => {
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800307 if (deleteConfrimed) {
308 this.$store
309 .dispatch('dumps/deleteDumps', [dump])
310 .then((messages) => {
311 messages.forEach(({ type, message }) => {
312 if (type === 'success') {
313 this.successToast(message);
314 } else if (type === 'error') {
315 this.errorToast(message);
316 }
317 });
318 });
319 }
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800320 });
321 }
322 },
323 onTableBatchAction(action) {
324 if (action === 'delete') {
325 this.$bvModal
326 .msgBoxConfirm(
327 this.$tc(
328 'pageDumps.modal.deleteDumpConfirmation',
329 this.selectedRows.length
330 ),
331 {
332 title: this.$tc(
333 'pageDumps.modal.deleteDump',
334 this.selectedRows.length
335 ),
336 okTitle: this.$tc(
337 'pageDumps.modal.deleteDump',
338 this.selectedRows.length
339 ),
340 cancelTitle: this.$t('global.action.cancel'),
341 }
342 )
343 .then((deleteConfrimed) => {
Yoshie Muranakaf415a082020-12-07 13:04:11 -0800344 if (deleteConfrimed) {
345 if (this.selectedRows.length === this.dumps.length) {
346 this.$store
347 .dispatch('dumps/deleteAllDumps')
348 .then((success) => this.successToast(success))
349 .catch(({ message }) => this.errorToast(message));
350 } else {
351 this.$store
352 .dispatch('dumps/deleteDumps', this.selectedRows)
353 .then((messages) => {
354 messages.forEach(({ type, message }) => {
355 if (type === 'success') {
356 this.successToast(message);
357 } else if (type === 'error') {
358 this.errorToast(message);
359 }
360 });
361 });
362 }
363 }
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800364 });
365 }
366 },
Sneha Patel3f9cfa22021-06-04 16:06:08 -0500367 exportFileName(row) {
Gunnar Millscc79a532021-11-30 19:33:42 -0600368 let filename = row.item.dumpType + '_' + row.item.id + '.tar.xz';
Sneha Patel3f9cfa22021-06-04 16:06:08 -0500369 filename = filename.replace(RegExp(' ', 'g'), '_');
370 return filename;
371 },
Yoshie Muranaka22d4d522020-12-03 10:58:35 -0800372 },
373};
374</script>