-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathadmin-institutions.component.ts
More file actions
59 lines (45 loc) · 2.08 KB
/
Copy pathadmin-institutions.component.ts
File metadata and controls
59 lines (45 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { createDispatchMap, select } from '@ngxs/store';
import { TranslateModule } from '@ngx-translate/core';
import { TabsModule } from 'primeng/tabs';
import { NgOptimizedImage } from '@angular/common';
import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core';
import { ActivatedRoute, Router, RouterOutlet } from '@angular/router';
import { Primitive } from '@osf/shared/helpers';
import { FetchInstitutionById, InstitutionsSearchSelectors } from '@osf/shared/stores/institutions-search';
import { LoadingSpinnerComponent, SelectComponent } from '@shared/components';
import { resourceTabOptions } from './constants';
import { AdminInstitutionResourceTab } from './enums';
@Component({
selector: 'osf-admin-institutions',
imports: [TabsModule, TranslateModule, RouterOutlet, NgOptimizedImage, LoadingSpinnerComponent, SelectComponent],
templateUrl: './admin-institutions.component.html',
styleUrl: './admin-institutions.component.scss',
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class AdminInstitutionsComponent implements OnInit {
private readonly router = inject(Router);
private readonly route = inject(ActivatedRoute);
institution = select(InstitutionsSearchSelectors.getInstitution);
isInstitutionLoading = select(InstitutionsSearchSelectors.getInstitutionLoading);
private readonly actions = createDispatchMap({
fetchInstitution: FetchInstitutionById,
});
resourceTabOptions = resourceTabOptions;
selectedTab = AdminInstitutionResourceTab.Summary;
ngOnInit() {
const institutionId = this.route.snapshot.params['institution-id'];
if (institutionId) {
this.actions.fetchInstitution(institutionId);
}
this.selectedTab =
(this.route.snapshot.firstChild?.routeConfig?.path as AdminInstitutionResourceTab) ||
AdminInstitutionResourceTab.Summary;
}
onTabChange(selectedValue: Primitive) {
const value = selectedValue as AdminInstitutionResourceTab;
this.selectedTab = value;
if (this.selectedTab) {
this.router.navigate([this.selectedTab], { relativeTo: this.route });
}
}
}