Skip to content

Commit

Permalink
Merge pull request #150 from satikaj/add-numbas-integration
Browse files Browse the repository at this point in the history
Fix Task Def model and service to keep track of Numbas config
  • Loading branch information
maddernd authored Mar 23, 2024
2 parents 98a8342 + 27f38cc commit 696abc0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 57 deletions.
8 changes: 3 additions & 5 deletions src/app/api/models/task-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,9 @@ export class TaskDefinition extends Entity {
hasTaskSheet: boolean;
hasTaskResources: boolean;
hasEnabledNumbasTest: boolean;
hasUploadedNumbasTest: boolean;
hasUnlimitedRetriesForNumbas: boolean;
hasTimeDelayForNumbas: boolean;
isNumbasRestrictedTo1Attempt: boolean;
hasNumbasData: boolean;
numbasTimeDelay: string = 'no delay';
numbasAttemptLimit: number = 0;
hasTaskAssessmentResources: boolean;
isGraded: boolean;
maxQualityPts: number;
Expand Down Expand Up @@ -217,7 +215,7 @@ export class TaskDefinition extends Entity {

public deleteNumbasTest(): Observable<any> {
const httpClient = AppInjector.get(HttpClient);
return httpClient.delete(this.numbasTestUploadUrl).pipe(tap(() => (this.hasUploadedNumbasTest = false)));
return httpClient.delete(this.numbasTestUploadUrl).pipe(tap(() => (this.hasNumbasData = false)));
}

public deleteTaskAssessmentResources(): Observable<any> {
Expand Down
31 changes: 0 additions & 31 deletions src/app/api/services/numbas.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,4 @@ export class NumbasService {

return mimeTypeMap[extension || ''] || 'text/plain';
}

/**
* Uploads a Numbas test file for a given unit and task.
*
* @param unitId - The ID of the unit
* @param taskId - The ID of the task
* @param file - File object representing the Numbas test to be uploaded
* @returns An Observable with the response from the server
*/
uploadTest(unitId: string, taskId: string, file: File): Observable<any> {
const uploadUrl = `${this.API_URL}/uploadNumbasTest`;
const formData = new FormData();

formData.append('file', file);
formData.append('unit_code', unitId);
formData.append('task_definition_id', taskId);

const httpOptions = {
headers: new HttpHeaders({
'Accept': 'application/json'
})
};

return this.http.post(uploadUrl, formData, httpOptions).pipe(
retry(3),
catchError((error: HttpErrorResponse) => {
console.error('Error uploading Numbas test:', error);
return throwError('Error uploading Numbas test.');
})
);
}
}
7 changes: 6 additions & 1 deletion src/app/api/services/task-definition.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ export class TaskDefinitionService extends CachedEntityService<TaskDefinition> {
'hasTaskSheet',
'hasTaskResources',
'hasTaskAssessmentResources',
'hasEnabledNumbasTest',
'hasNumbasData',
'numbasTimeDelay',
'numbasAttemptLimit',
'isGraded',
'maxQualityPts',
'overseerImageId',
Expand All @@ -114,7 +118,8 @@ export class TaskDefinitionService extends CachedEntityService<TaskDefinition> {
'plagiarismReportUrl',
'hasTaskSheet',
'hasTaskResources',
'hasTaskAssessmentResources'
'hasTaskAssessmentResources',
'hasNumbasData'
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
accept="application/zip"
[desiredFileName]="'Numbas zip'"
/>
@if (taskDefinition.hasUploadedNumbasTest) {
@if (taskDefinition.hasNumbasData) {
<div class="flex flex-row gap-4 pt-4">
<button mat-flat-button color="warn" (click)="removeNumbasTest()" class="flex-grow me-4">
Delete Numbas Zip
Expand All @@ -22,23 +22,29 @@
}
</div>

<div class="flex flex-row items-center">
<span> Select test rules: </span>
<mat-checkbox matInput [(ngModel)]="taskDefinition.hasUnlimitedRetriesForNumbas">Unlimited retries</mat-checkbox>
<mat-checkbox matInput [(ngModel)]="taskDefinition.hasTimeDelayForNumbas">Time delay</mat-checkbox>
<mat-checkbox matInput [(ngModel)]="taskDefinition.isNumbasRestrictedTo1Attempt">Restrict to 1 attempt</mat-checkbox>
</div>

@if (taskDefinition.hasTimeDelayForNumbas) {
<mat-form-field appearance="outline">
<mat-label>Time delay</mat-label>
<mat-select [(ngModel)]="taskDefinition.numbasTimeDelay">
<mat-option value="no delay">No delay</mat-option>
<mat-option value="30 min">30 min</mat-option>
<mat-option value="2 hours">2 hours</mat-option>
<mat-option value="1 day">1 day</mat-option>
<mat-option value="see tutor">See tutor</mat-option>
</mat-select>
</mat-form-field>
@if (taskDefinition.hasEnabledNumbasTest) {
<div class="flex-grow flex flex-row gap-4 pt-4">
<mat-form-field appearance="outline" class="basis-1/2">
<mat-label>Time delay</mat-label>
<mat-select [(ngModel)]="taskDefinition.numbasTimeDelay">
<mat-option value="no delay">No delay</mat-option>
<mat-option value="30 min">30 min</mat-option>
<mat-option value="2 hours">2 hours</mat-option>
<mat-option value="1 day">1 day</mat-option>
<mat-option value="see tutor">See tutor</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" class="basis-1/2">
<mat-label>Attempt Limit</mat-label>
<input
matInput
min="0"
max="100"
type="number"
[(value)]="taskDefinition.numbasAttemptLimit"
[formControl]="scoreControl"
/>
</mat-form-field>
</div>
}
</div>
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Inject, Input } from '@angular/core';
import { FormControl, Validators } from '@angular/forms';
import { alertService } from 'src/app/ajs-upgraded-providers';
import { TaskDefinition } from 'src/app/api/models/task-definition';
import { Unit } from 'src/app/api/models/unit';
Expand All @@ -19,6 +20,8 @@ export class TaskDefinitionNumbasComponent {
private taskDefinitionService: TaskDefinitionService
) {}

public scoreControl = new FormControl('', [Validators.max(100), Validators.min(0)]);

public get unit(): Unit {
return this.taskDefinition?.unit;
}
Expand All @@ -45,7 +48,6 @@ export class TaskDefinitionNumbasComponent {
next: () => this.alerts.add('success', 'Uploaded Numbas test data', 2000),
error: (message) => this.alerts.add('danger', message, 6000),
});
this.taskDefinition.hasUploadedNumbasTest = true;
} else {
this.alerts.add('danger', 'Please drop a zip file to upload Numbas test data for this task', 6000);
}
Expand Down

0 comments on commit 696abc0

Please sign in to comment.