]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/cat/vandelay/match-set-list.component.ts
LP1615805 No inputs after submit in patron search (AngularJS)
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / cat / vandelay / match-set-list.component.ts
1 import {Component, AfterViewInit, ViewChild} from '@angular/core';
2 import {Router} from '@angular/router';
3 import {Pager} from '@eg/share/util/pager';
4 import {IdlObject} from '@eg/core/idl.service';
5 import {PcrudService} from '@eg/core/pcrud.service';
6 import {OrgService} from '@eg/core/org.service';
7 import {AuthService} from '@eg/core/auth.service';
8 import {GridComponent} from '@eg/share/grid/grid.component';
9 import {GridDataSource, GridCellTextGenerator} from '@eg/share/grid/grid';
10 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
11
12 @Component({
13     templateUrl: 'match-set-list.component.html'
14 })
15 export class MatchSetListComponent implements AfterViewInit {
16
17     contextOrg: IdlObject;
18     gridSource: GridDataSource;
19     deleteSelected: (rows: IdlObject[]) => void;
20     createNew: () => void;
21     @ViewChild('grid', { static: true }) grid: GridComponent;
22     @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
23
24     cellTextGenerator: GridCellTextGenerator;
25
26     constructor(
27         private router: Router,
28         private pcrud: PcrudService,
29         private auth: AuthService,
30         private org: OrgService) {
31
32         this.gridSource = new GridDataSource();
33         this.contextOrg = this.org.get(this.auth.user().ws_ou());
34
35         this.gridSource.getRows = (pager: Pager) => {
36             const orgs = this.org.ancestors(this.contextOrg, true);
37             return this.pcrud.search('vms', {owner: orgs}, {
38                 order_by: {vms: ['name']},
39                 limit: pager.limit,
40                 offset: pager.offset
41             });
42         };
43
44         this.cellTextGenerator = {
45             name: row => row.name()
46         };
47
48         this.createNew = () => {
49             this.editDialog.mode = 'create';
50             this.editDialog.open({size: 'lg'})
51                 .subscribe(() => this.grid.reload());
52         };
53
54         this.deleteSelected = (matchSets: IdlObject[]) => {
55             matchSets.forEach(matchSet => matchSet.isdeleted(true));
56             this.pcrud.autoApply(matchSets).subscribe(
57                 val => console.debug('deleted: ' + val),
58                 (err: unknown) => {},
59                 ()  => this.grid.reload()
60             );
61         };
62     }
63
64     ngAfterViewInit() {
65         this.grid.onRowActivate.subscribe(
66             (matchSet: IdlObject) => {
67                 this.editDialog.mode = 'update';
68                 this.editDialog.recordId = matchSet.id();
69                 this.editDialog.open({size: 'lg'})
70                     // eslint-disable-next-line rxjs/no-nested-subscribe
71                     .subscribe(() => this.grid.reload());
72             }
73         );
74     }
75
76     orgOnChange(org: IdlObject) {
77         this.contextOrg = org;
78         this.grid.reload();
79     }
80 }
81