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
69 // cross-tab communications example
70 private sbChannel: any;
71 sbChannelText: string;
74 private idl: IdlService,
75 private org: OrgService,
76 private pcrud: PcrudService,
77 private strings: StringService,
78 private toast: ToastService,
79 private format: FormatService,
80 private printer: PrintService
82 // BroadcastChannel is not yet defined in PhantomJS and elsewhere
83 this.sbChannel = (typeof BroadcastChannel === 'undefined') ?
84 {} : new BroadcastChannel('eg.sbChannel');
85 this.sbChannel.onmessage = (e) => this.sbChannelHandler(e);
90 this.gridDataSource.data = [
91 {name: 'Jane', state: 'AZ'},
92 {name: 'Al', state: 'CA'},
93 {name: 'The Tick', state: 'TX'}
96 this.pcrud.retrieveAll('cmrcfld', {order_by: {cmrcfld: 'name'}})
97 .subscribe(format => {
98 if (!this.cbEntries) { this.cbEntries = []; }
99 this.cbEntries.push({id: format.id(), label: format.name()});
102 this.cbAsyncSource = term => {
103 return this.pcrud.search(
105 {name: {'ilike': `%${term}%`}}, // could -or search on label
106 {order_by: {cmrcfld: 'name'}}
107 ).pipe(map(marcField => {
108 return {id: marcField.id(), label: marcField.name()};
112 this.btSource.getRows = (pager: Pager, sort: any[]) => {
114 const orderBy: any = {cbt: 'name'};
116 orderBy.cbt = sort[0].name + ' ' + sort[0].dir;
119 return this.pcrud.retrieveAll('cbt', {
120 offset: pager.offset,
124 // example of inline fleshing
125 cbt.owner(this.org.get(cbt.owner()));
126 cbt.datetime_test = new Date();
132 this.complimentEvergreen = (rows: IdlObject[]) => alert('Evergreen is great!');
133 this.notOneSelectedRow = (rows: IdlObject[]) => (rows.length !== 1);
135 this.pcrud.retrieve('bre', 1, {}, {fleshSelectors: true})
137 // Format service will automatically find the selector
138 // value to display from our fleshed metarecord field.
139 this.aMetarecord = this.format.transform({
140 value: bib.metarecord(),
142 idlField: 'metarecord'
147 sbChannelHandler = msg => {
148 setTimeout(() => { this.sbChannelText = msg.data.msg; });
151 sendMessage($event) {
152 this.sbChannel.postMessage({msg : $event.target.value});
155 // Example of click handler for row action
156 complimentEvergreen2(rows: IdlObject[]) {
157 alert('I know, right?');
161 this.fmRecordEditor.open({size: 'lg'}).then(
162 ok => { console.debug(ok); },
164 if (err && err.dismissed) {
165 console.debug('dialog was dismissed');
173 btGridRowClassCallback(row: any): string {
174 if (row.id() === 1) {
175 return 'text-uppercase font-weight-bold text-danger';
179 btGridRowFlairCallback(row: any): GridRowFlairEntry {
180 const flair = {icon: null, title: null};
181 if (row.id() === 2) {
182 flair.icon = 'priority_high';
183 flair.title = 'I Am ID 2';
184 } else if (row.id() === 3) {
185 flair.icon = 'not_interested';
190 // apply to all 'name' columns regardless of row
191 btGridCellClassCallback(row: any, col: GridColumn): string {
192 if (col.name === 'name') {
193 if (row.id() === 7) {
194 return 'text-lowercase font-weight-bold text-info';
196 return 'text-uppercase font-weight-bold text-success';
202 template: this.printTemplate,
203 contextData: {world : this.world},
204 printContext: 'default'
208 text: '<b>hello</b>',
209 printContext: 'default'
215 template: this.printTemplate,
216 contextData: {world : this.world},
217 printContext: 'default',
223 console.log('HERE WITH ' + date);
224 this.testDate = date;
228 this.progressDialog.open();
230 // every 250ms emit x*10 for 0-10
231 observableTimer(0, 250).pipe(
235 val => this.progressDialog.update({value: val, max: 100}),
237 () => this.progressDialog.close()
242 this.toast.success('HELLO TOAST TEST');
243 setTimeout(() => this.toast.danger('DANGER TEST AHHH!'), 4000);
247 this.strings.interpolate('staff.sandbox.test', {name : 'janey'})
248 .then(txt => this.toast.success(txt));
251 this.strings.interpolate('staff.sandbox.test', {name : 'johnny'})
252 .then(txt => this.toast.success(txt));