Skip to content
Snippets Groups Projects
Commit 5184cfbd authored by Timothee P's avatar Timothee P :sunflower:
Browse files

stay on the same page or last after deleting many features & prevent undefined map

parent fe00e054
No related branches found
No related tags found
2 merge requests!424version 3.1.0,!310REDMINE_ISSUE-13296
......@@ -339,13 +339,7 @@ export default {
},
pageNumbers() {
const totalPages = Math.ceil(
this.featuresCount / this.pagination.pagesize
);
return [...Array(totalPages).keys()].map((pageNumb) => {
++pageNumb;
return pageNumb;
});
return this.createPagesArray(this.featuresCount, this.pagination.pagesize);
},
},
......@@ -476,17 +470,22 @@ export default {
},
deleteAllFeatureSelection() {
const initialFeaturesCount = this.featuresCount;
const initialCurrentPage = this.pagination.currentPage;
const promises = this.checkedFeatures.map(
(feature_id) => this.DELETE_FEATURE({ feature_id, noFeatureType: true })
);
Promise.all(promises).then((response) => {
console.log('response', response);
const deletedFeaturesCount = response.reduce((acc, curr) => curr.status === 204 ? acc += 1 : acc, 0);
const newFeaturesCount = initialFeaturesCount - deletedFeaturesCount;
const newPagesArray = this.createPagesArray(newFeaturesCount, this.pagination.pagesize);
const newLastPageNum = newPagesArray[newPagesArray.length - 1];
this.$store.commit('feature/UPDATE_CHECKED_FEATURES', []);
// ? limit only to last page if all its feature are deleted ?
this.pagination = { ...initialPagination }; //* reset initial pagination to avoid empty last page
console.log('this.pagination', this.pagination);
console.log('initialPagination', initialPagination);
this.fetchPagedFeatures();
if (initialCurrentPage > newLastPageNum) { //* if page doesn't exist anymore
this.toPage(newLastPageNum); //* go to new last page
} else {
this.fetchPagedFeatures();
}
})
.catch((err) => console.error(err));
this.toggleDeleteModal();
......@@ -547,8 +546,9 @@ export default {
featureAPI
.getFeaturesBbox(this.projectSlug, queryParams)
.then((bbox) => {
if (bbox) {
mapUtil.getMap().fitBounds(bbox, { padding: [25, 25] });
const map = mapUtil.getMap();
if (bbox && map) {
map.fitBounds(bbox, { padding: [25, 25] });
}
});
},
......@@ -587,7 +587,7 @@ export default {
fetchPagedFeatures(newUrl) {
let url = `${this.API_BASE_URL}projects/${this.projectSlug}/feature-paginated/?output=geojson&limit=${this.pagination.pagesize}&offset=${this.pagination.start}`;
//* if receiving next & previous url
//* if receiving next & previous url (// todo : might be not used anymore, to check)
if (newUrl && typeof newUrl === 'string') {
//newUrl = newUrl.replace("8000", "8010"); //* for dev uncomment to use proxy link
url = newUrl;
......@@ -622,6 +622,16 @@ export default {
//* Pagination for table *//
createPagesArray(featuresCount, pagesize) {
const totalPages = Math.ceil(
featuresCount / pagesize
);
return [...Array(totalPages).keys()].map((pageNumb) => {
++pageNumb;
return pageNumb;
});
},
handlePageChange(page) {
if (page === 'next') {
this.toNextPage();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment