Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<iframe
[hidden]="hidden"
#jplagIframe
src="/JPlag/"
frameborder="0"
style="overflow: hidden"
class="w-full h-screen overflow-hidden"
Expand Down
52 changes: 40 additions & 12 deletions src/app/projects/states/jplag/jplag-report-viewer.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {AlertService} from 'src/app/common/services/alert.service';

@Component({
selector: 'f-jplag-report-viewer',
Expand All @@ -9,21 +10,48 @@ export class JplagReportViewerComponent {

@Input() hidden: boolean = false;

constructor(private alertService: AlertService) {}

public uploadReport(file: Blob) {
// Send the JPlag report to load
this.jplagIframe.nativeElement.contentWindow?.postMessage({
type: 'upload-jplag-report',
file: file,
name: 'report.jplag',
});
const blobUrl = URL.createObjectURL(file);
this.jplagIframe.nativeElement.src = `/JPlag/?file=${encodeURIComponent(blobUrl)}`;
}

public openComparison(firstSubmissionId: string, secondSubmissionId: string) {
// Open comparisons between these two submissions (student usernames)
this.jplagIframe.nativeElement.contentWindow?.postMessage({
type: 'open-comparison',
firstSubmissionId,
secondSubmissionId,
});
const iframe = this.jplagIframe.nativeElement;

const tryClick = () => {
const doc = iframe.contentDocument;
if (!doc) return false;

const el =
doc.querySelector(
`a[href="/JPlag/comparison/${firstSubmissionId}/${secondSubmissionId}"]`,
) ||
doc.querySelector(`a[href="/JPlag/comparison/${secondSubmissionId}/${firstSubmissionId}"]`);

if (el) {
(el as HTMLElement).click();
return true;
}

return false;
};

// Attempt to find the Vue component for 5 seconds
let elapsed = 0;
const interval = setInterval(() => {
if (tryClick()) {
clearInterval(interval);
return;
}

elapsed += 50;

if (elapsed >= 5000) {
clearInterval(interval);
this.alertService.error('Could not open JPlag comparison.', 6000);
}
}, 50);
}
}