Merge pull request #3175 from mabashian/3072-inv-manage-host-checkboxes

Multi-select-list rollback and fixes
This commit is contained in:
Michael Abashian
2016-08-02 11:08:13 -04:00
committed by GitHub
6 changed files with 26 additions and 50 deletions

View File

@@ -51,23 +51,6 @@ export default
PaginateInit({ scope: scope, PaginateInit({ scope: scope,
list: list, url: url, pageSize: 5 }); list: list, url: url, pageSize: 5 });
if (scope.removePostRefresh) {
scope.removePostRefresh();
}
scope.removePostRefresh = scope.$on('PostRefresh', function () {
if(scope.allSelected && scope.allSelected.length > 0) {
// We need to check to see if any of the selected items are now in our list!
for(var i=0; i<scope.allSelected.length; i++) {
for(var j=0; j<scope[set].length; j++) {
if(scope.allSelected[i].id === scope[set][j].id && scope.allSelected[i].type === scope[set][j].type) {
// If so, let's go ahead and mark it as selected so that select-list-item knows to check the box
scope[set][j].isSelected = true;
}
}
}
}
});
scope.search(list.iterator); scope.search(list.iterator);
}); });
} }

View File

@@ -19,6 +19,7 @@ export default
hover: true, hover: true,
'class': 'table-no-border', 'class': 'table-no-border',
multiSelect: true, multiSelect: true,
trackBy: 'group.id',
fields: { fields: {
sync_status: { sync_status: {

View File

@@ -20,6 +20,7 @@ export default
hasChildren: true, hasChildren: true,
'class': 'table-no-border', 'class': 'table-no-border',
multiSelect: true, multiSelect: true,
trackBy: 'host.id',
fields: { fields: {
active_failures: { active_failures: {

View File

@@ -63,9 +63,16 @@ export default ['$scope',
* {@link multiSelectList.controller:multiSelectList#decorateItem `decorateItem`} * {@link multiSelectList.controller:multiSelectList#decorateItem `decorateItem`}
*/ */
this.registerItem = function(item) { this.registerItem = function(item) {
var decoratedItem = this.decorateItem(item); var foundItem = _.find($scope.items, function(existingItem) { return existingItem.id === item.id; });
$scope.items = $scope.items.concat(decoratedItem);
return decoratedItem; if(foundItem) {
return foundItem;
}
else {
var decoratedItem = this.decorateItem(item);
$scope.items = $scope.items.concat(decoratedItem);
return decoratedItem;
}
}; };
/** /**
@@ -99,6 +106,7 @@ export default ['$scope',
this.decorateItem = function(item) { this.decorateItem = function(item) {
return { return {
isSelected: false, isSelected: false,
id: item.id,
value: item value: item
}; };
}; };
@@ -129,11 +137,11 @@ export default ['$scope',
* Triggers {@link multiSelectList.selectionChanged `multiSelectList.selectionChanged`} * Triggers {@link multiSelectList.selectionChanged `multiSelectList.selectionChanged`}
*/ */
this.deselectAll = function() { this.deselectAll = function() {
$scope.items.forEach(function(item) { $scope.items.forEach(function(item) {
item.isSelected = false; item.isSelected = false;
}); });
$scope.selection.isExtended = false; $scope.selection.isExtended = false;
rebuildSelections(); rebuildSelections();
}; };

View File

@@ -33,11 +33,8 @@ export default
template: '<input type="checkbox" data-multi-select-list-item ng-model="isSelected" ng-change="userInteractionSelect()">', template: '<input type="checkbox" data-multi-select-list-item ng-model="isSelected" ng-change="userInteractionSelect()">',
link: function(scope, element, attrs, multiSelectList) { link: function(scope, element, attrs, multiSelectList) {
var initializeItem = function() { scope.decoratedItem = multiSelectList.registerItem(scope.item);
scope.decoratedItem = multiSelectList.registerItem(scope.item); scope.isSelected = scope.decoratedItem.isSelected ? true : false;
scope.isSelected = scope.item.isSelected ? true : false;
scope.decoratedItem.isSelected = scope.item.isSelected ? true : false;
};
scope.$watch('isSelected', function(value) { scope.$watch('isSelected', function(value) {
if (value === true) { if (value === true) {
@@ -47,23 +44,10 @@ export default
} }
}); });
scope.$watch('item', function() {
// This is necessary for page changes where $scope.item gets updated via ng-repeat
// but this link function never gets triggered (and scope.decoratedItem) never
// gets updated.
initializeItem();
});
scope.$on('$destroy', function() {
multiSelectList.deregisterItem(scope.decoratedItem);
});
scope.userInteractionSelect = function() { scope.userInteractionSelect = function() {
scope.$emit("selectedOrDeselected", scope.decoratedItem); scope.$emit("selectedOrDeselected", scope.decoratedItem);
}; };
initializeItem();
} }
}; };
}]; }];

View File

@@ -135,9 +135,9 @@ describeModule(mod.name)
context('selectionChanged event', function() { context('selectionChanged event', function() {
it('triggers with selections set to all the items', function() { it('triggers with selections set to all the items', function() {
var item1 = controller.registerItem({ name: 'blah' }); var item1 = controller.registerItem({ isSelected: false, id: 1, name: 'blah' });
var item2 = controller.registerItem({ name: 'diddy' }); var item2 = controller.registerItem({ isSelected: false, id: 2, name: 'diddy' });
var item3 = controller.registerItem({ name: 'doo' }); var item3 = controller.registerItem({ isSelected: false, id: 3, name: 'doo' });
var spy = sinon.spy(); var spy = sinon.spy();
$scope.$on('multiSelectList.selectionChanged', spy); $scope.$on('multiSelectList.selectionChanged', spy);
@@ -167,9 +167,9 @@ describeModule(mod.name)
it('tracks extended selection state', function() { it('tracks extended selection state', function() {
var spy = sinon.spy(); var spy = sinon.spy();
var item1 = controller.registerItem({ name: 'blah' }); var item1 = controller.registerItem({ isSelected: false, id: 1, name: 'blah' });
var item2 = controller.registerItem({ name: 'diddy' }); var item2 = controller.registerItem({ isSelected: false, id: 2, name: 'diddy' });
var item3 = controller.registerItem({ name: 'doo' }); var item3 = controller.registerItem({ isSelected: false, id: 3, name: 'doo' });
var allItems = _.pluck([item1, item2, item3], 'value'); var allItems = _.pluck([item1, item2, item3], 'value');
controller.selectAll(); controller.selectAll();
@@ -196,4 +196,3 @@ describeModule(mod.name)
}); });
}); });
}); });