Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions apps/editor/src/models/who/campaign.ts
Original file line number Diff line number Diff line change
@@ -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(),
),
};
}
}
7 changes: 7 additions & 0 deletions apps/editor/src/models/who/task.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -10,6 +11,7 @@ export interface TaskSnapshot {
annotationTasks: AnnotationTaskSnapshot[];
annotations?: AnnotationSnapshot[];
assignee: UserSnapshot;
campaign: CampaignSnapshot | Record<string, never>;
}

export enum TaskType {
Expand All @@ -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) {
Expand All @@ -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 {
Expand All @@ -65,6 +71,7 @@ export class Task {
annotation.toJSON(),
),
assignee: this.assignee.toJSON(),
campaign: this.campaign ? this.campaign.toJSON() : {},
};
}
}