]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/acq/funds/funds.component.ts
LP#1904244: Angular funds interface
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / admin / acq / funds / funds.component.ts
1 import {Component, OnInit, Input, ViewChild} from '@angular/core';
2 import {Router, ActivatedRoute, ParamMap} from '@angular/router';
3 import {Location} from '@angular/common';
4 import {NgbNav, NgbNavChangeEvent} from '@ng-bootstrap/ng-bootstrap';
5
6 @Component({
7     templateUrl: './funds.component.html'
8 })
9 export class FundsComponent implements OnInit {
10
11     activeTab: string;
12     fundId: number;
13     fundingSourceId: number;
14
15     constructor(
16         private location: Location,
17         private router: Router,
18         private route: ActivatedRoute
19     ) {}
20
21     ngOnInit() {
22         this.route.paramMap.subscribe((params: ParamMap) => {
23             const tab = params.get('tab');
24             const id = +params.get('id');
25             if (!id || !tab) { return; }
26             if (tab === 'fund' || tab === 'funding_source') {
27                 this.activeTab = tab;
28                 if (tab === 'fund') {
29                     this.fundId = id;
30                 } else {
31                     this.fundingSourceId = id;
32                 }
33             } else {
34                 return;
35             }
36         });
37     }
38
39     // Changing a tab in the UI means clearing the route (e.g.,
40     // if we originally navigated vi funds/fund/:id or
41     // funds/funding_source/:id
42     onNavChange(evt: NgbNavChangeEvent) {
43         // clear any IDs parsed from the original route
44         // to avoid reopening the fund or funding source
45         // dialogs when navigating back to the fund/funding source
46         // tab.
47         this.fundId = null;
48         this.fundingSourceId = null;
49         const url = this.router.createUrlTree(['/staff/admin/acq/funds']).toString();
50         this.location.go(url); // go without reloading
51     }
52 }