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) {
58 complimentEvergreen: (rows: IdlObject[]) => void;
59 notOneSelectedRow: (rows: IdlObject[]) => boolean;
62 private idl: IdlService,
63 private org: OrgService,
64 private pcrud: PcrudService,
65 private strings: StringService,
66 private toast: ToastService,
67 private printer: PrintService
73 this.gridDataSource.data = [
74 {name: 'Jane', state: 'AZ'},
75 {name: 'Al', state: 'CA'},
76 {name: 'The Tick', state: 'TX'}
79 this.pcrud.retrieveAll('cmrcfld', {order_by: {cmrcfld: 'name'}})
80 .subscribe(format => {
81 if (!this.cbEntries) { this.cbEntries = []; }
82 this.cbEntries.push({id: format.id(), label: format.name()});
85 this.cbAsyncSource = term => {
86 return this.pcrud.search(
88 {name: {'ilike': `%${term}%`}}, // could -or search on label
89 {order_by: {cmrcfld: 'name'}}
90 ).pipe(map(marcField => {
91 return {id: marcField.id(), label: marcField.name()};
95 this.btSource.getRows = (pager: Pager, sort: any[]) => {
97 const orderBy: any = {cbt: 'name'};
99 orderBy.cbt = sort[0].name + ' ' + sort[0].dir;
102 return this.pcrud.retrieveAll('cbt', {
103 offset: pager.offset,
107 // example of inline fleshing
108 cbt.owner(this.org.get(cbt.owner()));
109 cbt.datetime_test = new Date();
115 this.complimentEvergreen = (rows: IdlObject[]) => alert('Evergreen is great!');
116 this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
120 btGridRowClassCallback(row: any): string {
121 if (row.id() === 1) {
122 return 'text-uppercase font-weight-bold text-danger';
126 btGridRowFlairCallback(row: any): GridRowFlairEntry {
127 const flair = {icon: null, title: null};
128 if (row.id() === 2) {
129 flair.icon = 'priority_high';
130 flair.title = 'I Am ID 2';
131 } else if (row.id() === 3) {
132 flair.icon = 'not_interested';
137 // apply to all 'name' columns regardless of row
138 btGridCellClassCallback(row: any, col: GridColumn): string {
139 if (col.name === 'name') {
140 if (row.id() === 7) {
141 return 'text-lowercase font-weight-bold text-info';
143 return 'text-uppercase font-weight-bold text-success';
149 template: this.printTemplate,
150 contextData: {world : this.world},
151 printContext: 'default'
155 text: '<b>hello</b>',
156 printContext: 'default'
162 console.log('HERE WITH ' + date);
163 this.testDate = date;
167 this.progressDialog.open();
169 // every 250ms emit x*10 for 0-10
170 Observable.timer(0, 250).pipe(
174 val => this.progressDialog.update({value: val, max: 100}),
176 () => this.progressDialog.close()
181 this.toast.success('HELLO TOAST TEST');
182 setTimeout(() => this.toast.danger('DANGER TEST AHHH!'), 4000);
186 this.strings.interpolate('staff.sandbox.test', {name : 'janey'})
187 .then(txt => this.toast.success(txt));
190 this.strings.interpolate('staff.sandbox.test', {name : 'johnny'})
191 .then(txt => this.toast.success(txt));