Fix Visualize and Dashboard listing table logic so that selection only applies to the current page of items.

- Paging clears the selection.
- Searching clears the selection.
- Sorting clears the selection.
This commit is contained in:
CJ Cenizal 2017-02-06 11:05:16 -08:00
parent 734c85b5ab
commit de4f7b43e2
2 changed files with 33 additions and 8 deletions

View file

@ -50,6 +50,14 @@ export function DashboardListingController(
});
};
const deselectAll = () => {
selectedItems = [];
};
const selectAll = () => {
selectedItems = this.pageOfItems.slice(0);
};
this.items = [];
this.pageOfItems = [];
this.filter = '';
@ -65,14 +73,15 @@ export function DashboardListingController(
this.toggleSort = function toggleSort() {
this.isAscending = !this.isAscending;
deselectAll();
calculateItemsOnPage();
};
this.toggleAll = function toggleAll() {
if (this.areAllItemsChecked()) {
selectedItems = [];
deselectAll();
} else {
selectedItems = this.items.slice(0);
selectAll();
}
};
@ -90,7 +99,7 @@ export function DashboardListingController(
};
this.areAllItemsChecked = function areAllItemsChecked() {
return this.getSelectedItemsCount() === this.items.length;
return this.getSelectedItemsCount() === this.pageOfItems.length;
};
this.getSelectedItemsCount = function getSelectedItemsCount() {
@ -104,10 +113,11 @@ export function DashboardListingController(
dashboardService.delete(selectedIds)
.then(fetchObjects)
.then(() => {
selectedItems = [];
deselectAll();
})
.catch(error => notify.error(error));
};
confirmModal(
'Are you sure you want to delete the selected dashboards? This action is irreversible!',
{
@ -117,11 +127,13 @@ export function DashboardListingController(
};
this.onPageNext = () => {
deselectAll();
this.pager.nextPage();
calculateItemsOnPage();
};
this.onPagePrevious = () => {
deselectAll();
this.pager.previousPage();
calculateItemsOnPage();
};
@ -131,6 +143,7 @@ export function DashboardListingController(
};
$scope.$watch(() => this.filter, () => {
deselectAll();
fetchObjects();
});
}

View file

@ -51,6 +51,14 @@ export function VisualizeListingController(
});
};
const deselectAll = () => {
selectedItems = [];
};
const selectAll = () => {
selectedItems = this.pageOfItems.slice(0);
};
this.items = [];
this.pageOfItems = [];
this.filter = '';
@ -95,14 +103,15 @@ export function VisualizeListingController(
this.getSortPropertyByName(propertyName).isSelected = true;
}
deselectAll();
calculateItemsOnPage();
};
this.toggleAll = function toggleAll() {
if (this.areAllItemsChecked()) {
selectedItems = [];
deselectAll();
} else {
selectedItems = this.items.slice(0);
selectAll();
}
};
@ -120,7 +129,7 @@ export function VisualizeListingController(
};
this.areAllItemsChecked = function areAllItemsChecked() {
return this.getSelectedItemsCount() === this.items.length;
return this.getSelectedItemsCount() === this.pageOfItems.length;
};
this.getSelectedItemsCount = function getSelectedItemsCount() {
@ -134,7 +143,7 @@ export function VisualizeListingController(
visualizationService.delete(selectedIds)
.then(fetchObjects)
.then(() => {
selectedItems = [];
deselectAll();
})
.catch(error => notify.error(error));
};
@ -148,11 +157,13 @@ export function VisualizeListingController(
};
this.onPageNext = () => {
deselectAll();
this.pager.nextPage();
calculateItemsOnPage();
};
this.onPagePrevious = () => {
deselectAll();
this.pager.previousPage();
calculateItemsOnPage();
};
@ -162,6 +173,7 @@ export function VisualizeListingController(
};
$scope.$watch(() => this.filter, () => {
deselectAll();
fetchObjects();
});
}