diff --git a/apps/editor/src/models/who/campaign.ts b/apps/editor/src/models/who/campaign.ts new file mode 100644 index 000000000..b89e85cd1 --- /dev/null +++ b/apps/editor/src/models/who/campaign.ts @@ -0,0 +1,52 @@ +import { User, UserSnapshot } from "./user"; + +export interface CampaignSnapshot { + campaignUUID: string; + name: string; + description: string; + status: string; + datasets: string[]; + annotators: UserSnapshot[]; + reviewers: UserSnapshot[]; +} + +export class Campaign { + public campaignUUID: string; + public name: string; + public description: string; + public status: string; + public datasets: string[]; + public annotators: User[]; + public reviewers: User[]; + + // TODO: Properly type API response data + constructor(campaign: any) { + this.campaignUUID = campaign.campaignUUID; + this.name = campaign.name; + this.description = campaign.description; + this.status = campaign.status; + this.datasets = campaign.datasets; + this.annotators = campaign.annotators.map( + (annotator: any) => new User(annotator), + ); + this.reviewers = campaign.reviewers.map( + (reviewer: any) => new User(reviewer), + ); + } + + public toJSON(): CampaignSnapshot { + return { + campaignUUID: this.campaignUUID, + name: this.name, + description: this.description, + status: this.status, + datasets: this.datasets, + annotators: Object.values(this.annotators).map((annotator) => + annotator.toJSON(), + ), + reviewers: Object.values(this.reviewers).map((reviewer) => + reviewer.toJSON(), + ), + }; + } +} diff --git a/apps/editor/src/models/who/task.ts b/apps/editor/src/models/who/task.ts index 5745705cf..15257898b 100644 --- a/apps/editor/src/models/who/task.ts +++ b/apps/editor/src/models/who/task.ts @@ -1,5 +1,6 @@ import { Annotation, AnnotationSnapshot, AnnotationStatus } from "./annotation"; import { AnnotationTask, AnnotationTaskSnapshot } from "./annotationTask"; +import { Campaign, CampaignSnapshot } from "./campaign"; import { Sample } from "./sample"; import { User, UserSnapshot } from "./user"; @@ -10,6 +11,7 @@ export interface TaskSnapshot { annotationTasks: AnnotationTaskSnapshot[]; annotations?: AnnotationSnapshot[]; assignee: UserSnapshot; + campaign: CampaignSnapshot | Record; } export enum TaskType { @@ -26,6 +28,7 @@ export class Task { public samples: Sample[]; public annotations: Annotation[]; public assignee: User; + public campaign?: Campaign; // TODO: Properly type API response data constructor(task: any) { @@ -40,6 +43,9 @@ export class Task { (annotation: any) => new Annotation(annotation), ); this.assignee = new User(task.assignee); + if (task.campaign && Object.keys(task.campaign).length > 1) { + this.campaign = new Campaign(task.campaign); + } } public addNewAnnotation(): void { @@ -65,6 +71,7 @@ export class Task { annotation.toJSON(), ), assignee: this.assignee.toJSON(), + campaign: this.campaign ? this.campaign.toJSON() : {}, }; } }