]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/grid/grid-column.component.ts
fc18fc72582f534734a60dce8dada69157002f68
[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, GridColumnSet} 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     // Display date and time when datatype = timestamp
31     @Input() datePlusTime: boolean;
32
33     // Used in conjunction with cellTemplate
34     @Input() cellContext: any;
35     @Input() cellTemplate: TemplateRef<any>;
36
37     @Input() disableTooltip: boolean;
38
39     // get a reference to our container grid.
40     constructor(@Host() private grid: GridComponent) {}
41
42     ngOnInit() {
43
44         if (!this.grid) {
45             console.warn('GridColumnComponent needs an <eg-grid>');
46             return;
47         }
48
49         const col = new GridColumn();
50         col.name = this.name;
51         col.path = this.path;
52         col.label = this.label;
53         col.flex = this.flex;
54         col.hidden = this.hidden === true;
55         col.isIndex = this.index === true;
56         col.cellTemplate = this.cellTemplate;
57         col.cellContext = this.cellContext;
58         col.disableTooltip = this.disableTooltip;
59         col.isSortable = this.sortable;
60         col.isMultiSortable = this.multiSortable;
61         col.datatype = this.datatype;
62         col.datePlusTime = this.datePlusTime;
63         col.ternaryBool = this.ternaryBool;
64         col.isAuto = false;
65         this.grid.context.columnSet.add(col);
66     }
67 }
68