-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resources page with routing and list of resource types (#788)
- Loading branch information
1 parent
38f8694
commit 43b4b4f
Showing
18 changed files
with
354 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
export interface ResourceType { | ||
id: number; | ||
name: string; | ||
hasChildren: boolean; | ||
children: ResourceType[]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
AMW_angular/io/src/app/resources/resource-types.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { Observable, startWith, Subject } from 'rxjs'; | ||
import { toSignal } from '@angular/core/rxjs-interop'; | ||
import { shareReplay, switchMap } from 'rxjs/operators'; | ||
import { BaseService } from '../base/base.service'; | ||
import { ResourceType } from '../resource/resource-type'; | ||
|
||
@Injectable({ providedIn: 'root' }) | ||
export class ResourceTypesService extends BaseService { | ||
private reload$ = new Subject<ResourceType[]>(); | ||
|
||
private predefinedResourceTypes$ = this.getPredefinedResourceTypes(); | ||
|
||
private rootResourceTypes$ = this.reload$.pipe( | ||
startWith(null), | ||
switchMap(() => this.getRootResourceTypes()), | ||
shareReplay(1), | ||
); | ||
|
||
predefinedResourceTypes = toSignal(this.predefinedResourceTypes$, { initialValue: [] as ResourceType[] }); | ||
rootResourceTypes = toSignal(this.rootResourceTypes$, { initialValue: [] as ResourceType[] }); | ||
|
||
constructor(private http: HttpClient) { | ||
super(); | ||
} | ||
|
||
getAllResourceTypes(): Observable<ResourceType[]> { | ||
return this.http.get<ResourceType[]>(`${this.getBaseUrl()}/resources/resourceTypes`); | ||
} | ||
|
||
getPredefinedResourceTypes(): Observable<ResourceType[]> { | ||
return this.http.get<ResourceType[]>(`${this.getBaseUrl()}/resources/predefinedResourceTypes`); | ||
} | ||
|
||
getRootResourceTypes(): Observable<ResourceType[]> { | ||
return this.http.get<ResourceType[]>(`${this.getBaseUrl()}/resources/rootResourceTypes`); | ||
} | ||
|
||
refreshData() { | ||
this.reload$.next([]); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
AMW_angular/io/src/app/resources/resources-page.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<app-loading-indicator [isLoading]="isLoading()"></app-loading-indicator> | ||
<app-page> | ||
<div class="page-title">Resources</div> | ||
<div class="page-content"> | ||
@if (permissions().canViewResourceTypes) { | ||
<nav class="nav flex-column"> | ||
@for (resourceType of predefinedResourceTypes(); track resourceType.name) { | ||
<a>{{ resourceType.name }}</a> | ||
} | ||
</nav> | ||
<nav class="nav flex-column"> | ||
@for (resourceType of rootResourceTypes(); track resourceType.name) { | ||
<a (click)="toggleChildren(resourceType)"> | ||
{{ resourceType.name }} | ||
@if (resourceType.hasChildren) { | ||
<span>{{ expandedResourceTypeId === resourceType.id ? '-' : '+' }}</span> | ||
} | ||
</a> | ||
@if (resourceType.hasChildren && expandedResourceTypeId === resourceType.id) { | ||
<ul class="subnav"> | ||
@for (child of resourceType.children; track child.name) { | ||
<div class="grid-item"> | ||
<a>{{ child.name }}</a> | ||
</div> | ||
} | ||
</ul> | ||
} } | ||
</nav> | ||
} | ||
</div> | ||
</app-page> |
24 changes: 24 additions & 0 deletions
24
AMW_angular/io/src/app/resources/resources-page.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { ResourcesPageComponent } from './resources-page.component'; | ||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; | ||
import { provideHttpClientTesting } from '@angular/common/http/testing'; | ||
|
||
describe('ResourcesPageComponent', () => { | ||
let component: ResourcesPageComponent; | ||
let fixture: ComponentFixture<ResourcesPageComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ResourcesPageComponent], | ||
providers: [provideHttpClient(withInterceptorsFromDi()), provideHttpClientTesting()], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ResourcesPageComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
37 changes: 37 additions & 0 deletions
37
AMW_angular/io/src/app/resources/resources-page.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ChangeDetectionStrategy, Component, computed, inject, Signal, signal } from '@angular/core'; | ||
import { AuthService } from '../auth/auth.service'; | ||
import { PageComponent } from '../layout/page/page.component'; | ||
import { LoadingIndicatorComponent } from '../shared/elements/loading-indicator.component'; | ||
import { ResourceTypesService } from './resource-types.service'; | ||
import { ResourceType } from '../resource/resource-type'; | ||
|
||
@Component({ | ||
selector: 'app-resources-page', | ||
standalone: true, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [PageComponent, LoadingIndicatorComponent], | ||
templateUrl: './resources-page.component.html', | ||
}) | ||
export class ResourcesPageComponent { | ||
private authService = inject(AuthService); | ||
private resourceTypesService = inject(ResourceTypesService); | ||
|
||
predefinedResourceTypes: Signal<ResourceType[]> = this.resourceTypesService.predefinedResourceTypes; | ||
rootResourceTypes: Signal<ResourceType[]> = this.resourceTypesService.rootResourceTypes; | ||
isLoading = signal(false); | ||
expandedResourceTypeId: number | null = null; | ||
|
||
permissions = computed(() => { | ||
if (this.authService.restrictions().length > 0) { | ||
return { | ||
canViewResourceTypes: this.authService.hasPermission('RES_TYPE_LIST_TAB', 'ALL'), | ||
}; | ||
} else { | ||
return { canViewResourceTypes: false }; | ||
} | ||
}); | ||
|
||
toggleChildren(resourceType: ResourceType): void { | ||
this.expandedResourceTypeId = this.expandedResourceTypeId === resourceType.id ? null : resourceType.id; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { ResourcesPageComponent } from './resources-page.component'; | ||
|
||
export const resourcesRoute = [{ path: 'resources', component: ResourcesPageComponent }]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.