LP1779158 Angular7 and ng-lint updates
[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, GridColumn} 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') grid: GridComponent;
22     @ViewChild('editDialog') editDialog: FmRecordEditorComponent;
23
24     constructor(
25         private router: Router,
26         private pcrud: PcrudService,
27         private auth: AuthService,
28         private org: OrgService) {
29
30         this.gridSource = new GridDataSource();
31         this.contextOrg = this.org.get(this.auth.user().ws_ou());
32
33         this.gridSource.getRows = (pager: Pager) => {
34             const orgs = this.org.ancestors(this.contextOrg, true);
35             return this.pcrud.search('vms', {owner: orgs}, {
36                 order_by: {vms: ['name']},
37                 limit: pager.limit,
38                 offset: pager.offset
39             });
40         };
41
42         this.createNew = () => {
43             this.editDialog.mode = 'create';
44             this.editDialog.open({size: 'lg'}).then(
45                 ok => this.grid.reload(),
46                 err => {}
47             );
48         };
49
50         this.deleteSelected = (matchSets: IdlObject[]) => {
51             matchSets.forEach(matchSet => matchSet.isdeleted(true));
52             this.pcrud.autoApply(matchSets).subscribe(
53                 val => console.debug('deleted: ' + val),
54                 err => {},
55                 ()  => this.grid.reload()
56             );
57         };
58     }
59
60     ngAfterViewInit() {
61         this.grid.onRowActivate.subscribe(
62             (matchSet: IdlObject) => {
63                 this.editDialog.mode = 'update';
64                 this.editDialog.recId = matchSet.id();
65                 this.editDialog.open({size: 'lg'}).then(
66                     ok => this.grid.reload(),
67                     err => {}
68                 );
69             }
70         );
71     }
72
73     orgOnChange(org: IdlObject) {
74         this.contextOrg = org;
75         this.grid.reload();
76     }
77 }
78