Skip to content

Commit

Permalink
Merge pull request #436 from bkd-mba-fbi/feature/427-event-list
Browse files Browse the repository at this point in the history
refactor: adapt event text and link, refs #427
  • Loading branch information
mburri authored Jul 19, 2022
2 parents 3a39641 + 6423923 commit 3050ece
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Student } from 'src/app/shared/models/student.model';
import { Test } from '../../../shared/models/test.model';
import { EventsStateService } from '../../services/events-state.service';
import { Filter, TestStateService } from '../../services/test-state.service';
import { getState } from '../../utils/events';
import { getEventState } from '../../utils/events';
import { averageGrade, averagePoints } from '../../utils/tests';
import { map, take } from 'rxjs/operators';
import { Observable } from 'rxjs';
Expand Down Expand Up @@ -53,7 +53,9 @@ export class TestEditGradesComponent implements OnInit {
isEditFinalGradesAllowed(studentGrade: StudentGrade): Observable<boolean> {
return this.state.course$.pipe(
map((course) =>
Boolean(getState(course) && studentGrade.finalGrade.canGrade)
Boolean(
getEventState(course)?.value && studentGrade.finalGrade.canGrade
)
)
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/events/services/events-state.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ describe('EventsStateService', () => {
...evaluationStatus,
HasEvaluationStarted: true,
},
[studyClasses[1]]
[studyClasses[1]],
10300
),
buildCourse(
4,
Expand Down
29 changes: 16 additions & 13 deletions src/app/events/services/events-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { StudyClassesRestService } from 'src/app/shared/services/study-classes-r
import { spread } from 'src/app/shared/utils/function';
import { hasRole } from 'src/app/shared/utils/roles';
import { searchEntries } from 'src/app/shared/utils/search';
import { getState, isRated } from '../utils/events';
import { EventStateWithLabel, getEventState, isRated } from '../utils/events';
import { EventsRestService } from 'src/app/shared/services/events-rest.service';

export enum EventState {
Expand Down Expand Up @@ -126,7 +126,7 @@ export class EventsStateService {
courses: ReadonlyArray<Course>
): ReadonlyArray<Event> {
return courses.map((course) => {
const state = getState(course);
const state = getEventState(course);

return {
id: course.Id,
Expand All @@ -135,31 +135,34 @@ export class EventsStateService {
studentCount: course.AttendanceRef.StudentCount || 0,
dateFrom: course.DateFrom,
dateTo: course.DateTo,
state: state,
state: state?.value || null,
evaluationText: this.getEvaluationText(
state,
course.EvaluationStatusRef.EvaluationUntil
),
evaluationLink: this.getEvaluationLink(course),
evaluationLink: this.getEvaluationLink(state?.value, course),
};
});
}

private getEvaluationText(
state: Option<EventState>,
state: Option<EventStateWithLabel>,
date?: Maybe<Date>
): string {
return state === null
? ''
: this.translate.instant(`events.state.${state}`) +
(state === EventState.RatingUntil
const label = state?.label || state?.value;
return label
? this.translate.instant(`events.state.${label}`) +
(label === EventState.RatingUntil
? ` ${date ? format(date, 'dd.MM.yyyy') : ''}`
: '');
: '')
: '';
}

private getEvaluationLink(course: Course): Option<string> {
return course.EvaluationStatusRef.HasEvaluationStarted &&
!course.EvaluationStatusRef.HasTestGrading
private getEvaluationLink(
state: Maybe<EventState>,
course: Course
): Option<string> {
return state && state !== EventState.Tests
? this.buildLink(course.Id, 'evaluation')
: null;
}
Expand Down
27 changes: 15 additions & 12 deletions src/app/events/utils/events.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { canSetFinalGrade, getState, isRated } from './events';
import { canSetFinalGrade, getEventState, isRated } from './events';
import { buildCourse, buildFinalGrading } from '../../../spec-builders';
import { EventState } from '../services/events-state.service';
import {
EvaluationStatusRef,
FinalGrading,
} from 'src/app/shared/models/course.model';
import { EvaluationStatusRef } from 'src/app/shared/models/course.model';

describe('Course utils', () => {
describe('Get course state', () => {
Expand Down Expand Up @@ -35,7 +32,7 @@ describe('Course utils', () => {
);

// then
expect(getState(course)).toEqual(null);
expect(getEventState(course)).toEqual(null);
});

it('should get state add-tests', () => {
Expand All @@ -56,15 +53,16 @@ describe('Course utils', () => {
);

// then
expect(getState(course)).toEqual(EventState.Tests);
expect(getEventState(course)).toEqual({
value: EventState.Tests,
});
});

it('should get state rating-until', () => {
// given
const evaluationStatusRef = {
HasEvaluationStarted: true,
EvaluationUntil: new Date(2022, 2, 3),
HasReviewOfEvaluationStarted: false,
HasTestGrading: false,
Id: 6980,
};
Expand All @@ -77,15 +75,16 @@ describe('Course utils', () => {
);

// then
expect(getState(course)).toEqual(EventState.RatingUntil);
expect(getEventState(course)).toEqual({
value: EventState.RatingUntil,
});
});

it('should get state intermediate-rating', () => {
// given
const evaluationStatusRef = {
HasEvaluationStarted: true,
EvaluationUntil: null,
HasReviewOfEvaluationStarted: false,
HasTestGrading: false,
Id: 6980,
};
Expand All @@ -94,11 +93,15 @@ describe('Course utils', () => {
1234,
'Course in state intermediate-rating',
undefined,
evaluationStatusRef
evaluationStatusRef,
undefined,
10300
);

// then
expect(getState(course)).toEqual(EventState.IntermediateRating);
expect(getEventState(course)).toEqual({
value: EventState.IntermediateRating,
});
});
});

Expand Down
78 changes: 69 additions & 9 deletions src/app/events/utils/events.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,83 @@
import { Course } from '../../shared/models/course.model';
import { EventState } from '../services/events-state.service';

export function getState(course: Course): Option<EventState> {
export type EventStateWithLabel = {
value: EventState;
label?: string;
};

// To understand this logic see
// https://github.com/bkd-mba-fbi/webapp-schulverwaltung/issues/427
export function getEventState(course: Course): Option<EventStateWithLabel> {
const courseStatus = course.EvaluationStatusRef;

if (
courseStatus.HasEvaluationStarted === false &&
courseStatus.HasTestGrading === true
courseStatus.HasEvaluationStarted === true &&
(course.StatusId === 14030 || course.StatusId === 10350)
) {
return EventState.Tests;
// Bewertung
return {
value: EventState.Rating,
};
}

if (courseStatus.HasEvaluationStarted === true) {
if (courseStatus.EvaluationUntil == null) {
return EventState.IntermediateRating;
if (
courseStatus.HasEvaluationStarted === true &&
courseStatus.HasTestGrading === false
) {
if (
courseStatus.EvaluationUntil &&
courseStatus.EvaluationUntil >= new Date()
) {
// Bewertung bis
return {
value: EventState.RatingUntil,
};
}

if (
(courseStatus.EvaluationUntil === null ||
courseStatus.EvaluationUntil === undefined) &&
course.StatusId === 10300
) {
// Zwischenbewertung
return {
value: EventState.IntermediateRating,
};
}
}

if (courseStatus.EvaluationUntil >= new Date()) {
return EventState.RatingUntil;
if (
courseStatus.HasEvaluationStarted === false &&
courseStatus.HasTestGrading === true &&
courseStatus.HasReviewOfEvaluationStarted === false &&
course.StatusId !== 10260
) {
// Tests erfassen
return {
value: EventState.Tests,
};
}

if (
courseStatus.HasEvaluationStarted === true &&
courseStatus.HasTestGrading === true
) {
if (
courseStatus.EvaluationUntil === null ||
courseStatus.EvaluationUntil === undefined
) {
// Test erfassen, Label Zwischenbewertung
return {
value: EventState.Tests,
label: EventState.IntermediateRating,
};
} else if (courseStatus.EvaluationUntil >= new Date()) {
// Test erfassen, Label Bewertung bis
return {
value: EventState.Tests,
label: EventState.RatingUntil,
};
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/spec-builders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,8 @@ export function buildCourse(
designation?: string,
attendance?: AttendanceRef,
evaluationStatus?: EvaluationStatusRef,
classes?: StudyClass[]
classes?: StudyClass[],
statusId?: number
): Course {
return {
HRef: '',
Expand Down Expand Up @@ -495,7 +496,7 @@ export function buildCourse(
// IsPublished: t.boolean,
// LevelId: t.number,
// Level: t.string,
StatusId: 2,
StatusId: statusId || 2,
// Status: t.string,
// Lessons: null,
// EventManagers: null,
Expand Down

0 comments on commit 3050ece

Please sign in to comment.