]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-quality.component.ts
LP1615805 No inputs after submit in patron search (AngularJS)
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / cat / vandelay / match-set-quality.component.ts
1 import {Component, ViewChild, Input} from '@angular/core';
2 import {of} from 'rxjs';
3 import {IdlObject, IdlService} from '@eg/core/idl.service';
4 import {PcrudService} from '@eg/core/pcrud.service';
5 import {NetService} from '@eg/core/net.service';
6 import {AuthService} from '@eg/core/auth.service';
7 import {OrgService} from '@eg/core/org.service';
8 import {GridComponent} from '@eg/share/grid/grid.component';
9 import {GridDataSource} from '@eg/share/grid/grid';
10 import {Pager} from '@eg/share/util/pager';
11 import {MatchSetNewPointComponent} from './match-set-new-point.component';
12
13 @Component({
14     selector: 'eg-match-set-quality',
15     templateUrl: 'match-set-quality.component.html'
16 })
17 export class MatchSetQualityComponent {
18
19     // Match set arrives from parent async.
20     matchSet_: IdlObject;
21     @Input() set matchSet(ms: IdlObject) {
22         this.matchSet_ = ms;
23         if (ms) {
24             this.matchSetType = ms.mtype();
25             if (this.grid) {
26                 this.grid.reload();
27             }
28         }
29     }
30
31     newPointType: string;
32     matchSetType: string;
33     dataSource: GridDataSource;
34     @ViewChild('newPoint', { static: true }) newPoint: MatchSetNewPointComponent;
35     @ViewChild('grid', { static: true }) grid: GridComponent;
36     deleteSelected: (rows: IdlObject[]) => void;
37
38     constructor(
39         private idl: IdlService,
40         private pcrud: PcrudService,
41         private net: NetService,
42         private auth: AuthService,
43         private org: OrgService
44     ) {
45
46         this.dataSource = new GridDataSource();
47         this.dataSource.getRows = (pager: Pager, sort: any[]) => {
48
49             if (!this.matchSet_) {
50                 return of();
51             }
52
53             const orderBy: any = {};
54             if (sort.length) {
55                 orderBy.vmsq = sort[0].name + ' ' + sort[0].dir;
56             }
57
58             const searchOps = {
59                 offset: pager.offset,
60                 limit: pager.limit,
61                 order_by: orderBy
62             };
63
64             const search = {match_set: this.matchSet_.id()};
65             return this.pcrud.search('vmsq', search, searchOps);
66         };
67
68         this.deleteSelected = (rows: any[]) => {
69             this.pcrud.remove(rows).subscribe(
70                 ok  => console.log('deleted ', ok),
71                 (err: unknown) => console.error(err),
72                 ()  => this.grid.reload()
73             );
74         };
75     }
76
77     addQuality() {
78         const quality = this.idl.create('vmsq');
79         const values = this.newPoint.values;
80
81         quality.match_set(this.matchSet_.id());
82         quality.quality(values.matchScore);
83         quality.value(values.value);
84
85         if (values.recordAttr) {
86             quality.svf(values.recordAttr);
87         } else {
88             quality.tag(values.marcTag);
89             quality.subfield(values.marcSf);
90         }
91
92         this.pcrud.create(quality).subscribe(
93             ok  => console.debug('created ', ok),
94             (err: unknown) => console.error(err),
95             ()  => {
96                 this.newPointType = null;
97                 this.grid.reload();
98             }
99         );
100     }
101 }
102