@@ -7,6 +7,8 @@ import { TemplateCellCommon } from '../../directives/rows/template-cell.common';
77import { TemplateHeadThDirective } from '../../directives/rows/template-head-th.directive' ;
88import { ColumnsSchema , ImplicitContext , TableCellOptions } from '../../interfaces/table-builder.external' ;
99import { KeyMap , QueryListRef } from '../../interfaces/table-builder.internal' ;
10+ import { getValidHtmlBooleanAttribute } from '../../operators/get-valid-html-boolean-attribute' ;
11+ import { getValidPredicate } from '../../operators/get-valid-predicate' ;
1012import { SchemaBuilder } from './schema-builder.class' ;
1113
1214@Injectable ( )
@@ -53,21 +55,11 @@ export class TemplateParserService {
5355 onClick : cell . onClick ,
5456 dblClick : cell . dblClick ,
5557 useDeepPath : key . includes ( '.' ) ,
56- context : TemplateParserService . getValidHtmlBooleanAttribute ( cell . row )
57- ? ImplicitContext . ROW
58- : ImplicitContext . CELL ,
59- nowrap : TemplateParserService . getValidPredicate ( options . nowrap , cell . nowrap )
58+ context : getValidHtmlBooleanAttribute ( cell . row ) ? ImplicitContext . ROW : ImplicitContext . CELL ,
59+ nowrap : getValidHtmlBooleanAttribute ( getValidPredicate ( options . nowrap , cell . nowrap ) )
6060 } ;
6161 }
6262
63- private static getValidHtmlBooleanAttribute ( attribute : boolean ) : boolean {
64- return typeof attribute === 'string' ? true : attribute ;
65- }
66-
67- private static getValidPredicate < T > ( leftPredicate : T , rightPredicate : T ) : T {
68- return leftPredicate === null ? rightPredicate : leftPredicate ;
69- }
70-
7163 public toggleColumnVisibility ( key : string ) : void {
7264 this . schema . columns = this . schema . columns . map (
7365 ( column : ColumnsSchema ) : ColumnsSchema =>
@@ -128,10 +120,10 @@ export class TemplateParserService {
128120 const { key, th, td, emptyHead, headTitle } : NgxColumnComponent = column ;
129121 const thTemplate : TemplateCellCommon = th || new TemplateHeadThDirective ( null ) ;
130122 const tdTemplate : TemplateCellCommon = td || new TemplateBodyTdDirective ( null ) ;
131- const isEmptyHead : boolean = TemplateParserService . getValidHtmlBooleanAttribute ( emptyHead ) ;
123+ const isEmptyHead : boolean = getValidHtmlBooleanAttribute ( emptyHead ) ;
132124 const thOptions : TableCellOptions = TemplateParserService . templateContext ( key , thTemplate , this . columnOptions ) ;
133- const stickyLeft : boolean = TemplateParserService . getValidHtmlBooleanAttribute ( column . stickyLeft ) ;
134- const stickyRight : boolean = TemplateParserService . getValidHtmlBooleanAttribute ( column . stickyRight ) ;
125+ const stickyLeft : boolean = getValidHtmlBooleanAttribute ( column . stickyLeft ) ;
126+ const stickyRight : boolean = getValidHtmlBooleanAttribute ( column . stickyRight ) ;
135127 const canBeAddDraggable : boolean = ! ( stickyLeft || stickyRight ) ;
136128 const isModel : boolean = this . keyMap [ key ] ;
137129
@@ -140,26 +132,29 @@ export class TemplateParserService {
140132 isModel,
141133 isVisible : true ,
142134 excluded : ! this . allowedKeyMap [ key ] ,
143- verticalLine : TemplateParserService . getValidHtmlBooleanAttribute ( column . verticalLine ) ,
135+ verticalLine : getValidHtmlBooleanAttribute ( column . verticalLine ) ,
144136 td : TemplateParserService . templateContext ( key , tdTemplate , this . columnOptions ) ,
145- stickyLeft : TemplateParserService . getValidHtmlBooleanAttribute ( column . stickyLeft ) ,
146- stickyRight : TemplateParserService . getValidHtmlBooleanAttribute ( column . stickyRight ) ,
147- customColumn : TemplateParserService . getValidHtmlBooleanAttribute ( column . customKey ) ,
148- width : TemplateParserService . getValidPredicate ( column . width , this . columnOptions . width ) ,
149- cssClass : TemplateParserService . getValidPredicate ( column . cssClass , this . columnOptions . cssClass ) || [ ] ,
150- cssStyle : TemplateParserService . getValidPredicate ( column . cssStyle , this . columnOptions . cssStyle ) || [ ] ,
151- resizable : TemplateParserService . getValidPredicate ( column . resizable , this . columnOptions . resizable ) ,
152- stub : TemplateParserService . getValidPredicate ( this . columnOptions . stub , column . stub ) ,
153- filterable : TemplateParserService . getValidPredicate ( column . filterable , this . columnOptions . filterable ) ,
137+ stickyLeft : getValidHtmlBooleanAttribute ( column . stickyLeft ) ,
138+ stickyRight : getValidHtmlBooleanAttribute ( column . stickyRight ) ,
139+ customColumn : getValidHtmlBooleanAttribute ( column . customKey ) ,
140+ width : getValidPredicate ( column . width , this . columnOptions . width ) ,
141+ cssClass : getValidPredicate ( column . cssClass , this . columnOptions . cssClass ) || [ ] ,
142+ cssStyle : getValidPredicate ( column . cssStyle , this . columnOptions . cssStyle ) || [ ] ,
143+ resizable : getValidHtmlBooleanAttribute (
144+ getValidPredicate ( column . isDraggable , this . columnOptions . isDraggable )
145+ ) ,
146+ stub : getValidPredicate ( this . columnOptions . stub , column . stub ) ,
147+ filterable : getValidHtmlBooleanAttribute (
148+ getValidPredicate ( column . isFilterable , this . columnOptions . isFilterable )
149+ ) ,
154150 sortable : isModel
155- ? TemplateParserService . getValidPredicate ( column . sortable , this . columnOptions . sortable )
151+ ? getValidHtmlBooleanAttribute ( getValidPredicate ( column . isSortable , this . columnOptions . isSortable ) )
156152 : false ,
157153 draggable : canBeAddDraggable
158- ? TemplateParserService . getValidPredicate ( column . draggable , this . columnOptions . draggable )
154+ ? getValidHtmlBooleanAttribute ( getValidPredicate ( column . isDraggable , this . columnOptions . isDraggable ) )
159155 : false ,
160- overflowTooltip : TemplateParserService . getValidPredicate (
161- this . columnOptions . overflowTooltip ,
162- column . overflowTooltip
156+ overflowTooltip : getValidHtmlBooleanAttribute (
157+ getValidPredicate ( this . columnOptions . overflowTooltip , column . overflowTooltip )
163158 ) ,
164159 th : {
165160 ...thOptions ,
0 commit comments