]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts
LP2061136 - Stamping 1405 DB upgrade script
[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     // Used in conjunction with cellTemplate
44     @Input() cellContext: any;
45     @Input() cellTemplate: TemplateRef<any>;
46
47     @Input() disableTooltip: boolean;
48     @Input() asyncSupportsEmptyTermClick: boolean;
49
50     // get a reference to our container grid.
51     constructor(@Host() private grid: GridComponent) {}
52
53     ngOnInit() {
54
55         if (!this.grid) {
56             console.warn('GridColumnComponent needs an <eg-grid>');
57             return;
58         }
59
60         const col = new GridColumn();
61         col.name = this.name;
62         col.path = this.path;
63         col.label = this.label;
64         col.flex = this.flex;
65         col.hidden = this.hidden === true;
66         col.asyncSupportsEmptyTermClick = this.asyncSupportsEmptyTermClick === true;
67         col.isIndex = this.index === true;
68         col.cellTemplate = this.cellTemplate;
69         col.cellContext = this.cellContext;
70         col.disableTooltip = this.disableTooltip;
71         col.isSortable = this.sortable;
72         col.isFilterable = this.filterable;
73         col.filterOperator = this.initialFilterOperator;
74         col.filterValue = this.initialFilterValue;
75         col.isMultiSortable = this.multiSortable;
76         col.datatype = this.datatype;
77         col.datePlusTime = this.datePlusTime;
78         col.ternaryBool = this.ternaryBool;
79         col.timezoneContextOrg = this.timezoneContextOrg;
80         col.isAuto = false;
81         this.grid.context.columnSet.add(col);
82
83         if (this.cellTemplate &&
84             !this.grid.context.columnHasTextGenerator(col)) {
85             console.warn(
86                 'No cellTextGenerator provided for "' + col.name + '"');
87         }
88     }
89 }
90