Skip to content

Commit

Permalink
ramona fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayvirS committed Dec 3, 2024
1 parent d7a636a commit 38910db
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 80 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@if (comparison) {
<div class="plagiarism-details">
<jhi-plagiarism-header [splitControlSubject]="splitControlSubject" [exercise]="exercise" [comparison]="comparison"> </jhi-plagiarism-header>
<jhi-plagiarism-split-view [comparison]="comparison" [exercise]="exercise" [splitControlSubject]="splitControlSubject"> </jhi-plagiarism-split-view>
<jhi-plagiarism-header [splitControlSubject]="splitControlSubject" [exercise]="exercise" [comparison]="comparison" />
<jhi-plagiarism-split-view [comparison]="comparison" [exercise]="exercise" [splitControlSubject]="splitControlSubject" />
</div>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
}
@if (isProgrammingOrTextExercise) {
<jhi-text-submission-viewer
[fileSelectedSubject]="getFileSelectedSubject()"
[fileSelectedSubject]="this.fileSelectedSubject"
[exercise]="exercise"
[matches]="matchesA"
[plagiarismSubmission]="getTextSubmissionA()"
[isLockFilesEnabled]="isLockFilesEnabled"
[hideContent]="false"
[dropdownHoverSubject]="getDropdownHoverSubject()"
[showFilesSubject]="getShowFilesSubject()"
[dropdownHoverSubject]="this.dropdownHoverSubject"
[showFilesSubject]="this.showFilesSubject"
/>
}
}
Expand All @@ -34,14 +34,14 @@
}
@if (isProgrammingOrTextExercise) {
<jhi-text-submission-viewer
[fileSelectedSubject]="getFileSelectedSubject()"
[fileSelectedSubject]="this.fileSelectedSubject"
[exercise]="exercise"
[matches]="matchesB"
[plagiarismSubmission]="getTextSubmissionB()"
[isLockFilesEnabled]="isLockFilesEnabled"
[hideContent]="forStudent && dayjs(exercise.dueDate).isAfter(dayjs())"
[dropdownHoverSubject]="getDropdownHoverSubject()"
[showFilesSubject]="getShowFilesSubject()"
[dropdownHoverSubject]="this.dropdownHoverSubject"
[showFilesSubject]="this.showFilesSubject"
/>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ export class PlagiarismSplitViewComponent implements AfterViewInit, OnChanges, O
@ViewChildren(SplitPaneDirective) panes!: QueryList<SplitPaneDirective>;

plagiarismComparison: PlagiarismComparison<TextSubmissionElement | ModelingSubmissionElement>;
private fileSelectedSubject = new Subject<TextPlagiarismFileElement>();
private showFilesSubject = new Subject<boolean>();
private dropdownHoverSubject = new Subject<TextPlagiarismFileElement>();
fileSelectedSubject = new Subject<TextPlagiarismFileElement>();
showFilesSubject = new Subject<boolean>();
dropdownHoverSubject = new Subject<TextPlagiarismFileElement>();

public split: Split.Instance;

Expand Down Expand Up @@ -117,22 +117,6 @@ export class PlagiarismSplitViewComponent implements AfterViewInit, OnChanges, O
}
}

/**
* get the subject/listener for file selection
* @returns observable for fileselection
*/
getFileSelectedSubject() {
return this.fileSelectedSubject;
}

/**
* get the subject/listener for checking dropdown toggle status of split-pane-header in text-viewer component
* @returns subject for showFile change
*/
getShowFilesSubject() {
return this.showFilesSubject;
}

parseTextMatches(plagComparison: PlagiarismComparison<TextSubmissionElement>) {
if (plagComparison.matches) {
const matchesA = plagComparison.matches.map((match) => new SimpleMatch(match.startA, match.length)).sort((m1, m2) => m1.start - m2.start);
Expand Down Expand Up @@ -208,10 +192,6 @@ export class PlagiarismSplitViewComponent implements AfterViewInit, OnChanges, O
}
}

getDropdownHoverSubject() {
return this.dropdownHoverSubject;
}

