refactor plan + public plan models, re-commit

This commit is contained in:
mchouliara 2024-08-13 14:10:27 +03:00
parent 71243d7fde
commit af930d9c73
6 changed files with 78 additions and 98 deletions

View File

@ -1,4 +1,4 @@
import { PublicReferenceType } from "../plan/plan"; import { ReferenceType } from "../reference-type/reference-type";
export interface DashboardStatistics { export interface DashboardStatistics {
planCount: number; planCount: number;
@ -8,5 +8,5 @@ export interface DashboardStatistics {
export interface DashboardReferenceTypeStatistics { export interface DashboardReferenceTypeStatistics {
count: number; count: number;
referenceType: PublicReferenceType referenceType: ReferenceType
} }

View File

@ -1,12 +1,12 @@
import { BaseEntity } from "@common/base/base-entity.model"; import { BaseEntity } from "@common/base/base-entity.model";
import { Reference } from "../reference/reference"; import { BaseReference, Reference } from "../reference/reference";
import { Plan } from "./plan"; import { Plan, PublicPlan } from "./plan";
import { Guid } from "@common/types/guid"; import { Guid } from "@common/types/guid";
export interface PlanReference extends BaseEntity { export interface PlanReference extends BaseEntity {
plan?: Plan; plan: Plan;
reference?: Reference; reference: Reference;
data: PlanReferenceData; data?: PlanReferenceData;
} }
export interface PlanReferenceData { export interface PlanReferenceData {

View File

@ -15,29 +15,41 @@ import { IsActive } from '@app/core/common/enum/is-active.enum';
import { AppPermission } from '@app/core/common/enum/permission.enum'; import { AppPermission } from '@app/core/common/enum/permission.enum';
import { EntityType } from '@app/core/common/enum/entity-type'; import { EntityType } from '@app/core/common/enum/entity-type';
export interface Plan extends BasePlan { export interface BasePlan extends BaseEntity {
label?: string; label?: string;
version?: number; version?: number;
versionStatus?: PlanVersionStatus;
properties?: PlanProperties;
groupId?: String; groupId?: String;
description?: String; description?: String;
finalizedAt?: Date;
publishedAt?: Date; publishedAt?: Date;
creator?: User; finalizedAt?: Date;
accessType?: PlanAccessType; 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; blueprint?: PlanBlueprint;
language?: String; language?: String;
publicAfter?: Date; publicAfter?: Date;
planReferences?: PlanReference[];
planUsers?: PlanUser[]; planUsers?: PlanUser[];
descriptions?: Description[]; descriptions?: Description[];
planDescriptionTemplates?: PlanDescriptionTemplate[]; planDescriptionTemplates?: PlanDescriptionTemplate[];
entityDois?: EntityDoi[];
otherPlanVersions?: Plan[]; otherPlanVersions?: Plan[];
authorizationFlags?: AppPermission[]; authorizationFlags?: AppPermission[];
} }
export interface PublicPlan extends BasePlan {
planUsers: PublicPlanUser[];
descriptions: PublicDescription[];
otherPlanVersions?: PublicPlan[];
}
export interface PlanProperties { export interface PlanProperties {
planBlueprintValues: PlanBlueprintValue[]; planBlueprintValues: PlanBlueprintValue[];
contacts: PlanContact[]; contacts: PlanContact[];
@ -56,14 +68,21 @@ export interface PlanContact {
email: string; email: string;
} }
export interface BasePlanUser extends BaseEntity {
user: User;
role: PlanUserRole;
}
export interface PlanUser extends BaseEntity { export interface PlanUser extends BasePlanUser {
plan: Plan; plan: Plan;
user: User;
role: PlanUserRole;
sectionId: Guid; sectionId: Guid;
} }
export interface PublicPlanUser extends BasePlanUser{
plan: PublicPlan;
}
export interface PlanDescriptionTemplate extends BaseEntity { export interface PlanDescriptionTemplate extends BaseEntity {
plan?: Plan; plan?: Plan;
currentDescriptionTemplate?: DescriptionTemplate; currentDescriptionTemplate?: DescriptionTemplate;
@ -161,66 +180,4 @@ export interface PlanUserInvitePersist {
// //
// Public // 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[];
}

View File

@ -15,6 +15,14 @@ export interface Reference extends BaseEntity {
sourceType: ReferenceSourceType; sourceType: ReferenceSourceType;
} }
export interface BaseReference extends BaseEntity{
label: string;
type: ReferenceType;
description?: string;
reference?: string;
}
export interface Definition { export interface Definition {
fields: Field[]; fields: Field[];
} }

View File

@ -58,7 +58,7 @@ import { RouterUtilsService } from '@app/core/services/router/router-utils.servi
}) })
export class PlanOverviewComponent extends BaseComponent implements OnInit { export class PlanOverviewComponent extends BaseComponent implements OnInit {
plan: any | Plan | PublicPlan; plan: Plan | PublicPlan;
selectedBlueprint: PlanBlueprint; selectedBlueprint: PlanBlueprint;
researchers: PlanReference[] = []; researchers: PlanReference[] = [];
isNew = true; isNew = true;
@ -214,14 +214,14 @@ export class PlanOverviewComponent extends BaseComponent implements OnInit {
} }
get isActive(): boolean { get isActive(): boolean {
return this.plan && this.plan.isActive === IsActive.Active; return this.plan?.isActive != IsActive.Inactive;
} }
get selectedPlanVersion(): number { get selectedPlanVersion(): number {
return this.plan?.version; return this.plan?.version;
} }
get otherPlanVersions(): Plan | PublicPlan{ get otherPlanVersions(): Plan[] | PublicPlan[]{
return this.plan?.otherPlanVersions; return this.plan?.otherPlanVersions;
} }
@ -257,53 +257,68 @@ export class PlanOverviewComponent extends BaseComponent implements OnInit {
} }
canEditPlan(): boolean { 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 { 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 { canDeletePlan(): boolean {
const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : [];
return ( return (
this.isActive && this.isActive &&
(this.plan.authorizationFlags?.some(x => x === AppPermission.DeletePlan) || this.authentication.hasPermission(AppPermission.DeletePlan))) && (authorizationFlags?.some(x => x === AppPermission.DeletePlan) || this.authentication.hasPermission(AppPermission.DeletePlan)) &&
this.isPublicView == false && this.plan.belongsToCurrentTenant != false; this.isPublicView == false && this.plan.belongsToCurrentTenant != false
)
} }
canClonePlan(): boolean { 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 { canFinalizePlan(): boolean {
const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : [];
return ( return (
this.isActive && 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; this.isPublicView == false && this.plan.belongsToCurrentTenant != false;
} }
canExportPlan(): boolean { 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 { canInvitePlanUsers(): boolean {
const authorizationFlags = !this.isPublicView ? (this.plan as Plan).authorizationFlags : [];
return ( return (
this.isActive && 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; this.isPublicView == false && this.plan.belongsToCurrentTenant != false;
} }
canAssignPlanUsers(): boolean { 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 { 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() { 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() { cloneClicked() {
@ -588,8 +603,8 @@ export class PlanOverviewComponent extends BaseComponent implements OnInit {
getSectionNameById(sectionId: Guid): string { getSectionNameById(sectionId: Guid): string {
if (sectionId == null) return ''; if (sectionId == null) return '';
const blueprint = this.isPublicView ? null : (this.plan as Plan)?.blueprint;
let sections: PlanBlueprintDefinitionSection[] = this.plan?.blueprint?.definition?.sections?.filter((section: PlanBlueprintDefinitionSection) => sectionId === section.id); let sections: PlanBlueprintDefinitionSection[] = blueprint?.definition?.sections?.filter((section: PlanBlueprintDefinitionSection) => sectionId === section.id);
return sections == null ? '' : sections[0].label; return sections == null ? '' : sections[0].label;
} }

View File

@ -332,7 +332,7 @@ export class PlanBlueprintValueEditorModel implements PlanBlueprintValuePersist
this.fieldValue = item.fieldValue; this.fieldValue = item.fieldValue;
this.dateValue = item.dateValue; this.dateValue = item.dateValue;
this.numberValue = item.numberValue; 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 { return {
data: x.data, data: x.data,
reference: { reference: {