Merge "transfer-table: Rethink CHANGED message handler"
This commit is contained in:
commit
b6926e7bf1
@ -90,10 +90,10 @@
|
|||||||
|
|
||||||
// if available transfer table is updated dynamically (e.g. based on a dropdown
|
// if available transfer table is updated dynamically (e.g. based on a dropdown
|
||||||
// selection like in Launch Instance Boot Source), we need to update our data accordingly
|
// selection like in Launch Instance Boot Source), we need to update our data accordingly
|
||||||
var availableChangedWatcher = $scope.$on(events.AVAIL_CHANGED, onAvailChanged);
|
var tablesChangedWatcher = $scope.$on(events.TABLES_CHANGED, onTablesChanged);
|
||||||
|
|
||||||
$scope.$on('$destroy', function () {
|
$scope.$on('$destroy', function () {
|
||||||
availableChangedWatcher();
|
tablesChangedWatcher();
|
||||||
});
|
});
|
||||||
|
|
||||||
init(trModel);
|
init(trModel);
|
||||||
@ -208,18 +208,22 @@
|
|||||||
Array.prototype.push.apply(ctrl.allocated.sourceItems, orderedItems);
|
Array.prototype.push.apply(ctrl.allocated.sourceItems, orderedItems);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAvailChanged(e, args) {
|
function onTablesChanged(e, args) {
|
||||||
ctrl.available = {
|
if (args.data.available) {
|
||||||
sourceItems: args.data.available,
|
ctrl.available.sourceItems = args.data.available;
|
||||||
displayedItems: args.data.displayedAvailable ? args.data.displayedAvailable : []
|
}
|
||||||
};
|
if (args.data.displayedAvailable) {
|
||||||
|
ctrl.available.displayedItems = args.data.displayedAvailable;
|
||||||
for (var i = 0; i < ctrl.available.sourceItems.length; i++) {
|
}
|
||||||
var item = ctrl.available.sourceItems[i];
|
if (args.data.allocated) {
|
||||||
if (item.id in ctrl.allocatedIds) {
|
ctrl.allocated.sourceItems = args.data.allocated;
|
||||||
ctrl.allocated.sourceItems.splice(i, 1);
|
ctrl.allocatedIds = {};
|
||||||
delete ctrl.allocatedIds[item.id];
|
ctrl.allocated.sourceItems.forEach(function(item) {
|
||||||
}
|
ctrl.allocatedIds[item.id] = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (args.data.displayedAllocated) {
|
||||||
|
ctrl.allocated.displayedItems = args.data.displayedAllocated;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,19 +205,27 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function testTransferTableChanged() {
|
function testTransferTableChanged() {
|
||||||
var oldAvailableCount = 10;
|
scope.$broadcast(
|
||||||
trCtrl.available.sourceItems = generateItems(oldAvailableCount);
|
'horizon.framework.widgets.transfer-table.TABLES_CHANGED',
|
||||||
expect(trCtrl.available.sourceItems.length).toEqual(oldAvailableCount);
|
{data: {available: [{id: 1}]}}
|
||||||
|
);
|
||||||
var availableCount = 4;
|
scope.$broadcast(
|
||||||
var newItems = {
|
'horizon.framework.widgets.transfer-table.TABLES_CHANGED',
|
||||||
"data": { available: generateItems(availableCount) }
|
{data: {displayedAvailable: [{id: 2}]}}
|
||||||
};
|
);
|
||||||
spyOn(scope, '$broadcast').and.callThrough();
|
scope.$broadcast(
|
||||||
scope.$broadcast('horizon.framework.widgets.transfer-table.AVAIL_CHANGED', newItems);
|
'horizon.framework.widgets.transfer-table.TABLES_CHANGED',
|
||||||
expect(scope.$broadcast).toHaveBeenCalledWith(
|
{data: {allocated: [{id: 3}]}}
|
||||||
'horizon.framework.widgets.transfer-table.AVAIL_CHANGED', newItems);
|
);
|
||||||
expect(trCtrl.available.sourceItems.length).toEqual(availableCount);
|
scope.$broadcast(
|
||||||
|
'horizon.framework.widgets.transfer-table.TABLES_CHANGED',
|
||||||
|
{data: {displayedAllocated: [{id: 4}]}}
|
||||||
|
);
|
||||||
|
expect(trCtrl.available.sourceItems).toEqual([{id: 1}]);
|
||||||
|
expect(trCtrl.available.displayedItems).toEqual([{id: 2}]);
|
||||||
|
expect(trCtrl.allocated.sourceItems).toEqual([{id: 3}]);
|
||||||
|
expect(trCtrl.allocatedIds).toEqual({3: true});
|
||||||
|
expect(trCtrl.allocated.displayedItems).toEqual([{id: 4}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}); // end of core functions
|
}); // end of core functions
|
||||||
|
@ -82,7 +82,7 @@
|
|||||||
*/
|
*/
|
||||||
function events() {
|
function events() {
|
||||||
return {
|
return {
|
||||||
AVAIL_CHANGED: 'horizon.framework.widgets.transfer-table.AVAIL_CHANGED'
|
TABLES_CHANGED: 'horizon.framework.widgets.transfer-table.TABLES_CHANGED'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -334,7 +334,7 @@
|
|||||||
},
|
},
|
||||||
function onBootSourceChange(newValue, oldValue) {
|
function onBootSourceChange(newValue, oldValue) {
|
||||||
if (newValue !== oldValue) {
|
if (newValue !== oldValue) {
|
||||||
$scope.$broadcast(events.AVAIL_CHANGED, {
|
$scope.$broadcast(events.TABLES_CHANGED, {
|
||||||
'data': bootSources[newValue]
|
'data': bootSources[newValue]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
other:
|
||||||
|
- |
|
||||||
|
(For Horizon plugin developers) The AVAIL_CHANGED event of transfer
|
||||||
|
table is removed. It is superseded by event TABLES_CHANGED. The
|
||||||
|
name of AVAIL_CHANGED was misleading because it implicitly and
|
||||||
|
uncontrollably updated the allocated table too. The new event allows
|
||||||
|
independent updates to all four tables. We believe it is safe to
|
||||||
|
remove AVAIL_CHANGED without deprecation because its implementation
|
||||||
|
contained a bug that must have been discovered before if anybody
|
||||||
|
had used it. Anyway possible out-of-tree plugin maintainers are
|
||||||
|
recommended to consume the new event even if your plugins relied on
|
||||||
|
the buggy behavior of AVAIL_CHANGED.
|
Loading…
x
Reference in New Issue
Block a user