Skip to content

Commit

Permalink
feat(frontend): Update consent for multiple solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Clashsoft committed Sep 13, 2023
1 parent ebd9fa1 commit b3f2f6e
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 7 deletions.
12 changes: 7 additions & 5 deletions frontend/src/app/assignment/model/solution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<ngbx-modal #modal [back]="['../solutions']">
<ng-container modal-title>
Import Solutions
Import
</ng-container>
<ng-container modal-body>
<ul ngbNav #nav="ngbNav" [activeId]="(route.queryParams | async)?.mode" class="nav-tabs mb-3">
Expand Down Expand Up @@ -106,6 +106,35 @@
</ng-container>
</ng-template>
</li>
<li ngbNavItem="consent">
<a ngbNavLink routerLink="." [queryParams]="{mode: 'consent'}">
Consent
</a>
<ng-template ngbNavContent>
<p>
Import consent flags by pasting tab-, space- or comma-separated values below.
</p>
<details>
<summary>More Info</summary>
<p>
The first line should specify the column names (case insensitive), for example:
</p>
<p>
<code>github,demonstration,scientific,3p</code>
</p>
<p>
Instead of or in addition to <code>github</code>,
you can also use <code>name</code>, <code>studentid</code> or <code>email</code>,
but at least one of must be specified.
</p>
<p>
The columns <code>demonstration</code>, <code>scientific</code> and <code>3p</code> are optional
and accept boolean values like <code>true</code> or <code>false</code> (case-insensitive).
</p>
</details>
<textarea class="form-control" rows="10" [(ngModel)]="consentText"></textarea>
</ng-template>
</li>
</ul>
<div [ngbNavOutlet]="nav"></div>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -21,6 +21,7 @@ export class ImportModalComponent {
estimatedCosts?: EstimatedCosts;
finalCosts?: EstimatedCosts;
mossResult?: string;
consentText = '';

constructor(
private assignmentService: AssignmentService,
Expand Down Expand Up @@ -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;
}
Expand All @@ -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<ImportSolution[]> {
const lines = this.consentText.split('\n');
const splitter = /[\s,;]/;
const columns = lines[0].split(splitter);
const updates: Partial<Solution>[] = [];
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);
}
}
7 changes: 7 additions & 0 deletions frontend/src/app/assignment/services/solution.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ export class SolutionService {
return this.http.patch<Solution>(url, dto, {headers});
}

updateMany(assignment: string, dtos: Partial<Solution>[]): Observable<ImportSolution[]> {
const headers = {};
this.addAssignmentToken(headers, assignment);
const url = `${environment.assignmentsApiUrl}/assignments/${assignment}/solutions`;
return this.http.patch<ImportSolution[]>(url, dtos, {headers});
}

delete(assignment: string, solution: string): Observable<Solution> {
const headers = {};
this.addSolutionToken(headers, assignment, solution);
Expand Down

0 comments on commit b3f2f6e

Please sign in to comment.