import { FormGroup } from '@angular/forms' ; import cloneDeep from 'lodash.clonedeep' ; import { TableDataSource } from './table-data-source' ; export abstract class TableElement < T > { id : number ; editing : boolean ; currentData : T ; originalData ? : T ; source : TableDataSource < T > ; abstract get validator ( ) : FormGroup ; abstract set validator ( validator ) ; delete ( ) { this . source . delete ( this . id ) ; } confirmEditCreate ( ) { if ( this . id == - 1 ) return this . source . confirmCreate ( this ) ; else return this . source . confirmEdit ( this ) ; } startEdit ( ) { this . originalData = cloneDeep ( this . currentData ) ; this . editing = true ; } cancelOrDelete ( ) { if ( this . id == - 1 || ! this . editing ) this . delete ( ) ; else { this . currentData = this . originalData ; this . editing = false ; } } abstract isValid ( ) ; }