From af930d9c730fd862f195d7d6dbad8fd12d22480e Mon Sep 17 00:00:00 2001 From: mchouliara Date: Tue, 13 Aug 2024 14:10:27 +0300 Subject: [PATCH] refactor plan + public plan models, re-commit --- .../model/dashboard/dashboard-statistics.ts | 4 +- .../src/app/core/model/plan/plan-reference.ts | 10 +- frontend/src/app/core/model/plan/plan.ts | 105 ++++++------------ .../src/app/core/model/reference/reference.ts | 8 ++ .../plan/overview/plan-overview.component.ts | 47 +++++--- .../plan-editor.model.ts | 2 +- 6 files changed, 78 insertions(+), 98 deletions(-) diff --git a/frontend/src/app/core/model/dashboard/dashboard-statistics.ts b/frontend/src/app/core/model/dashboard/dashboard-statistics.ts index 7f935bf0a..61559f7bb 100644 --- a/frontend/src/app/core/model/dashboard/dashboard-statistics.ts +++ b/frontend/src/app/core/model/dashboard/dashboard-statistics.ts @@ -1,4 +1,4 @@ -import { PublicReferenceType } from "../plan/plan"; +import { ReferenceType } from "../reference-type/reference-type"; export interface DashboardStatistics { planCount: number; @@ -8,5 +8,5 @@ export interface DashboardStatistics { export interface DashboardReferenceTypeStatistics { count: number; - referenceType: PublicReferenceType + referenceType: ReferenceType } \ No newline at end of file diff --git a/frontend/src/app/core/model/plan/plan-reference.ts b/frontend/src/app/core/model/plan/plan-reference.ts index d5d5d41dc..fc8ee2a2f 100644 --- a/frontend/src/app/core/model/plan/plan-reference.ts +++ b/frontend/src/app/core/model/plan/plan-reference.ts @@ -1,12 +1,12 @@ import { BaseEntity } from "@common/base/base-entity.model"; -import { Reference } from "../reference/reference"; -import { Plan } from "./plan"; +import { BaseReference, Reference } from "../reference/reference"; +import { Plan, PublicPlan } from "./plan"; import { Guid } from "@common/types/guid"; export interface PlanReference extends BaseEntity { - plan?: Plan; - reference?: Reference; - data: PlanReferenceData; + plan: Plan; + reference: Reference; + data?: PlanReferenceData; } export interface PlanReferenceData { diff --git a/frontend/src/app/core/model/plan/plan.ts b/frontend/src/app/core/model/plan/plan.ts index efc5c811b..a11acfe63 100644 --- a/frontend/src/app/core/model/plan/plan.ts +++ b/frontend/src/app/core/model/plan/plan.ts @@ -15,29 +15,41 @@ import { IsActive } from '@app/core/common/enum/is-active.enum'; import { AppPermission } from '@app/core/common/enum/permission.enum'; import { EntityType } from '@app/core/common/enum/entity-type'; -export interface Plan extends BasePlan { - label?: string; +export interface BasePlan extends BaseEntity { + label?: string; version?: number; - versionStatus?: PlanVersionStatus; - properties?: PlanProperties; groupId?: String; description?: String; - finalizedAt?: Date; publishedAt?: Date; - creator?: User; + finalizedAt?: Date; accessType?: PlanAccessType; + planReferences?: PlanReference[]; + entityDois?: EntityDoi[]; + tenantId?: Guid; + status?: PlanStatus; + descriptions?: BaseDescription[]; +} +export interface Plan extends BasePlan { + versionStatus?: PlanVersionStatus; + properties?: PlanProperties; + creator?: User; blueprint?: PlanBlueprint; language?: String; publicAfter?: Date; - planReferences?: PlanReference[]; planUsers?: PlanUser[]; descriptions?: Description[]; planDescriptionTemplates?: PlanDescriptionTemplate[]; - entityDois?: EntityDoi[]; otherPlanVersions?: Plan[]; authorizationFlags?: AppPermission[]; } +export interface PublicPlan extends BasePlan { + planUsers: PublicPlanUser[]; + descriptions: PublicDescription[]; + otherPlanVersions?: PublicPlan[]; +} + + export interface PlanProperties { planBlueprintValues: PlanBlueprintValue[]; contacts: PlanContact[]; @@ -56,14 +68,21 @@ export interface PlanContact { email: string; } +export interface BasePlanUser extends BaseEntity { + user: User; + role: PlanUserRole; +} -export interface PlanUser extends BaseEntity { +export interface PlanUser extends BasePlanUser { plan: Plan; - user: User; - role: PlanUserRole; sectionId: Guid; } +export interface PublicPlanUser extends BasePlanUser{ + plan: PublicPlan; +} + + export interface PlanDescriptionTemplate extends BaseEntity { plan?: Plan; currentDescriptionTemplate?: DescriptionTemplate; @@ -161,66 +180,4 @@ export interface PlanUserInvitePersist { // // Public -// - -export interface PublicPlan extends BasePlan { - label?: string; - version?: number; - description?: string; - finalizedAt?: Date; - publishedAt?: Date; - groupId?: String; - accessType: PlanAccessType; - planReferences: PublicPlanReference[]; - planUsers: PublicPlanUser[]; - descriptions: PublicDescription[]; - entityDois: PublicEntityDoi[]; - otherPlanVersions?: PublicPlan[]; -} - -export interface PublicPlanReference { - id: Guid; - plan: PublicPlan; - reference: PublicReference; - isActive?: IsActive; -} - -export interface PublicReference { - id: Guid; - label: string; - type: PublicReferenceType; - description?: string; - reference?: string; -} - -export interface PublicReferenceType { - id: Guid; - name: string; - code: string; -} - -export interface PublicPlanUser { - id: Guid; - plan: PublicPlan; - user: PublicUser; - role: PlanUserRole; -} - -export interface PublicUser { - id: Guid; - name: string; -} - -export interface PublicEntityDoi { - id: Guid; - entityType: EntityType; - entityId: Guid; - repositoryId: string; - doi: string; -} - -export interface BasePlan extends BaseEntity { - tenantId?: Guid; - status?: PlanStatus; - descriptions?: BaseDescription[]; -} +// \ No newline at end of file diff --git a/frontend/src/app/core/model/reference/reference.ts b/frontend/src/app/core/model/reference/reference.ts index 5b53cf413..ea480f64d 100644 --- a/frontend/src/app/core/model/reference/reference.ts +++ b/frontend/src/app/core/model/reference/reference.ts @@ -15,6 +15,14 @@ export interface Reference extends BaseEntity { sourceType: ReferenceSourceType; } +export interface BaseReference extends BaseEntity{ + label: string; + type: ReferenceType; + description?: string; + reference?: string; +} + + export interface Definition { fields: Field[]; } diff --git a/frontend/src/app/ui/plan/overview/plan-overview.component.ts b/frontend/src/app/ui/plan/overview/plan-overview.component.ts index 8a98b212a..f5978a639 100644 --- a/frontend/src/app/ui/plan/overview/plan-overview.component.ts +++ b/frontend/src/app/ui/plan/overview/plan-overview.component.ts @@ -58,7 +58,7 @@ import { RouterUtilsService } from '@app/core/services/router/router-utils.servi }) export class PlanOverviewComponent extends BaseComponent implements OnInit { - plan: any | Plan | PublicPlan; + plan: Plan | PublicPlan; selectedBlueprint: PlanBlueprint; researchers: PlanReference[] = []; isNew = true; @@ -214,14 +214,14 @@ export class PlanOverviewComponent extends BaseComponent implements OnInit { } get isActive(): boolean { - return this.plan && this.plan.isActive === IsActive.Active; + return this.plan?.isActive != IsActive.Inactive; } get selectedPlanVersion(): number { return this.plan?.version; } - get otherPlanVersions(): Plan | PublicPlan{ + get otherPlanVersions(): Plan[] | PublicPlan[]{ return this.plan?.otherPlanVersions; } @@ -257,53 +257,68 @@ export class PlanOverviewComponent extends BaseComponent implements OnInit { } canEditPlan(): boolean { - return (this.isDraftPlan()) && (this.plan.authorizationFlags?.some(x => x === AppPermission.EditPlan) || this.authentication.hasPermission(AppPermission.EditPlan)) && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; + return (this.isDraftPlan()) && (authorizationFlags?.some(x => x === AppPermission.EditPlan) || this.authentication.hasPermission(AppPermission.EditPlan)) && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; } canCreateNewVersion(): boolean { - return (this.plan.authorizationFlags?.some(x => x === AppPermission.CreateNewVersionPlan) || this.authentication.hasPermission(AppPermission.CreateNewVersionPlan)) && this.plan.versionStatus === PlanVersionStatus.Current && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; + const versionStatus = !this.isPublicView ? (this.plan as Plan)?.versionStatus : null; + return (authorizationFlags?.some(x => x === AppPermission.CreateNewVersionPlan) || this.authentication.hasPermission(AppPermission.CreateNewVersionPlan)) && versionStatus === PlanVersionStatus.Current && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; } canDeletePlan(): boolean { + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; return ( this.isActive && - (this.plan.authorizationFlags?.some(x => x === AppPermission.DeletePlan) || this.authentication.hasPermission(AppPermission.DeletePlan))) && - this.isPublicView == false && this.plan.belongsToCurrentTenant != false; + (authorizationFlags?.some(x => x === AppPermission.DeletePlan) || this.authentication.hasPermission(AppPermission.DeletePlan)) && + this.isPublicView == false && this.plan.belongsToCurrentTenant != false + ) } canClonePlan(): boolean { - return (this.plan.authorizationFlags?.some(x => x === AppPermission.ClonePlan) || this.authentication.hasPermission(AppPermission.ClonePlan) || (this.authentication.hasPermission(AppPermission.PublicClonePlan) && this.isPublicView)); + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; + return ( + authorizationFlags?.some(x => x === AppPermission.ClonePlan) || + this.authentication.hasPermission(AppPermission.ClonePlan) || + (this.authentication.hasPermission(AppPermission.PublicClonePlan) && this.isPublicView) + ); } canFinalizePlan(): boolean { + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; return ( this.isActive && - (this.plan.authorizationFlags?.some(x => x === AppPermission.FinalizePlan) || this.authentication.hasPermission(AppPermission.FinalizePlan))) && + (authorizationFlags?.some(x => x === AppPermission.FinalizePlan) || this.authentication.hasPermission(AppPermission.FinalizePlan))) && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; } canExportPlan(): boolean { - return (this.plan.authorizationFlags?.some(x => x === AppPermission.ExportPlan) || this.authentication.hasPermission(AppPermission.ExportPlan)); + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; + return (authorizationFlags?.some(x => x === AppPermission.ExportPlan) || this.authentication.hasPermission(AppPermission.ExportPlan)); } canInvitePlanUsers(): boolean { + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; return ( this.isActive && - (this.plan.authorizationFlags?.some(x => x === AppPermission.InvitePlanUsers) || this.authentication.hasPermission(AppPermission.InvitePlanUsers))) && + (authorizationFlags?.some(x => x === AppPermission.InvitePlanUsers) || this.authentication.hasPermission(AppPermission.InvitePlanUsers))) && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; } canAssignPlanUsers(): boolean { - return (this.plan.authorizationFlags?.some(x => x === AppPermission.AssignPlanUsers) || this.authentication.hasPermission(AppPermission.AssignPlanUsers)) && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; + return (authorizationFlags?.some(x => x === AppPermission.AssignPlanUsers) || this.authentication.hasPermission(AppPermission.AssignPlanUsers)) && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; } canDepositPlan(): boolean { - return (this.plan.authorizationFlags?.some(x => x === AppPermission.DepositPlan) || this.authentication.hasPermission(AppPermission.DepositPlan)) && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; + const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : []; + return (authorizationFlags?.some(x => x === AppPermission.DepositPlan) || this.authentication.hasPermission(AppPermission.DepositPlan)) && this.isPublicView == false && this.plan.belongsToCurrentTenant != false; } editClicked() { - this.router.navigate([this.routerUtils.generateUrl(['/plans/edit', this.plan.id], '/')]); + this.router.navigate([this.routerUtils.generateUrl(['/plans/edit', this.plan.id.toString()], '/')]); } cloneClicked() { @@ -588,8 +603,8 @@ export class PlanOverviewComponent extends BaseComponent implements OnInit { getSectionNameById(sectionId: Guid): string { if (sectionId == null) return ''; - - let sections: PlanBlueprintDefinitionSection[] = this.plan?.blueprint?.definition?.sections?.filter((section: PlanBlueprintDefinitionSection) => sectionId === section.id); + const blueprint = this.isPublicView ? null : (this.plan as Plan)?.blueprint; + let sections: PlanBlueprintDefinitionSection[] = blueprint?.definition?.sections?.filter((section: PlanBlueprintDefinitionSection) => sectionId === section.id); return sections == null ? '' : sections[0].label; } diff --git a/frontend/src/app/ui/plan/plan-editor-blueprint/plan-editor.model.ts b/frontend/src/app/ui/plan/plan-editor-blueprint/plan-editor.model.ts index 4dfd589e1..399a7f6f9 100644 --- a/frontend/src/app/ui/plan/plan-editor-blueprint/plan-editor.model.ts +++ b/frontend/src/app/ui/plan/plan-editor-blueprint/plan-editor.model.ts @@ -332,7 +332,7 @@ export class PlanBlueprintValueEditorModel implements PlanBlueprintValuePersist this.fieldValue = item.fieldValue; this.dateValue = item.dateValue; this.numberValue = item.numberValue; - const references = planReferences?.filter(x => x.data.blueprintFieldId == this.fieldId && x.isActive == IsActive.Active).map(x => { + const references = planReferences?.filter(x => x.data?.blueprintFieldId == this.fieldId && x.isActive == IsActive.Active).map(x => { return { data: x.data, reference: {