Merge "Remove array metadata when no items + fix case"

This commit is contained in:
Jenkins
2016-08-01 07:29:06 +00:00
committed by Gerrit Code Review
3 changed files with 45 additions and 6 deletions

View File

@@ -82,7 +82,7 @@
break;
case 'array':
var data = /^(<.*?>) (.*)$/.exec(value);
if (data) {
if (data && data.length > 2) {
this.operator = data[1];
this.value = data[2].split(',');
}
@@ -440,7 +440,11 @@
var existing = {};
angular.forEach(this.flatTree, function (item) {
if (item.added && item.leaf) {
existing[item.leaf.name] = item.getLeafValue();
if (item.leaf.type === 'array' && item.leaf.value.length === 0) {
// Do nothing, the user has removed or not selected any array values
} else {
existing[item.leaf.name] = item.getLeafValue();
}
}
});
return existing;

View File

@@ -53,6 +53,19 @@
ctrl.saving = true;
var updated = ctrl.tree.getExisting();
var removed = angular.copy(existing.data);
// Glance v1 changes metadata property casing in the get request
// but to remove you still need to send back in using the proper original case.
// See https://bugs.launchpad.net/horizon/+bug/1606988
angular.forEach(removed, function bug1606988(value, removedKey) {
angular.forEach(ctrl.tree.flatTree, function compareToDefinitions(item) {
if (item.leaf && removedKey.toLocaleLowerCase() === item.leaf.name.toLocaleLowerCase()) {
removed[item.leaf.name] = value;
delete removed[removedKey];
}
});
});
angular.forEach(updated, function(value, key) {
delete removed[key];
});

View File

@@ -24,6 +24,27 @@
editMetadata: function() {}
};
var availableItem = {
'namespace': 'bug1606988',
'properties': {
'UPPER_lower': {
'items': {
'enum': [
'foo',
'bar'
],
'type': 'string'
},
'type': 'array'
}
}
};
var existing = {
'upper_lower': 'foo',
'custom': 'bar'
};
beforeEach(function() {
modalInstance = {
dismiss: jasmine.createSpy(),
@@ -62,7 +83,7 @@
expect(modalInstance.close).toHaveBeenCalled();
expect(metadataService.editMetadata)
.toHaveBeenCalledWith('aggregate', '123', {someProperty: 'someValue'}, []);
.toHaveBeenCalledWith('aggregate', '123', {'custom': 'bar'}, ['UPPER_lower']);
});
it('should clear saving flag on failed save', function() {
@@ -81,16 +102,17 @@
expect(modalInstance.close).not.toHaveBeenCalled();
expect(metadataService.editMetadata)
.toHaveBeenCalledWith('aggregate', '123', {someProperty: 'someValue'}, []);
.toHaveBeenCalledWith('aggregate', '123', {'custom': 'bar'}, ['UPPER_lower']);
});
function createController() {
//Purposely use different cases in available and existing.
return $controller('MetadataModalController', {
'$modalInstance': modalInstance,
'horizon.framework.widgets.metadata.tree.service': treeService,
'horizon.app.core.metadata.service': metadataService,
'available': {data: {}},
'existing': {data: {someProperty: 'someValue'}},
'available': {data: {items: [availableItem]}},
'existing': {data: existing},
'params': {resource: 'aggregate', id: '123'}
});
}