17affc529SSandeepa Singh<template> 27affc529SSandeepa Singh <b-container fluid="xl"> 37affc529SSandeepa Singh <page-title /> 47affc529SSandeepa Singh <b-row class="align-items-start"> 57affc529SSandeepa Singh <b-col sm="8" xl="6" class="d-sm-flex align-items-end mb-4"> 67affc529SSandeepa Singh <search 77affc529SSandeepa Singh :placeholder="$t('pagePostCodeLogs.table.searchLogs')" 87affc529SSandeepa Singh @change-search="onChangeSearchInput" 97affc529SSandeepa Singh @clear-search="onClearSearchInput" 107affc529SSandeepa Singh /> 117affc529SSandeepa Singh <div class="ml-sm-4"> 127affc529SSandeepa Singh <table-cell-count 137affc529SSandeepa Singh :filtered-items-count="filteredRows" 147affc529SSandeepa Singh :total-number-of-cells="allLogs.length" 157affc529SSandeepa Singh ></table-cell-count> 167affc529SSandeepa Singh </div> 177affc529SSandeepa Singh </b-col> 187affc529SSandeepa Singh <b-col sm="8" md="7" xl="6"> 197affc529SSandeepa Singh <table-date-filter @change="onChangeDateTimeFilter" /> 207affc529SSandeepa Singh </b-col> 217affc529SSandeepa Singh </b-row> 227affc529SSandeepa Singh <b-row> 237affc529SSandeepa Singh <b-col xl="12" class="text-right"> 247affc529SSandeepa Singh <b-button 25d8c71c00SKonstantin Aladyshev variant="link" 26d8c71c00SKonstantin Aladyshev :disabled="allLogs.length === 0" 27d8c71c00SKonstantin Aladyshev @click="deleteAllLogs" 28d8c71c00SKonstantin Aladyshev > 29d8c71c00SKonstantin Aladyshev <icon-delete /> {{ $t('global.action.deleteAll') }} 30d8c71c00SKonstantin Aladyshev </b-button> 31d8c71c00SKonstantin Aladyshev <b-button 327affc529SSandeepa Singh variant="primary" 337affc529SSandeepa Singh :disabled="allLogs.length === 0" 347affc529SSandeepa Singh :download="exportFileNameByDate()" 357affc529SSandeepa Singh :href="href" 367affc529SSandeepa Singh > 377affc529SSandeepa Singh <icon-export /> {{ $t('pagePostCodeLogs.button.exportAll') }} 387affc529SSandeepa Singh </b-button> 397affc529SSandeepa Singh </b-col> 407affc529SSandeepa Singh </b-row> 417affc529SSandeepa Singh <b-row> 427affc529SSandeepa Singh <b-col> 437affc529SSandeepa Singh <table-toolbar 447affc529SSandeepa Singh ref="toolbar" 457affc529SSandeepa Singh :selected-items-count="selectedRows.length" 467affc529SSandeepa Singh @clear-selected="clearSelectedRows($refs.table)" 477affc529SSandeepa Singh > 48b8182882SSandeepa Singh <template #toolbar-buttons> 497affc529SSandeepa Singh <table-toolbar-export 507affc529SSandeepa Singh :data="batchExportData" 51b8182882SSandeepa Singh :file-name="exportFileNameByDate()" 527affc529SSandeepa Singh /> 537affc529SSandeepa Singh </template> 547affc529SSandeepa Singh </table-toolbar> 557affc529SSandeepa Singh <b-table 567affc529SSandeepa Singh id="table-post-code-logs" 577affc529SSandeepa Singh ref="table" 587affc529SSandeepa Singh responsive="md" 597affc529SSandeepa Singh selectable 607affc529SSandeepa Singh no-select-on-click 617affc529SSandeepa Singh sort-icon-left 627affc529SSandeepa Singh hover 637affc529SSandeepa Singh no-sort-reset 647affc529SSandeepa Singh sort-desc 657affc529SSandeepa Singh show-empty 667affc529SSandeepa Singh sort-by="id" 677affc529SSandeepa Singh :fields="fields" 687affc529SSandeepa Singh :items="filteredLogs" 697affc529SSandeepa Singh :empty-text="$t('global.table.emptyMessage')" 707affc529SSandeepa Singh :empty-filtered-text="$t('global.table.emptySearchMessage')" 717affc529SSandeepa Singh :per-page="perPage" 727affc529SSandeepa Singh :current-page="currentPage" 737affc529SSandeepa Singh :filter="searchFilter" 7441057853SKenneth Fullbright :busy="isBusy" 757affc529SSandeepa Singh @filtered="onFiltered" 767affc529SSandeepa Singh @row-selected="onRowSelected($event, filteredLogs.length)" 777affc529SSandeepa Singh > 787affc529SSandeepa Singh <!-- Checkbox column --> 797affc529SSandeepa Singh <template #head(checkbox)> 807affc529SSandeepa Singh <b-form-checkbox 817affc529SSandeepa Singh v-model="tableHeaderCheckboxModel" 827affc529SSandeepa Singh data-test-id="postCode-checkbox-selectAll" 837affc529SSandeepa Singh :indeterminate="tableHeaderCheckboxIndeterminate" 847affc529SSandeepa Singh @change="onChangeHeaderCheckbox($refs.table)" 857affc529SSandeepa Singh > 867affc529SSandeepa Singh <span class="sr-only">{{ $t('global.table.selectAll') }}</span> 877affc529SSandeepa Singh </b-form-checkbox> 887affc529SSandeepa Singh </template> 897affc529SSandeepa Singh <template #cell(checkbox)="row"> 907affc529SSandeepa Singh <b-form-checkbox 917affc529SSandeepa Singh v-model="row.rowSelected" 927affc529SSandeepa Singh :data-test-id="`postCode-checkbox-selectRow-${row.index}`" 937affc529SSandeepa Singh @change="toggleSelectRow($refs.table, row.index)" 947affc529SSandeepa Singh > 957affc529SSandeepa Singh <span class="sr-only">{{ $t('global.table.selectItem') }}</span> 967affc529SSandeepa Singh </b-form-checkbox> 977affc529SSandeepa Singh </template> 987affc529SSandeepa Singh <!-- Date column --> 997affc529SSandeepa Singh <template #cell(date)="{ value }"> 100*de23ea23SSurya V <p class="mb-0">{{ $filters.formatDate(value) }}</p> 101*de23ea23SSurya V <p class="mb-0">{{ $filters.formatTime(value) }}</p> 1027affc529SSandeepa Singh </template> 1037affc529SSandeepa Singh 1047affc529SSandeepa Singh <!-- Actions column --> 1057affc529SSandeepa Singh <template #cell(actions)="row"> 1067affc529SSandeepa Singh <table-row-action 1077affc529SSandeepa Singh v-for="(action, index) in row.item.actions" 1087affc529SSandeepa Singh :key="index" 1097affc529SSandeepa Singh :value="action.value" 1107affc529SSandeepa Singh :title="action.title" 1117affc529SSandeepa Singh :row-data="row.item" 1127affc529SSandeepa Singh :btn-icon-only="true" 1137affc529SSandeepa Singh :export-name="exportFileNameByDate(action.value)" 1147affc529SSandeepa Singh :download-location="row.item.uri" 1157affc529SSandeepa Singh :download-in-new-tab="true" 116450bdb0aSSandeepa Singh :show-button="false" 1177affc529SSandeepa Singh > 1187affc529SSandeepa Singh <template #icon> 1197affc529SSandeepa Singh <icon-export v-if="action.value === 'export'" /> 1207affc529SSandeepa Singh <icon-download v-if="action.value === 'download'" /> 1217affc529SSandeepa Singh </template> 1227affc529SSandeepa Singh </table-row-action> 1237affc529SSandeepa Singh </template> 1247affc529SSandeepa Singh </b-table> 1257affc529SSandeepa Singh </b-col> 1267affc529SSandeepa Singh </b-row> 1277affc529SSandeepa Singh 1287affc529SSandeepa Singh <!-- Table pagination --> 1297affc529SSandeepa Singh <b-row> 1307affc529SSandeepa Singh <b-col sm="6"> 1317affc529SSandeepa Singh <b-form-group 1327affc529SSandeepa Singh class="table-pagination-select" 1337affc529SSandeepa Singh :label="$t('global.table.itemsPerPage')" 1347affc529SSandeepa Singh label-for="pagination-items-per-page" 1357affc529SSandeepa Singh > 1367affc529SSandeepa Singh <b-form-select 1377affc529SSandeepa Singh id="pagination-items-per-page" 1387affc529SSandeepa Singh v-model="perPage" 1397affc529SSandeepa Singh :options="itemsPerPageOptions" 1407affc529SSandeepa Singh /> 1417affc529SSandeepa Singh </b-form-group> 1427affc529SSandeepa Singh </b-col> 1437affc529SSandeepa Singh <b-col sm="6"> 1447affc529SSandeepa Singh <b-pagination 1457affc529SSandeepa Singh v-model="currentPage" 1467affc529SSandeepa Singh first-number 1477affc529SSandeepa Singh last-number 1487affc529SSandeepa Singh :per-page="perPage" 149f7000cd6SSukanya Pandey :total-rows="getTotalRowCount(filteredRows)" 1507affc529SSandeepa Singh aria-controls="table-post-code-logs" 1517affc529SSandeepa Singh /> 1527affc529SSandeepa Singh </b-col> 1537affc529SSandeepa Singh </b-row> 1547affc529SSandeepa Singh </b-container> 1557affc529SSandeepa Singh</template> 1567affc529SSandeepa Singh 1577affc529SSandeepa Singh<script> 158d8c71c00SKonstantin Aladyshevimport IconDelete from '@carbon/icons-vue/es/trash-can/20'; 1597affc529SSandeepa Singhimport IconDownload from '@carbon/icons-vue/es/download/20'; 1607affc529SSandeepa Singhimport IconExport from '@carbon/icons-vue/es/document--export/20'; 1617affc529SSandeepa Singhimport { omit } from 'lodash'; 1627affc529SSandeepa Singhimport PageTitle from '@/components/Global/PageTitle'; 1637affc529SSandeepa Singhimport Search from '@/components/Global/Search'; 1647affc529SSandeepa Singhimport TableCellCount from '@/components/Global/TableCellCount'; 1657affc529SSandeepa Singhimport TableDateFilter from '@/components/Global/TableDateFilter'; 1667affc529SSandeepa Singhimport TableRowAction from '@/components/Global/TableRowAction'; 1677affc529SSandeepa Singhimport TableToolbar from '@/components/Global/TableToolbar'; 1687affc529SSandeepa Singhimport TableToolbarExport from '@/components/Global/TableToolbarExport'; 1697affc529SSandeepa Singhimport LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; 1707affc529SSandeepa Singhimport TableFilterMixin from '@/components/Mixins/TableFilterMixin'; 1717affc529SSandeepa Singhimport BVPaginationMixin, { 1727affc529SSandeepa Singh currentPage, 1737affc529SSandeepa Singh perPage, 1747affc529SSandeepa Singh itemsPerPageOptions, 1757affc529SSandeepa Singh} from '@/components/Mixins/BVPaginationMixin'; 1767affc529SSandeepa Singhimport BVTableSelectableMixin, { 1777affc529SSandeepa Singh selectedRows, 1787affc529SSandeepa Singh tableHeaderCheckboxModel, 1797affc529SSandeepa Singh tableHeaderCheckboxIndeterminate, 1807affc529SSandeepa Singh} from '@/components/Mixins/BVTableSelectableMixin'; 1817affc529SSandeepa Singhimport BVToastMixin from '@/components/Mixins/BVToastMixin'; 1827affc529SSandeepa Singhimport TableSortMixin from '@/components/Mixins/TableSortMixin'; 1837affc529SSandeepa Singhimport TableRowExpandMixin, { 1847affc529SSandeepa Singh expandRowLabel, 1857affc529SSandeepa Singh} from '@/components/Mixins/TableRowExpandMixin'; 1867affc529SSandeepa Singhimport SearchFilterMixin, { 1877affc529SSandeepa Singh searchFilter, 1887affc529SSandeepa Singh} from '@/components/Mixins/SearchFilterMixin'; 189*de23ea23SSurya Vimport { useI18n } from 'vue-i18n'; 190*de23ea23SSurya Vimport i18n from '@/i18n'; 1917affc529SSandeepa Singh 1927affc529SSandeepa Singhexport default { 1937affc529SSandeepa Singh components: { 194d8c71c00SKonstantin Aladyshev IconDelete, 1957affc529SSandeepa Singh IconExport, 1967affc529SSandeepa Singh IconDownload, 1977affc529SSandeepa Singh PageTitle, 1987affc529SSandeepa Singh Search, 1997affc529SSandeepa Singh TableCellCount, 2007affc529SSandeepa Singh TableRowAction, 2017affc529SSandeepa Singh TableToolbar, 2027affc529SSandeepa Singh TableToolbarExport, 2037affc529SSandeepa Singh TableDateFilter, 2047affc529SSandeepa Singh }, 2057affc529SSandeepa Singh mixins: [ 2067affc529SSandeepa Singh BVPaginationMixin, 2077affc529SSandeepa Singh BVTableSelectableMixin, 2087affc529SSandeepa Singh BVToastMixin, 2097affc529SSandeepa Singh LoadingBarMixin, 2107affc529SSandeepa Singh TableFilterMixin, 2117affc529SSandeepa Singh TableSortMixin, 2127affc529SSandeepa Singh TableRowExpandMixin, 2137affc529SSandeepa Singh SearchFilterMixin, 2147affc529SSandeepa Singh ], 2157affc529SSandeepa Singh beforeRouteLeave(to, from, next) { 2167affc529SSandeepa Singh // Hide loader if the user navigates to another page 2177affc529SSandeepa Singh // before request is fulfilled. 2187affc529SSandeepa Singh this.hideLoader(); 2197affc529SSandeepa Singh next(); 2207affc529SSandeepa Singh }, 2217affc529SSandeepa Singh data() { 2227affc529SSandeepa Singh return { 223*de23ea23SSurya V $t: useI18n().t, 22441057853SKenneth Fullbright isBusy: true, 2257affc529SSandeepa Singh fields: [ 2267affc529SSandeepa Singh { 2277affc529SSandeepa Singh key: 'checkbox', 2287affc529SSandeepa Singh sortable: false, 2297affc529SSandeepa Singh }, 2307affc529SSandeepa Singh { 2317affc529SSandeepa Singh key: 'date', 232*de23ea23SSurya V label: i18n.global.t('pagePostCodeLogs.table.created'), 233b8182882SSandeepa Singh sortable: true, 2347affc529SSandeepa Singh }, 2357affc529SSandeepa Singh { 2367affc529SSandeepa Singh key: 'timeStampOffset', 237*de23ea23SSurya V label: i18n.global.t('pagePostCodeLogs.table.timeStampOffset'), 2387affc529SSandeepa Singh }, 2397affc529SSandeepa Singh { 2407affc529SSandeepa Singh key: 'bootCount', 241*de23ea23SSurya V label: i18n.global.t('pagePostCodeLogs.table.bootCount'), 2427affc529SSandeepa Singh }, 2437affc529SSandeepa Singh { 2447affc529SSandeepa Singh key: 'postCode', 245*de23ea23SSurya V label: i18n.global.t('pagePostCodeLogs.table.postCode'), 2467affc529SSandeepa Singh }, 2477affc529SSandeepa Singh { 2487affc529SSandeepa Singh key: 'actions', 2497affc529SSandeepa Singh label: '', 2507affc529SSandeepa Singh tdClass: 'text-right text-nowrap', 2517affc529SSandeepa Singh }, 2527affc529SSandeepa Singh ], 2537affc529SSandeepa Singh expandRowLabel, 2547affc529SSandeepa Singh activeFilters: [], 2557affc529SSandeepa Singh currentPage: currentPage, 2567affc529SSandeepa Singh filterStartDate: null, 2577affc529SSandeepa Singh filterEndDate: null, 2587affc529SSandeepa Singh itemsPerPageOptions: itemsPerPageOptions, 2597affc529SSandeepa Singh perPage: perPage, 2607affc529SSandeepa Singh searchFilter: searchFilter, 2617affc529SSandeepa Singh searchTotalFilteredRows: 0, 2627affc529SSandeepa Singh selectedRows: selectedRows, 2637affc529SSandeepa Singh tableHeaderCheckboxModel: tableHeaderCheckboxModel, 2647affc529SSandeepa Singh tableHeaderCheckboxIndeterminate: tableHeaderCheckboxIndeterminate, 2657affc529SSandeepa Singh }; 2667affc529SSandeepa Singh }, 2677affc529SSandeepa Singh computed: { 2687affc529SSandeepa Singh href() { 2697affc529SSandeepa Singh return `data:text/json;charset=utf-8,${this.exportAllLogsString()}`; 2707affc529SSandeepa Singh }, 2717affc529SSandeepa Singh filteredRows() { 2727affc529SSandeepa Singh return this.searchFilter 2737affc529SSandeepa Singh ? this.searchTotalFilteredRows 2747affc529SSandeepa Singh : this.filteredLogs.length; 2757affc529SSandeepa Singh }, 2767affc529SSandeepa Singh allLogs() { 2777affc529SSandeepa Singh return this.$store.getters['postCodeLogs/allPostCodes'].map( 2787affc529SSandeepa Singh (postCodes) => { 2797affc529SSandeepa Singh return { 2807affc529SSandeepa Singh ...postCodes, 2817affc529SSandeepa Singh actions: [ 2827affc529SSandeepa Singh { 2837affc529SSandeepa Singh value: 'export', 284*de23ea23SSurya V title: i18n.global.t('pagePostCodeLogs.action.exportLogs'), 2857affc529SSandeepa Singh }, 2867affc529SSandeepa Singh { 2877affc529SSandeepa Singh value: 'download', 288*de23ea23SSurya V title: i18n.global.t('pagePostCodeLogs.action.downloadDetails'), 2897affc529SSandeepa Singh }, 2907affc529SSandeepa Singh ], 2917affc529SSandeepa Singh }; 2928132399cSEd Tanous }, 2937affc529SSandeepa Singh ); 2947affc529SSandeepa Singh }, 2957affc529SSandeepa Singh batchExportData() { 2967affc529SSandeepa Singh return this.selectedRows.map((row) => omit(row, 'actions')); 2977affc529SSandeepa Singh }, 2987affc529SSandeepa Singh filteredLogsByDate() { 2997affc529SSandeepa Singh return this.getFilteredTableDataByDate( 3007affc529SSandeepa Singh this.allLogs, 3017affc529SSandeepa Singh this.filterStartDate, 3028132399cSEd Tanous this.filterEndDate, 3037affc529SSandeepa Singh ); 3047affc529SSandeepa Singh }, 3057affc529SSandeepa Singh filteredLogs() { 3067affc529SSandeepa Singh return this.getFilteredTableData( 3077affc529SSandeepa Singh this.filteredLogsByDate, 3088132399cSEd Tanous this.activeFilters, 3097affc529SSandeepa Singh ); 3107affc529SSandeepa Singh }, 3117affc529SSandeepa Singh }, 3127affc529SSandeepa Singh created() { 3137affc529SSandeepa Singh this.startLoader(); 31441057853SKenneth Fullbright this.$store.dispatch('postCodeLogs/getPostCodesLogData').finally(() => { 31541057853SKenneth Fullbright this.endLoader(); 31641057853SKenneth Fullbright this.isBusy = false; 31741057853SKenneth Fullbright }); 3187affc529SSandeepa Singh }, 3197affc529SSandeepa Singh methods: { 320d8c71c00SKonstantin Aladyshev deleteAllLogs() { 321d8c71c00SKonstantin Aladyshev this.$bvModal 322*de23ea23SSurya V .msgBoxConfirm(i18n.global.t('pageEventLogs.modal.deleteAllMessage'), { 323*de23ea23SSurya V title: i18n.global.t('pageEventLogs.modal.deleteAllTitle'), 324*de23ea23SSurya V okTitle: i18n.global.t('global.action.delete'), 325d8c71c00SKonstantin Aladyshev okVariant: 'danger', 326*de23ea23SSurya V cancelTitle: i18n.global.t('global.action.cancel'), 327d1ef18e6SPaul Fertser autoFocusButton: 'cancel', 328d8c71c00SKonstantin Aladyshev }) 329d8c71c00SKonstantin Aladyshev .then((deleteConfirmed) => { 330d8c71c00SKonstantin Aladyshev if (deleteConfirmed) { 331d8c71c00SKonstantin Aladyshev this.$store 332d8c71c00SKonstantin Aladyshev .dispatch('postCodeLogs/deleteAllPostCodeLogs', this.allLogs) 333d8c71c00SKonstantin Aladyshev .then((message) => this.successToast(message)) 334d8c71c00SKonstantin Aladyshev .catch(({ message }) => this.errorToast(message)); 335d8c71c00SKonstantin Aladyshev } 336d8c71c00SKonstantin Aladyshev }); 337d8c71c00SKonstantin Aladyshev }, 3387affc529SSandeepa Singh exportAllLogsString() { 3397affc529SSandeepa Singh { 3407affc529SSandeepa Singh return this.$store.getters['postCodeLogs/allPostCodes'].map( 3417affc529SSandeepa Singh (postCodes) => { 3427affc529SSandeepa Singh const allLogsString = JSON.stringify(postCodes); 3437affc529SSandeepa Singh return allLogsString; 3448132399cSEd Tanous }, 3457affc529SSandeepa Singh ); 3467affc529SSandeepa Singh } 3477affc529SSandeepa Singh }, 3487affc529SSandeepa Singh onFilterChange({ activeFilters }) { 3497affc529SSandeepa Singh this.activeFilters = activeFilters; 3507affc529SSandeepa Singh }, 3517affc529SSandeepa Singh onChangeDateTimeFilter({ fromDate, toDate }) { 3527affc529SSandeepa Singh this.filterStartDate = fromDate; 3537affc529SSandeepa Singh this.filterEndDate = toDate; 3547affc529SSandeepa Singh }, 3557affc529SSandeepa Singh onFiltered(filteredItems) { 3567affc529SSandeepa Singh this.searchTotalFilteredRows = filteredItems.length; 3577affc529SSandeepa Singh }, 3587affc529SSandeepa Singh // Create export file name based on date and action 3597affc529SSandeepa Singh exportFileNameByDate(value) { 3607affc529SSandeepa Singh let date = new Date(); 3617affc529SSandeepa Singh date = 3627affc529SSandeepa Singh date.toISOString().slice(0, 10) + 3637affc529SSandeepa Singh '_' + 3647affc529SSandeepa Singh date.toString().split(':').join('-').split(' ')[4]; 3657affc529SSandeepa Singh let fileName; 3667affc529SSandeepa Singh if (value === 'download') { 367*de23ea23SSurya V fileName = i18n.global.t('pagePostCodeLogs.downloadFilePrefix'); 3687affc529SSandeepa Singh } else if (value === 'export') { 369*de23ea23SSurya V fileName = i18n.global.t('pagePostCodeLogs.exportFilePrefix'); 3707affc529SSandeepa Singh } else { 371*de23ea23SSurya V fileName = i18n.global.t('pagePostCodeLogs.allExportFilePrefix'); 3727affc529SSandeepa Singh } 3737affc529SSandeepa Singh return fileName + date; 3747affc529SSandeepa Singh }, 3757affc529SSandeepa Singh }, 3767affc529SSandeepa Singh}; 3777affc529SSandeepa Singh</script> 378