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', { static: true }) grid: GridComponent;
22 @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
24 cellPrintValues: (row: any, cell: GridColumn) => string;
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 // Text-ify function for cells that use display templates.
45 this.cellPrintValues = (row: any, cell: GridColumn): string => {
52 this.createNew = () => {
53 this.editDialog.mode = 'create';
54 this.editDialog.open({size: 'lg'})
55 .subscribe(() => this.grid.reload());
58 this.deleteSelected = (matchSets: IdlObject[]) => {
59 matchSets.forEach(matchSet => matchSet.isdeleted(true));
60 this.pcrud.autoApply(matchSets).subscribe(
61 val => console.debug('deleted: ' + val),
63 () => this.grid.reload()
69 this.grid.onRowActivate.subscribe(
70 (matchSet: IdlObject) => {
71 this.editDialog.mode = 'update';
72 this.editDialog.recordId = matchSet.id();
73 this.editDialog.open({size: 'lg'})
74 .subscribe(() => this.grid.reload());
79 orgOnChange(org: IdlObject) {
80 this.contextOrg = org;