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';
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') grid: GridComponent;
22 @ViewChild('editDialog') editDialog: FmRecordEditorComponent;
25 private router: Router,
26 private pcrud: PcrudService,
27 private auth: AuthService,
28 private org: OrgService) {
30 this.gridSource = new GridDataSource();
31 this.contextOrg = this.org.get(this.auth.user().ws_ou());
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']},
42 this.createNew = () => {
43 this.editDialog.mode = 'create';
44 this.editDialog.open({size: 'lg'}).then(
45 ok => this.grid.reload(),
50 this.deleteSelected = (matchSets: IdlObject[]) => {
51 matchSets.forEach(matchSet => matchSet.isdeleted(true));
52 this.pcrud.autoApply(matchSets).subscribe(
53 val => console.debug('deleted: ' + val),
55 () => this.grid.reload()
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(),
73 orgOnChange(org: IdlObject) {
74 this.contextOrg = org;