/**
* Toggles the state of file locking and emits the new state to the parent component.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="split-pane-header" ngbDropdown>
<div class="split-pane-header-top" data-toggle="dropdown" [ngClass]="{ active: showFiles, clickable: hasFiles() }" (click)="toggleShowFiles()">
<div class="split-pane-header-top" data-toggle="dropdown" [ngClass]="{ active: showFiles, clickable: hasFiles() }" (click)="toggleShowFiles(true)">
@if (hasActiveFile()) {
<div class="split-pane-header-file-name">
<fa-icon class="file-arrow-down" [icon]="faChevronDown" />
Expand All @@ -15,8 +15,8 @@
class="split-pane-header-file"
ngbDropdownItem
(mouseenter)="triggerMouseEnter(file, idx)"
(click)="handleFileSelect(file, idx)"
[ngClass]="{ hover: idx === hoveredFileIdx }"
(click)="handleFileSelect(file, idx, true)"
[ngClass]="{ hover: idx === hoveredFileIndex }"
>
<span [class.split-pane-header-file-with-match]="file.hasMatch">{{ file.file }}</span>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ export class SplitPaneHeaderComponent implements OnChanges, OnInit, OnDestroy {

private fileSelectSubscription: Subscription;
private showFilesSubscription: Subscription;
private dropdownHoverSubscription: Subscription;

// Icons
faChevronDown = faChevronDown;
hoveredFileIdx: number;
hoveredFileIndex: number;

ngOnInit(): void {
this.subscribeToFileSelection();
Expand All @@ -47,19 +48,18 @@ export class SplitPaneHeaderComponent implements OnChanges, OnInit, OnDestroy {
* @private helper method
*/
private subscribeToFileSelection(): void {
this.fileSelectSubscription = this.fileSelectedSubject()!.subscribe((val) => {
this.fileSelectSubscription = this.fileSelectedSubject()!.subscribe((textPlagiarismElement) => {
if (this.isLockFilesEnabled()) {
this.handleLockedFileSelection(val.file, val.idx);
this.handleLockedFileSelection(textPlagiarismElement.file, textPlagiarismElement.idx);
}
});
}

private handleLockedFileSelection(file: FileWithHasMatch, idx: number): void {
let index;
if (this.files[idx]?.file === file.file) {
this.handleFileSelectWithoutPropagation(file, idx);
} else if ((index = this.getIndexOf(file)) >= 0) {
this.handleFileSelectWithoutPropagation(file, index);
const index = this.files[idx]?.file === file.file ? idx : this.getIndexOf(file);

if (index >= 0) {
this.handleFileSelect(file, index, false);
} else {
this.showFiles = false;
}
Expand All @@ -72,7 +72,7 @@ export class SplitPaneHeaderComponent implements OnChanges, OnInit, OnDestroy {
private subscribeToShowFiles(): void {
this.showFilesSubscription = this.showFilesSubject()!.subscribe((showFiles) => {
if (this.isLockFilesEnabled()! || (!this.isLockFilesEnabled()! && !showFiles)) {
this.toggleShowFilesWithoutPropagation(showFiles);
this.toggleShowFiles(false, showFiles);
}
});
}
Expand All @@ -82,20 +82,17 @@ export class SplitPaneHeaderComponent implements OnChanges, OnInit, OnDestroy {
* @private helper method
*/
private subscribeToDropdownHover(): void {
this.dropdownHoverSubject()!.subscribe((val) => {
this.dropdownHoverSubscription = this.dropdownHoverSubject()!.subscribe((textPlagiarismElement) => {
if (this.isLockFilesEnabled()) {
this.handleDropdownHover(val.file, val.idx);
this.handleDropdownHover(textPlagiarismElement.file, textPlagiarismElement.idx);
}
});
}

private handleDropdownHover(file: FileWithHasMatch, idx: number): void {
let index;
if (this.files[idx]?.file === file.file) {
this.hoveredFileIdx = idx;
} else if ((index = this.getIndexOf(file)) >= 0) {
this.hoveredFileIdx = index;
} else this.hoveredFileIdx = -1;
const index = this.files[idx]?.file === file.file ? idx : this.getIndexOf(file);

this.hoveredFileIndex = index >= 0 ? index : -1;
}

ngOnChanges(changes: SimpleChanges) {
Expand All @@ -111,9 +108,9 @@ export class SplitPaneHeaderComponent implements OnChanges, OnInit, OnDestroy {
}

ngOnDestroy(): void {
this.fileSelectSubscription?.unsubscribe();

this.showFilesSubscription?.unsubscribe();
this.fileSelectSubscription?.unsubscribe();
this.showFilesSubscription?.unsubscribe();
this.dropdownHoverSubscription?.unsubscribe();
}

hasActiveFile(): boolean {
Expand All @@ -128,44 +125,34 @@ export class SplitPaneHeaderComponent implements OnChanges, OnInit, OnDestroy {
* handles selection of file from dropdown, propagates change to fileslectionsubject component for lock sync
* @param file to be selected
* @param idx index of the file from the dropdown
* @param propagateChanges propagate changes to listeners subscribed to fileSelectedSubject
*/
handleFileSelect(file: FileWithHasMatch, idx: number): void {
this.fileSelectedSubject()!.next({ idx: idx, file: file });
this.activeFileIndex = idx;
this.showFiles = false;
this.selectFile.emit(file.file);
}

/**
* handles selection of file from dropdown, do NOT propagates change to fileslectionsubject component for lock sync
* @param file to be selected
* @param idx index of the file from the dropdown
*/
handleFileSelectWithoutPropagation(file: FileWithHasMatch, idx: number) {
handleFileSelect(file: FileWithHasMatch, idx: number, propagateChanges: boolean): void {
if (propagateChanges) {
this.fileSelectedSubject()!.next({ idx: idx, file: file });
file.hasMatch = true;
}
this.activeFileIndex = idx;
this.showFiles = false;
this.selectFile.emit(file.file);
file.hasMatch = true;
}

hasFiles(): boolean {
return this.files?.length ? true : false;
}

toggleShowFiles(): void {
if (this.hasFiles()) {
this.showFiles = !this.showFiles;
this.showFilesSubject()!.next(this.showFiles);
}
return !!this.files?.length;
}

/**
* handles toggle of the dropdown, do NOT propagate change to emit toggle to parent component component for lock sync
* @param showFiles dropdown toggle status
* Toggles the dropdown visibility and optionally propagates changes to the parent component.
* @param showFiles Optional toggle status; if undefined, the status will be toggled.
* @param propagateChanges Whether to propagate the change to the parent component.
*/
toggleShowFilesWithoutPropagation(showFiles: boolean): void {
toggleShowFiles(propagateChanges: boolean, showFiles?: boolean): void {
if (this.hasFiles()) {
this.showFiles = showFiles;
this.showFiles = showFiles !== undefined ? showFiles : !this.showFiles;

if (propagateChanges) {
this.showFilesSubject()!.next(this.showFiles);
}
}
}

Expand Down

0 comments on commit 38910db

Please sign in to comment.