Adds support for directly patching boolean attributes

Prior to this change we patched boolean attributes using a 'True'/'False'
string values, and relied on client code to do appropriate coercion.
This approach means that we lose type information in the UI code. With
this change we use the boolean value in the patch process.

Change-Id: I9199f97e2434fe505b633f49ebfa74581d2bc589
This commit is contained in:
Peter Piela 2017-07-29 09:26:29 -04:00
parent 2c88c1b7d0
commit d56e262bff
3 changed files with 12 additions and 7 deletions

View File

@ -29,6 +29,7 @@
'$rootScope',
'$controller',
'$uibModalInstance',
'horizon.framework.widgets.toast.service',
'$log',
'$q',
'horizon.app.core.openstack-service-api.ironic',
@ -41,6 +42,7 @@
function EditPortController($rootScope,
$controller,
$uibModalInstance,
toastService,
$log,
$q,
ironic,
@ -102,8 +104,8 @@
$log.info("Updating port " + JSON.stringify(port));
patcher.buildPatch(port.address, ctrl.address.value, "/address");
patcher.buildPatch(port.pxe_enabled ? 'True' : 'False',
ctrl.pxeEnabled.value,
patcher.buildPatch(port.pxe_enabled,
ctrl.pxeEnabled.value === 'True',
"/pxe_enabled");
patcher.buildPatch(port.local_link_connection,
ctrl.localLinkConnection.toPortAttr(),

View File

@ -26,6 +26,7 @@
EditPortgroupController.$inject = [
'$controller',
'$uibModalInstance',
'horizon.framework.widgets.toast.service',
'$log',
'horizon.app.core.openstack-service-api.ironic',
'horizon.dashboard.admin.ironic.update-patch.service',
@ -34,6 +35,7 @@
function EditPortgroupController($controller,
$uibModalInstance,
toastService,
$log,
ironic,
updatePatchService,
@ -72,9 +74,8 @@
patcher.buildPatch(portgroup.address, ctrl.address.value, "/address");
patcher.buildPatch(portgroup.name, ctrl.name.value, "/name");
patcher.buildPatch(portgroup.standalone_ports_supported
? 'True' : 'False',
ctrl.standalone_ports_supported.value,
patcher.buildPatch(portgroup.standalone_ports_supported,
ctrl.standalone_ports_supported.value === 'True',
"/standalone_ports_supported");
patcher.buildPatch(portgroup.mode,
ctrl.mode.value,

View File

@ -59,13 +59,15 @@
* @description Check whether an item is a property
*
* @param {object} item - item to be tested
* @return {boolean} True if the item is a number, string, or date
* @return {boolean} True if the item is a number, string, date,
* or boolean.
*/
function isProperty(item) {
return item === null ||
angular.isNumber(item) ||
angular.isString(item) ||
angular.isDate(item);
angular.isDate(item) ||
typeof item === 'boolean';
}
/**