]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts
LP1835982 Remove more deprecated cellPrintValue refs
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / share / grid / grid-column.component.ts
1 import {Component, Input, OnInit, Host, TemplateRef} from '@angular/core';
2 import {GridColumn} from './grid';
3 import {GridComponent} from './grid.component';
4
5 @Component({
6   selector: 'eg-grid-column',
7   template: '<ng-template></ng-template>'
8 })
9
10 export class GridColumnComponent implements OnInit {
11
12     // Note most input fields should match class fields for GridColumn
13     @Input() name: string;
14     @Input() path: string;
15     @Input() label: string;
16     @Input() flex: number;
17     // is this the index field?
18     @Input() index: boolean;
19
20     // Columns are assumed to be visible unless hidden=true.
21     @Input() hidden: boolean;
22
23     @Input() sortable: boolean;
24     @Input() datatype: string;
25     @Input() multiSortable: boolean;
26
27     // If true, boolean fields support 3 values: true, false, null (unset)
28     @Input() ternaryBool: boolean;
29
30     // result filtering
31     @Input() filterable: boolean;
32
33     // Display date and time when datatype = timestamp
34     @Input() datePlusTime: boolean;
35
36     // Display using a specific OU's timestamp when datatype = timestamp
37     @Input() timezoneContextOrg: number;
38
39     // Used in conjunction with cellTemplate
40     @Input() cellContext: any;
41     @Input() cellTemplate: TemplateRef<any>;
42
43     @Input() disableTooltip: boolean;
44
45     // get a reference to our container grid.
46     constructor(@Host() private grid: GridComponent) {}
47
48     ngOnInit() {
49
50         if (!this.grid) {
51             console.warn('GridColumnComponent needs an <eg-grid>');
52             return;
53         }
54
55         const col = new GridColumn();
56         col.name = this.name;
57         col.path = this.path;
58         col.label = this.label;
59         col.flex = this.flex;
60         col.hidden = this.hidden === true;
61         col.isIndex = this.index === true;
62         col.cellTemplate = this.cellTemplate;
63         col.cellContext = this.cellContext;
64         col.disableTooltip = this.disableTooltip;
65         col.isSortable = this.sortable;
66         col.isFilterable = this.filterable;
67         col.isMultiSortable = this.multiSortable;
68         col.datatype = this.datatype;
69         col.datePlusTime = this.datePlusTime;
70         col.ternaryBool = this.ternaryBool;
71         col.timezoneContextOrg = this.timezoneContextOrg;
72         col.isAuto = false;
73         this.grid.context.columnSet.add(col);
74
75         if (this.cellTemplate &&
76             !this.grid.context.columnHasTextGenerator(col)) {
77             console.warn(
78                 'No cellTextGenerator provided for "' + col.name + '"');
79         }
80     }
81 }
82