Merge "Syntactic sugar for setting multiple properties in registry"
This commit is contained in:
commit
96595dcfc2
@ -100,6 +100,7 @@
|
||||
self.type = typeCode;
|
||||
self.initActions = initActions;
|
||||
self.setProperty = setProperty;
|
||||
self.setProperties = setProperties;
|
||||
self.getProperties = getProperties;
|
||||
self.getName = getName;
|
||||
self.setNames = setNames;
|
||||
@ -193,6 +194,31 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name setProperties
|
||||
* @description
|
||||
* Syntactic sugar for setProperty.
|
||||
* Allows an object of properties where the key is the id and the value
|
||||
* can either be a string or an object. If the value is a string, we assume
|
||||
* that it is the label. If the value is an object, we use the object as
|
||||
* the property for that key.
|
||||
* @example
|
||||
```
|
||||
var properties = {
|
||||
id: gettext('ID'),
|
||||
enabled: { label: gettext('Enabled') }
|
||||
};
|
||||
resourceType.setproperties(properties);
|
||||
*/
|
||||
function setProperties(properties) {
|
||||
angular.forEach(properties, function(value, key) {
|
||||
var prop = angular.isString(value) ? { label: value } : value;
|
||||
setProperty(key, prop);
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a copy of any properties that have been registered.
|
||||
* @returns {*}
|
||||
|
@ -78,9 +78,14 @@
|
||||
describe('label', function() {
|
||||
var label;
|
||||
beforeEach(function() {
|
||||
var properties = {
|
||||
id: 'eyedee',
|
||||
bd: { label: 'beedee' }
|
||||
};
|
||||
var value = service.getResourceType('something', {})
|
||||
.setProperty('example', {label: gettext("Example")})
|
||||
.setProperty('bad_example', {});
|
||||
.setProperty('bad_example', {})
|
||||
.setProperties(properties);
|
||||
label = value.label;
|
||||
});
|
||||
|
||||
@ -95,6 +100,11 @@
|
||||
it('returns the nice label if there is one', function() {
|
||||
expect(label('example')).toBe('Example');
|
||||
});
|
||||
|
||||
it('returns the properties set via the properties descriptor', function() {
|
||||
expect(label('id')).toBe('eyedee');
|
||||
expect(label('bd')).toBe('beedee');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getName', function() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user