mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
New 'core:/utils/ObjectUtils', additional unit tests
This commit is contained in:
@@ -347,11 +347,6 @@ describe('ObjectDataRow', () => {
|
||||
expect(row.getValue('some.missing.property')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should return undefined when getting value for missing target', () => {
|
||||
let row = new ObjectDataRow({});
|
||||
expect(row.getObjectValue(null, 'id')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('should check top level value exists', () => {
|
||||
let row = new ObjectDataRow({ id: 1 });
|
||||
|
||||
|
@@ -16,6 +16,7 @@
|
||||
*/
|
||||
|
||||
import { DatePipe } from '@angular/common';
|
||||
import { ObjectUtils } from 'ng2-alfresco-core';
|
||||
|
||||
import {
|
||||
DataTableAdapter,
|
||||
@@ -147,40 +148,8 @@ export class ObjectDataRow implements DataRow {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a value from an object by composed key
|
||||
* documentList.getObjectValue({ item: { nodeType: 'cm:folder' }}, 'item.nodeType') ==> 'cm:folder'
|
||||
* @param target
|
||||
* @param key
|
||||
* @returns {string}
|
||||
*/
|
||||
getObjectValue(target: any, key: string): any {
|
||||
|
||||
if (!target) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
let keys = key.split('.');
|
||||
key = '';
|
||||
|
||||
do {
|
||||
key += keys.shift();
|
||||
let value = target[key];
|
||||
if (value !== undefined && (typeof value === 'object' || !keys.length)) {
|
||||
target = value;
|
||||
key = '';
|
||||
} else if (!keys.length) {
|
||||
target = undefined;
|
||||
} else {
|
||||
key += '.';
|
||||
}
|
||||
} while (keys.length);
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
getValue(key: string): any {
|
||||
return this.getObjectValue(this.obj, key);
|
||||
return ObjectUtils.getValue(this.obj, key);
|
||||
}
|
||||
|
||||
hasValue(key: string): boolean {
|
||||
|
Reference in New Issue
Block a user