diff --git a/frontend/src/app/assignment/model/solution.ts b/frontend/src/app/assignment/model/solution.ts index 0fb0c35eb..d3a1ccc2f 100644 --- a/frontend/src/app/assignment/model/solution.ts +++ b/frontend/src/app/assignment/model/solution.ts @@ -12,6 +12,12 @@ export const authorInfoProperties = [ ['GitHub Username', 'github'], ] as const; +export interface Consent { + demonstration?: boolean; + scientific?: boolean; + '3P'?: boolean; +} + export default class Solution { _id?: string; token?: string; @@ -21,11 +27,7 @@ export default class Solution { author: AuthorInfo; solution: string; commit?: string; - consent?: { - demonstration?: boolean; - scientific?: boolean; - '3P'?: boolean; - }; + consent?: Consent; timestamp?: Date; points?: number; diff --git a/frontend/src/app/assignment/modules/assignment/import-modal/import-modal.component.html b/frontend/src/app/assignment/modules/assignment/import-modal/import-modal.component.html index 387720c46..828b5ab27 100644 --- a/frontend/src/app/assignment/modules/assignment/import-modal/import-modal.component.html +++ b/frontend/src/app/assignment/modules/assignment/import-modal/import-modal.component.html @@ -1,6 +1,6 @@ - Import Solutions + Import
diff --git a/frontend/src/app/assignment/modules/assignment/import-modal/import-modal.component.ts b/frontend/src/app/assignment/modules/assignment/import-modal/import-modal.component.ts index ffcd1af65..dd47dbacc 100644 --- a/frontend/src/app/assignment/modules/assignment/import-modal/import-modal.component.ts +++ b/frontend/src/app/assignment/modules/assignment/import-modal/import-modal.component.ts @@ -2,7 +2,7 @@ import {Component} from '@angular/core'; import {ActivatedRoute} from '@angular/router'; import {ToastService} from '@mean-stream/ngbx'; import {SolutionService} from '../../../services/solution.service'; -import {EstimatedCosts, ImportSolution} from "../../../model/solution"; +import Solution, {AuthorInfo, Consent, EstimatedCosts, ImportSolution} from "../../../model/solution"; import {EMPTY, Observable} from "rxjs"; import {AssignmentService} from "../../../services/assignment.service"; @@ -21,6 +21,7 @@ export class ImportModalComponent { estimatedCosts?: EstimatedCosts; finalCosts?: EstimatedCosts; mossResult?: string; + consentText = ''; constructor( private assignmentService: AssignmentService, @@ -63,6 +64,8 @@ export class ImportModalComponent { return this.solutionService.importEmbeddings(assignmentId); case 'moss': return this.assignmentService.moss(assignmentId); + case 'consent': + return this.importConsent(assignmentId); default: return EMPTY; } @@ -79,4 +82,47 @@ export class ImportModalComponent { estimateCosts() { this.solutionService.importEmbeddings(this.route.snapshot.params.aid, true).subscribe(costs => this.estimatedCosts = costs); } + + importConsent(assignment: string): Observable { + const lines = this.consentText.split('\n'); + const splitter = /[\s,;]/; + const columns = lines[0].split(splitter); + const updates: Partial[] = []; + for (let i = 1; i < lines.length; i++){ + const values = lines[i].split(splitter); + const author: AuthorInfo = {}; + const consent: Consent = {}; + for (let j = 0; j < columns.length; j++) { + const column = columns[j].toLowerCase(); + const value = values[j]; + switch (column) { + case 'name': + author.name = value; + break; + case 'studentid': + author.studentId = value; + break; + case 'email': + author.email = value; + break; + case 'github': + author.github = value; + break; + case 'demonstration': + consent.demonstration = Boolean(value.toLowerCase()); + break; + case 'scientific': + consent.scientific = Boolean(value.toLowerCase()); + break; + case '3p': + consent['3P'] = Boolean(value.toLowerCase()); + break; + } + } + if (Object.keys(author).length) { + updates.push({author, consent}); + } + } + return this.solutionService.updateMany(assignment, updates); + } } diff --git a/frontend/src/app/assignment/services/solution.service.ts b/frontend/src/app/assignment/services/solution.service.ts index 67ba6bdb9..acdefdac1 100644 --- a/frontend/src/app/assignment/services/solution.service.ts +++ b/frontend/src/app/assignment/services/solution.service.ts @@ -203,6 +203,13 @@ export class SolutionService { return this.http.patch(url, dto, {headers}); } + updateMany(assignment: string, dtos: Partial[]): Observable { + const headers = {}; + this.addAssignmentToken(headers, assignment); + const url = `${environment.assignmentsApiUrl}/assignments/${assignment}/solutions`; + return this.http.patch(url, dtos, {headers}); + } + delete(assignment: string, solution: string): Observable { const headers = {}; this.addSolutionToken(headers, assignment, solution);