From bbcb3dd3b9d3f0ebba683710d1b17272d201bd68 Mon Sep 17 00:00:00 2001 From: BenjaVR Date: Fri, 1 Mar 2019 00:09:16 +0100 Subject: [PATCH] Show capacity warning per education instead of per department + do not close modal with mask click --- .../departments/DepartmentsFormModal.tsx | 1 + src/components/educations/EducationsFormModal.tsx | 1 + src/components/planning/PlanningDetailsModal.tsx | 2 +- src/components/planning/PlanningsFormModal.tsx | 14 ++++++++++---- src/components/planning/PlanningsPage.tsx | 2 ++ .../schools/SchoolInternshipSummaryModal.tsx | 2 +- src/components/schools/SchoolsFormModal.tsx | 1 + src/components/students/StudentsFormModal.tsx | 1 + src/components/students/StudentsTable.tsx | 2 +- src/models/Department.ts | 8 ++++++++ 10 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/components/departments/DepartmentsFormModal.tsx b/src/components/departments/DepartmentsFormModal.tsx index ed0f28c..5594c0c 100644 --- a/src/components/departments/DepartmentsFormModal.tsx +++ b/src/components/departments/DepartmentsFormModal.tsx @@ -159,6 +159,7 @@ class DepartmentFormModal extends React.Component
diff --git a/src/components/educations/EducationsFormModal.tsx b/src/components/educations/EducationsFormModal.tsx index deff5b5..72b5577 100644 --- a/src/components/educations/EducationsFormModal.tsx +++ b/src/components/educations/EducationsFormModal.tsx @@ -63,6 +63,7 @@ class EducationFormModal extends React.Component diff --git a/src/components/planning/PlanningDetailsModal.tsx b/src/components/planning/PlanningDetailsModal.tsx index 6997df3..98d2402 100644 --- a/src/components/planning/PlanningDetailsModal.tsx +++ b/src/components/planning/PlanningDetailsModal.tsx @@ -50,7 +50,7 @@ class PlanningDetailsModal extends React.Component {this.renderTitle(this.props.selectedDate)} {this.renderDepartments(studentsPlannedThisDay)} diff --git a/src/components/planning/PlanningsFormModal.tsx b/src/components/planning/PlanningsFormModal.tsx index f0afcf5..2e82aab 100644 --- a/src/components/planning/PlanningsFormModal.tsx +++ b/src/components/planning/PlanningsFormModal.tsx @@ -8,6 +8,7 @@ import { studentsPlannedFullyInRange, studentsPlannedInDay, studentsPlannedParti import { nameof } from "../../helpers/nameof"; import { FormValidationTrigger } from "../../helpers/types"; import { Department } from "../../models/Department"; +import { Education } from "../../models/Education"; import { IStudentInternship, Student } from "../../models/Student"; import { StudentsRepository } from "../../services/repositories/StudentsRepository"; import styles from "./PlanningsFormModal.module.scss"; @@ -20,6 +21,7 @@ interface IPlanningsFormModalProps { departments: Department[]; areDepartmentsLoading: boolean; isEdit: boolean; + educations: Education[]; onCloseRequest: () => void; submitInternship(internship: IStudentInternship): Promise; } @@ -92,6 +94,7 @@ class PlanningsFormModal extends React.Component @@ -257,12 +260,15 @@ class PlanningsFormModal extends React.Component this.props.studentToPlan !== undefined && edu.id === this.props.studentToPlan.educationId); + const isCrossingTheCapacityLimits = education === undefined + ? false + : department.getCapacityForEducation(education) <= department.getUsedCapacityForEducation(students, education); - if (isCrossingTheCapacityLimits) { + if (isCrossingTheCapacityLimits && education !== undefined) { const intersectingDates: moment.Moment[] = []; for (const m = moment(internship.startDate); m.diff(internship.endDate, "days") <= 0; m.add(1, "day")) { - if (department.totalCapacity <= department.getUsedCapacity(studentsPlannedInDay(students, m))) { + if (department.totalCapacity <= department.getUsedCapacityForEducation(studentsPlannedInDay(students, m), education)) { intersectingDates.push(moment(m)); } } @@ -270,7 +276,7 @@ class PlanningsFormModal extends React.Component -

Er is minstens één geselecteerde dag waar de capaciteit voor {department.name} werd overschreden.

+

Er is minstens één geselecteerde dag waar de capaciteit voor {department.name} (opleiding {education.name}) werd overschreden.

Bent u zeker dat u wilt verdergaan?

    {intersectingDates.map((intersectingDate) => { diff --git a/src/components/planning/PlanningsPage.tsx b/src/components/planning/PlanningsPage.tsx index afff7ce..fb3e1f4 100644 --- a/src/components/planning/PlanningsPage.tsx +++ b/src/components/planning/PlanningsPage.tsx @@ -166,6 +166,7 @@ class PlanningsPage extends React.Component diff --git a/src/components/students/StudentsFormModal.tsx b/src/components/students/StudentsFormModal.tsx index b4e6935..0167607 100644 --- a/src/components/students/StudentsFormModal.tsx +++ b/src/components/students/StudentsFormModal.tsx @@ -90,6 +90,7 @@ class StudentsFormModal extends React.Component diff --git a/src/components/students/StudentsTable.tsx b/src/components/students/StudentsTable.tsx index faf0c30..302ae1c 100644 --- a/src/components/students/StudentsTable.tsx +++ b/src/components/students/StudentsTable.tsx @@ -81,7 +81,7 @@ class StudentsTable extends React.Component diff --git a/src/models/Department.ts b/src/models/Department.ts index 444a9f1..03dc649 100644 --- a/src/models/Department.ts +++ b/src/models/Department.ts @@ -40,6 +40,14 @@ export class Department extends ModelBase { }).length; } + public getUsedCapacityForEducation(students: Student[], education: Education): number { + return students.filter((student) => { + return student.internship !== undefined + && student.internship.departmentId === this.id + && student.educationId === education.id; + }).length; + } + public getCapacityForEducation(education: Education): number { const educationCapacity = this.capacityPerEducation.find((capacity) => capacity.educationId === education.id); return educationCapacity === undefined