Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
| 3 | <page-title /> |
| 4 | <b-row> |
| 5 | <b-col sm="6" lg="5" xl="4"> |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 6 | <page-section :section-title="$t('pageDumps.initiateDump')"> |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 7 | <dumps-form /> |
| 8 | </page-section> |
| 9 | </b-col> |
| 10 | </b-row> |
| 11 | <b-row> |
| 12 | <b-col xl="10"> |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 13 | <page-section :section-title="$t('pageDumps.dumpsAvailableOnBmc')"> |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 14 | <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 Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 44 | sort-desc |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 45 | 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 Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 94 | :download-location="row.item.data" |
Sneha Patel | 3f9cfa2 | 2021-06-04 16:06:08 -0500 | [diff] [blame] | 95 | :export-name="exportFileName(row)" |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 96 | @click-table-action="onTableRowAction($event, row.item)" |
| 97 | > |
| 98 | <template #icon> |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 99 | <icon-download v-if="action.value === 'download'" /> |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 100 | <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 Pandey | f7000cd | 2021-08-26 18:34:49 +0530 | [diff] [blame] | 108 | <!-- 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 Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 134 | </b-container> |
| 135 | </template> |
| 136 | |
| 137 | <script> |
| 138 | import IconDelete from '@carbon/icons-vue/es/trash-can/20'; |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 139 | import IconDownload from '@carbon/icons-vue/es/download/20'; |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 140 | |
| 141 | import DumpsForm from './DumpsForm'; |
| 142 | import PageSection from '@/components/Global/PageSection'; |
| 143 | import PageTitle from '@/components/Global/PageTitle'; |
| 144 | import Search from '@/components/Global/Search'; |
| 145 | import TableCellCount from '@/components/Global/TableCellCount'; |
| 146 | import TableDateFilter from '@/components/Global/TableDateFilter'; |
| 147 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 148 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 149 | |
| 150 | import BVTableSelectableMixin, { |
| 151 | selectedRows, |
| 152 | tableHeaderCheckboxModel, |
| 153 | tableHeaderCheckboxIndeterminate, |
| 154 | } from '@/components/Mixins/BVTableSelectableMixin'; |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 155 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Sukanya Pandey | f7000cd | 2021-08-26 18:34:49 +0530 | [diff] [blame] | 156 | import BVPaginationMixin, { |
| 157 | currentPage, |
| 158 | perPage, |
| 159 | itemsPerPageOptions, |
| 160 | } from '@/components/Mixins/BVPaginationMixin'; |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 161 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| 162 | import SearchFilterMixin, { |
| 163 | searchFilter, |
| 164 | } from '@/components/Mixins/SearchFilterMixin'; |
| 165 | import TableFilterMixin from '@/components/Mixins/TableFilterMixin'; |
| 166 | |
| 167 | export default { |
| 168 | components: { |
| 169 | DumpsForm, |
| 170 | IconDelete, |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 171 | IconDownload, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 172 | PageSection, |
| 173 | PageTitle, |
| 174 | Search, |
| 175 | TableCellCount, |
| 176 | TableDateFilter, |
| 177 | TableRowAction, |
| 178 | TableToolbar, |
| 179 | }, |
| 180 | mixins: [ |
| 181 | BVTableSelectableMixin, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 182 | BVToastMixin, |
Sukanya Pandey | f7000cd | 2021-08-26 18:34:49 +0530 | [diff] [blame] | 183 | BVPaginationMixin, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 184 | 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 Pandey | f7000cd | 2021-08-26 18:34:49 +0530 | [diff] [blame] | 234 | currentPage: currentPage, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 235 | filterEndDate: null, |
| 236 | filterStartDate: null, |
Sukanya Pandey | f7000cd | 2021-08-26 18:34:49 +0530 | [diff] [blame] | 237 | itemsPerPageOptions: itemsPerPageOptions, |
| 238 | perPage: perPage, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 239 | searchFilter, |
| 240 | searchFilteredItemsCount: 0, |
| 241 | selectedRows, |
| 242 | tableHeaderCheckboxIndeterminate, |
| 243 | tableHeaderCheckboxModel, |
| 244 | }; |
| 245 | }, |
| 246 | computed: { |
| 247 | dumps() { |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 248 | return this.$store.getters['dumps/bmcDumps']; |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 249 | }, |
| 250 | tableItems() { |
| 251 | return this.dumps.map((item) => { |
| 252 | return { |
| 253 | ...item, |
| 254 | actions: [ |
| 255 | { |
Yoshie Muranaka | a87f3e7 | 2021-01-04 14:08:04 -0800 | [diff] [blame] | 256 | value: 'download', |
| 257 | title: this.$t('global.action.download'), |
| 258 | }, |
| 259 | { |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 260 | 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(); |
| 283 | this.$store.dispatch('dumps/getBmcDumps').finally(() => this.endLoader()); |
| 284 | }, |
| 285 | methods: { |
| 286 | convertBytesToMegabytes(bytes) { |
| 287 | return parseFloat((bytes / 1000000).toFixed(3)); |
| 288 | }, |
| 289 | onChangeSearchFilter(items) { |
| 290 | this.searchFilteredItemsCount = items.length; |
| 291 | }, |
| 292 | onChangeDateTimeFilter({ fromDate, toDate }) { |
| 293 | this.filterStartDate = fromDate; |
| 294 | this.filterEndDate = toDate; |
| 295 | }, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 296 | onTableRowAction(action, dump) { |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 297 | if (action === 'delete') { |
| 298 | this.$bvModal |
| 299 | .msgBoxConfirm(this.$tc('pageDumps.modal.deleteDumpConfirmation'), { |
| 300 | title: this.$tc('pageDumps.modal.deleteDump'), |
| 301 | okTitle: this.$tc('pageDumps.modal.deleteDump'), |
| 302 | cancelTitle: this.$t('global.action.cancel'), |
| 303 | }) |
| 304 | .then((deleteConfrimed) => { |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 305 | if (deleteConfrimed) { |
| 306 | this.$store |
| 307 | .dispatch('dumps/deleteDumps', [dump]) |
| 308 | .then((messages) => { |
| 309 | messages.forEach(({ type, message }) => { |
| 310 | if (type === 'success') { |
| 311 | this.successToast(message); |
| 312 | } else if (type === 'error') { |
| 313 | this.errorToast(message); |
| 314 | } |
| 315 | }); |
| 316 | }); |
| 317 | } |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 318 | }); |
| 319 | } |
| 320 | }, |
| 321 | onTableBatchAction(action) { |
| 322 | if (action === 'delete') { |
| 323 | this.$bvModal |
| 324 | .msgBoxConfirm( |
| 325 | this.$tc( |
| 326 | 'pageDumps.modal.deleteDumpConfirmation', |
| 327 | this.selectedRows.length |
| 328 | ), |
| 329 | { |
| 330 | title: this.$tc( |
| 331 | 'pageDumps.modal.deleteDump', |
| 332 | this.selectedRows.length |
| 333 | ), |
| 334 | okTitle: this.$tc( |
| 335 | 'pageDumps.modal.deleteDump', |
| 336 | this.selectedRows.length |
| 337 | ), |
| 338 | cancelTitle: this.$t('global.action.cancel'), |
| 339 | } |
| 340 | ) |
| 341 | .then((deleteConfrimed) => { |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 342 | if (deleteConfrimed) { |
| 343 | if (this.selectedRows.length === this.dumps.length) { |
| 344 | this.$store |
| 345 | .dispatch('dumps/deleteAllDumps') |
| 346 | .then((success) => this.successToast(success)) |
| 347 | .catch(({ message }) => this.errorToast(message)); |
| 348 | } else { |
| 349 | this.$store |
| 350 | .dispatch('dumps/deleteDumps', this.selectedRows) |
| 351 | .then((messages) => { |
| 352 | messages.forEach(({ type, message }) => { |
| 353 | if (type === 'success') { |
| 354 | this.successToast(message); |
| 355 | } else if (type === 'error') { |
| 356 | this.errorToast(message); |
| 357 | } |
| 358 | }); |
| 359 | }); |
| 360 | } |
| 361 | } |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 362 | }); |
| 363 | } |
| 364 | }, |
Sneha Patel | 3f9cfa2 | 2021-06-04 16:06:08 -0500 | [diff] [blame] | 365 | exportFileName(row) { |
Gunnar Mills | cc79a53 | 2021-11-30 19:33:42 -0600 | [diff] [blame] | 366 | let filename = row.item.dumpType + '_' + row.item.id + '.tar.xz'; |
Sneha Patel | 3f9cfa2 | 2021-06-04 16:06:08 -0500 | [diff] [blame] | 367 | filename = filename.replace(RegExp(' ', 'g'), '_'); |
| 368 | return filename; |
| 369 | }, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 370 | }, |
| 371 | }; |
| 372 | </script> |