From 1326c7c9acd7ceaafc342c55fdd6bd4a56194dd1 Mon Sep 17 00:00:00 2001 From: Stephan Girod Date: Tue, 24 Dec 2024 11:23:31 +0100 Subject: [PATCH] feat: show functions on resourcetype --- AMW_angular/io/src/app/auth/auth.service.ts | 9 +++++-- .../resource-edit-functions.component.ts | 6 ++--- .../resource-edit-page.component.html | 22 ++++++++-------- .../resources/resource-functions.service.ts | 3 ++- .../resource-type-edit-functions.component.ts | 25 ++++++++++--------- .../resource-type-edit-page.component.html | 24 ++++++++++-------- .../resource-type-edit-page.component.ts | 12 ++++++--- 7 files changed, 56 insertions(+), 45 deletions(-) diff --git a/AMW_angular/io/src/app/auth/auth.service.ts b/AMW_angular/io/src/app/auth/auth.service.ts index 2971943a8..8683fec38 100644 --- a/AMW_angular/io/src/app/auth/auth.service.ts +++ b/AMW_angular/io/src/app/auth/auth.service.ts @@ -65,11 +65,16 @@ export class AuthService extends BaseService { ); } - hasResourceTypePermission(permissionName: string, action: string, resourceType: string): boolean { + hasResourceTypePermission(permissionName: string, action: string, resourceTypeName: string): boolean { return ( this.restrictions() .filter((entry) => entry.permission.name === permissionName) - .filter((entry) => entry.resourceTypeName === resourceType || this.isDefaultType(entry, resourceType)) + .filter( + (entry) => + entry.resourceTypeName === resourceTypeName || + this.isDefaultType(entry, resourceTypeName) || + entry.resourceTypeName === null, + ) .map((entry) => entry.action) .find((entry) => entry === Action.ALL || entry === action) !== undefined ); diff --git a/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-functions/resource-edit-functions.component.ts b/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-functions/resource-edit-functions.component.ts index 5aa2674a9..86375c8fc 100644 --- a/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-functions/resource-edit-functions.component.ts +++ b/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-functions/resource-edit-functions.component.ts @@ -61,8 +61,6 @@ export class ResourceEditFunctionsComponent { } }); - // then for editmodal it's read or edit - functionsData = computed(() => { if (this.functions()?.length > 0) { const [instance, resource] = this.splitFunctions(this.functions()); @@ -71,7 +69,7 @@ export class ResourceEditFunctionsComponent { result.push({ title: 'Resource Instance Functions', entries: instance, - canEdit: this.permissions().canEdit, + canEdit: this.permissions().canEdit || this.permissions().canShowInstanceFunctions, // fixme old gui used the `Edit`-link also for only viewing a function canDelete: this.permissions().canDelete, }); } @@ -79,7 +77,7 @@ export class ResourceEditFunctionsComponent { result.push({ title: 'Resource Type Functions', entries: resource, - canOverwrite: this.permissions().canEdit, + canOverwrite: this.permissions().canEdit || this.permissions().canShowInstanceFunctions, // fixme old gui used the `Edit`-link also for only viewing a function }); } return result; diff --git a/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-page.component.html b/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-page.component.html index 41a3f4cf4..7c2ba9dc2 100644 --- a/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-page.component.html +++ b/AMW_angular/io/src/app/resources/resource-edit-page/resource-edit-page.component.html @@ -16,18 +16,16 @@ Loaded resource: {{ this.resource()?.name }} -
- - -
+ + } diff --git a/AMW_angular/io/src/app/resources/resource-functions.service.ts b/AMW_angular/io/src/app/resources/resource-functions.service.ts index 894bb65ed..036b5acac 100644 --- a/AMW_angular/io/src/app/resources/resource-functions.service.ts +++ b/AMW_angular/io/src/app/resources/resource-functions.service.ts @@ -18,12 +18,13 @@ export class ResourceFunctionsService extends BaseService { shareReplay(1), ); - private functionByTypeId$: Observable = this.functions$.pipe( + private functionByTypeId$: Observable = this.functionsForType$.pipe( switchMap((id: number) => this.getResourceTypeFunctions(id)), shareReplay(1), ); functions = toSignal(this.functionById$, { initialValue: [] }); + functionsForType = toSignal(this.functionByTypeId$, { initialValue: [] }); constructor(private http: HttpClient) { super(); diff --git a/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-functions/resource-type-edit-functions.component.ts b/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-functions/resource-type-edit-functions.component.ts index 6f8ba51c3..f79e43a9f 100644 --- a/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-functions/resource-type-edit-functions.component.ts +++ b/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-functions/resource-type-edit-functions.component.ts @@ -10,7 +10,6 @@ import { ResourceFunctionsService } from '../../resource-functions.service'; import { ResourceFunction } from '../../resource-function'; import { ResourceType } from '../../../resource/resource-type'; -const RESOURCE_PERM = 'RESOURCE_AMWFUNCTION'; const RESOURCETYPE_PERM = 'RESOURCETYPE_AMWFUNCTION'; @Component({ @@ -26,7 +25,7 @@ export class ResourceTypeEditFunctionsComponent { resourceType = input.required(); contextId = input.required(); - functions = this.functionsService.functions; + functions = this.functionsService.functionsForType; isLoading = computed(() => { if (this.resourceType() != null) { @@ -36,10 +35,9 @@ export class ResourceTypeEditFunctionsComponent { }); permissions = computed(() => { - if (this.authService.restrictions().length > 0) { + if (this.authService.restrictions().length > 0 && this.resourceType()) { return { - canShowInstanceFunctions: this.authService.hasPermission(RESOURCE_PERM, Action.READ), - canShowSuperTypeFunctions: this.authService.hasPermission(RESOURCETYPE_PERM, Action.READ), + canShowInstanceFunctions: this.authService.hasPermission(RESOURCETYPE_PERM, Action.READ), canAdd: (this.contextId() === 1 || this.contextId === null) && this.authService.hasResourceTypePermission(RESOURCETYPE_PERM, Action.CREATE, this.resourceType().name), @@ -53,7 +51,6 @@ export class ResourceTypeEditFunctionsComponent { } else { return { canShowInstanceFunctions: false, - canShowSuperTypeFunctions: false, canAdd: false, canEdit: false, canDelete: false, @@ -63,12 +60,16 @@ export class ResourceTypeEditFunctionsComponent { functionsData = computed(() => { if (this.functions()?.length > 0) { - if (this.permissions().canShowSuperTypeFunctions) { - return { - title: 'Type Functions', - entries: this.mapListEntries(this.functions()), - canOverwrite: this.permissions().canEdit, - }; + if (this.permissions().canShowInstanceFunctions) { + const entries = this.mapListEntries(this.functions()); + return [ + { + title: 'Type Functions', + entries: entries, + canEdit: this.permissions().canEdit || this.permissions().canShowInstanceFunctions, // fixme old gui used the `Edit`-link also for only viewing a function + canDelete: this.permissions().canDelete, + }, + ]; } else return null; } }); diff --git a/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.html b/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.html index 88e097446..0f061a470 100644 --- a/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.html +++ b/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.html @@ -16,17 +16,19 @@ Loaded resourceType: {{ this.resourceType()?.name }} -
- -
+ + } diff --git a/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.ts b/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.ts index 2cff30638..45460a065 100644 --- a/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.ts +++ b/AMW_angular/io/src/app/resources/resource-type-edit-page/resource-type-edit-page.component.ts @@ -4,19 +4,25 @@ 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'; +import { ResourceEditFunctionsComponent } from '../resource-edit-page/resource-edit-functions/resource-edit-functions.component'; +import { ResourceTypeEditFunctionsComponent } from './resource-type-edit-functions/resource-type-edit-functions.component'; @Component({ selector: 'app-resource-type-edit-page', standalone: true, - imports: [LoadingIndicatorComponent, PageComponent, TileComponent], + imports: [ + LoadingIndicatorComponent, + PageComponent, + TileComponent, + ResourceEditFunctionsComponent, + ResourceTypeEditFunctionsComponent, + ], templateUrl: './resource-type-edit-page.component.html', }) export class ResourceTypeEditPageComponent {