diff --git a/ui/src/app/administrative/reports/categories/records-report.component.ts b/ui/src/app/administrative/reports/categories/records-report.component.ts index f028126a4..442881c9d 100644 --- a/ui/src/app/administrative/reports/categories/records-report.component.ts +++ b/ui/src/app/administrative/reports/categories/records-report.component.ts @@ -1,4 +1,4 @@ -4; /* +/* * Copyright (c) 2018 The members of the EXAM Consortium (https://confluence.csc.fi/display/EXAM/Konsortio-organisaatio) * * Licensed under the EUPL, Version 1.1 or - as soon they will be approved by the European Commission - subsequent diff --git a/ui/src/app/calendar/calendar-title-resolver.service.ts b/ui/src/app/calendar/calendar-title-resolver.service.ts deleted file mode 100644 index e558a816b..000000000 --- a/ui/src/app/calendar/calendar-title-resolver.service.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; - -@Injectable({ providedIn: 'root' }) -export class CalendarTitleResolverService implements Resolve { - resolve(route: ActivatedRouteSnapshot) { - return `EXAM - book a reservation for exam #${route.params.id}`; - } -} diff --git a/ui/src/app/enrolment/exams/exam-enrolment-title-resolver.service.ts b/ui/src/app/enrolment/exams/exam-enrolment-title-resolver.service.ts deleted file mode 100644 index 459263bab..000000000 --- a/ui/src/app/enrolment/exams/exam-enrolment-title-resolver.service.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { Injectable } from '@angular/core'; -import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; - -@Injectable({ providedIn: 'root' }) -export class ExamEnrolmentTitleResolverService implements Resolve { - resolve(route: ActivatedRouteSnapshot) { - return `EXAM - enrolment #${route.params.id}`; - } -} diff --git a/ui/src/app/examination/examination.component.ts b/ui/src/app/examination/examination.component.ts index 1b62c7e29..d6c19389e 100644 --- a/ui/src/app/examination/examination.component.ts +++ b/ui/src/app/examination/examination.component.ts @@ -135,8 +135,5 @@ export class ExaminationComponent implements OnInit, OnDestroy { throw Error('invalid index'); }; - private onUnload = (event: BeforeUnloadEvent) => { - event.preventDefault(); - return (event.returnValue = ''); - }; + private onUnload = (event: BeforeUnloadEvent) => event.preventDefault(); } diff --git a/ui/src/app/facility/rooms/room-mass-edit.component.ts b/ui/src/app/facility/rooms/room-mass-edit.component.ts index 1090aaea5..c572b9ea1 100644 --- a/ui/src/app/facility/rooms/room-mass-edit.component.ts +++ b/ui/src/app/facility/rooms/room-mass-edit.component.ts @@ -168,9 +168,8 @@ export class MultiRoomComponent implements OnInit { this.toast.error(this.translate.instant('i18n_select_room_error')); return; } - outOfService - ? this.roomService.openExceptionDialog(this.addExceptions, true, allExceptions) - : this.roomService.openExceptionDialog(this.addExceptions, false, allExceptions); + if (outOfService) this.roomService.openExceptionDialog(this.addExceptions, true, allExceptions); + else this.roomService.openExceptionDialog(this.addExceptions, false, allExceptions); }; selectAll = () => { diff --git a/ui/src/app/question/basequestion/question.component.ts b/ui/src/app/question/basequestion/question.component.ts index 515b810c6..844932f6a 100644 --- a/ui/src/app/question/basequestion/question.component.ts +++ b/ui/src/app/question/basequestion/question.component.ts @@ -154,8 +154,5 @@ export class QuestionComponent implements OnInit, OnDestroy, CanComponentDeactiv } }; - private onUnload = (event: BeforeUnloadEvent) => { - event.preventDefault(); - return this.questionForm?.dirty ? (event.returnValue = '') : null; - }; + private onUnload = (event: BeforeUnloadEvent) => event.preventDefault(); } diff --git a/ui/src/app/question/examquestion/exam-question.component.ts b/ui/src/app/question/examquestion/exam-question.component.ts index 74593028d..ab007d803 100644 --- a/ui/src/app/question/examquestion/exam-question.component.ts +++ b/ui/src/app/question/examquestion/exam-question.component.ts @@ -232,8 +232,5 @@ export class ExamQuestionComponent implements OnInit, OnDestroy { window.addEventListener('beforeunload', this.onUnload); }); - private onUnload = (event: BeforeUnloadEvent) => { - event.preventDefault(); - return this.questionForm?.dirty ? (event.returnValue = '') : null; - }; + private onUnload = (event: BeforeUnloadEvent) => event.preventDefault(); } diff --git a/ui/src/app/review/assessment/feedback/feedback.component.ts b/ui/src/app/review/assessment/feedback/feedback.component.ts index a63abc6cc..b75448f77 100644 --- a/ui/src/app/review/assessment/feedback/feedback.component.ts +++ b/ui/src/app/review/assessment/feedback/feedback.component.ts @@ -141,9 +141,9 @@ export class FeedbackComponent implements OnInit { if (!attachment) { return; } - this.collaborative && attachment.externalId - ? this.Attachment.downloadCollaborativeAttachment(attachment.externalId, attachment.fileName) - : this.Attachment.downloadFeedbackAttachment(this.exam); + if (this.collaborative && attachment.externalId) + this.Attachment.downloadCollaborativeAttachment(attachment.externalId, attachment.fileName); + else this.Attachment.downloadFeedbackAttachment(this.exam); }; removeFeedbackAttachment = () => { diff --git a/ui/src/app/review/assessment/questions/essay-question.component.ts b/ui/src/app/review/assessment/questions/essay-question.component.ts index 7cf14516d..af93d2c34 100644 --- a/ui/src/app/review/assessment/questions/essay-question.component.ts +++ b/ui/src/app/review/assessment/questions/essay-question.component.ts @@ -20,7 +20,6 @@ import { NgbCollapse } from '@ng-bootstrap/ng-bootstrap'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { ToastrService } from 'ngx-toastr'; import type { Exam, ExamParticipation, ExamSectionQuestion } from 'src/app/exam/exam.model'; -import type { ExaminationQuestion } from 'src/app/examination/examination.model'; import { AssessmentService } from 'src/app/review/assessment/assessment.service'; import type { ReviewQuestion } from 'src/app/review/review.model'; import { AttachmentService } from 'src/app/shared/attachment/attachment.service'; @@ -118,8 +117,8 @@ export class EssayQuestionComponent implements OnInit { insertEssayScore = () => { if (this.collaborative) { - return this.Assessment.saveCollaborativeEssayScore$( - this.sectionQuestion as ExaminationQuestion, + this.Assessment.saveCollaborativeEssayScore$( + this.sectionQuestion, this.id, this.ref, this.participation._rev as string, @@ -128,8 +127,9 @@ export class EssayQuestionComponent implements OnInit { this.scored.emit(resp.rev); }); } else { - return this.Assessment.saveEssayScore$(this.sectionQuestion as ExaminationQuestion).subscribe(() => { - this.toast.info(this.translate.instant('i18n_graded')), this.scored.emit(); + this.Assessment.saveEssayScore$(this.sectionQuestion).subscribe(() => { + this.toast.info(this.translate.instant('i18n_graded')); + this.scored.emit(); }); } }; diff --git a/ui/src/app/review/questions/assessment/question-assessment.component.ts b/ui/src/app/review/questions/assessment/question-assessment.component.ts index 93e9e07d5..19c1196ee 100644 --- a/ui/src/app/review/questions/assessment/question-assessment.component.ts +++ b/ui/src/app/review/questions/assessment/question-assessment.component.ts @@ -25,7 +25,7 @@ import { } from '@ng-bootstrap/ng-bootstrap'; import { TranslateModule, TranslateService } from '@ngx-translate/core'; import { ToastrService } from 'ngx-toastr'; -import { forkJoin } from 'rxjs'; +import { catchError, forkJoin, Observable, of, tap } from 'rxjs'; import { AssessmentService } from 'src/app/review/assessment/assessment.service'; import { QuestionFlowComponent } from 'src/app/review/questions/flow/question-flow.component'; import { QuestionReviewService } from 'src/app/review/questions/question-review.service'; @@ -115,7 +115,7 @@ export class QuestionAssessmentComponent implements OnInit { isFinalized = (review: QuestionReview) => this.QuestionReview.isFinalized(review); saveAssessments = (answers: ReviewQuestion[]) => - forkJoin(answers.map(this.saveEvaluation)).subscribe(() => (this.reviews = [...this.reviews])); + forkJoin(answers.map(this.saveEvaluation$)).subscribe(() => (this.reviews = [...this.reviews])); downloadQuestionAttachment = () => this.Attachment.downloadQuestionAttachment(this.selectedReview.question); @@ -130,10 +130,12 @@ export class QuestionAssessmentComponent implements OnInit { this.lockedAnswers = this.selectedReview.answers.filter(this.isLocked); }; - private saveEvaluation = (answer: ReviewQuestion) => { - return new Promise((resolve) => { - answer.essayAnswer.evaluatedScore = answer.essayAnswer.temporaryScore; - this.Assessment.saveEssayScore$(answer).subscribe(() => { + private saveEvaluation$ = (answer: ReviewQuestion): Observable => { + // TODO: this looks shady with rollback and all, whatabout smth like + // const tempAnswer: ReviewQuestion = {...answer, essayAnswer: {... answer.essayAnswer, evaluatedScore: answer.essayAnswer.temporaryScore}}; + answer.essayAnswer.evaluatedScore = answer.essayAnswer.temporaryScore; + return this.Assessment.saveEssayScore$(answer).pipe( + tap(() => { this.toast.info(this.translate.instant('i18n_graded')); if (this.assessedAnswers.indexOf(answer) === -1) { this.unassessedAnswers.splice(this.unassessedAnswers.indexOf(answer), 1); @@ -152,15 +154,14 @@ export class QuestionAssessmentComponent implements OnInit { } } } - resolve(); }), - (err: string) => { - // Roll back - answer.essayAnswer.evaluatedScore = answer.essayAnswer.temporaryScore; - this.toast.error(err); - resolve(); - }; - }); + catchError((err) => { + // Roll back + answer.essayAnswer.evaluatedScore = answer.essayAnswer.temporaryScore; + this.toast.error(err); + return of(); + }), + ); }; private isLocked = (answer: ReviewQuestion) => { diff --git a/ui/src/app/shared/file/file.service.ts b/ui/src/app/shared/file/file.service.ts index 2d607b735..d9dcfbffb 100644 --- a/ui/src/app/shared/file/file.service.ts +++ b/ui/src/app/shared/file/file.service.ts @@ -106,7 +106,7 @@ export class FileService { ia[i] = byteString.charCodeAt(i); } blob = new Blob([ia], { type: contentType }); - } catch (e) { + } catch { // Maybe this isn't base64, try plaintext approaches const text = contentType === 'application/json' ? JSON.stringify(data, null, 2) : data; blob = new Blob([text], { type: contentType });