-
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.
refactor: split resource- and resource-type-edit-page
- Loading branch information
Showing
7 changed files
with
177 additions
and
16 deletions.
There are no files selected for viewing
9 changes: 4 additions & 5 deletions
9
AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-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
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
32 changes: 32 additions & 0 deletions
32
...gular/io/src/app/resources/resource-type-edit-page/resource-type-edit-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,32 @@ | ||
<app-loading-indicator [isLoading]="isLoading()"></app-loading-indicator> | ||
<app-page> | ||
<div class="page-title">Edit {{ this.resourceType()?.name }}</div> | ||
|
||
<div class="page-content"> | ||
@if (this.resourceType()?.name && !permissions().canEditResourceType) { | ||
<div class="container"> | ||
<span class="text-warning-2">Not Authorized! You are not allowed to Edit-ResourceTypes.</span> | ||
</div> | ||
} @else if (id() === 0 ) { | ||
<div class="container"> | ||
<span>Please provide a resourceType-id to edit a resource.</span> | ||
</div> | ||
} @else { | ||
<div class="container"> | ||
Loaded resourceType: | ||
{{ this.resourceType()?.name }} | ||
</div> | ||
<div> | ||
<app-tile-component | ||
[title]="'Templates'" | ||
[actionName]="'New Template'" | ||
[canAction]="true" | ||
[isVisible]="false" | ||
[lists]="templatesData()" | ||
(tileAction)="add()" | ||
(listAction)="doListAction($event)" | ||
></app-tile-component> | ||
</div> | ||
} | ||
</div> | ||
</app-page> |
37 changes: 37 additions & 0 deletions
37
...ar/io/src/app/resources/resource-type-edit-page/resource-type-edit-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,37 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'; | ||
import { provideHttpClientTesting } from '@angular/common/http/testing'; | ||
import { ResourceTypeEditPageComponent } from './resource-type-edit-page.component'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { of, Subject } from 'rxjs'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
describe('ResourceEditPageComponent', () => { | ||
let component: ResourceTypeEditPageComponent; | ||
let fixture: ComponentFixture<ResourceTypeEditPageComponent>; | ||
|
||
const mockRoute: any = { queryParamMap: of() }; | ||
mockRoute.queryParamMap = new Subject<Map<string, number>>(); | ||
mockRoute.queryParamMap.next({ | ||
id: 42, | ||
}); | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [ResourceTypeEditPageComponent, RouterTestingModule.withRoutes([])], | ||
providers: [ | ||
provideHttpClient(withInterceptorsFromDi()), | ||
provideHttpClientTesting(), | ||
{ provide: ActivatedRoute, useValue: mockRoute }, | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(ResourceTypeEditPageComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
95 changes: 95 additions & 0 deletions
95
...angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-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,95 @@ | ||
import { Component, computed, inject, Signal, signal } from '@angular/core'; | ||
import { LoadingIndicatorComponent } from '../../shared/elements/loading-indicator.component'; | ||
import { PageComponent } from '../../layout/page/page.component'; | ||
import { ActivatedRoute } from '@angular/router'; | ||
import { map } from 'rxjs/operators'; | ||
import { toSignal } from '@angular/core/rxjs-interop'; | ||
import { ResourceService } from '../../resource/resource.service'; | ||
import { Resource } from '../../resource/resource'; | ||
import { EntryAction, TileListEntry, TileListEntryOutput } from '../../shared/tile/tile-list/tile-list.component'; | ||
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; | ||
import { TileComponent } from '../../shared/tile/tile.component'; | ||
import { AuthService } from '../../auth/auth.service'; | ||
import { ResourceType } from '../../resource/resource-type'; | ||
import { ResourceTypesService } from '../../resource/resource-types.service'; | ||
|
||
@Component({ | ||
selector: 'app-resource-type-edit-page', | ||
standalone: true, | ||
imports: [LoadingIndicatorComponent, PageComponent, TileComponent], | ||
templateUrl: './resource-type-edit-page.component.html', | ||
}) | ||
export class ResourceTypeEditPageComponent { | ||
private authService = inject(AuthService); | ||
private modalService = inject(NgbModal); | ||
private resourceTypeService = inject(ResourceTypesService); | ||
private route = inject(ActivatedRoute); | ||
|
||
id = toSignal(this.route.queryParamMap.pipe(map((params) => Number(params.get('id')))), { initialValue: 0 }); | ||
contextId = toSignal(this.route.queryParamMap.pipe(map((params) => Number(params.get('ctx')))), { initialValue: 1 }); | ||
resourceType: Signal<ResourceType> = this.resourceTypeService.resourceType; | ||
|
||
isLoading = computed(() => { | ||
if (this.id()) { | ||
this.resourceTypeService.setIdForResourceType(this.id()); | ||
return false; | ||
} else return false; | ||
}); | ||
|
||
permissions = computed(() => { | ||
if (this.authService.restrictions().length > 0) { | ||
return { | ||
canEditResourceType: this.authService.hasPermission('RESOURCETYPE', 'READ'), | ||
}; | ||
} else { | ||
return { canEditResourceType: false }; | ||
} | ||
}); | ||
|
||
templatesData = signal([ | ||
{ | ||
title: 'Instance Templates', | ||
entries: [ | ||
{ name: 'startJob_0.sh', description: 'startJob_0.sh', id: 0 }, | ||
{ name: 'startJob_1.sh', description: 'job 2 again', id: 1 }, | ||
] as TileListEntry[], | ||
canEdit: true, | ||
canDelete: true, | ||
}, | ||
{ | ||
title: 'Resource Type Templates', | ||
entries: [{ name: 'seg', description: 'segmentation', id: 666 }] as TileListEntry[], | ||
canOverwrite: false, | ||
}, | ||
]); | ||
|
||
add() { | ||
this.modalService.open('This would open a modal to add something'); | ||
} | ||
|
||
doListAction($event: TileListEntryOutput) { | ||
switch ($event.action) { | ||
case EntryAction.edit: | ||
this.editFunction($event.id); | ||
return; | ||
case EntryAction.delete: | ||
this.deleteFunction($event.id); | ||
return; | ||
case EntryAction.overwrite: | ||
this.overwriteFunction($event.id); | ||
return; | ||
} | ||
} | ||
|
||
private editFunction(id: number) { | ||
this.modalService.open('This would open a modal to edit function with id:' + id); | ||
} | ||
|
||
private deleteFunction(id: number) { | ||
this.modalService.open('This would open a modal to delete function with id:' + id); | ||
} | ||
|
||
private overwriteFunction(id: number) { | ||
this.modalService.open('This would open a modal to overwrite function with id:' + 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
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,7 +1,9 @@ | ||
import { ResourcesPageComponent } from './resources-page.component'; | ||
import { ResourceEditPageComponent } from './resource-edit-page/resource-edit-page.component'; | ||
import { ResourceTypeEditPageComponent } from './resource-type-edit-page/resource-type-edit-page.component'; | ||
|
||
export const resourcesRoute = [ | ||
{ path: 'resources', component: ResourcesPageComponent }, | ||
{ path: 'resource/edit', component: ResourceEditPageComponent }, | ||
{ path: 'resourceType/edit', component: ResourceTypeEditPageComponent }, | ||
]; |