Add feature for adding students on-the-fly
This commit is contained in:
parent
66ef196617
commit
1a0bb96f69
|
@ -7,6 +7,7 @@
|
|||
<label id="student-edit-lastname-label" for="student-edit-lastname-input">Nachname</label>
|
||||
<input id="student-edit-lastname-input" name="student-edit-lastname-input" type="text" [(ngModel)]="model.lastname" />
|
||||
|
||||
<ng-container *ngIf="!simple">
|
||||
<label id="student-edit-birthday-label" for="student-edit-birthday-input">Geburtsdatum</label>
|
||||
<input id="student-edit-birthday-input" name="student-edit-birthday-input" type="date" [(ngModel)]="model.birthday" />
|
||||
|
||||
|
@ -35,6 +36,7 @@
|
|||
|
||||
<label id="student-edit-email-label" for="student-edit-email-input">E-Mail</label>
|
||||
<input id="student-edit-email-input" name="student-edit-email-input" type="text" [(ngModel)]="model.email" />
|
||||
</ng-container>
|
||||
</form>
|
||||
<div style="text-align:center;">
|
||||
<button class="button-save" (click)="save()">Save</button>
|
||||
|
|
|
@ -12,6 +12,9 @@ export class StudentEditComponent implements OnInit {
|
|||
@Input()
|
||||
public student?: Student = undefined;
|
||||
|
||||
@Input()
|
||||
public simple: boolean = false;
|
||||
|
||||
@Output()
|
||||
public closing = new EventEmitter();
|
||||
|
||||
|
@ -36,7 +39,7 @@ export class StudentEditComponent implements OnInit {
|
|||
|
||||
public save(): void {
|
||||
if(this.student){
|
||||
this.studentsService.set(this.model).subscribe(_ => this.closing.emit());
|
||||
this.studentsService.set(this.sanitize(this.model)).subscribe(_ => this.closing.emit());
|
||||
} else {
|
||||
this.closing.emit();
|
||||
}
|
||||
|
@ -46,4 +49,20 @@ export class StudentEditComponent implements OnInit {
|
|||
return this.student ? 'show' : 'hidden';
|
||||
}
|
||||
|
||||
private sanitize(student: Student): Student {
|
||||
if(student){
|
||||
student.firstname ??= '';
|
||||
student.lastname ??= '';
|
||||
student.gender ??= 0;
|
||||
student.street ??= '';
|
||||
student.house ??= 0;
|
||||
student.house_suffix ??= '';
|
||||
student.zip ??= '';
|
||||
student.city ??= '';
|
||||
student.phone ??= '';
|
||||
student.email ??= '';
|
||||
}
|
||||
|
||||
return student;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
<div class="grid-item">
|
||||
<h1>{{courseVisit?.name}}</h1>
|
||||
<h2>{{courseVisit?.date | date: 'dd.MM.yyyy'}}, {{courseVisit?.begin}} - {{courseVisit?.end}}</h2>
|
||||
<button class="button-add" (click)="add()">Hinzufügen</button>
|
||||
</div>
|
||||
<div class="grid-item">
|
||||
</div>
|
||||
|
@ -35,3 +36,5 @@
|
|||
<div class="grid-item">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<li-student-edit [student]="addedStudent" (closing)="commit()" [simple]="true"></li-student-edit>
|
|
@ -21,6 +21,15 @@ table {
|
|||
margin: auto;
|
||||
}
|
||||
|
||||
button {
|
||||
color: white;
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
button.button-add {
|
||||
background-color: #411ccc;
|
||||
}
|
||||
|
||||
a:link,
|
||||
a:visited,
|
||||
a:active {
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
import { formatDate } from '@angular/common';
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { CourseVisit } from 'src/app/models/course-visit';
|
||||
import { Student } from 'src/app/models/student';
|
||||
import { StudentEnrollment } from 'src/app/models/student-enrollment';
|
||||
import { StudentVisit } from 'src/app/models/student-visit';
|
||||
import { Visit } from 'src/app/models/visit';
|
||||
import { EnrollService } from 'src/app/services/enroll/enroll.service';
|
||||
import { VisitsService } from 'src/app/services/visits/visits.service';
|
||||
|
||||
@Component({
|
||||
|
@ -16,7 +20,10 @@ export class VisitsComponent implements OnInit {
|
|||
public courseVisit?: CourseVisit;
|
||||
public dataSource = new MatTableDataSource<StudentVisit>();
|
||||
|
||||
public constructor(private visitsService: VisitsService) { }
|
||||
public addedStudent?: Student;
|
||||
|
||||
|
||||
public constructor(private visitsService: VisitsService, private enrollService: EnrollService) { }
|
||||
|
||||
public ngOnInit() {
|
||||
this.getData();
|
||||
|
@ -37,7 +44,7 @@ export class VisitsComponent implements OnInit {
|
|||
}
|
||||
|
||||
private getData(): void {
|
||||
//const now = new Date('2022-11-03 19:17:00');
|
||||
//const now = new Date('2023-04-24 16:01:01');
|
||||
const now = new Date();
|
||||
|
||||
this.visitsService.get(now)
|
||||
|
@ -52,4 +59,20 @@ export class VisitsComponent implements OnInit {
|
|||
});
|
||||
}
|
||||
|
||||
public add(): void {
|
||||
this.addedStudent = <Student>{};
|
||||
}
|
||||
|
||||
public commit(): void {
|
||||
this.enrollService.set(
|
||||
-1,
|
||||
[<StudentEnrollment>{
|
||||
cid: this.courseVisit?.cid,
|
||||
begin: formatDate(new Date(), 'yyyy-MM-dd', 'en-US'),
|
||||
end: formatDate(new Date('2100-01-01'), 'yyyy-MM-dd', 'en-US')
|
||||
}]).subscribe(_ => {
|
||||
this.addedStudent = undefined;
|
||||
this.getData();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import { HttpClient, HttpParams } from '@angular/common/http';
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { Enrollment } from 'src/app/models/enrollment';
|
||||
import { Student } from 'src/app/models/student';
|
||||
import { StudentEnrollment } from 'src/app/models/student-enrollment';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
|
|
Loading…
Reference in New Issue