Skip to content

Commit

Permalink
Add hours per week to subject edit and subject detail. Uncommented li…
Browse files Browse the repository at this point in the history
…ne of code in RegistrationValidationService to use hours per week. #131
  • Loading branch information
Xopabyteh committed Apr 14, 2024
1 parent 3f00325 commit d8dd4b8
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Contracts/SubjectDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public SubjectValidator()
RuleFor(x => x.CategoryId).NotEmpty().WithName("Kategorie");
RuleFor(x => x.ScheduleDayOfWeek).NotEmpty().WithName("Den");
RuleFor(x => x.ScheduleSlotInDay).NotEmpty().WithName("Čas");
RuleFor(x => x.HoursPerWeek).Must(BeMoreThanZero).WithName("Dotované hodiny");
}

private bool BeMoreThanZero(int arg)
{
return arg > 0;
}
}
}
1 change: 1 addition & 0 deletions Contracts/SubjectListItemDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public record SubjectListItemDto : SubjectReferenceDto
public int? Capacity { get; set; }
public DayOfWeek? ScheduleDayOfWeek { get; set; }
public ScheduleSlotInDay? ScheduleSlotInDay { get; set; }
public int HoursPerWeek { get; set; }
public List<int> EducationalAreaIds { get; set; } = new List<int>();
public List<int> GradeIds { get; set; } = new List<int>();
public List<int> TeacherIds { get; set; } = new List<int>();
Expand Down
4 changes: 3 additions & 1 deletion Services/SubjectMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public async Task MapFromSubjectDtoAsync(SubjectDto subjectDto, Subject subject,
subject.ScheduleDayOfWeek = subjectDto.ScheduleDayOfWeek.Value;
subject.ScheduleSlotInDay = subjectDto.ScheduleSlotInDay.Value;
subject.CanRegisterRepeatedly = subjectDto.CanRegisterRepeatedly;
subject.HoursPerWeek = subjectDto.HoursPerWeek;

var teacherRelationsUpdateFromResult = subject.TeacherRelations.UpdateFrom(subjectDto.TeacherIds,
targetKeySelector: t => t.TeacherId,
Expand Down Expand Up @@ -92,7 +93,8 @@ public async Task<SubjectDto> MapToSubjectDtoAsync(Subject subject, Cancellation
TeacherIds = subject.TeacherRelations.Select(tr => tr.TeacherId).ToList(),
ScheduleSlotInDay = subject.ScheduleSlotInDay,
ScheduleDayOfWeek = subject.ScheduleDayOfWeek,
CanRegisterRepeatedly = subject.CanRegisterRepeatedly
CanRegisterRepeatedly = subject.CanRegisterRepeatedly,
HoursPerWeek = subject.HoursPerWeek
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ static bool IsRegistrationWithinAreaCspOrCp(StudentSubjectRegistration registrat
// return new StudentCspOrCpRegistrationProgress(false, 0, 0);
//}

// Calculate the sum of hours in those fields
var ammOfHoursInCsOrCp = forRegistrations
.Aggregate(0, (total, reg) =>
IsRegistrationWithinAreaCspOrCp(reg)
//? total + reg.Subject.HoursPerWeek // Xopa: Todo: uncomment this, when HoursPerWeek is implemented
? total + 2
? total + reg.Subject.HoursPerWeek
: total);

// Xopa: Todo: Something like this?
Expand Down
1 change: 1 addition & 0 deletions Web.Client/Pages/Electives/SubjectDetail.razor
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<HxCardText>
<TextValue Label="Vyučující" Value="@GetTeachers(subject.TeacherIds)" />
<TextValue Label="Rozvrh" Value="@ValueFormatter.GetScheduleTimeSlot(subject.ScheduleDayOfWeek, subject.ScheduleSlotInDay)" />
<TextValue Label="Dotované hodiny týdně" Value="@($"{subject.HoursPerWeek}h")"/>
<TextValue Label="Počet zápisů primárních (+náhradních)" Value="@($"{subject.StudentRegistrationsCountMain} / {subject.Capacity?.ToString() ?? "\x221E"} (+{subject.StudentRegistrationsCountSecondary})")" />
<TextValue Label="@(subject.GradeIds.Count != 1 ? "Ročníky" : "Ročník")" Value="@GetGrades(subject.GradeIds)" />
<TextValue Label="Skupina" Value="@SubjectCategoriesDataStore.GetByKey(subject.CategoryId.Value)?.Name" />
Expand Down
1 change: 1 addition & 0 deletions Web.Client/Pages/Electives/SubjectEdit.razor
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<HxInputNumber @bind-Value="model.Capacity" Label="Kapacita" Hint="Ponechte prázné pro neomezenou kapacitu" Placeholder="Neomezená" />
<TeacherMultiPicker @bind-Value="model.TeacherIds" Label="Vyučující" />
<ScheduleTimeSlotPicker @bind-Day="model.ScheduleDayOfWeek" @bind-Slot="model.ScheduleSlotInDay" />
<HxInputNumber @bind-Value="model.HoursPerWeek" Label="Dotované hodiny" />
<GradeMultiPicker @bind-Value="model.GradeIds" Label="Ročník(y)" />
<SubjectCategoryPicker @bind-Value="model.CategoryId" Label="Skupina" />
<EducationalAreaMultiPicker @bind-Value="model.EducationalAreaIds" Label="Vzdělávací oblast(i)" />
Expand Down

0 comments on commit d8dd4b8

Please sign in to comment.