import { HtmlUtils } from '../Utils/HtmlUtils' ; import { Utils } from '../Utils/Utils' ; import { HyperLinkComponent } from '../modules/detail-list-templates/hyper-link/hyper-link.component' ; import { CopyTextComponent } from '../modules/detail-list-templates/copy-text/copy-text.component' ; import { RowDisplayComponent } from '../modules/event-store/row-display/row-display.component' ; import { FullDescriptionComponent } from '../modules/event-store/full-description/full-description.component' ; import { DetailBaseComponent } from '../ViewModels/detail-table-base.component' ; import { Type } from '@angular/core' ; import { UtcTimestampComponent } from '../modules/detail-list-templates/utc-timestamp/utc-timestamp.component' ; import { ITextAndBadge } from '../Utils/ValueResolver' ; import { ShortenComponent } from '../modules/detail-list-templates/shorten/shorten.component' ; export class ListSettings { public search = '' ; public sortPropertyPaths : string [ ] = [ ] ; public sortReverse = false ; private iCurrentPage = 1 ; private iItemCount = 0 ; public get count ( ) : number { return this . iItemCount ; } public set count ( itemCount ) { this . iItemCount = itemCount ; if ( this . currentPage > this . pageCount ) { this . currentPage = this . pageCount ; } } public get hasEnabledFilters ( ) : boolean { return this . columnSettings . some ( cs => cs . config . enableFilter ) ; } public get currentPage ( ) : number { return this . iCurrentPage ; } public set currentPage ( page ) { if ( page < 1 ) { this . iCurrentPage = 1 ; } else if ( page > this . pageCount ) { if ( this . pageCount > 0 ) { this . iCurrentPage = this . pageCount ; } else { this . iCurrentPage = 1 ; } } else { this . iCurrentPage = page ; } } public get begin ( ) : number { return ( this . currentPage - 1 ) * this . limit ; } public get pageCount ( ) : number { return Math . ceil ( this . count / this . limit ) ; } public setPageWithIndex ( index ) { this . currentPage = Math . floor ( index / this . limit ) + 1 ; } param limit param defaultSortPropertyPaths param columnSettings param secondRowColumnSettings param secondRowCollapsible public constructor ( public limit , public defaultSortPropertyPaths , public tableName , public columnSettings , public secondRowColumnSettings = [ ] , public secondRowCollapsible = false , public showSecondRow = ( item ) => true , public searchable = true ) { this . sortPropertyPaths = defaultSortPropertyPaths ; } public sort ( sortPropertyPaths ) { this . sortPropertyPaths = sortPropertyPaths ; this . sortReverse = ! this . sortReverse ; } public isSortedByColumn ( columnSetting ) { return Utils . arraysAreEqual ( this . sortPropertyPaths , columnSetting . config . sortPropertyPaths ) ; } public reset ( ) { this . columnSettings . forEach ( cs => cs . reset ( ) ) ; this . search = '' ; this . sortPropertyPaths = this . defaultSortPropertyPaths ; this . sortReverse = false ; this . currentPage = 1 ; } public getPluckedObject ( item ) { if ( this . columnSettings . length > 0 ) { const newObj = { } ; Utils . unique ( this . columnSettings . concat ( this . secondRowColumnSettings ) ) . forEach ( column => newObj [ column . propertyPath ] = column . getTextValue ( item ) ) ; return newObj ; } return item ; } } export class FilterValue { public isChecked = true ; public constructor ( public value ) { } } param sortPropertyPaths param enableFilter param getDisplayHtml param colspan param clickEvent param canNotExport param alternateExportFormat export interface IListColumnAdditionalSettings { sortPropertyPaths ? : string [ ] ; enableFilter ? : boolean ; getDisplayHtml ? : ( item , property ) => string ; colspan ? : number ; clickEvent ? : ( item ) => void ; canNotExport ? : boolean ; alternateExportFormat ? : ( item ) => string ; } export interface ITemplate { template : Type < DetailBaseComponent > ; } export class ListColumnSetting { public filterValues : FilterValue [ ] = [ ] ; public fixedWidthPx ? : number ; public get hasFilters ( ) : boolean { return this . config . enableFilter && this . filterValues . length > 0 ; } public get hasEffectiveFilters ( ) : boolean { return this . filterValues . some ( filter => ! filter . isChecked ) ; } public get sortable ( ) : boolean { return this . config . sortPropertyPaths . length > 0 ; } public get allChecked ( ) { return this . filterValues . every ( val => val . isChecked ) ; } public get noneChecked ( ) { return this . filterValues . every ( val => ! val . isChecked ) ; } param propertyPath param displayName public constructor ( public propertyPath , public displayName , public config ? ) { const internalConfig = { enableFilter : false , colspan : 1 , clickEvent : ( item ) => null , canNotExport : false , sortPropertyPaths : [ propertyPath ] , ... config } ; this . config = internalConfig ; } public reset ( ) { this . filterValues . forEach ( filter => filter . isChecked = true ) ; } public getProperty ( item ) { if ( this . propertyPath && this . propertyPath . startsWith ( '#' ) ) { return this . propertyPath . substr ( 1 ) ; } return Utils . result ( item , this . propertyPath ) ; } public isBadge ( item ) { return Utils . isBadge ( item ) ; } public getTextValue ( item ) { const property = this . getProperty ( item ) ; if ( property === undefined || property === null ) { return '' ; } return property . toString ( ) ; } public getDisplayContentsInHtml ( item ) { const property = this . getProperty ( item ) ; if ( this . config . getDisplayHtml ) { return this . config . getDisplayHtml ( item , property ) ; } if ( property === undefined || property === null ) { return '' ; } return property . toString ( ) ; } checkAll ( ) { this . filterValues . forEach ( value => { value . isChecked = true ; } ) ; } uncheckAll ( ) { this . filterValues . forEach ( value => { value . isChecked = false ; } ) ; } getValue ( item ) { return Utils . result ( item , this . propertyPath ) ; } } export class ListColumnSettingForBadge extends ListColumnSetting { public constructor ( propertyPath , displayName ) { super ( propertyPath , displayName , { enableFilter : true , sortPropertyPaths : [ propertyPath + '.text' ] , getDisplayHtml : ( item , property ) => HtmlUtils . getBadgeHtml ( property ) , alternateExportFormat : ( item ) => item . text } ) ; } public getTextValue ( item ) { const property = this . getProperty ( item ) ; if ( property ) { return property . text ; } return '' ; } } export class ListColumnSettingWithFilter extends ListColumnSetting { public constructor ( propertyPath , displayName , config ? ) { super ( propertyPath , displayName , { enableFilter : true , ... config } ) ; } } export class ListColumnSettingForLink extends ListColumnSetting { template = HyperLinkComponent ; public constructor ( propertyPath , displayName , public href ) { super ( propertyPath , displayName , { enableFilter : false , } ) ; } } export class ListColumnSettingWithCopyText extends ListColumnSetting { template = CopyTextComponent ; public constructor ( propertyPath , displayName , config ? ) { super ( propertyPath , displayName , config ) ; } } export class ListColumnSettingWithUtcTime extends ListColumnSetting { template = UtcTimestampComponent ; public constructor ( propertyPath , displayName , config ? ) { super ( propertyPath , displayName , config ) ; } } export class ListColumnSettingWithEventStoreRowDisplay extends ListColumnSetting implements ITemplate { template = RowDisplayComponent ; public constructor ( ) { super ( 'raw.kind' , 'Type' , { enableFilter : true } ) ; } } export class ListColumnSettingWithEventStoreFullDescription extends ListColumnSetting implements ITemplate { template = FullDescriptionComponent ; public constructor ( ) { super ( 'raw.eventInstanceId' , '' , { colspan : - 1 , enableFilter : false } ) ; } } export class ListColumnSettingWithCustomComponent extends ListColumnSetting implements ITemplate { public constructor ( public template , public propertyPath = '' , public displayName = '' , config ? ) { super ( propertyPath , displayName , config ) ; } } export class ListColumnSettingWithShorten extends ListColumnSetting { template = ShortenComponent ; public constructor ( propertyPath , displayName , public maxWidth , config ? ) { super ( propertyPath , displayName , config ) ; } }