LP1847800 Admin grids support config_field links
[working/Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / admin / server / floating-group / floating-group.component.ts
1 import {Pager} from '@eg/share/util/pager';
2 import {Component, Input, ViewChild, OnInit} from '@angular/core';
3 import {Location} from '@angular/common';
4 import {Router, ActivatedRoute} from '@angular/router';
5 import {FormatService} from '@eg/core/format.service';
6 import {IdlService, IdlObject} from '@eg/core/idl.service';
7 import {GridDataSource} from '@eg/share/grid/grid';
8 import {GridComponent} from '@eg/share/grid/grid.component';
9 import {ToastService} from '@eg/share/toast/toast.service';
10 import {PcrudService} from '@eg/core/pcrud.service';
11 import {OrgService} from '@eg/core/org.service';
12 import {PermService} from '@eg/core/perm.service';
13 import {AuthService} from '@eg/core/auth.service';
14 import {AdminPageComponent} from '../../../share/admin-page/admin-page.component';
15
16 @Component({
17     templateUrl: './floating-group.component.html'
18 })
19
20 export class FloatingGroupComponent extends AdminPageComponent implements OnInit {
21
22     idlClass = 'cfg';
23
24     gridDataSource: GridDataSource = new GridDataSource();
25
26     @ViewChild('grid', {static: true}) grid: GridComponent;
27
28     constructor(
29         route: ActivatedRoute,
30         ngLocation: Location,
31         format: FormatService,
32         idl: IdlService,
33         org: OrgService,
34         auth: AuthService,
35         pcrud: PcrudService,
36         perm: PermService,
37         toast: ToastService,
38         private router: Router
39     ) {
40         super(route, ngLocation, format, idl, org, auth, pcrud, perm, toast);
41     }
42
43     ngOnInit() {
44         super.ngOnInit();
45         this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
46
47             const orderBy: any = {};
48             if (sort.length) {
49                 orderBy.cfg = sort[0].name + ' ' + sort[0].dir;
50             }
51
52             const searchOps = {
53                 offset: pager.offset,
54                 limit: pager.limit,
55                 order_by: orderBy
56             };
57
58             return this.pcrud.retrieveAll('cfg', searchOps);
59         };
60
61         this.grid.onRowActivate.subscribe(
62             (idlThing: IdlObject) => {
63                 const idToEdit = idlThing.id();
64                 this.navigateToEditPage(idToEdit);
65             }
66         );
67     }
68
69     editSelected = (floatingGroups: IdlObject[]) => {
70         const idToEdit = floatingGroups[0].id();
71         this.navigateToEditPage(idToEdit);
72     }
73
74     deleteSelected = (floatingGroups: IdlObject[]) => {
75         super.deleteSelected(floatingGroups);
76     }
77
78     navigateToEditPage(id: any) {
79         this.router.navigate(['/staff/admin/server/config/floating_group/' + id]);
80     }
81
82     // this was left mostly blank to ensure a modal does not open for edits
83     showEditDialog(idlThing: IdlObject): Promise<any> {
84         return;
85     }
86
87  }