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';
17 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.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('fmRecordEditor')
34 private fmRecordEditor: FmRecordEditorComponent;
36 // @ViewChild('helloStr') private helloStr: StringComponent;
38 gridDataSource: GridDataSource = new GridDataSource();
40 cbEntries: ComboboxEntry[];
41 // supplier of async combobox data
42 cbAsyncSource: (term: string) => Observable<ComboboxEntry>;
44 btSource: GridDataSource = new GridDataSource();
45 world = 'world'; // for local template version
46 btGridTestContext: any = {hello : this.world};
53 @Input() set testString(str: string) {
61 dynamicTitleText: string;
63 complimentEvergreen: (rows: IdlObject[]) => void;
64 notOneSelectedRow: (rows: IdlObject[]) => boolean;
66 // selector field value on metarecord object
70 private idl: IdlService,
71 private org: OrgService,
72 private pcrud: PcrudService,
73 private strings: StringService,
74 private toast: ToastService,
75 private format: FormatService,
76 private printer: PrintService
82 this.gridDataSource.data = [
83 {name: 'Jane', state: 'AZ'},
84 {name: 'Al', state: 'CA'},
85 {name: 'The Tick', state: 'TX'}
88 this.pcrud.retrieveAll('cmrcfld', {order_by: {cmrcfld: 'name'}})
89 .subscribe(format => {
90 if (!this.cbEntries) { this.cbEntries = []; }
91 this.cbEntries.push({id: format.id(), label: format.name()});
94 this.cbAsyncSource = term => {
95 return this.pcrud.search(
97 {name: {'ilike': `%${term}%`}}, // could -or search on label
98 {order_by: {cmrcfld: 'name'}}
99 ).pipe(map(marcField => {
100 return {id: marcField.id(), label: marcField.name()};
104 this.btSource.getRows = (pager: Pager, sort: any[]) => {
106 const orderBy: any = {cbt: 'name'};
108 orderBy.cbt = sort[0].name + ' ' + sort[0].dir;
111 return this.pcrud.retrieveAll('cbt', {
112 offset: pager.offset,
116 // example of inline fleshing
117 cbt.owner(this.org.get(cbt.owner()));
118 cbt.datetime_test = new Date();
124 this.complimentEvergreen = (rows: IdlObject[]) => alert('Evergreen is great!');
125 this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
127 this.pcrud.retrieve('bre', 1, {}, {fleshSelectors: true})
129 // Format service will automatically find the selector
130 // value to display from our fleshed metarecord field.
131 this.aMetarecord = this.format.transform({
132 value: bib.metarecord(),
134 idlField: 'metarecord'
140 this.fmRecordEditor.open({size: 'lg'}).then(
141 ok => { console.debug(ok); },
143 if (err && err.dismissed) {
144 console.debug('dialog was dismissed');
152 btGridRowClassCallback(row: any): string {
153 if (row.id() === 1) {
154 return 'text-uppercase font-weight-bold text-danger';
158 btGridRowFlairCallback(row: any): GridRowFlairEntry {
159 const flair = {icon: null, title: null};
160 if (row.id() === 2) {
161 flair.icon = 'priority_high';
162 flair.title = 'I Am ID 2';
163 } else if (row.id() === 3) {
164 flair.icon = 'not_interested';
169 // apply to all 'name' columns regardless of row
170 btGridCellClassCallback(row: any, col: GridColumn): string {
171 if (col.name === 'name') {
172 if (row.id() === 7) {
173 return 'text-lowercase font-weight-bold text-info';
175 return 'text-uppercase font-weight-bold text-success';
181 template: this.printTemplate,
182 contextData: {world : this.world},
183 printContext: 'default'
187 text: '<b>hello</b>',
188 printContext: 'default'
194 console.log('HERE WITH ' + date);
195 this.testDate = date;
199 this.progressDialog.open();
201 // every 250ms emit x*10 for 0-10
202 observableTimer(0, 250).pipe(
206 val => this.progressDialog.update({value: val, max: 100}),
208 () => this.progressDialog.close()
213 this.toast.success('HELLO TOAST TEST');
214 setTimeout(() => this.toast.danger('DANGER TEST AHHH!'), 4000);
218 this.strings.interpolate('staff.sandbox.test', {name : 'janey'})
219 .then(txt => this.toast.success(txt));
222 this.strings.interpolate('staff.sandbox.test', {name : 'johnny'})
223 .then(txt => this.toast.success(txt));