import { CommonUtils } from '@farris/ui-common'; import { TreeNode } from './types/treenode'; import { Pipe, PipeTransform } from '@angular/core'; import { TreeTableColumn } from './types/treetable-column'; @Pipe({name: 'tipmsg'}) export class CellTipsPipe implements PipeTransform { constructor(private commonUtils: CommonUtils) {} transform(col: any, ...args: any[]): any { if (col.showTips) { return this.getCellTooltipContent(col, args[0]); } return ''; } private getCellTooltipContent(col: TreeTableColumn, tn: TreeNode) { let txt = this.commonUtils.getValue(col.field, tn.data); if (col.tipContent) { if ( typeof col.tipContent === 'string') { txt = col.tipContent; } else if (typeof col.tipContent === 'function') { txt = col.tipContent(txt, tn.data, col); } } else { if (col.formatter) { if (typeof col.formatter === 'object') { if (col.formatter.type === 'enum') { txt = this.commonUtils.getEnumTitleFromColumnOptions(txt, col.formatter.options); } } } } return txt; } }