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 refreshInterval = 2000; // ms
19 private idl: IdlService,
20 private auth: AuthService,
21 private pcrud: PcrudService,
22 private vandelay: VandelayService
28 // Default to showing all trackers created today.
33 this.sinceDate = d.toISOString();
38 dateFilterChange(iso: string) {
41 if (this.pollTimeout) {
42 clearTimeout(this.pollTimeout);
43 this.pollTimeout = null;
52 // Report on recent trackers for this workstation and for the
53 // logged in user. Always show active trackers regardless
59 {workstation: this.auth.user().wsid()},
60 {usr: this.auth.user().id()}
64 {create_time: {'>=': this.sinceDate}},
71 this.pcrud.search('vst', query, {order_by: {vst: 'create_time'}})
74 // The screen flickers less if the tracker array is
75 // updated inline instead of rebuilt every time.
78 this.trackers.filter(t => t.id() === tracker.id())[0];
81 existing.update_time(tracker.update_time());
82 existing.state(tracker.state());
83 existing.total_actions(tracker.total_actions());
84 existing.actions_performed(tracker.actions_performed());
87 // Only show the import tracker when both an enqueue
88 // and import tracker exist for a given session.
89 const sameSes = this.trackers.filter(
90 t => t.session_key() === tracker.session_key())[0];
93 if (sameSes.action_type() === 'enqueue') {
94 // Remove the enqueueu tracker
96 for (let idx = 0; idx < this.trackers.length; idx++) {
97 const trkr = this.trackers[idx];
98 if (trkr.id() === sameSes.id()) {
100 `removing tracker ${trkr.id()} from the list`);
101 this.trackers.splice(idx, 1);
105 } else if (sameSes.action_type() === 'import') {
106 // Avoid adding the new enqueue tracker
111 console.debug(`adding tracker ${tracker.id()} to list`);
113 this.trackers.unshift(tracker);
114 this.fleshTrackerQueue(tracker);
120 this.trackers.filter(t => t.state() === 'active');
122 // Continue updating the display with updated tracker
123 // data as long as we have any active trackers.
124 if (active.length > 0) {
125 this.pollTimeout = setTimeout(
126 () => this.pollTrackers(), this.refreshInterval);
128 this.pollTimeout = null;
134 fleshTrackerQueue(tracker: IdlObject) {
135 const qClass = tracker.record_type() === 'bib' ? 'vbq' : 'vaq';
136 this.pcrud.retrieve(qClass, tracker.queue())
137 .subscribe(queue => tracker.queue(queue));