Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add jplag frontend #873

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
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
56 changes: 40 additions & 16 deletions src/app/api/models/task-definition.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
import { HttpClient } from '@angular/common/http';
import { Entity, EntityMapping } from 'ngx-entity-service';
import { Observable, tap } from 'rxjs';
import { AppInjector } from 'src/app/app-injector';
import { DoubtfireConstants } from 'src/app/config/constants/doubtfire-constants';
import { Grade, GroupSet, TutorialStream, Unit } from './doubtfire-model';
import { TaskDefinitionService } from '../services/task-definition.service';

export type UploadRequirement = { key: string; name: string; type: string; tiiCheck?: boolean; tiiPct?: number };
import {HttpClient, HttpResponse} from '@angular/common/http';
import {Entity, EntityMapping} from 'ngx-entity-service';
import {firstValueFrom, Observable, tap} from 'rxjs';
import {AppInjector} from 'src/app/app-injector';
import {DoubtfireConstants} from 'src/app/config/constants/doubtfire-constants';
import {Grade, GroupSet, TutorialStream, Unit} from './doubtfire-model';
import {TaskDefinitionService} from '../services/task-definition.service';

export type UploadRequirement = {
key: string;
name: string;
type: string;
tiiCheck?: boolean;
tiiPct?: number;
};

export type SimilarityCheck = { key: string; type: string; pattern: string };
export type SimilarityCheck = {key: string; type: string; pattern: string};

export class TaskDefinition extends Entity {
id: number;
Expand Down Expand Up @@ -36,7 +42,7 @@ export class TaskDefinition extends Entity {
maxQualityPts: number;
overseerImageId: number;
assessmentEnabled: boolean;
mossLanguage: string = 'moss c';
jplagLanguage: string = 'c';

readonly unit: Unit;

Expand Down Expand Up @@ -67,15 +73,15 @@ export class TaskDefinition extends Entity {
entity: this,
cache: this.unit.taskDefinitionCache,
constructorParams: this.unit,
}
},
);
} else {
return svc.update(
{
unitId: this.unit.id,
id: this.id,
},
{ entity: this }
{entity: this},
);
}
}
Expand Down Expand Up @@ -122,7 +128,10 @@ export class TaskDefinition extends Entity {
}

public matches(text: string): boolean {
return this.abbreviation.toLowerCase().indexOf(text) !== -1 || this.name.toLowerCase().indexOf(text) !== -1;
return (
this.abbreviation.toLowerCase().indexOf(text) !== -1 ||
this.name.toLowerCase().indexOf(text) !== -1
);
}

/**
Expand Down Expand Up @@ -160,7 +169,7 @@ export class TaskDefinition extends Entity {
return this.plagiarismChecks?.length > 0;
}

public get needsMoss(): boolean {
public get needsJplag(): boolean {
return this.uploadRequirements.some((upreq) => upreq.type === 'code' && upreq.tiiCheck);
}

Expand Down Expand Up @@ -188,14 +197,29 @@ export class TaskDefinition extends Entity {
}/task_assessment_resources.json`;
}

public async hasJplagReport(): Promise<boolean> {
const url = `${AppInjector.get(DoubtfireConstants).API_URL}/units/${this.unit.id}/task_definitions/${this.id}/has_jplag_report`;
//console.log(url);
try {
const response = await fetch(url);
const result = await response.json();
return result === 'true';
} catch (error) {
console.error('Error fetching JPLAG report:', error);
return false;
}
}

public deleteTaskSheet(): Observable<any> {
const httpClient = AppInjector.get(HttpClient);
return httpClient.delete(this.taskSheetUploadUrl).pipe(tap(() => (this.hasTaskSheet = false)));
}

public deleteTaskResources(): Observable<any> {
const httpClient = AppInjector.get(HttpClient);
return httpClient.delete(this.taskResourcesUploadUrl).pipe(tap(() => (this.hasTaskResources = false)));
return httpClient
.delete(this.taskResourcesUploadUrl)
.pipe(tap(() => (this.hasTaskResources = false)));
}

public deleteTaskAssessmentResources(): Observable<any> {
Expand Down
6 changes: 3 additions & 3 deletions src/app/api/models/task-similarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { DoubtfireConstants } from 'src/app/config/constants/doubtfire-constants
import { Observable } from 'rxjs';

export enum TaskSimilarityType {
Moss = 'MossTaskSimilarity',
Jplag = 'JplagTaskSimilarity',
TurnItIn = 'TiiTaskSimilarity',
}

Expand Down Expand Up @@ -62,8 +62,8 @@ export class TaskSimilarity extends Entity {

public get friendlyTypeName(): string {
switch (this.type) {
case TaskSimilarityType.Moss:
return 'MOSS';
case TaskSimilarityType.Jplag:
return 'JPLAG';
case TaskSimilarityType.TurnItIn:
return 'TurnItIn';
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/api/services/task-definition.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class TaskDefinitionService extends CachedEntityService<TaskDefinition> {
'description',
'weighting',
'targetGrade',
'mossLanguage',
'jplagLanguage',
{
keys: 'targetDate',
toEntityFn: MappingFunctions.mapDateToEndOfDay,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@ <h1 class="mat-headline"></h1>
</mat-panel-title>
<mat-panel-description> {{ part.description }} </mat-panel-description>
@if (similarity.readyForViewer) {
<button
matTooltip="View report for this similarity"
mat-icon-button
aria-label="View Detailed Report"
(click)="openReport($event, similarity)"
>
<mat-icon>summarize</mat-icon>
</button>
@if (similarity.type === 'JplagTaskSimilarity') {
<button
matTooltip="Download report for this similarity"
mat-icon-button
aria-label="View Detailed Report"
(click)="downloadJPLAGReport()"
>
<mat-icon>download</mat-icon>
</button>
} @else {
<button
matTooltip="View similarity for this part"
mat-icon-button
aria-label="View Similarity"
(click)="openViewer($event, similarity, part)"
>
<mat-icon>summarize</mat-icon>
</button>
}
}
@if (i === 0) {
<button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { TaskSimilarity } from 'src/app/api/models/task-similarity';
import { TaskSimilarityService } from 'src/app/api/services/task-similarity.service';
import { AlertService } from 'src/app/common/services/alert.service';
import { SelectedTaskService } from '../../../../selected-task.service';
import {FileDownloaderService} from 'src/app/common/file-downloader/file-downloader.service';
import { DoubtfireConstants } from 'src/app/config/constants/doubtfire-constants';
import { AppInjector } from 'src/app/app-injector';

@Component({
selector: 'f-task-similarity-view',
Expand All @@ -19,7 +22,8 @@ export class TaskSimilarityViewComponent implements OnChanges {
constructor(
private taskSimilarityService: TaskSimilarityService,
private alertsService: AlertService,
private selectedTaskService: SelectedTaskService
private selectedTaskService: SelectedTaskService,
private fileDownloaderService: FileDownloaderService,
) {}

ngOnChanges(changes: SimpleChanges) {
Expand Down Expand Up @@ -54,4 +58,16 @@ export class TaskSimilarityViewComponent implements OnChanges {
window.open(url, '_blank');
});
}

downloadJPLAGReport() {
const taskDef = this.task.definition;
this.fileDownloaderService.downloadFile(
//this.taskData.selectedTask.jplagReportUrl()
`${AppInjector.get(DoubtfireConstants).API_URL}/units/${
this.task.unit.id
}/task_definitions/${taskDef.id}/jplag_report`,
`${this.task.unit.code}-${taskDef.abbreviation}-jplag-report.zip`,
);
window.open('https://jplag.github.io/JPlag/', '_blank');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<mat-checkbox [(ngModel)]="upreq.tiiCheck">TurnItIn</mat-checkbox>
}
@if (upreq.type === 'code') {
<mat-checkbox [(ngModel)]="upreq.tiiCheck">Moss</mat-checkbox>
<mat-checkbox [(ngModel)]="upreq.tiiCheck">Jplag</mat-checkbox>
}
</td>
</ng-container>
Expand Down Expand Up @@ -74,19 +74,19 @@
<tr mat-footer-row *matFooterRowDef="['actions']"></tr>
</table>

@if (taskDefinition.needsMoss) {
@if (taskDefinition.needsJplag) {
<div class="flex-grow flex flex-row gap-4">
<mat-form-field appearance="outline" class="basis-1/2">
<mat-label>Language used for Moss checks</mat-label>
<mat-select [(ngModel)]="taskDefinition.mossLanguage">
<mat-option value="moss c">C</mat-option>
<mat-option value="moss csharp">C#</mat-option>
<mat-option value="moss cc">C++</mat-option>
<mat-option value="moss python">Python</mat-option>
<mat-label>Language used for JPLAG checks</mat-label>
<mat-select [(ngModel)]="taskDefinition.jplagLanguage">
<mat-option value="c">C</mat-option>
<mat-option value="csharp">C#</mat-option>
<mat-option value="cpp">C++</mat-option>
<mat-option value="python">Python</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="outline" class="basis-1/2">
<mat-label>Similarity percent to flag for Moss checks</mat-label>
<mat-label>Similarity percent to flag for JPLAG checks</mat-label>
<input matInput [(ngModel)]="taskDefinition.plagiarismWarnPct" type="number" />
</mat-form-field>
</div>
Expand Down
Loading