@ -6,8 +6,12 @@
* /
* /
import { ChangeDetectionStrategy , ChangeDetectorRef , Component , Input , OnChanges , SimpleChanges } from '@angular/core' ;
import { ChangeDetectionStrategy , ChangeDetectorRef , Component , Input , OnChanges , SimpleChanges } from '@angular/core' ;
import { ResourceOwner } from '@app/framework' ;
import { StatefulComponent } from '@app/framework' ;
import { FieldWrappings , HtmlValue , TableField , TableSettings , Types } from '@app/shared/internal' ;
import { HtmlValue , TableField , TableSettings , Types } from '@app/shared/internal' ;
interface State {
wrapping : boolean ;
}
@Component ( {
@Component ( {
selector : 'sqx-content-value[value]' ,
selector : 'sqx-content-value[value]' ,
@ -15,34 +19,30 @@ import { FieldWrappings, HtmlValue, TableField, TableSettings, Types } from '@ap
templateUrl : './content-value.component.html' ,
templateUrl : './content-value.component.html' ,
changeDetection : ChangeDetectionStrategy.OnPush ,
changeDetection : ChangeDetectionStrategy.OnPush ,
} )
} )
export class ContentValueComponent extends ResourceOwner implements OnChanges {
export class ContentValueComponent extends StatefulComponent < State > implements OnChanges {
@Input ( )
@Input ( )
public value ! : any ;
public value ! : any ;
@Input ( )
@Input ( )
public field ! : TableField ;
public field? : TableField ;
@Input ( )
@Input ( )
public fields? : TableSettings ;
public fields? : TableSettings ;
public wrapping = false ;
public get title() {
return this . isString && this . isPlain ? this . value : undefined ;
}
public get isString() {
public get isString() {
return this . field . rootField ? . properties . fieldType === 'String' ;
return this . field ? . rootField ? . properties . fieldType === 'String' ;
}
}
public get isPlain() {
public get isPlain() {
return ! Types . is ( this . value , HtmlValue ) ;
return ! Types . is ( this . value , HtmlValue ) ;
}
}
public get title() {
constructor ( changeDetector : ChangeDetectorRef ) {
return this . isString ? this . value : undefined ;
super ( changeDetector , { wrapping : false } ) ;
}
constructor (
private readonly changeDetector : ChangeDetectorRef ,
) {
super ( ) ;
}
}
public ngOnChanges ( changes : SimpleChanges ) {
public ngOnChanges ( changes : SimpleChanges ) {
@ -51,24 +51,18 @@ export class ContentValueComponent extends ResourceOwner implements OnChanges {
this . own ( this . fields ? . fieldWrappings
this . own ( this . fields ? . fieldWrappings
. subscribe ( wrappings = > {
. subscribe ( wrappings = > {
this . updateWrapping ( wrappings ) ;
const wrapping = wrappings [ this . field ? . name ! ] ;
this . next ( { wrapping } ) ;
} ) ) ;
} ) ) ;
}
}
}
}
public toggle() {
public toggle() {
this . fields ? . toggleWrapping ( this . field ? . name ) ;
if ( ! this . field ) {
}
private updateWrapping ( wrappings : FieldWrappings ) {
const wrapping = wrappings [ this . field ? . name ] ;
if ( wrapping === this . wrapping ) {
return ;
return ;
}
}
this . wrapping = wrapping ;
this . fields ? . toggleWrapping ( this . field ? . name ) ;
this . changeDetector . detectChanges ( ) ;
}
}
}
}