Skip to content

Commit 12cf76c

Browse files
committed
add note filtering
1 parent 23c62f3 commit 12cf76c

4 files changed

Lines changed: 25 additions & 4 deletions

File tree

src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const routes: Routes = [
2121
{ path: 'pupil/:id', component: PupilComponent, canActivate: [LoginService] },
2222
{ path: 'notes', component: NotesComponent, canActivate: [LoginService] },
2323
{ path: 'notes/:id', component: NotesComponent, canActivate: [LoginService] },
24-
{ path: 'notes/pupil/:pId', component: NotesComponent, canActivate: [LoginService] },
24+
{ path: 'notes/pupil/:pId', component: NotesComponent, canActivate: [LoginService], data: [{filter: 'pupil'}] },
2525
{ path: 'dashboard', component: DashboardComponent, canActivate: [LoginService] }
2626
];
2727

src/app/data.service.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ export class DataService {
8686
return this.getTeachers().find(x => x.mail.toLowerCase() == mail.toLowerCase());
8787
}
8888

89+
getTeacherName(id) {
90+
let t = this.getTeacher(id);
91+
return t.firstName + " " + t.lastName;
92+
}
93+
8994
removeTeacher(id) {
9095
let teachers = this.getTeachers();
9196
teachers = teachers.filter(e => e.id !== id);
@@ -184,6 +189,11 @@ export class DataService {
184189
return pupils.filter(e => e.id == id)[0];
185190
}
186191

192+
getPupilName(id) {
193+
let p = this.getPupil(id);
194+
return p.firstName + " " + p.lastName;
195+
}
196+
187197
addPupil(firstName, lastName, classId) {
188198
let pupils = this.getPupils();
189199
let id = Math.max.apply(this, pupils.map(e => e.id)) + 1; //generate new id

src/app/notes/notes.component.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<div *ngIf="!id">
22
<div class="container">
3-
<h1>Einträgeübersicht</h1>
3+
<h1 *ngIf="!pupilId">Einträgeübersicht</h1>
4+
<h1 *ngIf="pupilId" >Einträgeübersicht für {{dataService.getPupilName(pupilId)}}</h1>
45
<div class="row row-spacing">
56
<button class="btn btn-success" (click)="add()">
67
<i class="fa fa-plus" aria-hidden="true"></i>
@@ -15,7 +16,7 @@ <h1>Einträgeübersicht</h1>
1516
<th>Datum</th>
1617
<th></th>
1718
</tr>
18-
<tr class="clickable" *ngFor="let note of dataService.getNotes()" routerLink="/notes/{{note.id}}">
19+
<tr class="clickable" *ngFor="let note of getNotes()" routerLink="/notes/{{note.id}}">
1920
<td>{{dataService.getNotePupilName(note.id)}}</td>
2021
<td>{{dataService.getNoteTeacherName(note.id)}}</td>
2122
<td>

src/app/notes/notes.component.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {Location} from "@angular/common";
1212
export class NotesComponent implements OnInit, OnDestroy {
1313

1414
private id: string;
15+
private pupilId: string;
1516
private sub: any;
1617
notes: any;
1718
interval: any;
@@ -32,6 +33,7 @@ export class NotesComponent implements OnInit, OnDestroy {
3233
this.model = this.dataService.getNote(this.id);
3334
this.convertToModelDate(this.model.date);
3435
}
36+
this.pupilId = params['pId'];
3537
});
3638
}
3739

@@ -71,13 +73,21 @@ export class NotesComponent implements OnInit, OnDestroy {
7173
console.log(l);
7274
}
7375

74-
@ViewChild('addNote') addNote;
76+
getNotes() {
77+
let n = this.dataService.getNotes();
78+
if (this.pupilId)
79+
return n.filter(e => e.id === this.pupilId);
80+
else
81+
return n;
82+
}
7583

7684
convertToModelDate(d) {
7785
this.model.datePicker = {year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDay() + 1};
7886
this.model.time = {hour: d.getHours(), minute: d.getMinutes()};
7987
}
8088

89+
@ViewChild('addNote') addNote;
90+
8191
add() {
8292
let d = new Date();
8393
this.convertToModelDate(d);

0 commit comments

Comments
 (0)