From a38ec498410d2292203793f4481cdc910a95d274 Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Tue, 12 Nov 2024 14:03:02 +0100 Subject: [PATCH 01/14] Implemented scrolling down behaviour --- .../complaints-student-view.component.html | 3 ++- .../complaints-student-view.component.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html index ae902f4ec8de..7aa44f148eff 100644 --- a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html +++ b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html @@ -23,7 +23,7 @@ id="complain" class="btn btn-primary" [class.not-allowed]="(!isExamMode && remainingNumberOfComplaints === 0) || !timeOfComplaintValid" - (click)="formComplaintType = ComplaintType.COMPLAINT" + (click)="startComplaint()" [disabled]="(!isExamMode && remainingNumberOfComplaints === 0) || !timeOfComplaintValid" title="{{ (!isExamMode && remainingNumberOfComplaints === 0) || !timeOfComplaintValid @@ -66,3 +66,4 @@ } } +
diff --git a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts index b469dcab432f..bad9052d4bbc 100644 --- a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts +++ b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnInit } from '@angular/core'; +import { Component, ElementRef, Input, OnInit, ViewChild } from '@angular/core'; import { Exercise, getCourseFromExercise } from 'app/entities/exercise.model'; import { Complaint, ComplaintType } from 'app/entities/complaint.model'; import { ComplaintService } from 'app/complaints/complaint.service'; @@ -28,6 +28,8 @@ export class ComplaintsStudentViewComponent implements OnInit { // flag to indicate exam test run. Default set to false. @Input() testRun = false; + @ViewChild('bottom') bottom: ElementRef; + submission: Submission; complaint: Complaint; course?: Course; @@ -149,4 +151,14 @@ export class ComplaintsStudentViewComponent implements OnInit { } return false; } + + startComplaint(): void { + this.formComplaintType = ComplaintType.COMPLAINT; + // Wait for the view to update + setTimeout(() => this.scrollToBottom(), 0); + } + + private scrollToBottom(): void { + this.bottom.nativeElement.scrollIntoView({ behavior: 'smooth' }); + } } From ce4d3bdadc04bf289252a6356e807bce10732e26 Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Tue, 12 Nov 2024 14:14:17 +0100 Subject: [PATCH 02/14] Added comments --- .../complaints-student-view.component.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts index bad9052d4bbc..51f1198e4e40 100644 --- a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts +++ b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts @@ -152,12 +152,18 @@ export class ComplaintsStudentViewComponent implements OnInit { return false; } + /** + * Opens the complaint form for the student to submit a complaint and scrolls to the bottom of the page to make the form visible + */ startComplaint(): void { this.formComplaintType = ComplaintType.COMPLAINT; // Wait for the view to update setTimeout(() => this.scrollToBottom(), 0); } + /** + * Scrolls to the bottom of the page + */ private scrollToBottom(): void { this.bottom.nativeElement.scrollIntoView({ behavior: 'smooth' }); } From 3e997dbfbed78af36dc7c3cb468062b0604ebc0c Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Tue, 12 Nov 2024 14:43:52 +0100 Subject: [PATCH 03/14] Add same behaviour for "Request more feedback" button --- .../complaints-student-view.component.html | 7 ++++--- .../complaints-student-view.component.ts | 16 ++++++++-------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html index 7aa44f148eff..eae77c7b9d7c 100644 --- a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html +++ b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html @@ -16,6 +16,7 @@ }

} + @if (isCorrectUserToFileAction && !complaint) {
@if (isExamMode || (course?.maxComplaints && course!.maxComplaints! > 0)) { @@ -23,7 +24,7 @@ id="complain" class="btn btn-primary" [class.not-allowed]="(!isExamMode && remainingNumberOfComplaints === 0) || !timeOfComplaintValid" - (click)="startComplaint()" + (click)="startComplaint(ComplaintType.COMPLAINT)" [disabled]="(!isExamMode && remainingNumberOfComplaints === 0) || !timeOfComplaintValid" title="{{ (!isExamMode && remainingNumberOfComplaints === 0) || !timeOfComplaintValid @@ -37,7 +38,7 @@
} -
@if (!complaint && formComplaintType) {
+
} @if (complaint) {
diff --git a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts index 4a5cd1faf0e0..b0292ee1e69a 100644 --- a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts +++ b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts @@ -167,6 +167,6 @@ export class ComplaintsStudentViewComponent implements OnInit { * Function to scroll to the complaint form */ private scrollToComplaint(): void { - this.complaintScrollpoint?.nativeElement.scrollIntoView({ behavior: 'smooth' }); + this.complaintScrollpoint?.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'end' }); } } From 2820dcec30a0d3c2b47eb73fae4303801a1fa42a Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Tue, 12 Nov 2024 22:42:17 +0100 Subject: [PATCH 12/14] Fix coderabbit issue --- .../complaints/complaint-student-view.component.spec.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts b/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts index 513f1a5ca8b9..6b9155c37887 100644 --- a/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts +++ b/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts @@ -241,14 +241,14 @@ describe('ComplaintsStudentViewComponent', () => { it('should set complaint type COMPLAINT and scroll to complaint form when pressing complaint', fakeAsync(() => { testInitWithResultStub(of()); - const courseWithMaxComplaints = { + const courseWithMaxComplaints: Course = { ...Course, maxComplaints: 3, - } as Course; - const exerciseWithMaxComplaints = { + }; + const exerciseWithMaxComplaints: Exercise = { ...courseExercise, course: courseWithMaxComplaints, - } as Exercise; + }; component.course = courseWithMaxComplaints; component.exercise = exerciseWithMaxComplaints; From 3ca663e28a779d399a3fdb992dc5296c8bba8475 Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Tue, 12 Nov 2024 22:43:19 +0100 Subject: [PATCH 13/14] Fix typo "Course" to "course" --- .../complaints/complaint-student-view.component.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts b/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts index 6b9155c37887..310fb0cc3c0b 100644 --- a/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts +++ b/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts @@ -242,7 +242,7 @@ describe('ComplaintsStudentViewComponent', () => { it('should set complaint type COMPLAINT and scroll to complaint form when pressing complaint', fakeAsync(() => { testInitWithResultStub(of()); const courseWithMaxComplaints: Course = { - ...Course, + ...course, maxComplaints: 3, }; const exerciseWithMaxComplaints: Exercise = { From ec2ee11f6c28d4ba7eddc5e50b9dd921b19eaac7 Mon Sep 17 00:00:00 2001 From: Julian Gassner Date: Tue, 12 Nov 2024 23:13:17 +0100 Subject: [PATCH 14/14] Adapt test to test for new scroll behaviour --- .../complaints-student-view.component.html | 2 +- .../complaints-student-view.component.ts | 3 +-- .../complaints/complaint-student-view.component.spec.ts | 6 +++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html index 50ad8f4097a4..783d822a2e84 100644 --- a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html +++ b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.html @@ -59,8 +59,8 @@ (onSubmit)="loadPotentialComplaint()" />
-
} +
@if (complaint) {
diff --git a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts index b0292ee1e69a..26d9308a110e 100644 --- a/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts +++ b/src/main/webapp/app/complaints/complaints-for-students/complaints-student-view.component.ts @@ -158,8 +158,7 @@ export class ComplaintsStudentViewComponent implements OnInit { */ openComplaintForm(complainType: ComplaintType): void { this.formComplaintType = complainType; - // Wait for the view to update - this.cdr.detectChanges(); + this.cdr.detectChanges(); // Wait for the view to update this.scrollToComplaint(); } diff --git a/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts b/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts index 310fb0cc3c0b..91172f9c6516 100644 --- a/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts +++ b/src/test/javascript/spec/component/complaints/complaint-student-view.component.spec.ts @@ -178,7 +178,7 @@ describe('ComplaintsStudentViewComponent', () => { expect(component.formComplaintType).toBe(ComplaintType.COMPLAINT); // Wait for setTimeout to execute tick(); - expect(scrollIntoViewMock).toHaveBeenCalledWith({ behavior: 'smooth' }); + expect(scrollIntoViewMock).toHaveBeenCalledWith({ behavior: 'smooth', block: 'end' }); })); it('should be visible on test run', fakeAsync(() => { @@ -273,7 +273,7 @@ describe('ComplaintsStudentViewComponent', () => { expect(component.formComplaintType).toBe(ComplaintType.COMPLAINT); tick(); // Wait for update to happen - expect(scrollIntoViewMock).toHaveBeenCalledWith({ behavior: 'smooth' }); + expect(scrollIntoViewMock).toHaveBeenCalledWith({ behavior: 'smooth', block: 'end' }); })); it('should set complaint type MORE_FEEDBACK and scroll to complaint form when pressing complaint', fakeAsync(() => { @@ -301,7 +301,7 @@ describe('ComplaintsStudentViewComponent', () => { expect(component.formComplaintType).toBe(ComplaintType.MORE_FEEDBACK); tick(); // Wait for update to happen - expect(scrollIntoViewMock).toHaveBeenCalledWith({ behavior: 'smooth' }); + expect(scrollIntoViewMock).toHaveBeenCalledWith({ behavior: 'smooth', block: 'end' }); })); it('should not be available if before or at assessment due date', fakeAsync(() => {