]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/server/floating-group/edit-floating-group.component.ts
LP1840287 Floating group admin minor code tweaks
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / admin / server / floating-group / edit-floating-group.component.ts
1 import {Component, Input, OnInit} from '@angular/core';
2 import {Router, ActivatedRoute} from '@angular/router';
3 import {GridDataSource} from '@eg/share/grid/grid';
4 import {Pager} from '@eg/share/util/pager';
5 import {PcrudService} from '@eg/core/pcrud.service';
6 import {IdlObject, IdlService } from '@eg/core/idl.service';
7
8 @Component({
9     templateUrl: './edit-floating-group.component.html'
10 })
11
12 export class EditFloatingGroupComponent implements OnInit {
13
14     dataSource: GridDataSource;
15
16     // defaultNewRecord is used when creating a new entry to give a default floating_group
17     defaultNewRecord: IdlObject;
18
19     // This is the ID of the floating group being edited currently
20     currentId: number;
21
22     constructor(
23         private route: ActivatedRoute,
24         private pcrud: PcrudService,
25         private idl: IdlService,
26     ) {
27     }
28
29     ngOnInit() {
30         this.currentId = parseInt(this.route.snapshot.paramMap.get('id'), 10);
31         this.defaultNewRecord = this.idl.create('cfgm');
32         this.defaultNewRecord.floating_group(this.currentId);
33         this.dataSource = new GridDataSource();
34
35         this.dataSource.getRows = (pager: Pager, sort: any[]) => {
36             const orderBy: any = {};
37             if (sort.length) {
38                 orderBy.cfgm = sort[0].name + ' ' + sort[0].dir;
39             }
40
41             const searchOps = {
42                 offset: pager.offset,
43                 limit: pager.limit,
44                 order_by: orderBy
45             };
46
47             return this.pcrud.search('cfgm',
48                 {floating_group: this.currentId}, searchOps);
49         };
50     }
51 }