2 import {timer as observableTimer, Observable, of} from 'rxjs';
3 import {Component, OnInit, ViewChild, Input, TemplateRef} from '@angular/core';
4 import {ProgressDialogComponent} from '@eg/share/dialog/progress.component';
5 import {ToastService} from '@eg/share/toast/toast.service';
6 import {StringService} from '@eg/share/string/string.service';
7 import {map, take} from 'rxjs/operators';
8 import {GridDataSource, GridColumn, GridRowFlairEntry} from '@eg/share/grid/grid';
9 import {IdlService, IdlObject} from '@eg/core/idl.service';
10 import {PcrudService} from '@eg/core/pcrud.service';
11 import {OrgService} from '@eg/core/org.service';
12 import {Pager} from '@eg/share/util/pager';
13 import {DateSelectComponent} from '@eg/share/date-select/date-select.component';
14 import {PrintService} from '@eg/share/print/print.service';
15 import {ComboboxEntry} from '@eg/share/combobox/combobox.component';
18 templateUrl: 'sandbox.component.html'
20 export class SandboxComponent implements OnInit {
22 @ViewChild('progressDialog')
23 private progressDialog: ProgressDialogComponent;
25 @ViewChild('dateSelect')
26 private dateSelector: DateSelectComponent;
28 @ViewChild('printTemplate')
29 private printTemplate: TemplateRef<any>;
31 // @ViewChild('helloStr') private helloStr: StringComponent;
33 gridDataSource: GridDataSource = new GridDataSource();
35 cbEntries: ComboboxEntry[];
36 // supplier of async combobox data
37 cbAsyncSource: (term: string) => Observable<ComboboxEntry>;
39 btSource: GridDataSource = new GridDataSource();
40 world = 'world'; // for local template version
41 btGridTestContext: any = {hello : this.world};
48 @Input() set testString(str: string) {
56 complimentEvergreen: (rows: IdlObject[]) => void;
57 notOneSelectedRow: (rows: IdlObject[]) => boolean;
60 private idl: IdlService,
61 private org: OrgService,
62 private pcrud: PcrudService,
63 private strings: StringService,
64 private toast: ToastService,
65 private printer: PrintService
71 this.gridDataSource.data = [
72 {name: 'Jane', state: 'AZ'},
73 {name: 'Al', state: 'CA'},
74 {name: 'The Tick', state: 'TX'}
77 this.pcrud.retrieveAll('cmrcfld', {order_by: {cmrcfld: 'name'}})
78 .subscribe(format => {
79 if (!this.cbEntries) { this.cbEntries = []; }
80 this.cbEntries.push({id: format.id(), label: format.name()});
83 this.cbAsyncSource = term => {
84 return this.pcrud.search(
86 {name: {'ilike': `%${term}%`}}, // could -or search on label
87 {order_by: {cmrcfld: 'name'}}
88 ).pipe(map(marcField => {
89 return {id: marcField.id(), label: marcField.name()};
93 this.btSource.getRows = (pager: Pager, sort: any[]) => {
95 const orderBy: any = {cbt: 'name'};
97 orderBy.cbt = sort[0].name + ' ' + sort[0].dir;
100 return this.pcrud.retrieveAll('cbt', {
101 offset: pager.offset,
105 // example of inline fleshing
106 cbt.owner(this.org.get(cbt.owner()));
107 cbt.datetime_test = new Date();
113 this.complimentEvergreen = (rows: IdlObject[]) => alert('Evergreen is great!');
114 this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
118 btGridRowClassCallback(row: any): string {
119 if (row.id() === 1) {
120 return 'text-uppercase font-weight-bold text-danger';
124 btGridRowFlairCallback(row: any): GridRowFlairEntry {
125 const flair = {icon: null, title: null};
126 if (row.id() === 2) {
127 flair.icon = 'priority_high';
128 flair.title = 'I Am ID 2';
129 } else if (row.id() === 3) {
130 flair.icon = 'not_interested';
135 // apply to all 'name' columns regardless of row
136 btGridCellClassCallback(row: any, col: GridColumn): string {
137 if (col.name === 'name') {
138 if (row.id() === 7) {
139 return 'text-lowercase font-weight-bold text-info';
141 return 'text-uppercase font-weight-bold text-success';
147 template: this.printTemplate,
148 contextData: {world : this.world},
149 printContext: 'default'
153 text: '<b>hello</b>',
154 printContext: 'default'
160 console.log('HERE WITH ' + date);
161 this.testDate = date;
165 this.progressDialog.open();
167 // every 250ms emit x*10 for 0-10
168 observableTimer(0, 250).pipe(
172 val => this.progressDialog.update({value: val, max: 100}),
174 () => this.progressDialog.close()
179 this.toast.success('HELLO TOAST TEST');
180 setTimeout(() => this.toast.danger('DANGER TEST AHHH!'), 4000);
184 this.strings.interpolate('staff.sandbox.test', {name : 'janey'})
185 .then(txt => this.toast.success(txt));
188 this.strings.interpolate('staff.sandbox.test', {name : 'johnny'})
189 .then(txt => this.toast.success(txt));