]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts
LP 2061136 follow-up: ng lint --fix
[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     // optional initial filter values
34     @Input() initialFilterOperator: string;
35     @Input() initialFilterValue: string;
36
37     // Display date and time when datatype = timestamp
38     @Input() datePlusTime: boolean;
39
40     // Display using a specific OU's timestamp when datatype = timestamp
41     @Input() timezoneContextOrg: number;
42
43     @Input() dateOnlyIntervalField: string;
44
45     // Used in conjunction with cellTemplate
46     @Input() cellContext: any;
47     @Input() cellTemplate: TemplateRef<any>;
48
49     @Input() disableTooltip: boolean;
50     @Input() asyncSupportsEmptyTermClick: boolean;
51
52     // Required columns are those that must be present in any auto-generated
53     // queries regardless of whether they are visible in the display.
54     @Input() required = false;
55
56     // IDL class of the object which contains this field.
57     @Input() idlClass: string;
58
59     // get a reference to our container grid.
60     constructor(@Host() private grid: GridComponent) {}
61
62     ngOnInit() {
63
64         if (!this.grid) {
65             console.warn('GridColumnComponent needs an <eg-grid>');
66             return;
67         }
68
69         const col = new GridColumn();
70         col.name = this.name;
71         col.path = this.path;
72         col.label = this.label;
73         col.flex = this.flex;
74         col.required = this.required;
75         col.hidden = this.hidden === true;
76         col.asyncSupportsEmptyTermClick = this.asyncSupportsEmptyTermClick === true;
77         col.isIndex = this.index === true;
78         col.cellTemplate = this.cellTemplate;
79         col.cellContext = this.cellContext;
80         col.disableTooltip = this.disableTooltip;
81         col.isSortable = this.sortable;
82         col.isFilterable = this.filterable;
83         col.filterOperator = this.initialFilterOperator;
84         col.filterValue = this.initialFilterValue;
85         col.isMultiSortable = this.multiSortable;
86         col.datatype = this.datatype;
87         col.datePlusTime = this.datePlusTime;
88         col.ternaryBool = this.ternaryBool;
89         col.timezoneContextOrg = this.timezoneContextOrg;
90         col.dateOnlyIntervalField = this.dateOnlyIntervalField;
91         col.idlClass = this.idlClass;
92         col.dateOnlyIntervalField = this.dateOnlyIntervalField;
93         col.isAuto = false;
94
95         this.grid.context.columnSet.add(col);
96
97         if (this.cellTemplate &&
98             !this.grid.context.columnHasTextGenerator(col)) {
99             console.warn(
100                 'No cellTextGenerator provided for "' + col.name + '"');
101         }
102     }
103 }
104