Skip to content

Commit

Permalink
Fix Visualize and Dashboard listing table logic so that selection onl…
Browse files Browse the repository at this point in the history
…y applies to the current page of items.

- Paging clears the selection.
- Searching clears the selection.
- Sorting clears the selection.
  • Loading branch information
cjcenizal committed Feb 6, 2017
1 parent 734c85b commit de4f7b4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ export function DashboardListingController(
});
};

const deselectAll = () => {
selectedItems = [];
};

const selectAll = () => {
selectedItems = this.pageOfItems.slice(0);
};

this.items = [];
this.pageOfItems = [];
this.filter = '';
Expand All @@ -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();
}
};

Expand All @@ -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() {
Expand All @@ -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!',
{
Expand All @@ -117,11 +127,13 @@ export function DashboardListingController(
};

this.onPageNext = () => {
deselectAll();
this.pager.nextPage();
calculateItemsOnPage();
};

this.onPagePrevious = () => {
deselectAll();
this.pager.previousPage();
calculateItemsOnPage();
};
Expand All @@ -131,6 +143,7 @@ export function DashboardListingController(
};

$scope.$watch(() => this.filter, () => {
deselectAll();
fetchObjects();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export function VisualizeListingController(
});
};

const deselectAll = () => {
selectedItems = [];
};

const selectAll = () => {
selectedItems = this.pageOfItems.slice(0);
};

this.items = [];
this.pageOfItems = [];
this.filter = '';
Expand Down Expand Up @@ -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();
}
};

Expand All @@ -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() {
Expand All @@ -134,7 +143,7 @@ export function VisualizeListingController(
visualizationService.delete(selectedIds)
.then(fetchObjects)
.then(() => {
selectedItems = [];
deselectAll();
})
.catch(error => notify.error(error));
};
Expand All @@ -148,11 +157,13 @@ export function VisualizeListingController(
};

this.onPageNext = () => {
deselectAll();
this.pager.nextPage();
calculateItemsOnPage();
};

this.onPagePrevious = () => {
deselectAll();
this.pager.previousPage();
calculateItemsOnPage();
};
Expand All @@ -162,6 +173,7 @@ export function VisualizeListingController(
};

$scope.$watch(() => this.filter, () => {
deselectAll();
fetchObjects();
});
}

0 comments on commit de4f7b4

Please sign in to comment.