1 import {Component, OnInit} from '@angular/core';
2 import {IdlService, IdlObject} from '@eg/core/idl.service';
3 import {AuthService} from '@eg/core/auth.service';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {VandelayService} from './vandelay.service';
8 templateUrl: 'recent-imports.component.html'
11 export class RecentImportsComponent implements OnInit {
13 trackers: IdlObject[];
14 // eslint-disable-next-line no-magic-numbers
15 refreshInterval = 2000; // ms
20 private idl: IdlService,
21 private auth: AuthService,
22 private pcrud: PcrudService,
23 private vandelay: VandelayService
29 // Default to showing all trackers created today.
34 this.sinceDate = d.toISOString();
39 dateFilterChange(iso: string) {
42 if (this.pollTimeout) {
43 clearTimeout(this.pollTimeout);
44 this.pollTimeout = null;
53 // Report on recent trackers for this workstation and for the
54 // logged in user. Always show active trackers regardless
60 {workstation: this.auth.user().wsid()},
61 {usr: this.auth.user().id()}
65 {create_time: {'>=': this.sinceDate}},
72 this.pcrud.search('vst', query, {order_by: {vst: 'create_time'}})
75 // The screen flickers less if the tracker array is
76 // updated inline instead of rebuilt every time.
79 this.trackers.filter(t => t.id() === tracker.id())[0];
82 existing.update_time(tracker.update_time());
83 existing.state(tracker.state());
84 existing.total_actions(tracker.total_actions());
85 existing.actions_performed(tracker.actions_performed());
88 // Only show the import tracker when both an enqueue
89 // and import tracker exist for a given session.
90 const sameSes = this.trackers.filter(
91 t => t.session_key() === tracker.session_key())[0];
94 if (sameSes.action_type() === 'enqueue') {
95 // Remove the enqueueu tracker
97 for (let idx = 0; idx < this.trackers.length; idx++) {
98 const trkr = this.trackers[idx];
99 if (trkr.id() === sameSes.id()) {
101 `removing tracker ${trkr.id()} from the list`);
102 this.trackers.splice(idx, 1);
106 } else if (sameSes.action_type() === 'import') {
107 // Avoid adding the new enqueue tracker
112 console.debug(`adding tracker ${tracker.id()} to list`);
114 this.trackers.unshift(tracker);
115 this.fleshTrackerQueue(tracker);
118 (err: unknown) => {},
121 this.trackers.filter(t => t.state() === 'active');
123 // Continue updating the display with updated tracker
124 // data as long as we have any active trackers.
125 if (active.length > 0) {
126 this.pollTimeout = setTimeout(
127 () => this.pollTrackers(), this.refreshInterval);
129 this.pollTimeout = null;
135 fleshTrackerQueue(tracker: IdlObject) {
136 const qClass = tracker.record_type() === 'bib' ? 'vbq' : 'vaq';
137 this.pcrud.retrieve(qClass, tracker.queue())
138 .subscribe(queue => tracker.queue(queue));