From fb715463d4621eb746450832f099e711b3459302 Mon Sep 17 00:00:00 2001 From: Sofia Papacharalampous Date: Mon, 8 Jul 2024 16:48:14 +0300 Subject: [PATCH] ui changes on dmp listing --- .../model/builder/plan/PlanBuilder.java | 1 + .../java/org/opencdmp/model/plan/Plan.java | 11 +++++-- dmp-frontend/src/app/core/model/plan/plan.ts | 1 + .../plan-listing-item.component.html | 21 +++++++++++--- .../plan-listing-item.component.ts | 29 ++++++++++++++++++- .../ui/plan/listing/plan-listing.component.ts | 1 + .../tenant-switch/tenant-switch.component.ts | 2 +- 7 files changed, 57 insertions(+), 9 deletions(-) diff --git a/backend/core/src/main/java/org/opencdmp/model/builder/plan/PlanBuilder.java b/backend/core/src/main/java/org/opencdmp/model/builder/plan/PlanBuilder.java index f8d2bf06f..030dd26ff 100644 --- a/backend/core/src/main/java/org/opencdmp/model/builder/plan/PlanBuilder.java +++ b/backend/core/src/main/java/org/opencdmp/model/builder/plan/PlanBuilder.java @@ -118,6 +118,7 @@ public class PlanBuilder extends BaseBuilder { for (PlanEntity d : data) { Plan m = new Plan(); if (fields.hasField(this.asIndexer(Plan._id))) m.setId(d.getId()); + if (fields.hasField(this.asIndexer(Plan._tenantId))) m.setTenantId(d.getTenantId()); if (fields.hasField(this.asIndexer(Plan._label))) m.setLabel(d.getLabel()); if (fields.hasField(this.asIndexer(Plan._version))) m.setVersion(d.getVersion()); if (fields.hasField(this.asIndexer(Plan._status))) m.setStatus(d.getStatus()); diff --git a/backend/core/src/main/java/org/opencdmp/model/plan/Plan.java b/backend/core/src/main/java/org/opencdmp/model/plan/Plan.java index 913f847bd..750b59cee 100644 --- a/backend/core/src/main/java/org/opencdmp/model/plan/Plan.java +++ b/backend/core/src/main/java/org/opencdmp/model/plan/Plan.java @@ -19,6 +19,9 @@ public class Plan { private UUID id; public static final String _id = "id"; + private UUID tenantId; + public static final String _tenantId = "tenantId"; + private String label; public static final String _label = "label"; @@ -102,9 +105,11 @@ public class Plan { return id; } - public void setId(UUID id) { - this.id = id; - } + public void setId(UUID id) { this.id = id; } + + public UUID getTenantId() { return tenantId; } + + public void setTenantId(UUID tenantId) { this.tenantId = tenantId; } public String getLabel() { return label; diff --git a/dmp-frontend/src/app/core/model/plan/plan.ts b/dmp-frontend/src/app/core/model/plan/plan.ts index e17d1ae3f..49e126cc0 100644 --- a/dmp-frontend/src/app/core/model/plan/plan.ts +++ b/dmp-frontend/src/app/core/model/plan/plan.ts @@ -220,6 +220,7 @@ export interface PublicEntityDoi { } export interface BasePlan extends BaseEntity { + tenantId?: Guid; status?: PlanStatus; descriptions?: BaseDescription[]; } diff --git a/dmp-frontend/src/app/ui/plan/listing/listing-item/plan-listing-item.component.html b/dmp-frontend/src/app/ui/plan/listing/listing-item/plan-listing-item.component.html index 96b635f3b..13449182d 100644 --- a/dmp-frontend/src/app/ui/plan/listing/listing-item/plan-listing-item.component.html +++ b/dmp-frontend/src/app/ui/plan/listing/listing-item/plan-listing-item.component.html @@ -2,16 +2,29 @@
{{ 'PLAN-LISTING.PLAN' | translate }}
-
{{ 'PLAN-LISTING.EDITED' | translate }}: {{ plan.updatedAt | dateTimeFormatter: "d MMMM y" }}
-
{{ 'PLAN-LISTING.PUBLISHED' | translate }}: {{ plan.finalizedAt | dateTimeFormatter: "d MMMM y" }}
+
+
+ +
{{getTenantName(plan.tenantId)}}
+
.
+
+
{{ 'PLAN-LISTING.EDITED' | translate }}: {{ plan.updatedAt | dateTimeFormatter: "d MMMM y" }}
+
{{ 'PLAN-LISTING.PUBLISHED' | translate }}: {{ plan.finalizedAt | dateTimeFormatter: "d MMMM y" }}
+
+
{{plan.label}}
{{ enumUtils.toPlanUserRolesString(planService.getCurrentUserRolesInPlan(plan?.planUsers)) }} . public{{'TYPES.PLAN-VISIBILITY.PUBLIC' | translate}} - done{{ enumUtils.toPlanStatusString(plan.status) }} - create{{ enumUtils.toPlanStatusString(plan.status) }} + done{{ enumUtils.toPlanStatusString(plan.status) }} + + create{{ enumUtils.toPlanStatusString(plan.status) }} + + + visibility{{ enumUtils.toPlanStatusString(plan.status) }} + . {{'PLAN-LISTING.VERSION' | translate}} {{plan.version}} . diff --git a/dmp-frontend/src/app/ui/plan/listing/listing-item/plan-listing-item.component.ts b/dmp-frontend/src/app/ui/plan/listing/listing-item/plan-listing-item.component.ts index fa3659bb3..3d6128f94 100644 --- a/dmp-frontend/src/app/ui/plan/listing/listing-item/plan-listing-item.component.ts +++ b/dmp-frontend/src/app/ui/plan/listing/listing-item/plan-listing-item.component.ts @@ -31,6 +31,12 @@ import { PlanDeleteDialogComponent } from '../../plan-delete-dialog/plan-delete- import { AnalyticsService } from '@app/core/services/matomo/analytics-service'; import { HttpErrorHandlingService } from '@common/modules/errors/error-handling/http-error-handling.service'; import { RouterUtilsService } from '@app/core/services/router/router-utils.service'; +import { Observable } from 'rxjs'; +import { Tenant } from '@app/core/model/tenant/tenant'; +import { InterceptorType } from '@common/http/interceptors/interceptor-type'; +import { BaseHttpParams } from '@common/http/base-http-params'; +import { TenantHandlingService } from '@app/core/services/tenant/tenant-handling.service'; +import { PrincipalService } from '@app/core/services/http/principal.service'; @Component({ selector: 'app-plan-listing-item-component', @@ -49,6 +55,7 @@ export class PlanListingItemComponent extends BaseComponent implements OnInit { isPublished: boolean; planStatusEnum = PlanStatus; fileTransformerEntityTypeEnum = FileTransformerEntityType; + tenants: Tenant[] = []; constructor( public routerUtils: RouterUtilsService, @@ -69,6 +76,7 @@ export class PlanListingItemComponent extends BaseComponent implements OnInit { private fileUtils: FileUtils, private analyticsService: AnalyticsService, private httpErrorHandlingService: HttpErrorHandlingService, + private principalService: PrincipalService, ) { super(); } @@ -86,12 +94,22 @@ export class PlanListingItemComponent extends BaseComponent implements OnInit { this.isPublished = false; if (this.plan.status === PlanStatus.Finalized && this.plan.accessType === PlanAccessType.Public) { this.isPublished = true } } + + + this.loadUserTenants().pipe(takeUntil(this._destroyed)).subscribe( tenants => { + this.tenants = tenants; + }); } public isAuthenticated(): boolean { return this.authentication.currentAccountIsAuthenticated(); } + + public getTenantName(id: Guid): string { + return this.tenants?.find(t => t?.id == id)?.name; + } + inviteToPlan() { const dialogRef = this.dialog.open(PlanInvitationDialogComponent, { // height: '250px', @@ -231,7 +249,7 @@ export class PlanListingItemComponent extends BaseComponent implements OnInit { } canEditPlan(): boolean { - return (this.plan.authorizationFlags?.some(x => x === AppPermission.EditPlan) || this.authentication.hasPermission(AppPermission.EditPlan)) && this.isPublic == false && this.plan.belongsToCurrentTenant != false; + return (this.isDraft) && (this.plan.authorizationFlags?.some(x => x === AppPermission.EditPlan) || this.authentication.hasPermission(AppPermission.EditPlan)) && this.isPublic == false && this.plan.belongsToCurrentTenant != false; } canCreateNewVersion(): boolean { @@ -261,4 +279,13 @@ export class PlanListingItemComponent extends BaseComponent implements OnInit { canAssignPlanUsers(): boolean { return (this.plan.authorizationFlags?.some(x => x === AppPermission.AssignPlanUsers) || this.authentication.hasPermission(AppPermission.AssignPlanUsers)) && this.isPublic == false && this.plan.belongsToCurrentTenant != false; } + + loadUserTenants(): Observable> { + const params = new BaseHttpParams(); + params.interceptorContext = { + excludedInterceptors: [InterceptorType.TenantHeaderInterceptor] + }; + return this.principalService.myTenants({ params: params }); + } + } diff --git a/dmp-frontend/src/app/ui/plan/listing/plan-listing.component.ts b/dmp-frontend/src/app/ui/plan/listing/plan-listing.component.ts index fb9c7b2f4..e9e486f63 100644 --- a/dmp-frontend/src/app/ui/plan/listing/plan-listing.component.ts +++ b/dmp-frontend/src/app/ui/plan/listing/plan-listing.component.ts @@ -437,6 +437,7 @@ export class PlanListingComponent extends BaseListingComponent(x => x.belongsToCurrentTenant), nameof(x => x.finalizedAt), nameof(x => x.hash), + nameof(x => x.tenantId), [nameof(x => x.authorizationFlags), AppPermission.CreateNewVersionPlan].join('.'), [nameof(x => x.authorizationFlags), AppPermission.DeletePlan].join('.'), [nameof(x => x.authorizationFlags), AppPermission.ClonePlan].join('.'), diff --git a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts index cf3702a83..e3a167cf5 100644 --- a/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts +++ b/dmp-frontend/src/app/ui/tenant/tenant-switch/tenant-switch.component.ts @@ -30,7 +30,7 @@ export class TenantSwitchComponent extends BaseComponent implements OnInit { } ngOnInit() { - this.tenants = this.loadUserTenants(); //TODO + this.tenants = this.loadUserTenants(); } loadUserTenants(): Observable> {