From 5d08e413f96f6269748fb38acfd59e014fb284b3 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Wed, 27 Nov 2024 16:03:58 +0100 Subject: [PATCH 01/12] migrate exam-scores-average-scores-graph to input --- ...-scores-average-scores-graph.component.html | 2 +- ...am-scores-average-scores-graph.component.ts | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.html b/src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.html index 35ab48c1854a..958122437f2b 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.html +++ b/src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.html @@ -1,6 +1,6 @@
-
+
(); + course = input.required(); courseId: number; examId: number; @@ -56,12 +56,12 @@ export class ExamScoresAverageScoresGraphComponent implements OnInit { } private initializeChart(): void { - this.lookup[this.averageScores.title] = { absoluteValue: this.averageScores.averagePoints! }; - const exerciseGroupAverage = this.averageScores.averagePercentage ? this.averageScores.averagePercentage : 0; - this.ngxData.push({ name: this.averageScores.title, value: exerciseGroupAverage }); + this.lookup[this.averageScores().title] = { absoluteValue: this.averageScores().averagePoints! }; + const exerciseGroupAverage = this.averageScores().averagePercentage ?? 0; + this.ngxData.push({ name: this.averageScores().title, value: exerciseGroupAverage }); this.ngxColor.domain.push(this.determineColor(true, exerciseGroupAverage)); this.xScaleMax = this.xScaleMax > exerciseGroupAverage ? this.xScaleMax : exerciseGroupAverage; - this.averageScores.exerciseResults.forEach((exercise) => { + this.averageScores().exerciseResults.forEach((exercise) => { const exerciseAverage = exercise.averagePercentage ?? 0; this.xScaleMax = this.xScaleMax > exerciseAverage ? this.xScaleMax : exerciseAverage; this.ngxData.push({ name: exercise.exerciseId + ' ' + exercise.title, value: exerciseAverage }); @@ -77,14 +77,14 @@ export class ExamScoresAverageScoresGraphComponent implements OnInit { } roundAndPerformLocalConversion(points: number | undefined) { - return this.localeConversionService.toLocaleString(roundValueSpecifiedByCourseSettings(points, this.course), this.course!.accuracyOfScores!); + return this.localeConversionService.toLocaleString(roundValueSpecifiedByCourseSettings(points, this.course()), this.course()!.accuracyOfScores!); } /** * We navigate to the exercise scores page when the user clicks on a data point */ navigateToExercise(exerciseId: number, exerciseType: ExerciseType) { - navigateToExamExercise(this.navigationUtilService, this.courseId, this.examId, this.averageScores.exerciseGroupId, exerciseType, exerciseId, 'scores'); + navigateToExamExercise(this.navigationUtilService, this.courseId, this.examId, this.averageScores().exerciseGroupId, exerciseType, exerciseId, 'scores'); } /** From 99087a04fc0840f748f3248ddec052732ed42969 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Wed, 27 Nov 2024 19:13:17 +0100 Subject: [PATCH 02/12] migrate to standalone and inject --- ...m-scores-average-scores-graph.component.ts | 22 +++++---- .../exam/exam-scores/exam-scores.component.ts | 47 +++++++++++++------ .../exam/exam-scores/exam-scores.module.ts | 3 +- 3 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.ts b/src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.ts index 5aad2af60cf0..a76a05026816 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.ts +++ b/src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, input } from '@angular/core'; +import { Component, OnInit, inject, input } from '@angular/core'; import { StatisticsService } from 'app/shared/statistics-graph/statistics.service'; import { TranslateService } from '@ngx-translate/core'; import { GraphColors } from 'app/entities/statistics.model'; @@ -9,17 +9,27 @@ import { ActivatedRoute } from '@angular/router'; import { ExerciseType } from 'app/entities/exercise.model'; import { ArtemisNavigationUtilService, navigateToExamExercise } from 'app/utils/navigation.utils'; import { Course } from 'app/entities/course.model'; -import { Color, ScaleType } from '@swimlane/ngx-charts'; +import { BarChartModule, Color, ScaleType } from '@swimlane/ngx-charts'; import { NgxChartsSingleSeriesDataEntry } from 'app/shared/chart/ngx-charts-datatypes'; import { axisTickFormattingWithPercentageSign } from 'app/shared/statistics-graph/statistics-graph.utils'; +import { TranslateDirective } from 'app/shared/language/translate.directive'; +import { ArtemisSharedCommonModule } from 'app/shared/shared-common.module'; type NameToValueMap = { [name: string]: any }; @Component({ selector: 'jhi-exam-scores-average-scores-graph', templateUrl: './exam-scores-average-scores-graph.component.html', + standalone: true, + imports: [TranslateDirective, BarChartModule, ArtemisSharedCommonModule], }) export class ExamScoresAverageScoresGraphComponent implements OnInit { + private navigationUtilService = inject(ArtemisNavigationUtilService); + private activatedRoute = inject(ActivatedRoute); + private service = inject(StatisticsService); + private translateService = inject(TranslateService); + private localeConversionService = inject(LocaleConversionService); + averageScores = input.required(); course = input.required(); @@ -39,14 +49,6 @@ export class ExamScoresAverageScoresGraphComponent implements OnInit { xScaleMax = 100; lookup: NameToValueMap = {}; - constructor( - private navigationUtilService: ArtemisNavigationUtilService, - private activatedRoute: ActivatedRoute, - private service: StatisticsService, - private translateService: TranslateService, - private localeConversionService: LocaleConversionService, - ) {} - ngOnInit(): void { this.activatedRoute.params.subscribe((params) => { this.courseId = +params['courseId']; diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts b/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts index 94a6f375b3b7..3c09d79156e4 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts +++ b/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts @@ -1,8 +1,8 @@ -import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit } from '@angular/core'; +import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy, OnInit, inject } from '@angular/core'; import { Subscription, forkJoin, of } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { ExamManagementService } from 'app/exam/manage/exam-management.service'; -import { ActivatedRoute } from '@angular/router'; +import { ActivatedRoute, RouterLink } from '@angular/router'; import { SortService } from 'app/shared/service/sort.service'; import { download, generateCsv, mkConfig } from 'export-to-csv'; import { @@ -58,6 +58,14 @@ import { USERNAME_KEY, } from 'app/shared/export/export-constants'; import { BonusStrategy } from 'app/entities/bonus.model'; +import { FaIconComponent } from '@fortawesome/angular-fontawesome'; +import { TranslateDirective } from '../../shared/language/translate.directive'; +import { ExportModule } from '../../shared/export/export.module'; +import { NgStyle } from '@angular/common'; +import { ArtemisParticipantScoresModule } from '../../shared/participant-scores/participant-scores.module'; +import { ExamScoresAverageScoresGraphComponent } from './exam-scores-average-scores-graph.component'; +import { ArtemisSharedComponentModule } from '../../shared/components/shared-component.module'; +import { ArtemisSharedCommonModule } from '../../shared/shared-common.module'; export enum MedianType { PASSED, @@ -70,8 +78,31 @@ export enum MedianType { templateUrl: './exam-scores.component.html', changeDetection: ChangeDetectionStrategy.OnPush, styleUrls: ['./exam-scores.component.scss', '../../shared/chart/vertical-bar-chart.scss'], + standalone: true, + imports: [ + FaIconComponent, + TranslateDirective, + ExportModule, + RouterLink, + NgStyle, + ArtemisParticipantScoresModule, + ExamScoresAverageScoresGraphComponent, + ArtemisSharedComponentModule, + ArtemisSharedCommonModule, + ], }) export class ExamScoresComponent implements OnInit, OnDestroy { + private route = inject(ActivatedRoute); + private examService = inject(ExamManagementService); + private sortService = inject(SortService); + private alertService = inject(AlertService); + private changeDetector = inject(ChangeDetectorRef); + private languageHelper = inject(JhiLanguageHelper); + private localeConversionService = inject(LocaleConversionService); + private participantScoresService = inject(ParticipantScoresService); + private gradingSystemService = inject(GradingSystemService); + private courseManagementService = inject(CourseManagementService); + public examScoreDTO: ExamScoreDTO; public exerciseGroups: ExerciseGroup[]; public studentResults: StudentResult[]; @@ -130,18 +161,6 @@ export class ExamScoresComponent implements OnInit, OnDestroy { faExclamationTriangle = faExclamationTriangle; private languageChangeSubscription?: Subscription; - constructor( - private route: ActivatedRoute, - private examService: ExamManagementService, - private sortService: SortService, - private alertService: AlertService, - private changeDetector: ChangeDetectorRef, - private languageHelper: JhiLanguageHelper, - private localeConversionService: LocaleConversionService, - private participantScoresService: ParticipantScoresService, - private gradingSystemService: GradingSystemService, - private courseManagementService: CourseManagementService, - ) {} ngOnInit() { this.route.params.subscribe((params) => { diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores.module.ts b/src/main/webapp/app/exam/exam-scores/exam-scores.module.ts index e439030cb776..fc4d3df9b992 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores.module.ts +++ b/src/main/webapp/app/exam/exam-scores/exam-scores.module.ts @@ -12,7 +12,6 @@ import { ArtemisParticipantScoresModule } from 'app/shared/participant-scores/pa import { ExportModule } from 'app/shared/export/export.module'; @NgModule({ - declarations: [ExamScoresComponent, ExamScoresAverageScoresGraphComponent], imports: [ ArtemisSharedModule, ArtemisExamScoresRoutingModule, @@ -23,6 +22,8 @@ import { ExportModule } from 'app/shared/export/export.module'; BarChartModule, ArtemisParticipantScoresModule, ExportModule, + ExamScoresComponent, + ExamScoresAverageScoresGraphComponent, ], }) export class ArtemisExamScoresModule {} From d4341ed0f726658bcf168597330da2c2e9c57fa8 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Sun, 1 Dec 2024 11:11:36 +0100 Subject: [PATCH 03/12] fix test --- ...res-average-scores-graph.component.spec.ts | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts b/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts index f962626e8e37..b47b6f34c85d 100644 --- a/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts +++ b/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts @@ -1,6 +1,6 @@ import { ComponentFixture, TestBed } from '@angular/core/testing'; import { TranslateService } from '@ngx-translate/core'; -import { MockDirective, MockModule, MockPipe, MockProvider } from 'ng-mocks'; +import { MockDirective, MockModule, MockProvider } from 'ng-mocks'; import { of } from 'rxjs'; import { HttpResponse } from '@angular/common/http'; import { ExamScoresAverageScoresGraphComponent } from 'app/exam/exam-scores/exam-scores-average-scores-graph.component'; @@ -9,7 +9,6 @@ import { MockTranslateService } from '../../../helpers/mocks/service/mock-transl import { AggregatedExerciseGroupResult, AggregatedExerciseResult } from 'app/exam/exam-scores/exam-score-dtos.model'; import { CourseManagementService } from 'app/course/manage/course-management.service'; import { BarChartModule } from '@swimlane/ngx-charts'; -import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe'; import { GraphColors } from 'app/entities/statistics.model'; import { NgxChartsSingleSeriesDataEntry } from 'app/shared/chart/ngx-charts-datatypes'; import { ExerciseType } from 'app/entities/exercise.model'; @@ -56,7 +55,7 @@ describe('ExamScoresAverageScoresGraphComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ imports: [ArtemisTestModule, MockModule(BarChartModule), RouterModule.forRoot([])], - declarations: [ExamScoresAverageScoresGraphComponent, MockPipe(ArtemisTranslatePipe), MockDirective(TranslateDirective)], + declarations: [ExamScoresAverageScoresGraphComponent, MockDirective(TranslateDirective)], providers: [ MockProvider(CourseManagementService, { find: () => { @@ -70,16 +69,14 @@ describe('ExamScoresAverageScoresGraphComponent', () => { }), { provide: TranslateService, useClass: MockTranslateService }, ], - }) - .compileComponents() - .then(() => { - fixture = TestBed.createComponent(ExamScoresAverageScoresGraphComponent); - component = fixture.componentInstance; - navigateToExerciseMock = jest.spyOn(component, 'navigateToExercise').mockImplementation(); - - component.averageScores = returnValue; - fixture.detectChanges(); - }); + }).compileComponents(); + + fixture = TestBed.createComponent(ExamScoresAverageScoresGraphComponent); + component = fixture.componentInstance; + navigateToExerciseMock = jest.spyOn(component, 'navigateToExercise').mockImplementation(); + + fixture.componentRef.setInput('averageScores', returnValue); + fixture.detectChanges(); }); it('should set ngx data objects and bar colors correctly', () => { @@ -99,8 +96,13 @@ describe('ExamScoresAverageScoresGraphComponent', () => { }); const adaptExpectedData = (averagePoints: number, newColor: string, expectedColorDomain: string[], expectedData: NgxChartsSingleSeriesDataEntry[]) => { - component.averageScores.averagePoints = averagePoints; - component.averageScores.averagePercentage = averagePoints * 10; + const updatedAverageScores = { + ...component.averageScores(), // Include existing fields if necessary + averagePoints: averagePoints, + averagePercentage: averagePoints * 10, + }; + + fixture.componentRef.setInput('averageScores', updatedAverageScores); expectedColorDomain[0] = newColor; expectedData[0].value = averagePoints * 10; component.ngxColor.domain = []; @@ -146,7 +148,10 @@ describe('ExamScoresAverageScoresGraphComponent', () => { it('should look up absolute value', () => { const roundAndPerformLocalConversionSpy = jest.spyOn(component, 'roundAndPerformLocalConversion'); - component.course = { accuracyOfScores: 2 }; + const updatedCourse = { + accuracyOfScores: 2, + }; + fixture.componentRef.setInput('course', updatedCourse); component.lookup['test'] = { absoluteValue: 40 }; const result = component.lookupAbsoluteValue('test'); From 47dc99636930814c7e924a99c48c27627873f9f1 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Sun, 1 Dec 2024 11:15:28 +0100 Subject: [PATCH 04/12] remove comment --- .../exam-scores-average-scores-graph.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts b/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts index b47b6f34c85d..510d4ce13558 100644 --- a/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts +++ b/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts @@ -97,7 +97,7 @@ describe('ExamScoresAverageScoresGraphComponent', () => { const adaptExpectedData = (averagePoints: number, newColor: string, expectedColorDomain: string[], expectedData: NgxChartsSingleSeriesDataEntry[]) => { const updatedAverageScores = { - ...component.averageScores(), // Include existing fields if necessary + ...component.averageScores(), averagePoints: averagePoints, averagePercentage: averagePoints * 10, }; From 5b421a4b6a34d53d08a289701fa2b0f363686c84 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Sun, 1 Dec 2024 16:59:40 +0100 Subject: [PATCH 05/12] fix tests --- .../exam-scores/exam-scores.component.spec.ts | 43 ++++++++----------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/src/test/javascript/spec/component/exam/exam-scores/exam-scores.component.spec.ts b/src/test/javascript/spec/component/exam/exam-scores/exam-scores.component.spec.ts index df9ddaa86480..3d82fa3ba673 100644 --- a/src/test/javascript/spec/component/exam/exam-scores/exam-scores.component.spec.ts +++ b/src/test/javascript/spec/component/exam/exam-scores/exam-scores.component.spec.ts @@ -1,5 +1,6 @@ -import { HttpResponse } from '@angular/common/http'; +import { HttpResponse, provideHttpClient } from '@angular/common/http'; import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { provideHttpClientTesting } from '@angular/common/http/testing'; import { ActivatedRoute, Router } from '@angular/router'; import { FaIconComponent } from '@fortawesome/angular-fontawesome'; import { TranslateService } from '@ngx-translate/core'; @@ -14,15 +15,14 @@ import { ExerciseResult, StudentResult, } from 'app/exam/exam-scores/exam-score-dtos.model'; +import { MockComponent, MockDirective, MockModule, MockPipe, MockProvider } from 'ng-mocks'; +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { ExamScoresComponent, MedianType } from 'app/exam/exam-scores/exam-scores.component'; import { ExamManagementService } from 'app/exam/manage/exam-management.service'; -import { HelpIconComponent } from 'app/shared/components/help-icon.component'; -import { DeleteButtonDirective } from 'app/shared/delete-dialog/delete-button.directive'; import { ParticipantScoresService, ScoresDTO } from 'app/shared/participant-scores/participant-scores.service'; import { ArtemisTranslatePipe } from 'app/shared/pipes/artemis-translate.pipe'; import { SortService } from 'app/shared/service/sort.service'; import { cloneDeep } from 'lodash-es'; -import { MockComponent, MockDirective, MockPipe, MockProvider } from 'ng-mocks'; import { EMPTY, of } from 'rxjs'; import { GradingSystemService } from 'app/grading-system/grading-system.service'; import { GradingScale } from 'app/entities/grading-scale.model'; @@ -35,7 +35,6 @@ import { CourseManagementService } from 'app/course/manage/course-management.ser import { MockRouter } from '../../../helpers/mocks/mock-router'; import { AccountService } from 'app/core/auth/account.service'; import { MockRouterLinkDirective } from '../../../helpers/mocks/directive/mock-router-link.directive'; -import { ParticipantScoresDistributionComponent } from 'app/shared/participant-scores/participant-scores-distribution/participant-scores-distribution.component'; import { LocaleConversionService } from 'app/shared/service/locale-conversion.service'; import { ArtemisNavigationUtilService } from 'app/utils/navigation.utils'; import { CsvDecimalSeparator, CsvExportOptions, CsvFieldSeparator, CsvQuoteStrings } from 'app/shared/export/export-modal.component'; @@ -55,9 +54,9 @@ import { REGISTRATION_NUMBER_KEY, USERNAME_KEY, } from 'app/shared/export/export-constants'; -import { ExportButtonComponent } from 'app/shared/export/export-button.component'; import { PlagiarismVerdict } from 'app/exercises/shared/plagiarism/types/PlagiarismVerdict'; import { BonusStrategy } from 'app/entities/bonus.model'; +import { MockTranslateService } from '../../../helpers/mocks/service/mock-translate.service'; describe('ExamScoresComponent', () => { let fixture: ComponentFixture; @@ -276,30 +275,28 @@ describe('ExamScoresComponent', () => { beforeEach(() => { TestBed.configureTestingModule({ + imports: [MockModule(BrowserAnimationsModule)], declarations: [ ExamScoresComponent, MockPipe(ArtemisTranslatePipe), MockComponent(FaIconComponent), - MockComponent(HelpIconComponent), - MockComponent(ExportButtonComponent), MockDirective(TranslateDirective), MockDirective(SortByDirective), MockDirective(SortDirective), - MockDirective(DeleteButtonDirective), MockComponent(ExamScoresAverageScoresGraphComponent), MockRouterLinkDirective, - MockComponent(ParticipantScoresDistributionComponent), ], providers: [ { provide: ActivatedRoute, useValue: { params: of({ courseId: 1, examId: 1 }) } }, { provide: Router, useClass: MockRouter }, + { provide: TranslateService, useClass: MockTranslateService }, + provideHttpClient(), + provideHttpClientTesting(), MockProvider(AccountService), MockProvider(ArtemisNavigationUtilService), - MockProvider(TranslateService), MockProvider(ExamManagementService), MockProvider(SortService), MockProvider(AlertService), - MockProvider(ParticipantScoresService), MockProvider(GradingSystemService, { findGradingScaleForExam: () => { return of( @@ -328,18 +325,16 @@ describe('ExamScoresComponent', () => { }, }), ], - }) - .compileComponents() - .then(() => { - fixture = TestBed.createComponent(ExamScoresComponent); - comp = fixture.componentInstance; - examService = fixture.debugElement.injector.get(ExamManagementService); - gradingSystemService = fixture.debugElement.injector.get(GradingSystemService); - const participationScoreService = fixture.debugElement.injector.get(ParticipantScoresService); - findExamScoresSpy = jest - .spyOn(participationScoreService, 'findExamScores') - .mockReturnValue(of(new HttpResponse({ body: [examScoreStudent1, examScoreStudent2, examScoreStudent3] }))); - }); + }).compileComponents(); + + fixture = TestBed.createComponent(ExamScoresComponent); + comp = fixture.componentInstance; + examService = fixture.debugElement.injector.get(ExamManagementService); + gradingSystemService = fixture.debugElement.injector.get(GradingSystemService); + const participationScoreService = fixture.debugElement.injector.get(ParticipantScoresService); + findExamScoresSpy = jest + .spyOn(participationScoreService, 'findExamScores') + .mockReturnValue(of(new HttpResponse({ body: [examScoreStudent1, examScoreStudent2, examScoreStudent3] }))); }); afterEach(() => { From 92bd1f888861201ae9ce0fa69d09196d00bf0973 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Mon, 2 Dec 2024 10:06:07 +0100 Subject: [PATCH 06/12] exam-scores-average-scores-graph.component.spec.ts --- .../exam-scores-average-scores-graph.component.spec.ts | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts b/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts index 510d4ce13558..49da1a162d28 100644 --- a/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts +++ b/src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts @@ -96,13 +96,9 @@ describe('ExamScoresAverageScoresGraphComponent', () => { }); const adaptExpectedData = (averagePoints: number, newColor: string, expectedColorDomain: string[], expectedData: NgxChartsSingleSeriesDataEntry[]) => { - const updatedAverageScores = { - ...component.averageScores(), - averagePoints: averagePoints, - averagePercentage: averagePoints * 10, - }; + component.averageScores().averagePoints = averagePoints; + component.averageScores().averagePercentage = averagePoints * 10; - fixture.componentRef.setInput('averageScores', updatedAverageScores); expectedColorDomain[0] = newColor; expectedData[0].value = averagePoints * 10; component.ngxColor.domain = []; From 2af5153891efd7d0d10e86a93d0247dfe0adb3c4 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Wed, 11 Dec 2024 19:58:27 +0100 Subject: [PATCH 07/12] remove redundant module --- .../exam/exam-scores/exam-scores.module.ts | 29 ------------------- .../app/exam/manage/exam-management.module.ts | 2 -- 2 files changed, 31 deletions(-) delete mode 100644 src/main/webapp/app/exam/exam-scores/exam-scores.module.ts diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores.module.ts b/src/main/webapp/app/exam/exam-scores/exam-scores.module.ts deleted file mode 100644 index fc4d3df9b992..000000000000 --- a/src/main/webapp/app/exam/exam-scores/exam-scores.module.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { NgModule } from '@angular/core'; -import { ExamScoresComponent } from './exam-scores.component'; -import { ArtemisSharedModule } from 'app/shared/shared.module'; -import { ArtemisExamScoresRoutingModule } from 'app/exam/exam-scores/exam-scores.route'; -import { ArtemisDataTableModule } from 'app/shared/data-table/data-table.module'; -import { NgxDatatableModule } from '@siemens/ngx-datatable'; -import { ArtemisResultModule } from 'app/exercises/shared/result/result.module'; -import { ArtemisSharedComponentModule } from 'app/shared/components/shared-component.module'; -import { ExamScoresAverageScoresGraphComponent } from 'app/exam/exam-scores/exam-scores-average-scores-graph.component'; -import { BarChartModule } from '@swimlane/ngx-charts'; -import { ArtemisParticipantScoresModule } from 'app/shared/participant-scores/participant-scores.module'; -import { ExportModule } from 'app/shared/export/export.module'; - -@NgModule({ - imports: [ - ArtemisSharedModule, - ArtemisExamScoresRoutingModule, - ArtemisDataTableModule, - NgxDatatableModule, - ArtemisResultModule, - ArtemisSharedComponentModule, - BarChartModule, - ArtemisParticipantScoresModule, - ExportModule, - ExamScoresComponent, - ExamScoresAverageScoresGraphComponent, - ], -}) -export class ArtemisExamScoresModule {} 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 ddc813cc21f6..bec14f2b7a72 100644 --- a/src/main/webapp/app/exam/manage/exam-management.module.ts +++ b/src/main/webapp/app/exam/manage/exam-management.module.ts @@ -1,6 +1,5 @@ import { NgModule } from '@angular/core'; import { RouterModule } from '@angular/router'; -import { ArtemisExamScoresModule } from 'app/exam/exam-scores/exam-scores.module'; import { ExamManagementComponent } from 'app/exam/manage/exam-management.component'; import { examManagementState } from 'app/exam/manage/exam-management.route'; import { ExamUpdateComponent } from 'app/exam/manage/exams/exam-update.component'; @@ -81,7 +80,6 @@ const ENTITY_STATES = [...examManagementState]; imports: [ RouterModule.forChild(ENTITY_STATES), ArtemisTextExerciseModule, - ArtemisExamScoresModule, ArtemisSharedModule, FormDateTimePickerModule, ArtemisSharedComponentModule, From 7b0bd396b2216ad8176d2769b7eb362d03aa7ac2 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Wed, 11 Dec 2024 20:19:19 +0100 Subject: [PATCH 08/12] refactor exam scores routes --- .../app/exam/exam-scores/exam-scores.route.ts | 25 ++++++++----------- .../app/exam/manage/exam-management.module.ts | 3 ++- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores.route.ts b/src/main/webapp/app/exam/exam-scores/exam-scores.route.ts index 2635eae62e5f..3221086138f7 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores.route.ts +++ b/src/main/webapp/app/exam/exam-scores/exam-scores.route.ts @@ -1,23 +1,18 @@ -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; -import { UserRouteAccessService } from 'app/core/auth/user-route-access-service'; +import { Route, Routes } from '@angular/router'; import { ExamScoresComponent } from 'app/exam/exam-scores/exam-scores.component'; -import { Authority } from 'app/shared/constants/authority.constants'; -const routes: Routes = [ +export const examScoresRoute: Route[] = [ { path: ':examId/scores', component: ExamScoresComponent, - data: { - authorities: [Authority.ADMIN, Authority.INSTRUCTOR], - pageTitle: 'artemisApp.examScores.title', - }, - canActivate: [UserRouteAccessService], }, ]; -@NgModule({ - imports: [RouterModule.forChild(routes)], - exports: [RouterModule], -}) -export class ArtemisExamScoresRoutingModule {} +const EXAM_SCORES_ROUTES = [...examScoresRoute]; + +export const examScoresState: Routes = [ + { + path: '', + children: EXAM_SCORES_ROUTES, + }, +]; 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 bec14f2b7a72..701f8bb3ff1a 100644 --- a/src/main/webapp/app/exam/manage/exam-management.module.ts +++ b/src/main/webapp/app/exam/manage/exam-management.module.ts @@ -71,8 +71,9 @@ 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'; +import { examScoresState } from 'app/exam/exam-scores/exam-scores.route'; -const ENTITY_STATES = [...examManagementState]; +const ENTITY_STATES = [...examManagementState, ...examScoresState]; @NgModule({ // TODO: For better modularization we could define an exercise module with the corresponding exam routes From 60418559fe77e23a9ad879d9d24c92202d87d286 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Sat, 21 Dec 2024 14:45:07 +0100 Subject: [PATCH 09/12] remove redundant imports --- .../exam/exam-scores/exam-scores.component.ts | 25 +++++-------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts b/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts index 3c09d79156e4..7fb100ed3560 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts +++ b/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts @@ -58,14 +58,11 @@ import { USERNAME_KEY, } from 'app/shared/export/export-constants'; import { BonusStrategy } from 'app/entities/bonus.model'; -import { FaIconComponent } from '@fortawesome/angular-fontawesome'; -import { TranslateDirective } from '../../shared/language/translate.directive'; -import { ExportModule } from '../../shared/export/export.module'; -import { NgStyle } from '@angular/common'; -import { ArtemisParticipantScoresModule } from '../../shared/participant-scores/participant-scores.module'; -import { ExamScoresAverageScoresGraphComponent } from './exam-scores-average-scores-graph.component'; -import { ArtemisSharedComponentModule } from '../../shared/components/shared-component.module'; -import { ArtemisSharedCommonModule } from '../../shared/shared-common.module'; +import { ExamScoresAverageScoresGraphComponent } from 'app/exam/exam-scores/exam-scores-average-scores-graph.component'; +import { ArtemisParticipantScoresModule } from 'app/shared/participant-scores/participant-scores.module'; +import { ExportModule } from 'app/shared/export/export.module'; +import { ArtemisSharedCommonModule } from 'app/shared/shared-common.module'; +import { ArtemisSharedComponentModule } from 'app/shared/components/shared-component.module'; export enum MedianType { PASSED, @@ -79,17 +76,7 @@ export enum MedianType { changeDetection: ChangeDetectionStrategy.OnPush, styleUrls: ['./exam-scores.component.scss', '../../shared/chart/vertical-bar-chart.scss'], standalone: true, - imports: [ - FaIconComponent, - TranslateDirective, - ExportModule, - RouterLink, - NgStyle, - ArtemisParticipantScoresModule, - ExamScoresAverageScoresGraphComponent, - ArtemisSharedComponentModule, - ArtemisSharedCommonModule, - ], + imports: [RouterLink, ArtemisSharedComponentModule, ArtemisSharedCommonModule, ExamScoresAverageScoresGraphComponent, ArtemisParticipantScoresModule, ExportModule], }) export class ExamScoresComponent implements OnInit, OnDestroy { private route = inject(ActivatedRoute); From a01ef4bc9406434376a5fed24856c65ac6df2742 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Sat, 21 Dec 2024 18:56:01 +0100 Subject: [PATCH 10/12] fix error with displaying course scores --- src/main/webapp/app/exam/exam-scores/exam-scores.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts b/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts index 7fb100ed3560..97bb7fb19d39 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts +++ b/src/main/webapp/app/exam/exam-scores/exam-scores.component.ts @@ -682,7 +682,7 @@ export class ExamScoresComponent implements OnInit, OnDestroy { * Localizes a number, e.g. switching the decimal separator */ localize(numberToLocalize: number): string { - return this.localeConversionService.toLocaleString(numberToLocalize, this.course!.accuracyOfScores!); + return this.localeConversionService.toLocaleString(numberToLocalize, this.course?.accuracyOfScores); } /** From 1b756c01fcca704695d5ab677bc3c4a409f31b85 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Thu, 2 Jan 2025 22:19:34 +0100 Subject: [PATCH 11/12] fix issue with router link --- .../webapp/app/exam/exam-scores/exam-scores.component.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores.component.html b/src/main/webapp/app/exam/exam-scores/exam-scores.component.html index 2fe2e07c3e3a..40b23cc91347 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores.component.html +++ b/src/main/webapp/app/exam/exam-scores/exam-scores.component.html @@ -35,11 +35,11 @@

@if (examScoreDTO.maxPoints) {

{{ 'artemisApp.examScores.maxPoints' | artemisTranslate }}: {{ localize(examScoreDTO.maxPoints) }},
} - +
{{ exerciseGroups.length }} {{ 'artemisApp.examScores.noExerciseGroups' | artemisTranslate }}
,
- +
{{ aggregatedExamResults.noOfRegisteredUsers }} {{ 'artemisApp.examScores.registered' | artemisTranslate }}
From d0905159bd401e5fc540e812c85e1d280feb7794 Mon Sep 17 00:00:00 2001 From: Michal Kawka Date: Fri, 3 Jan 2025 14:56:12 +0100 Subject: [PATCH 12/12] add missing auth checks --- src/main/webapp/app/exam/exam-scores/exam-scores.route.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/webapp/app/exam/exam-scores/exam-scores.route.ts b/src/main/webapp/app/exam/exam-scores/exam-scores.route.ts index 3221086138f7..c0b815477e42 100644 --- a/src/main/webapp/app/exam/exam-scores/exam-scores.route.ts +++ b/src/main/webapp/app/exam/exam-scores/exam-scores.route.ts @@ -1,5 +1,7 @@ import { Route, Routes } from '@angular/router'; import { ExamScoresComponent } from 'app/exam/exam-scores/exam-scores.component'; +import { Authority } from 'app/shared/constants/authority.constants'; +import { UserRouteAccessService } from 'app/core/auth/user-route-access-service'; export const examScoresRoute: Route[] = [ { @@ -14,5 +16,10 @@ export const examScoresState: Routes = [ { path: '', children: EXAM_SCORES_ROUTES, + data: { + authorities: [Authority.ADMIN, Authority.INSTRUCTOR], + pageTitle: 'artemisApp.examScores.title', + }, + canActivate: [UserRouteAccessService], }, ];