d72a81bfa841d4b82d50ed817bf1e831c65258cd
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / cat / vandelay / queue-items.component.ts
1 import {Component, OnInit, ViewChild} from '@angular/core';
2 import {Observable} from 'rxjs/Observable';
3 import 'rxjs/add/observable/of';
4 import {map} from 'rxjs/operators/map';
5 import {Router, ActivatedRoute, ParamMap} from '@angular/router';              
6 import {Pager} from '@eg/share/util/pager';                                    
7 import {IdlObject} from '@eg/core/idl.service';
8 import {NetService} from '@eg/core/net.service';
9 import {AuthService} from '@eg/core/auth.service';
10 import {GridComponent} from '@eg/share/grid/grid.component';
11 import {GridDataSource} from '@eg/share/grid/grid';
12 import {VandelayService} from './vandelay.service';
13
14 @Component({
15   templateUrl: 'queue-items.component.html'
16 })
17 export class QueueItemsComponent {
18
19     queueType: string;
20     queueId: number;
21     filterImportErrors: boolean;
22     limitToImportErrors: (checked: boolean) => void;
23
24     gridSource: GridDataSource;
25     @ViewChild('itemsGrid') itemsGrid: GridComponent;
26
27     constructor(
28         private router: Router,
29         private route: ActivatedRoute,
30         private net: NetService,
31         private auth: AuthService,
32         private vandelay: VandelayService) {
33
34         this.route.paramMap.subscribe((params: ParamMap) => {                  
35             this.queueId = +params.get('id');
36             this.queueType = params.get('qtype');
37         });
38
39         this.gridSource = new GridDataSource();
40
41         // queue API does not support sorting
42         this.gridSource.getRows = (pager: Pager) => {
43             return this.net.request(
44                 'open-ils.vandelay',
45                 'open-ils.vandelay.import_item.queue.retrieve',
46                 this.auth.token(), this.queueId, {
47                     with_import_error: this.filterImportErrors,
48                     offset: pager.offset,
49                     limit: pager.limit
50                 }
51             );
52         };
53
54         this.limitToImportErrors = (checked: boolean) => {
55             this.filterImportErrors = checked;
56             this.itemsGrid.reload();
57         }
58     }
59 }
60