import { Injectable , OnDestroy , QueryList } from '@angular/core' ; import { BehaviorSubject , Subject } from 'rxjs' ; import { ResizableTableColumnComponent } from './resizable-table-column.component' ; @ Injectable ( ) export abstract class BaseResizableTableService implements OnDestroy { abstract type : ResizableTableType ; /** Emit an event whenever a column is resized */ onResize$ = new Subject < void > ( ) ; /** Store the current width of the table */ tableWidth : number = 0 ; /** Determine if we are currently resizing */ isResizing$ = new BehaviorSubject < boolean > ( false ) ; /** Indicate when the columns are ready */ isInitialised$ = new BehaviorSubject < boolean > ( false ) ; /** Store the percentage widths of each column */ columns : ReadonlyArray < number > = [ ] ; abstract resizeColumn ( index , delta , isDragging ? ) ; abstract setColumns ( columns ) ; abstract setUniformWidths ( ) ; abstract getColumnDisabled ( index ) ; /** Cleanup when service is disposed */ ngOnDestroy ( ) { this . onResize$ . complete ( ) ; } /** Update the resizing state */ setResizing ( isResizing ) { this . isResizing$ . next ( isResizing ) ; } /** Get the width of a column in a specific unit */ getColumnWidth ( index , unit , columns = this . columns ) { switch ( unit ) { case ColumnUnit . Percentage : return columns [ index ] ; case ColumnUnit . Pixel : return ( this . tableWidth / 100 ) * columns [ index ] ; } } } export enum ColumnUnit { Pixel , Percentage } export enum ResizableTableType { Standard , Expand }