-
Notifications
You must be signed in to change notification settings - Fork 303
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Development: Migrate the git diff report module to standalone compone…
…nts (#9443)
- Loading branch information
Showing
31 changed files
with
589 additions
and
629 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
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
12 changes: 6 additions & 6 deletions
12
...app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.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
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
90 changes: 49 additions & 41 deletions
90
.../webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.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 |
---|---|---|
@@ -1,58 +1,66 @@ | ||
import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; | ||
import { ChangeDetectionStrategy, Component, ViewEncapsulation, computed, input, output } from '@angular/core'; | ||
import { ProgrammingExerciseGitDiffEntry } from 'app/entities/hestia/programming-exercise-git-diff-entry.model'; | ||
import { faAngleDown, faAngleUp } from '@fortawesome/free-solid-svg-icons'; | ||
import { GitDiffFilePanelTitleComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component'; | ||
import { GitDiffLineStatComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component'; | ||
import { GitDiffFileComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-file.component'; | ||
import { ArtemisSharedModule } from 'app/shared/shared.module'; | ||
|
||
@Component({ | ||
selector: 'jhi-git-diff-file-panel', | ||
templateUrl: './git-diff-file-panel.component.html', | ||
styleUrls: ['./git-diff-file-panel.component.scss'], | ||
encapsulation: ViewEncapsulation.None, | ||
standalone: true, | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
imports: [GitDiffFilePanelTitleComponent, GitDiffLineStatComponent, GitDiffFileComponent, ArtemisSharedModule], | ||
}) | ||
export class GitDiffFilePanelComponent implements OnInit { | ||
@Input() diffEntries: ProgrammingExerciseGitDiffEntry[]; | ||
export class GitDiffFilePanelComponent { | ||
protected readonly faAngleUp = faAngleUp; | ||
protected readonly faAngleDown = faAngleDown; | ||
|
||
@Input() templateFileContent: string | undefined; | ||
readonly diffEntries = input.required<ProgrammingExerciseGitDiffEntry[]>(); | ||
readonly originalFileContent = input<string>(); | ||
readonly modifiedFileContent = input<string>(); | ||
readonly diffForTemplateAndSolution = input<boolean>(true); | ||
readonly allowSplitView = input<boolean>(true); | ||
readonly onDiffReady = output<boolean>(); | ||
|
||
@Input() solutionFileContent: string | undefined; | ||
|
||
@Input() diffForTemplateAndSolution = true; | ||
|
||
@Input() allowSplitView = true; | ||
|
||
@Output() onDiffReady = new EventEmitter<boolean>(); | ||
|
||
previousFilePath: string | undefined; | ||
filePath: string | undefined; | ||
|
||
addedLineCount: number; | ||
removedLineCount: number; | ||
|
||
faAngleUp = faAngleUp; | ||
faAngleDown = faAngleDown; | ||
|
||
ngOnInit(): void { | ||
this.filePath = this.diffEntries | ||
.map((entry) => entry.filePath) | ||
readonly originalFilePath = computed(() => | ||
this.diffEntries() | ||
.map((entry) => entry.previousFilePath) | ||
.filter((filePath) => filePath) | ||
.first(); | ||
.first(), | ||
); | ||
|
||
this.previousFilePath = this.diffEntries | ||
.map((entry) => entry.previousFilePath) | ||
readonly modifiedFilePath = computed(() => | ||
this.diffEntries() | ||
.map((entry) => entry.filePath) | ||
.filter((filePath) => filePath) | ||
.first(); | ||
.first(), | ||
); | ||
|
||
this.addedLineCount = this.diffEntries | ||
.filter((entry) => entry && entry.filePath && entry.startLine && entry.lineCount) | ||
.flatMap((entry) => { | ||
return this.solutionFileContent?.split('\n').slice(entry.startLine! - 1, entry.startLine! + entry.lineCount! - 1); | ||
}) | ||
.filter((line) => line && line.trim().length !== 0).length; | ||
readonly addedLineCount = computed( | ||
() => | ||
this.diffEntries() | ||
.filter((entry) => entry && entry.filePath && entry.startLine && entry.lineCount) | ||
.flatMap((entry) => { | ||
return this.modifiedFileContent() | ||
?.split('\n') | ||
.slice(entry.startLine! - 1, entry.startLine! + entry.lineCount! - 1); | ||
}) | ||
.filter((line) => line && line.trim().length !== 0).length, | ||
); | ||
|
||
this.removedLineCount = this.diffEntries | ||
.filter((entry) => entry && entry.previousFilePath && entry.previousStartLine && entry.previousLineCount) | ||
.flatMap((entry) => { | ||
return this.templateFileContent?.split('\n').slice(entry.previousStartLine! - 1, entry.previousStartLine! + entry.previousLineCount! - 1); | ||
}) | ||
.filter((line) => line && line.trim().length !== 0).length; | ||
} | ||
readonly removedLineCount = computed( | ||
() => | ||
this.diffEntries() | ||
.filter((entry) => entry && entry.previousFilePath && entry.previousStartLine && entry.previousLineCount) | ||
.flatMap((entry) => { | ||
return this.originalFileContent() | ||
?.split('\n') | ||
.slice(entry.previousStartLine! - 1, entry.previousStartLine! + entry.previousLineCount! - 1); | ||
}) | ||
.filter((line) => line && line.trim().length !== 0).length, | ||
); | ||
} |
4 changes: 2 additions & 2 deletions
4
...main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.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 |
---|---|---|
@@ -1,9 +1,9 @@ | ||
<div class="ph-1"> | ||
@if (fileUnchanged) { | ||
@if (fileUnchanged()) { | ||
<div class="w-100 d-flex justify-content-center"> | ||
<span class="p-2" jhiTranslate="artemisApp.repository.commitHistory.commitDetails.fileUnchanged"></span> | ||
</div> | ||
} | ||
<!-- The editor is only hidden, not removed, as we still want it to report its readiness. --> | ||
<jhi-monaco-diff-editor [hidden]="fileUnchanged" [allowSplitView]="allowSplitView" (onReadyForDisplayChange)="onDiffReady.emit($event)" /> | ||
<jhi-monaco-diff-editor [hidden]="fileUnchanged()" [allowSplitView]="allowSplitView()" (onReadyForDisplayChange)="onDiffReady.emit($event)" /> | ||
</div> |
Oops, something went wrong.