module Sfx { export class DetailViewPartDirective implements ng . IDirective { public restrict = "AE" ; public replace = true ; public controller = DetailViewPartController ; public controllerAs = "ctrl" ; public templateUrl = "partials/detail-view-part.html" ; public scope = { data : "=" , title : "=" } ; public link ( $scope , element , attributes , ctrl ) { $scope . noFixedLayout = false ; attributes . $observe ( "noFixedLayout" , function ( ) { $scope . noFixedLayout = $scope . $eval ( attributes . noFixedLayout ) ; } ) ; $scope . $watchGroup ( [ "data.raw" , "data" ] , function ( newValue , oldValue ) { $scope . resolvedData = ctrl . getResolvedDataObject ( $scope . data ) ; } ) ; } } export class ResolvedObject { [ index ] : any ; } export class DetailViewPartController { public getResolvedObjectSize ( object ) { return _ . size ( object ) ; } public getResolvedPropertyType ( value ) { if ( this . isResolvedObject ( value ) ) { return "Object" ; } else if ( this . isArray ( value ) ) { return "Array" ; } else if ( this . isHtml ( value ) ) { return "Html" ; } else { return "Value" ; } } public getResolvedDataObject ( data , preserveEmptyProperties = false ) { if ( ! data ) { return null ; } if ( data instanceof ResolvedObject ) { return data ; } if ( data . hasOwnProperty ( "raw" ) ) { if ( _ . isUndefined ( data . raw ) || _ . isNull ( data . raw ) ) { return null ; } return this . getResolvedDataObjectInternal ( data . raw , data , preserveEmptyProperties ) ; } return this . getResolvedDataObjectInternal ( data , null , preserveEmptyProperties ) ; } private isResolvedObject ( value ) { return value instanceof ResolvedObject ; } private isArray ( value ) { return _ . isArray ( value ) ; } private isHtml ( value ) { return HtmlUtils . isHtml ( value ) ; } private getResolvedDataObjectInternal ( data , parent , preserveEmptyProperties = false ) { let resolvedObject = new ResolvedObject ( ) ; _ . forOwn ( data , ( value , name ) => { let resolvedName = _ . startCase ( name ) ; let resolvedValue = null ; if ( parent && parent . decorators ) { if ( parent . decorators . showList && ! _ . includes ( parent . decorators . showList , name ) ) { return ; } else if ( parent . decorators . hideList && _ . includes ( parent . decorators . hideList , name ) ) { return ; } if ( parent . decorators . decorators && parent . decorators . decorators [ name ] ) { if ( parent . decorators . decorators [ name ] . displayName ) { resolvedName = parent . decorators . decorators [ name ] . displayName ( name ) ; } if ( parent . decorators . decorators [ name ] . displayValueInHtml ) { resolvedValue = parent . decorators . decorators [ name ] . displayValueInHtml ( value ) ; } } } if ( ! resolvedValue ) { if ( parent ) { resolvedValue = parent [ name ] || parent [ _ . camelCase ( name ) ] ; } if ( ! resolvedValue ) { resolvedValue = data [ name ] ; } } if ( _ . isNumber ( resolvedValue ) || _ . isBoolean ( resolvedValue ) ) { } else if ( _ . isUndefined ( resolvedValue ) || _ . isNull ( resolvedValue ) || _ . isEmpty ( resolvedValue ) ) { if ( preserveEmptyProperties ) { resolvedValue = Constants . Empty ; } else { resolvedValue = null ; } } else if ( _ . isArray ( resolvedValue ) ) { if ( ! _ . isObject ( _ . first ( resolvedValue ) ) ) { resolvedValue = `[${ _ . map ( resolvedValue , v => v . toString ( ) ) . join ( ", " ) }]` ; } else { resolvedValue = _ . map ( resolvedValue , v => this . getResolvedDataObject ( v , true ) ) ; } } else if ( _ . isObject ( resolvedValue ) ) { if ( Utils . isBadge ( resolvedValue ) ) { if ( resolvedValue . text && resolvedValue . badgeClass ) { resolvedValue = HtmlUtils . getBadgeHtml ( resolvedValue ) ; } else { resolvedValue = resolvedValue . text ; } } else { resolvedValue = this . getResolvedDataObject ( resolvedValue ) ; } } if ( _ . isEmpty ( resolvedName ) ) { resolvedName = Constants . Empty ; } if ( resolvedValue !== null ) { resolvedObject [ resolvedName ] = resolvedValue ; } } ) ; return _ . size ( resolvedObject ) > 0 ? resolvedObject : null ; } } }