forked from doubtfire-lms/doubtfire-web
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from satikaj/add-numbas-integration
Adjust Unit Chair admin page to allow upload of numbas test
- Loading branch information
Showing
6 changed files
with
164 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ditor/task-definition-editor/task-definition-numbas/task-definition-numbas.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<div class="flex flex-col gap-4"> | ||
<mat-checkbox matInput required [(ngModel)]="taskDefinition.hasEnabledNumbasTest"> | ||
Enable Numbas Test | ||
</mat-checkbox> | ||
|
||
<div class="basis-1/2 flex flex-col"> | ||
<f-file-drop | ||
mode="event" | ||
(filesDropped)="uploadNumbasTest($event)" | ||
accept="application/zip" | ||
[desiredFileName]="'Numbas zip'" | ||
/> | ||
@if (taskDefinition.hasUploadedNumbasTest) { | ||
<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 | ||
</button> | ||
<button mat-flat-button color="accent" (click)="downloadNumbasTest()" class="flex-grow ms-4"> | ||
Download Numbas Zip | ||
</button> | ||
</div> | ||
} | ||
</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> | ||
} | ||
</div> |
Empty file.
69 changes: 69 additions & 0 deletions
69
...-editor/task-definition-editor/task-definition-numbas/task-definition-numbas.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { Component, Inject, Input } from '@angular/core'; | ||
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'; | ||
import { TaskDefinitionService } from 'src/app/api/services/task-definition.service'; | ||
import { FileDownloaderService } from 'src/app/common/file-downloader/file-downloader.service'; | ||
|
||
@Component({ | ||
selector: 'f-task-definition-numbas', | ||
templateUrl: 'task-definition-numbas.component.html', | ||
styleUrls: ['task-definition-numbas.component.scss'], | ||
}) | ||
export class TaskDefinitionNumbasComponent { | ||
@Input() taskDefinition: TaskDefinition; | ||
|
||
constructor( | ||
private fileDownloaderService: FileDownloaderService, | ||
@Inject(alertService) private alerts: any, | ||
private taskDefinitionService: TaskDefinitionService | ||
) {} | ||
|
||
public get unit(): Unit { | ||
return this.taskDefinition?.unit; | ||
} | ||
|
||
public downloadNumbasTest() { | ||
this.fileDownloaderService.downloadFile( | ||
this.taskDefinition.getNumbasTestUrl(true), | ||
this.taskDefinition.name + '-Numbas.zip', | ||
); | ||
} | ||
|
||
public removeNumbasTest() { | ||
this.taskDefinition.deleteNumbasTest().subscribe({ | ||
next: () => this.alerts.add('success', 'Deleted Numbas test', 2000), | ||
error: (message) => this.alerts.add('danger', message, 6000), | ||
}); | ||
} | ||
|
||
public uploadNumbasTest(files: FileList) { | ||
const validFiles = Array.from(files as ArrayLike<File>).filter((f) => f.type === 'application/zip'); | ||
if (validFiles.length > 0) { | ||
const file = validFiles[0]; | ||
// Temporary until Numbas backend is fixed: save uploaded file to local Downloads folder | ||
this.saveZipFile(file); | ||
this.taskDefinition.hasUploadedNumbasTest = true; | ||
// this.taskDefinitionService.uploadNumbasTest(this.taskDefinition, file).subscribe({ | ||
// next: () => this.alerts.add('success', 'Uploaded Numbas test', 2000), | ||
// error: (message) => this.alerts.add('danger', message, 6000), | ||
// }); | ||
} else { | ||
this.alerts.add('danger', 'Please drop a ZIP to upload for this task', 6000); | ||
} | ||
} | ||
|
||
private saveZipFile(zipData) { | ||
const blob = new Blob([zipData], {type: 'application/zip'}); | ||
|
||
// Create an anchor element and set its href to the blob URL | ||
const link = document.createElement('a'); | ||
link.href = URL.createObjectURL(blob); | ||
link.download = 'numbas.zip'; | ||
|
||
// Append the link to the document, trigger the download, then remove the link | ||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
} | ||
} |