]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-body-cell.component.ts
Docs: merge 3.2 release notes
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-body-cell.component.ts
1 import {Component, Input, OnInit, AfterViewInit,
2     TemplateRef, ElementRef, AfterContentChecked} from '@angular/core';
3 import {GridContext, GridColumn, GridRowSelector,
4     GridColumnSet, GridDataSource} from './grid';
5
6 @Component({
7   selector: 'eg-grid-body-cell',
8   templateUrl: './grid-body-cell.component.html'
9 })
10
11 export class GridBodyCellComponent implements OnInit, AfterContentChecked {
12
13     @Input() context: GridContext;
14     @Input() row: any;
15     @Input() column: GridColumn;
16
17     initDone: boolean;
18     tooltipContent: string | TemplateRef<any>;
19
20     constructor(
21         private elm: ElementRef
22     ) {}
23
24     ngOnInit() {}
25
26     ngAfterContentChecked() {
27         this.setTooltip();
28     }
29
30     // Returns true if the contents of this cell exceed the
31     // boundaries of its container.
32     cellOverflows(): boolean {
33         let node = this.elm.nativeElement;
34         if (node) {
35             node = node.parentNode;
36             return node && (
37                 node.scrollHeight > node.clientHeight ||
38                 node.scrollWidth > node.clientWidth
39             );
40         }
41         return false;
42     }
43
44     // Tooltips are only applied to cells whose contents exceed
45     // their container.
46     // Applying an empty string value prevents a tooltip from rendering.
47     setTooltip() {
48         if (this.cellOverflows()) {
49             this.tooltipContent = this.column.cellTemplate ||
50                 this.context.getRowColumnValue(this.row, this.column);
51         } else {
52             // No tooltip
53             this.tooltipContent = '';
54         }
55     }
56 }
57