diff --git a/src/main/webapp/app/detail-overview-list/components/programming-diff-report-detail/programming-diff-report-detail.component.ts b/src/main/webapp/app/detail-overview-list/components/programming-diff-report-detail/programming-diff-report-detail.component.ts index e95dbf256ee2..94fb86848f4f 100644 --- a/src/main/webapp/app/detail-overview-list/components/programming-diff-report-detail/programming-diff-report-detail.component.ts +++ b/src/main/webapp/app/detail-overview-list/components/programming-diff-report-detail/programming-diff-report-detail.component.ts @@ -1,20 +1,20 @@ -import { Component, Input, OnDestroy, inject } from '@angular/core'; +import { Component, Input, OnDestroy, inject, signal } from '@angular/core'; import type { ProgrammingDiffReportDetail } from 'app/detail-overview-list/detail.model'; import { FeatureToggle } from 'app/shared/feature-toggle/feature-toggle.service'; import { ButtonSize, ButtonType, TooltipPlacement } from 'app/shared/components/button.component'; import { faCodeCompare } from '@fortawesome/free-solid-svg-icons'; import { ProgrammingExerciseGitDiffReport } from 'app/entities/hestia/programming-exercise-git-diff-report.model'; import { GitDiffReportModalComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report-modal.component'; -import { GitDiffReportModule } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.module'; import { ArtemisSharedComponentModule } from 'app/shared/components/shared-component.module'; import { ArtemisSharedModule } from 'app/shared/shared.module'; import { NgbModal, NgbModalRef } from '@ng-bootstrap/ng-bootstrap'; +import { GitDiffLineStatComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component'; @Component({ selector: 'jhi-programming-diff-report-detail', templateUrl: 'programming-diff-report-detail.component.html', standalone: true, - imports: [ArtemisSharedModule, ArtemisSharedComponentModule, GitDiffReportModule], + imports: [ArtemisSharedModule, ArtemisSharedComponentModule, GitDiffLineStatComponent], }) export class ProgrammingDiffReportDetailComponent implements OnDestroy { protected readonly FeatureToggle = FeatureToggle; @@ -38,7 +38,7 @@ export class ProgrammingDiffReportDetailComponent implements OnDestroy { return; } - this.modalRef = this.modalService.open(GitDiffReportModalComponent, { windowClass: 'diff-view-modal' }); - this.modalRef.componentInstance.report = gitDiff; + this.modalRef = this.modalService.open(GitDiffReportModalComponent, { windowClass: GitDiffReportModalComponent.WINDOW_CLASS }); + this.modalRef.componentInstance.report = signal(gitDiff); } } diff --git a/src/main/webapp/app/detail-overview-list/detail.module.ts b/src/main/webapp/app/detail-overview-list/detail.module.ts index 28a1f3a8abb9..c661ae788647 100644 --- a/src/main/webapp/app/detail-overview-list/detail.module.ts +++ b/src/main/webapp/app/detail-overview-list/detail.module.ts @@ -6,7 +6,6 @@ import { ArtemisSharedComponentModule } from 'app/shared/components/shared-compo import { SubmissionResultStatusModule } from 'app/overview/submission-result-status.module'; import { ArtemisProgrammingExerciseStatusModule } from 'app/exercises/programming/manage/status/programming-exercise-status.module'; import { ArtemisProgrammingExerciseActionsModule } from 'app/exercises/programming/shared/actions/programming-exercise-actions.module'; -import { GitDiffReportModule } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.module'; import { ArtemisProgrammingExerciseInstructionsEditorModule } from 'app/exercises/programming/manage/instructions-editor/programming-exercise-instructions-editor.module'; import { ArtemisProgrammingExerciseLifecycleModule } from 'app/exercises/programming/shared/lifecycle/programming-exercise-lifecycle.module'; import { AssessmentInstructionsModule } from 'app/assessment/assessment-instructions/assessment-instructions.module'; @@ -25,7 +24,6 @@ import { NoDataComponent } from 'app/shared/no-data-component'; SubmissionResultStatusModule, ArtemisProgrammingExerciseStatusModule, ArtemisProgrammingExerciseActionsModule, - GitDiffReportModule, ArtemisProgrammingExerciseInstructionsEditorModule, ArtemisProgrammingExerciseLifecycleModule, AssessmentInstructionsModule, diff --git a/src/main/webapp/app/exam/manage/exam-management.module.ts b/src/main/webapp/app/exam/manage/exam-management.module.ts index a932fdd227b9..b9a9829ab1fa 100644 --- a/src/main/webapp/app/exam/manage/exam-management.module.ts +++ b/src/main/webapp/app/exam/manage/exam-management.module.ts @@ -67,11 +67,11 @@ import { ArtemisExamNavigationBarModule } from 'app/exam/participate/exam-naviga import { ArtemisExamSubmissionComponentsModule } from 'app/exam/participate/exercises/exam-submission-components.module'; import { MatSliderModule } from '@angular/material/slider'; import { ProgrammingExerciseExamDiffComponent } from './student-exams/student-exam-timeline/programming-exam-diff/programming-exercise-exam-diff.component'; -import { GitDiffReportModule } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.module'; import { ArtemisProgrammingExerciseModule } from 'app/exercises/programming/shared/programming-exercise.module'; import { DetailModule } from 'app/detail-overview-list/detail.module'; import { ArtemisDurationFromSecondsPipe } from 'app/shared/pipes/artemis-duration-from-seconds.pipe'; import { NoDataComponent } from 'app/shared/no-data-component'; +import { GitDiffLineStatComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component'; const ENTITY_STATES = [...examManagementState]; @@ -110,10 +110,10 @@ const ENTITY_STATES = [...examManagementState]; ArtemisExamNavigationBarModule, ArtemisExamSubmissionComponentsModule, MatSliderModule, - GitDiffReportModule, ArtemisProgrammingExerciseModule, DetailModule, NoDataComponent, + GitDiffLineStatComponent, ], declarations: [ ExamManagementComponent, diff --git a/src/main/webapp/app/exam/manage/student-exams/student-exam-timeline/programming-exam-diff/programming-exercise-exam-diff.component.ts b/src/main/webapp/app/exam/manage/student-exams/student-exam-timeline/programming-exam-diff/programming-exercise-exam-diff.component.ts index 7eafe4900d96..81a3f247a809 100644 --- a/src/main/webapp/app/exam/manage/student-exams/student-exam-timeline/programming-exam-diff/programming-exercise-exam-diff.component.ts +++ b/src/main/webapp/app/exam/manage/student-exams/student-exam-timeline/programming-exam-diff/programming-exercise-exam-diff.component.ts @@ -1,4 +1,4 @@ -import { ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angular/core'; +import { ChangeDetectorRef, Component, EventEmitter, Input, OnDestroy, OnInit, Output, signal } from '@angular/core'; import { ProgrammingExercise } from 'app/entities/programming/programming-exercise.model'; import { ProgrammingSubmission } from 'app/entities/programming/programming-submission.model'; import { FeatureToggle } from 'app/shared/feature-toggle/feature-toggle.service'; @@ -123,10 +123,10 @@ export class ProgrammingExerciseExamDiffComponent extends ExamPageComponent impl * Shows the git-diff in a modal. */ showGitDiff(): void { - const modalRef = this.modalService.open(GitDiffReportModalComponent, { size: 'xl' }); - modalRef.componentInstance.report = this.exercise.gitDiffReport; - modalRef.componentInstance.diffForTemplateAndSolution = false; - modalRef.componentInstance.cachedRepositoryFiles = this.cachedRepositoryFiles; + const modalRef = this.modalService.open(GitDiffReportModalComponent, { windowClass: GitDiffReportModalComponent.WINDOW_CLASS }); + modalRef.componentInstance.report = signal(this.exercise.gitDiffReport); + modalRef.componentInstance.diffForTemplateAndSolution = signal(false); + modalRef.componentInstance.cachedRepositoryFiles = signal(this.cachedRepositoryFiles); this.cachedRepositoryFilesService.getCachedRepositoryFilesObservable().subscribe((cachedRepositoryFiles) => { this.cachedRepositoryFiles = cachedRepositoryFiles; }); diff --git a/src/main/webapp/app/exercises/programming/hestia/generation-overview/code-hint-generation-overview/code-hint-generation-overview.module.ts b/src/main/webapp/app/exercises/programming/hestia/generation-overview/code-hint-generation-overview/code-hint-generation-overview.module.ts index 05be60e77689..a9d7088b56c9 100644 --- a/src/main/webapp/app/exercises/programming/hestia/generation-overview/code-hint-generation-overview/code-hint-generation-overview.module.ts +++ b/src/main/webapp/app/exercises/programming/hestia/generation-overview/code-hint-generation-overview/code-hint-generation-overview.module.ts @@ -9,13 +9,13 @@ import { CoverageGenerationStepComponent } from '../steps/coverage-generation-st import { SolutionEntryGenerationStepComponent } from '../steps/solution-entry-generation-step/solution-entry-generation-step.component'; import { CodeHintGenerationStepComponent } from '../steps/code-hint-generation-step/code-hint-generation-step.component'; import { TestwiseCoverageReportModule } from 'app/exercises/programming/hestia/testwise-coverage-report/testwise-coverage-report.module'; -import { GitDiffReportModule } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.module'; import { CodeHintGenerationOverviewComponent } from 'app/exercises/programming/hestia/generation-overview/code-hint-generation-overview/code-hint-generation-overview.component'; import { RouterModule } from '@angular/router'; import { ArtemisMarkdownModule } from 'app/shared/markdown.module'; import { MatExpansionModule } from '@angular/material/expansion'; import { CodeHintGenerationStatusStepComponent } from 'app/exercises/programming/hestia/generation-overview/code-hint-generation-status/code-hint-generation-status-step.component'; import { ManualSolutionEntryCreationModalComponent } from '../manual-solution-entry-creation-modal/manual-solution-entry-creation-modal.component'; +import { GitDiffReportComponent } from 'app/exercises/programming/hestia/git-diff-report/git-diff-report.component'; @NgModule({ imports: [ @@ -24,13 +24,9 @@ import { ManualSolutionEntryCreationModalComponent } from '../manual-solution-en ArtemisExerciseHintSharedModule, ArtemisSharedComponentModule, TestwiseCoverageReportModule, - GitDiffReportModule, - GitDiffReportModule, - TestwiseCoverageReportModule, - ArtemisSharedComponentModule, ArtemisMarkdownModule, - ArtemisExerciseHintSharedModule, MatExpansionModule, + GitDiffReportComponent, ], declarations: [ CodeHintGenerationStatusComponent, diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component.html b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component.html index 80802af1dbd1..8b470a3e9fd5 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component.html +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component.html @@ -1,13 +1,13 @@
- {{ title }} - @if (fileStatus !== FileStatus.UNCHANGED) { + {{ title() }} + @if (fileStatus() !== FileStatus.UNCHANGED) { } diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component.ts b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component.ts index 3e7706581b88..74b0f35dfab0 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component.ts +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel-title.component.ts @@ -1,4 +1,6 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core'; +import { TranslateDirective } from 'app/shared/language/translate.directive'; +import { CommonModule } from '@angular/common'; enum FileStatus { CREATED = 'created', @@ -10,35 +12,33 @@ enum FileStatus { selector: 'jhi-git-diff-file-panel-title', templateUrl: './git-diff-file-panel-title.component.html', styleUrls: ['./git-diff-file-panel-title.component.scss'], + standalone: true, + changeDetection: ChangeDetectionStrategy.OnPush, + imports: [TranslateDirective, CommonModule], }) -export class GitDiffFilePanelTitleComponent implements OnInit { - @Input() - previousFilePath?: string; +export class GitDiffFilePanelTitleComponent { + readonly originalFilePath = input(); + readonly modifiedFilePath = input(); - @Input() - filePath?: string; + readonly titleAndFileStatus = computed(() => this.getTitleAndFileStatus()); + readonly title = computed(() => this.titleAndFileStatus().title); + readonly fileStatus = computed(() => this.titleAndFileStatus().fileStatus); - title?: string; - fileStatus: FileStatus = FileStatus.UNCHANGED; - - // Expose to template protected readonly FileStatus = FileStatus; - ngOnInit(): void { - if (this.filePath && this.previousFilePath) { - if (this.filePath !== this.previousFilePath) { - this.title = `${this.previousFilePath} → ${this.filePath}`; - this.fileStatus = FileStatus.RENAMED; + private getTitleAndFileStatus(): { title?: string; fileStatus: FileStatus } { + const originalFilePath = this.originalFilePath(); + const modifiedFilePath = this.modifiedFilePath(); + if (modifiedFilePath && originalFilePath) { + if (modifiedFilePath !== originalFilePath) { + return { title: `${originalFilePath} → ${modifiedFilePath}`, fileStatus: FileStatus.RENAMED }; } else { - this.title = this.filePath; - this.fileStatus = FileStatus.UNCHANGED; + return { title: modifiedFilePath, fileStatus: FileStatus.UNCHANGED }; } - } else if (this.filePath) { - this.title = this.filePath; - this.fileStatus = FileStatus.CREATED; + } else if (modifiedFilePath) { + return { title: modifiedFilePath, fileStatus: FileStatus.CREATED }; } else { - this.title = this.previousFilePath; - this.fileStatus = FileStatus.DELETED; + return { title: originalFilePath, fileStatus: FileStatus.DELETED }; } } } diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component.html b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component.html index 7b8fafd1178e..bb9245843140 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component.html +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component.html @@ -1,13 +1,13 @@
- +
diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component.ts b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component.ts index cd36cfc5b5f5..9e01edae26b9 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component.ts +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file-panel.component.ts @@ -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(); + readonly originalFileContent = input(); + readonly modifiedFileContent = input(); + readonly diffForTemplateAndSolution = input(true); + readonly allowSplitView = input(true); + readonly onDiffReady = output(); - @Input() solutionFileContent: string | undefined; - - @Input() diffForTemplateAndSolution = true; - - @Input() allowSplitView = true; - - @Output() onDiffReady = new EventEmitter(); - - 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, + ); } diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.html b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.html index e06148d20072..2f9ca3570472 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.html +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.html @@ -1,9 +1,9 @@
- @if (fileUnchanged) { + @if (fileUnchanged()) {
} - +
diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.ts b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.ts index 8c5c283c3c68..45456a115513 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.ts +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-file.component.ts @@ -1,56 +1,31 @@ -import { Component, EventEmitter, Input, OnInit, Output, ViewChild, ViewEncapsulation } from '@angular/core'; +import { ChangeDetectionStrategy, Component, ViewEncapsulation, computed, effect, input, output, viewChild } from '@angular/core'; import { ProgrammingExerciseGitDiffEntry } from 'app/entities/hestia/programming-exercise-git-diff-entry.model'; import { MonacoDiffEditorComponent } from 'app/shared/monaco-editor/monaco-diff-editor.component'; +import { TranslateDirective } from 'app/shared/language/translate.directive'; @Component({ selector: 'jhi-git-diff-file', templateUrl: './git-diff-file.component.html', encapsulation: ViewEncapsulation.None, + standalone: true, + changeDetection: ChangeDetectionStrategy.OnPush, + imports: [MonacoDiffEditorComponent, TranslateDirective], }) -export class GitDiffFileComponent implements OnInit { - @ViewChild(MonacoDiffEditorComponent, { static: true }) - monacoDiffEditor: MonacoDiffEditorComponent; - - @Input() - diffForTemplateAndSolution: boolean = false; - - @Input() - diffEntries: ProgrammingExerciseGitDiffEntry[]; - - @Input() - originalFileContent?: string; - - @Input() - modifiedFileContent?: string; - - @Input() - allowSplitView = true; - - @Output() - onDiffReady = new EventEmitter(); - - originalFilePath?: string; - modifiedFilePath?: string; - fileUnchanged = false; - - ngOnInit(): void { - this.determineFilePaths(); - this.monacoDiffEditor.setFileContents(this.originalFileContent, this.originalFilePath, this.modifiedFileContent, this.modifiedFilePath); - this.fileUnchanged = this.originalFileContent === this.modifiedFileContent; - } - - /** - * Determines the previous and current file path of the current file - */ - private determineFilePaths() { - this.modifiedFilePath = this.diffEntries - .map((entry) => entry.filePath) - .filter((filePath) => filePath) - .first(); - - this.originalFilePath = this.diffEntries - .map((entry) => entry.previousFilePath) - .filter((filePath) => filePath) - .first(); +export class GitDiffFileComponent { + readonly monacoDiffEditor = viewChild.required(MonacoDiffEditorComponent); + readonly diffForTemplateAndSolution = input(false); + readonly diffEntries = input.required(); + readonly originalFileContent = input(); + readonly originalFilePath = input(); + readonly modifiedFileContent = input(); + readonly modifiedFilePath = input(); + readonly allowSplitView = input(true); + readonly onDiffReady = output(); + readonly fileUnchanged = computed(() => this.originalFileContent() === this.modifiedFileContent()); + + constructor() { + effect(() => { + this.monacoDiffEditor().setFileContents(this.originalFileContent(), this.originalFilePath(), this.modifiedFileContent(), this.modifiedFilePath()); + }); } } diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component.html b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component.html index d23e649b7439..654c3a70afed 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component.html +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component.html @@ -1,11 +1,11 @@ - +{{ addedLineCount }} - -{{ removedLineCount }} + +{{ addedLineCount() }} + -{{ removedLineCount() }} - @for (i of [].constructor(addedSquareCount); track $index) { + @for (i of addedSquareArray(); track $index) { } - @for (i of [].constructor(removedSquareCount); track $index) { + @for (i of removedSquareArray(); track $index) { } diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component.ts b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component.ts index 8f25b7794bfc..b82ab8d02c02 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component.ts +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-line-stat.component.ts @@ -1,34 +1,34 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core'; @Component({ selector: 'jhi-git-diff-line-stat', templateUrl: './git-diff-line-stat.component.html', styleUrls: ['./git-diff-line-stat.component.scss'], + standalone: true, + changeDetection: ChangeDetectionStrategy.OnPush, }) -export class GitDiffLineStatComponent implements OnInit { - @Input() - addedLineCount: number = 0; - @Input() - removedLineCount: number = 0; - addedSquareCount: number; - removedSquareCount: number; +export class GitDiffLineStatComponent { + readonly addedLineCount = input(0); + readonly removedLineCount = input(0); + readonly squareCounts = computed(() => this.getSquareCounts()); + readonly addedSquareArray = computed(() => Array.from({ length: this.squareCounts().addedSquareCount })); + readonly removedSquareArray = computed(() => Array.from({ length: this.squareCounts().removedSquareCount })); - ngOnInit(): void { - if (!this.addedLineCount && !this.removedLineCount) { - this.addedSquareCount = 1; - this.removedSquareCount = 1; - } else if (this.addedLineCount === 0) { - this.addedSquareCount = 0; - this.removedSquareCount = 5; - } else if (this.removedLineCount === 0) { - this.addedSquareCount = 5; - this.removedSquareCount = 0; + private getSquareCounts(): { addedSquareCount: number; removedSquareCount: number } { + const addedLineCount = this.addedLineCount(); + const removedLineCount = this.removedLineCount(); + if (!addedLineCount && !removedLineCount) { + return { addedSquareCount: 1, removedSquareCount: 1 }; + } else if (addedLineCount === 0) { + return { addedSquareCount: 0, removedSquareCount: 5 }; + } else if (removedLineCount === 0) { + return { addedSquareCount: 5, removedSquareCount: 0 }; } else { - const totalLineCount = this.addedLineCount + this.removedLineCount; + const totalLineCount = addedLineCount + removedLineCount; // Calculates the amount of green rectangles to show between 1 and 4 // This is the rounded percentage of added lines divided by total lines - this.addedSquareCount = Math.round(Math.max(1, Math.min(4, (this.addedLineCount / totalLineCount) * 5))); - this.removedSquareCount = 5 - this.addedSquareCount; + const addedSquareCount = Math.round(Math.max(1, Math.min(4, (addedLineCount / totalLineCount) * 5))); + return { addedSquareCount, removedSquareCount: 5 - addedSquareCount }; } } } diff --git a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report-modal.component.html b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report-modal.component.html index 198b27469831..6b95cf90f178 100644 --- a/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report-modal.component.html +++ b/src/main/webapp/app/exercises/programming/hestia/git-diff-report/git-diff-report-modal.component.html @@ -2,22 +2,22 @@