Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Development: Utilize server endpoint for getting longest working time in exam assessment #8749

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,24 @@ export class ExamAssessmentButtonsComponent implements OnInit {
this.courseService.find(this.courseId).subscribe((courseResponse) => {
this.course = courseResponse.body!;
});
const studentExamObservable = this.studentExamService.findAllForExam(this.courseId, this.examId).pipe(
tap((res) => {
// TODO: directly load the longest working time from the server and avoid loading all student exams
this.setStudentExams(res.body);
this.longestWorkingTime = Math.max.apply(
null,
this.studentExams.map((studentExam) => studentExam.workingTime),
);

/*
Prepare workingTimeObservable to perform the following on subscribe:
- set the longestWorkingTime
- trigger (re)calculation of whether the exam is over
*/
const workingTimeObservable = this.studentExamService.getLongestWorkingTimeForExam(this.courseId, this.examId).pipe(
tap((value) => {
this.longestWorkingTime = value;
this.calculateIsExamOver();
}),
);

/*
Prepare examObservable to perform the following on subscribe:
- set the exam
- trigger (re)calculation of whether the exam is over
*/
const examObservable = this.examManagementService.find(this.courseId, this.examId, true).pipe(
tap((examResponse) => {
this.exam = examResponse.body!;
Expand All @@ -84,7 +90,7 @@ export class ExamAssessmentButtonsComponent implements OnInit {
);

// Calculate hasStudentsWithoutExam only when both observables emitted
forkJoin([studentExamObservable, examObservable]).subscribe(() => {
forkJoin([workingTimeObservable, examObservable]).subscribe(() => {
this.isLoading = false;
});
});
Expand Down Expand Up @@ -151,10 +157,4 @@ export class ExamAssessmentButtonsComponent implements OnInit {
this.isExamOver = endDate.isBefore(dayjs());
}
}

private setStudentExams(studentExams: any): void {
if (studentExams) {
this.studentExams = studentExams;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { MockRouterLinkDirective } from '../../helpers/mocks/directive/mock-rout
describe('ExamAssessmentButtons', () => {
let examAssessmentButtonsFixture: ComponentFixture<ExamAssessmentButtonsComponent>;
let examAssessmentButtonsComponent: ExamAssessmentButtonsComponent;
let studentExams: StudentExam[] = [];
let course: Course;
let studentOne: User;
let studentExamOne: StudentExam | undefined;
Expand Down Expand Up @@ -59,13 +58,8 @@ describe('ExamAssessmentButtons', () => {
},
}),
MockProvider(StudentExamService, {
findAllForExam: () => {
return of(
new HttpResponse({
body: studentExams,
status: 200,
}),
);
getLongestWorkingTimeForExam: () => {
return of(studentExamOne?.workingTime ?? 0);
},
}),
MockProvider(CourseManagementService, {
Expand Down Expand Up @@ -120,8 +114,6 @@ describe('ExamAssessmentButtons', () => {
studentExamOne.workingTime = 70;
studentExamOne.user = studentOne;

studentExams = [studentExamOne];

TestBed.configureTestingModule({
imports: [ArtemisTestModule],
declarations: [ExamAssessmentButtonsComponent, MockDirective(MockHasAnyAuthorityDirective), MockPipe(ArtemisTranslatePipe), MockRouterLinkDirective],
Expand Down
Loading