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, GridCellTextGenerator} from '@eg/share/grid/grid';
10 import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
13 templateUrl: 'match-set-list.component.html'
15 export class MatchSetListComponent implements AfterViewInit {
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;
24 cellTextGenerator: GridCellTextGenerator;
27 private router: Router,
28 private pcrud: PcrudService,
29 private auth: AuthService,
30 private org: OrgService) {
32 this.gridSource = new GridDataSource();
33 this.contextOrg = this.org.get(this.auth.user().ws_ou());
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']},
44 this.cellTextGenerator = {
45 name: row => row.name()
48 this.createNew = () => {
49 this.editDialog.mode = 'create';
50 this.editDialog.open({size: 'lg'})
51 .subscribe(() => this.grid.reload());
54 this.deleteSelected = (matchSets: IdlObject[]) => {
55 matchSets.forEach(matchSet => matchSet.isdeleted(true));
56 this.pcrud.autoApply(matchSets).subscribe(
57 val => console.debug('deleted: ' + val),
59 () => this.grid.reload()
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 .subscribe(() => this.grid.reload());
75 orgOnChange(org: IdlObject) {
76 this.contextOrg = org;