1 import {Component, EventEmitter, Input, Output, OnChanges, OnInit, ViewChild} from '@angular/core';
2 import {Router} from '@angular/router';
3 import {Observable, from, of} from 'rxjs';
4 import {map, tap, switchMap, mergeMap} from 'rxjs/operators';
5 import {AuthService} from '@eg/core/auth.service';
6 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
7 import {FormatService} from '@eg/core/format.service';
8 import {GridComponent} from '@eg/share/grid/grid.component';
9 import {GridDataSource} from '@eg/share/grid/grid';
10 import {IdlService, IdlObject} from '@eg/core/idl.service';
11 import {EventService} from '@eg/core/event.service';
12 import {PcrudService} from '@eg/core/pcrud.service';
13 import {Pager} from '@eg/share/util/pager';
14 import {ToastService} from '@eg/share/toast/toast.service';
15 import {NetService} from '@eg/core/net.service';
16 import {OrgService} from '@eg/core/org.service';
17 import {BibRecordService, BibRecordSummary} from '@eg/share/catalog/bib-record.service';
19 // A filterable grid of A/T events for circ or ahr hook core types
22 selector: 'eg-event-grid',
23 templateUrl: './event-grid.component.html'
26 export class EventGridComponent implements OnChanges, OnInit {
28 @Input() patron: number;
29 @Input() event_type: string;
31 gridSource: GridDataSource;
32 numRowsSelected: number;
34 act_on_events: (action: string, rows: IdlObject[]) => void;
35 noRowSelected: (rows: IdlObject[]) => boolean;
37 @ViewChild('grid', { static: true }) grid: GridComponent;
40 private idl: IdlService,
41 private auth: AuthService,
42 private bib: BibRecordService,
43 private format: FormatService,
44 private pcrud: PcrudService,
45 private router: Router,
46 private toast: ToastService,
47 private net: NetService,
48 private evt: EventService,
49 private org: OrgService
55 this.gridSource = new GridDataSource();
57 this.gridSource.getRows = (pager: Pager, sort: any[]): Observable<IdlObject> => {
58 // TODO: why is this getting called twice on page load?
60 const orderBy: any = {atoul: 'id'};
62 orderBy.atoul = sort[0].name + ' ' + sort[0].dir;
65 // base query to grab everything
66 const base: Object = {};
67 base[this.idl.classes['atoul'].pkey] = {'!=' : null};
68 base['context_user'] = (this.patron ? this.patron : {'>' : 0})
71 if (this.event_type == 'circ') {
72 base['target_circ'] = { '>' : 0 }
74 base['target_hold'] = { '>' : 0 }
77 const query: any = new Array();
80 // and add any filters
81 Object.keys(this.gridSource.filters).forEach(key => {
82 Object.keys(this.gridSource.filters[key]).forEach(key2 => {
83 query.push(this.gridSource.filters[key][key2]);
87 return this.pcrud.search('atoul',
91 atoul: ['context_item', 'context_user'],
100 this.act_on_events = (action: string, rows: IdlObject[]) => {
103 'open-ils.actor.user.event.' + action + '.batch',
104 this.auth.token(), rows.map( event => event.id() )
107 if (this.evt.parse(res)) {
108 console.error('parsed error response',res);
110 console.log('success',res);
114 console.error('error',err);
117 console.log('finis');
123 this.noRowSelected = (rows: IdlObject[]) => (rows.length == 0);
126 ngOnChanges() { this.reloadGrid(); }
128 reloadGrid() { this.grid.reload(); }