Skip to content

Commit

Permalink
Show capacity warning per education instead of per department
Browse files Browse the repository at this point in the history
+ do not close modal with mask click
  • Loading branch information
BenjaVR committed Feb 28, 2019
1 parent 821b354 commit bbcb3dd
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/components/departments/DepartmentsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class DepartmentFormModal extends React.Component<DepartmentFormModalProps, IDep
confirmLoading={this.state.isSubmitting}
destroyOnClose={true}
afterClose={this.handleAfterClose}
maskClosable={false}
>
<Form>
<FormItem label="Naam">
Expand Down
1 change: 1 addition & 0 deletions src/components/educations/EducationsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class EducationFormModal extends React.Component<EducationFormModalProps, IEduca
okText={this.props.okText}
confirmLoading={this.state.isSubmitting}
destroyOnClose={true}
maskClosable={false}
>
<Form>
<FormItem label="Naam">
Expand Down
2 changes: 1 addition & 1 deletion src/components/planning/PlanningDetailsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class PlanningDetailsModal extends React.Component<IPlanningDetailsModalProps, I
onCancel={this.handleClose}
width={700}
footer={null}
maskClosable={true}
maskClosable={false}
>
{this.renderTitle(this.props.selectedDate)}
{this.renderDepartments(studentsPlannedThisDay)}
Expand Down
14 changes: 10 additions & 4 deletions src/components/planning/PlanningsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -20,6 +21,7 @@ interface IPlanningsFormModalProps {
departments: Department[];
areDepartmentsLoading: boolean;
isEdit: boolean;
educations: Education[];
onCloseRequest: () => void;
submitInternship(internship: IStudentInternship): Promise<void>;
}
Expand Down Expand Up @@ -92,6 +94,7 @@ class PlanningsFormModal extends React.Component<PlanningsFormModalProps, IPlann
okText={this.props.okText}
confirmLoading={this.state.isSubmitting}
destroyOnClose={true}
maskClosable={false}
afterClose={this.handleFormClosed}
>
<Form onKeyDown={this.handleKeyDown}>
Expand Down Expand Up @@ -257,20 +260,23 @@ class PlanningsFormModal extends React.Component<PlanningsFormModalProps, IPlann
return student.id !== this.props.studentToPlan.id;
});

const isCrossingTheCapacityLimits = department.totalCapacity <= department.getUsedCapacity(students);
const education = this.props.educations.find((edu) => 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));
}
}
Modal.confirm({
title: "Capaciteit overschreden",
content: (
<React.Fragment>
<p>Er is minstens één geselecteerde dag waar de capaciteit voor <b>{department.name}</b> werd overschreden.</p>
<p>Er is minstens één geselecteerde dag waar de capaciteit voor <b>{department.name}</b> (opleiding <b>{education.name}</b>) werd overschreden.</p>
<p>Bent u zeker dat u wilt verdergaan?</p>
<ul>
{intersectingDates.map((intersectingDate) => {
Expand Down
2 changes: 2 additions & 0 deletions src/components/planning/PlanningsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class PlanningsPage extends React.Component<PlanningsPageProps, IPlanningsPageSt
departments={this.state.departments}
areDepartmentsLoading={this.state.areDepartmentsLoading}
isEdit={false}
educations={this.state.educations}
/>
<PlanningsFormModal
title={this.state.plannedStudentToEdit === undefined
Expand All @@ -179,6 +180,7 @@ class PlanningsPage extends React.Component<PlanningsPageProps, IPlanningsPageSt
departments={this.state.departments}
areDepartmentsLoading={this.state.areDepartmentsLoading}
isEdit={true}
educations={this.state.educations}
/>
<PlanningDetailsModal
departments={this.state.departments}
Expand Down
2 changes: 1 addition & 1 deletion src/components/schools/SchoolInternshipSummaryModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class SchoolInternshipSummaryModal extends React.Component<SchoolInternshipSumma
visible={this.props.isVisible}
footer={null}
closable={true}
maskClosable={true}
maskClosable={false}
onCancel={this.handleClose}
destroyOnClose={true}
width={700}
Expand Down
1 change: 1 addition & 0 deletions src/components/schools/SchoolsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ class SchoolsFormModal extends React.Component<SchoolFormModalProps, ISchoolsFor
okText={this.props.okText}
confirmLoading={this.state.isSubmitting}
destroyOnClose={true}
maskClosable={false}
>
<Form>
<FormItem label="Naam">
Expand Down
1 change: 1 addition & 0 deletions src/components/students/StudentsFormModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class StudentsFormModal extends React.Component<StudentFormModalProps, IStudents
okText={this.props.okText}
confirmLoading={this.state.isSubmitting}
destroyOnClose={true}
maskClosable={false}
>
<Form layout="horizontal">
<FormItem label="Voornaam">
Expand Down
2 changes: 1 addition & 1 deletion src/components/students/StudentsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class StudentsTable extends React.Component<IStudentsTableProps, IStudentTableSt
title={`Stage voor ${selectedStudent !== undefined ? selectedStudent.fullName : ""}`}
visible={this.state.isPlanningDetailsOpen}
closable={true}
maskClosable={true}
maskClosable={false}
onCancel={this.handleClosePlanningDetails}
footer={(
<div className={specificStyles.studentInternshipModalFooter}>
Expand Down
8 changes: 8 additions & 0 deletions src/models/Department.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ export class Department extends ModelBase<IDepartment> {
}).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
Expand Down

0 comments on commit bbcb3dd

Please sign in to comment.