1 import {Component, OnInit, ViewChild, Input, TemplateRef} from '@angular/core';
2 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
3 import {ToastService} from '@eg/share/toast/toast.service';
4 import {StringService} from '@eg/share/string/string.service';
5 import {Observable} from 'rxjs/Observable';
6 import 'rxjs/add/observable/timer';
7 import {of} from 'rxjs';
8 import {map} from 'rxjs/operators/map';
9 import {take} from 'rxjs/operators/take';
10 import {GridDataSource, GridColumn, GridRowFlairEntry} from '@eg/share/grid/grid';
11 import {IdlService, IdlObject} from '@eg/core/idl.service';
12 import {PcrudService} from '@eg/core/pcrud.service';
13 import {OrgService} from '@eg/core/org.service';
14 import {Pager} from '@eg/share/util/pager';
15 import {DateSelectComponent} from '@eg/share/date-select/date-select.component';
16 import {PrintService} from '@eg/share/print/print.service';
17 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
20 templateUrl: 'sandbox.component.html'
22 export class SandboxComponent implements OnInit {
24 @ViewChild('progressDialog')
25 private progressDialog: ProgressDialogComponent;
27 @ViewChild('dateSelect')
28 private dateSelector: DateSelectComponent;
30 @ViewChild('printTemplate')
31 private printTemplate: TemplateRef<any>;
33 // @ViewChild('helloStr') private helloStr: StringComponent;
35 gridDataSource: GridDataSource = new GridDataSource();
37 cbEntries: ComboboxEntry[];
38 // supplier of async combobox data
39 cbAsyncSource: (term: string) => Observable<ComboboxEntry>;
41 btSource: GridDataSource = new GridDataSource();
42 world = 'world'; // for local template version
43 btGridTestContext: any = {hello : this.world};
50 @Input() set testString(str: string) {
59 private idl: IdlService,
60 private org: OrgService,
61 private pcrud: PcrudService,
62 private strings: StringService,
63 private toast: ToastService,
64 private printer: PrintService
70 this.gridDataSource.data = [
71 {name: 'Jane', state: 'AZ'},
72 {name: 'Al', state: 'CA'},
73 {name: 'The Tick', state: 'TX'}
76 this.pcrud.retrieveAll('cmrcfld', {order_by: {cmrcfld: 'name'}})
77 .subscribe(format => {
78 if (!this.cbEntries) { this.cbEntries = []; }
79 this.cbEntries.push({id: format.id(), label: format.name()});
82 this.cbAsyncSource = term => {
83 return this.pcrud.search(
85 {name: {'ilike': `%${term}%`}}, // could -or search on label
86 {order_by: {cmrcfld: 'name'}}
87 ).pipe(map(marcField => {
88 return {id: marcField.id(), label: marcField.name()};
92 this.btSource.getRows = (pager: Pager, sort: any[]) => {
94 const orderBy: any = {cbt: 'name'};
96 orderBy.cbt = sort[0].name + ' ' + sort[0].dir;
99 return this.pcrud.retrieveAll('cbt', {
100 offset: pager.offset,
104 // example of inline fleshing
105 cbt.owner(this.org.get(cbt.owner()));
106 cbt.datetime_test = new Date();
113 btGridRowClassCallback(row: any): string {
114 if (row.id() === 1) {
115 return 'text-uppercase font-weight-bold text-danger';
119 btGridRowFlairCallback(row: any): GridRowFlairEntry {
120 const flair = {icon: null, title: null};
121 if (row.id() === 2) {
122 flair.icon = 'priority_high';
123 flair.title = 'I Am ID 2';
124 } else if (row.id() === 3) {
125 flair.icon = 'not_interested';
130 // apply to all 'name' columns regardless of row
131 btGridCellClassCallback(row: any, col: GridColumn): string {
132 if (col.name === 'name') {
133 if (row.id() === 7) {
134 return 'text-lowercase font-weight-bold text-info';
136 return 'text-uppercase font-weight-bold text-success';
142 template: this.printTemplate,
143 contextData: {world : this.world},
144 printContext: 'default'
148 text: '<b>hello</b>',
149 printContext: 'default'
155 console.log('HERE WITH ' + date);
156 this.testDate = date;
160 this.progressDialog.open();
162 // every 250ms emit x*10 for 0-10
163 Observable.timer(0, 250).pipe(
167 val => this.progressDialog.update({value: val, max: 100}),
169 () => this.progressDialog.close()
174 this.toast.success('HELLO TOAST TEST');
175 setTimeout(() => this.toast.danger('DANGER TEST AHHH!'), 4000);
179 this.strings.interpolate('staff.sandbox.test', {name : 'janey'})
180 .then(txt => this.toast.success(txt));
183 this.strings.interpolate('staff.sandbox.test', {name : 'johnny'})
184 .then(txt => this.toast.success(txt));