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" |
| 94 | @click-table-action="onTableRowAction($event, row.item)" |
| 95 | > |
| 96 | <template #icon> |
| 97 | <icon-delete v-if="action.value === 'delete'" /> |
| 98 | </template> |
| 99 | </table-row-action> |
| 100 | </template> |
| 101 | </b-table> |
| 102 | </page-section> |
| 103 | </b-col> |
| 104 | </b-row> |
| 105 | </b-container> |
| 106 | </template> |
| 107 | |
| 108 | <script> |
| 109 | import IconDelete from '@carbon/icons-vue/es/trash-can/20'; |
| 110 | |
| 111 | import DumpsForm from './DumpsForm'; |
| 112 | import PageSection from '@/components/Global/PageSection'; |
| 113 | import PageTitle from '@/components/Global/PageTitle'; |
| 114 | import Search from '@/components/Global/Search'; |
| 115 | import TableCellCount from '@/components/Global/TableCellCount'; |
| 116 | import TableDateFilter from '@/components/Global/TableDateFilter'; |
| 117 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 118 | import TableToolbar from '@/components/Global/TableToolbar'; |
| 119 | |
| 120 | import BVTableSelectableMixin, { |
| 121 | selectedRows, |
| 122 | tableHeaderCheckboxModel, |
| 123 | tableHeaderCheckboxIndeterminate, |
| 124 | } from '@/components/Mixins/BVTableSelectableMixin'; |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 125 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 126 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| 127 | import SearchFilterMixin, { |
| 128 | searchFilter, |
| 129 | } from '@/components/Mixins/SearchFilterMixin'; |
| 130 | import TableFilterMixin from '@/components/Mixins/TableFilterMixin'; |
| 131 | |
| 132 | export default { |
| 133 | components: { |
| 134 | DumpsForm, |
| 135 | IconDelete, |
| 136 | PageSection, |
| 137 | PageTitle, |
| 138 | Search, |
| 139 | TableCellCount, |
| 140 | TableDateFilter, |
| 141 | TableRowAction, |
| 142 | TableToolbar, |
| 143 | }, |
| 144 | mixins: [ |
| 145 | BVTableSelectableMixin, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 146 | BVToastMixin, |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 147 | LoadingBarMixin, |
| 148 | SearchFilterMixin, |
| 149 | TableFilterMixin, |
| 150 | ], |
| 151 | beforeRouteLeave(to, from, next) { |
| 152 | // Hide loader if the user navigates to another page |
| 153 | // before request is fulfilled. |
| 154 | this.hideLoader(); |
| 155 | next(); |
| 156 | }, |
| 157 | data() { |
| 158 | return { |
| 159 | fields: [ |
| 160 | { |
| 161 | key: 'checkbox', |
| 162 | sortable: false, |
| 163 | }, |
| 164 | { |
| 165 | key: 'dateTime', |
| 166 | label: this.$t('pageDumps.table.dateAndTime'), |
| 167 | sortable: true, |
| 168 | }, |
| 169 | { |
| 170 | key: 'dumpType', |
| 171 | label: this.$t('pageDumps.table.dumpType'), |
| 172 | sortable: true, |
| 173 | }, |
| 174 | { |
| 175 | key: 'id', |
| 176 | label: this.$t('pageDumps.table.id'), |
| 177 | sortable: true, |
| 178 | }, |
| 179 | { |
| 180 | key: 'size', |
| 181 | label: this.$t('pageDumps.table.size'), |
| 182 | sortable: true, |
| 183 | }, |
| 184 | { |
| 185 | key: 'actions', |
| 186 | sortable: false, |
| 187 | label: '', |
| 188 | tdClass: 'text-right text-nowrap', |
| 189 | }, |
| 190 | ], |
| 191 | batchActions: [ |
| 192 | { |
| 193 | value: 'delete', |
| 194 | label: this.$t('global.action.delete'), |
| 195 | }, |
| 196 | ], |
| 197 | filterEndDate: null, |
| 198 | filterStartDate: null, |
| 199 | searchFilter, |
| 200 | searchFilteredItemsCount: 0, |
| 201 | selectedRows, |
| 202 | tableHeaderCheckboxIndeterminate, |
| 203 | tableHeaderCheckboxModel, |
| 204 | }; |
| 205 | }, |
| 206 | computed: { |
| 207 | dumps() { |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 208 | return this.$store.getters['dumps/bmcDumps']; |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 209 | }, |
| 210 | tableItems() { |
| 211 | return this.dumps.map((item) => { |
| 212 | return { |
| 213 | ...item, |
| 214 | actions: [ |
| 215 | { |
| 216 | value: 'delete', |
| 217 | title: this.$t('global.action.delete'), |
| 218 | }, |
| 219 | ], |
| 220 | }; |
| 221 | }); |
| 222 | }, |
| 223 | filteredTableItems() { |
| 224 | return this.getFilteredTableDataByDate( |
| 225 | this.tableItems, |
| 226 | this.filterStartDate, |
| 227 | this.filterEndDate, |
| 228 | 'dateTime' |
| 229 | ); |
| 230 | }, |
| 231 | filteredItemCount() { |
| 232 | return this.searchFilter |
| 233 | ? this.searchFilteredItemsCount |
| 234 | : this.filteredTableItems.length; |
| 235 | }, |
| 236 | }, |
| 237 | created() { |
| 238 | this.startLoader(); |
| 239 | this.$store.dispatch('dumps/getBmcDumps').finally(() => this.endLoader()); |
| 240 | }, |
| 241 | methods: { |
| 242 | convertBytesToMegabytes(bytes) { |
| 243 | return parseFloat((bytes / 1000000).toFixed(3)); |
| 244 | }, |
| 245 | onChangeSearchFilter(items) { |
| 246 | this.searchFilteredItemsCount = items.length; |
| 247 | }, |
| 248 | onChangeDateTimeFilter({ fromDate, toDate }) { |
| 249 | this.filterStartDate = fromDate; |
| 250 | this.filterEndDate = toDate; |
| 251 | }, |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 252 | onTableRowAction(action, dump) { |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 253 | if (action === 'delete') { |
| 254 | this.$bvModal |
| 255 | .msgBoxConfirm(this.$tc('pageDumps.modal.deleteDumpConfirmation'), { |
| 256 | title: this.$tc('pageDumps.modal.deleteDump'), |
| 257 | okTitle: this.$tc('pageDumps.modal.deleteDump'), |
| 258 | cancelTitle: this.$t('global.action.cancel'), |
| 259 | }) |
| 260 | .then((deleteConfrimed) => { |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 261 | if (deleteConfrimed) { |
| 262 | this.$store |
| 263 | .dispatch('dumps/deleteDumps', [dump]) |
| 264 | .then((messages) => { |
| 265 | messages.forEach(({ type, message }) => { |
| 266 | if (type === 'success') { |
| 267 | this.successToast(message); |
| 268 | } else if (type === 'error') { |
| 269 | this.errorToast(message); |
| 270 | } |
| 271 | }); |
| 272 | }); |
| 273 | } |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 274 | }); |
| 275 | } |
| 276 | }, |
| 277 | onTableBatchAction(action) { |
| 278 | if (action === 'delete') { |
| 279 | this.$bvModal |
| 280 | .msgBoxConfirm( |
| 281 | this.$tc( |
| 282 | 'pageDumps.modal.deleteDumpConfirmation', |
| 283 | this.selectedRows.length |
| 284 | ), |
| 285 | { |
| 286 | title: this.$tc( |
| 287 | 'pageDumps.modal.deleteDump', |
| 288 | this.selectedRows.length |
| 289 | ), |
| 290 | okTitle: this.$tc( |
| 291 | 'pageDumps.modal.deleteDump', |
| 292 | this.selectedRows.length |
| 293 | ), |
| 294 | cancelTitle: this.$t('global.action.cancel'), |
| 295 | } |
| 296 | ) |
| 297 | .then((deleteConfrimed) => { |
Yoshie Muranaka | f415a08 | 2020-12-07 13:04:11 -0800 | [diff] [blame] | 298 | if (deleteConfrimed) { |
| 299 | if (this.selectedRows.length === this.dumps.length) { |
| 300 | this.$store |
| 301 | .dispatch('dumps/deleteAllDumps') |
| 302 | .then((success) => this.successToast(success)) |
| 303 | .catch(({ message }) => this.errorToast(message)); |
| 304 | } else { |
| 305 | this.$store |
| 306 | .dispatch('dumps/deleteDumps', this.selectedRows) |
| 307 | .then((messages) => { |
| 308 | messages.forEach(({ type, message }) => { |
| 309 | if (type === 'success') { |
| 310 | this.successToast(message); |
| 311 | } else if (type === 'error') { |
| 312 | this.errorToast(message); |
| 313 | } |
| 314 | }); |
| 315 | }); |
| 316 | } |
| 317 | } |
Yoshie Muranaka | 22d4d52 | 2020-12-03 10:58:35 -0800 | [diff] [blame] | 318 | }); |
| 319 | } |
| 320 | }, |
| 321 | }, |
| 322 | }; |
| 323 | </script> |