Skip to content

Commit

Permalink
fix: attendance status now always reliably saved (#2641)
Browse files Browse the repository at this point in the history
fixes #2615
  • Loading branch information
tomwwinter authored Oct 31, 2024
1 parent 4922fd1 commit a3e369f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
</button>
</td>
<td>
<app-entity-block
[entityId]="childId"
entityType="Child"
></app-entity-block>
<app-entity-block [entityId]="childId"></app-entity-block>
</td>
<td>
<app-attendance-status-select
Expand Down Expand Up @@ -66,10 +63,7 @@
>
<mat-card-content>
<div class="attendance-item--header margin-bottom-regular">
<app-entity-block
[entityId]="childId"
entityType="Child"
></app-entity-block>
<app-entity-block [entityId]="childId"></app-entity-block>

<button
mat-icon-button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export class EditAttendanceComponent
mobile = false;

@Input() declare entity: Note;
attendanceForm: FormControl<Map<string, EventAttendance>>;

constructor(screenWithObserver: ScreenWidthObserver) {
super();
Expand All @@ -65,23 +64,22 @@ export class EditAttendanceComponent
category.valueChanges.pipe(startWith(category.value)).subscribe((val) => {
this.showAttendance = !!val?.isMeeting;
if (this.showAttendance) {
this.attendanceForm = new FormControl(
let childrenAttendanceForm = new FormControl(
this.entity.copy()["childrenAttendance"],
);
this.parent.addControl("childrenAttendance", this.attendanceForm);
this.parent.addControl("childrenAttendance", childrenAttendanceForm);
} else {
this.parent.removeControl("childrenAttendance");
this.attendanceForm = undefined;
}
});
}
}

getAttendance(childId: string) {
let attendance = this.attendanceForm.value.get(childId);
let attendance = this.parent.get("childrenAttendance").value.get(childId);
if (!attendance) {
attendance = new EventAttendance();
this.attendanceForm.value.set(childId, attendance);
this.parent.get("childrenAttendance").value.set(childId, attendance);
}
return attendance;
}
Expand All @@ -90,14 +88,13 @@ export class EditAttendanceComponent
const children = this.formControl.value;
const index = children.indexOf(id);
children.splice(index, 1);
this.attendanceForm.value.delete(id);
this.parent.get("childrenAttendance").value.delete(id);
this.formControl.markAsDirty();
this.formControl.setValue([...children]);
}

updateAttendanceValue(childId, property: "status" | "remarks", newValue) {
this.formControl.markAsDirty();
this.getAttendance(childId)[property] = newValue;
this.attendanceForm.setValue(this.attendanceForm.value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export class EntitySelectComponent<
}

this._entityType = Array.isArray(type) ? type : [type];
this.loadAvailableEntities();
this.loadAvailableEntities().then((_) => {});
}

private _entityType: string[];
Expand All @@ -91,7 +91,7 @@ export class EntitySelectComponent<
@Input() label: string;

/**
* The placeholder is what is seen when someone clicks into the input-
* The placeholder is what is seen when someone clicks into the input
* field and adds new entities.
* In the note-details-view, this is "Add children..."
* The placeholder is only displayed if `loading === false`
Expand Down Expand Up @@ -174,7 +174,7 @@ export class EntitySelectComponent<
* @private
*/
private async alignAvailableAndSelectedEntities(availableEntities: E[]) {
if (this.form.value === null || this.form.value === undefined) {
if (this.form?.value === null || this.form?.value === undefined) {
return;
}

Expand Down Expand Up @@ -245,7 +245,7 @@ export class EntitySelectComponent<
if (this._entityType?.length < 1) {
return;
}
if (this._entityType.length > 1) {
if (this._entityType?.length > 1) {
Logging.warn(
"EntitySelect with multiple types is always creating a new entity of the first listed type only.",
);
Expand Down

0 comments on commit a3e369f

Please sign in to comment.