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';
16 import {FormatService} from '@eg/core/format.service';
19 templateUrl: 'sandbox.component.html'
21 export class SandboxComponent implements OnInit {
23 @ViewChild('progressDialog')
24 private progressDialog: ProgressDialogComponent;
26 @ViewChild('dateSelect')
27 private dateSelector: DateSelectComponent;
29 @ViewChild('printTemplate')
30 private printTemplate: TemplateRef<any>;
32 // @ViewChild('helloStr') private helloStr: StringComponent;
34 gridDataSource: GridDataSource = new GridDataSource();
36 cbEntries: ComboboxEntry[];
37 // supplier of async combobox data
38 cbAsyncSource: (term: string) => Observable<ComboboxEntry>;
40 btSource: GridDataSource = new GridDataSource();
41 world = 'world'; // for local template version
42 btGridTestContext: any = {hello : this.world};
49 @Input() set testString(str: string) {
57 dynamicTitleText: string;
59 complimentEvergreen: (rows: IdlObject[]) => void;
60 notOneSelectedRow: (rows: IdlObject[]) => boolean;
62 // selector field value on metarecord object
66 private idl: IdlService,
67 private org: OrgService,
68 private pcrud: PcrudService,
69 private strings: StringService,
70 private toast: ToastService,
71 private format: FormatService,
72 private printer: PrintService
78 this.gridDataSource.data = [
79 {name: 'Jane', state: 'AZ'},
80 {name: 'Al', state: 'CA'},
81 {name: 'The Tick', state: 'TX'}
84 this.pcrud.retrieveAll('cmrcfld', {order_by: {cmrcfld: 'name'}})
85 .subscribe(format => {
86 if (!this.cbEntries) { this.cbEntries = []; }
87 this.cbEntries.push({id: format.id(), label: format.name()});
90 this.cbAsyncSource = term => {
91 return this.pcrud.search(
93 {name: {'ilike': `%${term}%`}}, // could -or search on label
94 {order_by: {cmrcfld: 'name'}}
95 ).pipe(map(marcField => {
96 return {id: marcField.id(), label: marcField.name()};
100 this.btSource.getRows = (pager: Pager, sort: any[]) => {
102 const orderBy: any = {cbt: 'name'};
104 orderBy.cbt = sort[0].name + ' ' + sort[0].dir;
107 return this.pcrud.retrieveAll('cbt', {
108 offset: pager.offset,
112 // example of inline fleshing
113 cbt.owner(this.org.get(cbt.owner()));
114 cbt.datetime_test = new Date();
120 this.complimentEvergreen = (rows: IdlObject[]) => alert('Evergreen is great!');
121 this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
123 this.pcrud.retrieve('bre', 1, {}, {fleshSelectors: true})
125 // Format service will automatically find the selector
126 // value to display from our fleshed metarecord field.
127 this.aMetarecord = this.format.transform({
128 value: bib.metarecord(),
130 idlField: 'metarecord'
135 btGridRowClassCallback(row: any): string {
136 if (row.id() === 1) {
137 return 'text-uppercase font-weight-bold text-danger';
141 btGridRowFlairCallback(row: any): GridRowFlairEntry {
142 const flair = {icon: null, title: null};
143 if (row.id() === 2) {
144 flair.icon = 'priority_high';
145 flair.title = 'I Am ID 2';
146 } else if (row.id() === 3) {
147 flair.icon = 'not_interested';
152 // apply to all 'name' columns regardless of row
153 btGridCellClassCallback(row: any, col: GridColumn): string {
154 if (col.name === 'name') {
155 if (row.id() === 7) {
156 return 'text-lowercase font-weight-bold text-info';
158 return 'text-uppercase font-weight-bold text-success';
164 template: this.printTemplate,
165 contextData: {world : this.world},
166 printContext: 'default'
170 text: '<b>hello</b>',
171 printContext: 'default'
177 console.log('HERE WITH ' + date);
178 this.testDate = date;
182 this.progressDialog.open();
184 // every 250ms emit x*10 for 0-10
185 observableTimer(0, 250).pipe(
189 val => this.progressDialog.update({value: val, max: 100}),
191 () => this.progressDialog.close()
196 this.toast.success('HELLO TOAST TEST');
197 setTimeout(() => this.toast.danger('DANGER TEST AHHH!'), 4000);
201 this.strings.interpolate('staff.sandbox.test', {name : 'janey'})
202 .then(txt => this.toast.success(txt));
205 this.strings.interpolate('staff.sandbox.test', {name : 'johnny'})
206 .then(txt => this.toast.success(txt));