Skip to content

Commit 55b9227

Browse files
committed
Fix id comparison for specific pupil view
1 parent dab64b5 commit 55b9227

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

src/app/class/class.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h1>Klassenübersicht</h1>
1313
<th>Klassenstufe</th>
1414
<th></th>
1515
</tr>
16-
<tr class="clickable" *ngFor="let cl of dataService.getClasses()" routerLink="/class/{{cl.id}}">
16+
<tr class="clickable" *ngFor="let cl of dataService.getClassesVisible()" routerLink="/class/{{cl.id}}">
1717
<td>{{cl.name}}</td>
1818
<td>{{cl.grade}}</td>
1919
<td>

src/app/notes/notes.component.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import {Component, OnInit, OnDestroy, ViewChild} from '@angular/core';
2-
import {ActivatedRoute, Router} from "@angular/router";
3-
import {DataService} from "../data.service";
4-
import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
5-
import {Location} from "@angular/common";
1+
import { Component, OnInit, OnDestroy, ViewChild } from '@angular/core';
2+
import { ActivatedRoute, Router } from "@angular/router";
3+
import { DataService } from "../data.service";
4+
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
5+
import { Location } from "@angular/common";
66

77
@Component({
88
selector: 'app-notes',
@@ -17,21 +17,21 @@ export class NotesComponent implements OnInit, OnDestroy {
1717
notes: any;
1818
interval: any;
1919

20-
model: any = {pupilId: -1, teacherId: -1, text: "", date: new Date()};
20+
model: any = { pupilId: -1, teacherId: -1, text: "", date: new Date() };
2121

2222
constructor(private route: ActivatedRoute,
23-
private dataService: DataService,
24-
private modalService: NgbModal,
25-
private router: Router,
26-
private location: Location) {
23+
private dataService: DataService,
24+
private modalService: NgbModal,
25+
private router: Router,
26+
private location: Location) {
2727
}
2828

2929
ngOnInit() {
3030
this.sub = this.route.params.subscribe(params => {
3131
this.id = +params['id']; //get ID from route parameter
3232
if (!this.overview()) {
3333
this.model = this.dataService.getNote(this.id);
34-
if(this.model)
34+
if (this.model)
3535
this.convertToModelDate(this.model.date);
3636
}
3737
this.pupilId = +params['pId'];
@@ -52,7 +52,7 @@ export class NotesComponent implements OnInit, OnDestroy {
5252
}
5353

5454
goBack() {
55-
if(this.pupilView()) {
55+
if (this.pupilView()) {
5656
this.router.navigate(['/notes/pupil', this.pupilId]);
5757
}
5858
else
@@ -84,23 +84,23 @@ export class NotesComponent implements OnInit, OnDestroy {
8484

8585
getNotes() {
8686
let n = this.dataService.getNotes();
87-
if (this.pupilId)
88-
return n.filter(e => e.id === this.pupilId);
87+
if (!isNaN(this.pupilId))
88+
return n.filter(e => e.pupilId == this.pupilId);
8989
else
9090
return n;
9191
}
9292

9393
convertToModelDate(d) {
94-
this.model.datePicker = {year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDate()};
95-
this.model.time = {hour: d.getHours(), minute: d.getMinutes()};
94+
this.model.datePicker = { year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDate() };
95+
this.model.time = { hour: d.getHours(), minute: d.getMinutes() };
9696
}
9797

9898
@ViewChild('addNote') addNote;
9999

100100
add() {
101101
let d = new Date();
102102
this.convertToModelDate(d);
103-
if(this.pupilId)
103+
if (!isNaN(this.pupilId))
104104
this.model.pupilId = this.pupilId;
105105
this.modalService.open(this.addNote).result.then((res) => {
106106
if (res) { //if modal got closed with data
@@ -120,11 +120,11 @@ export class NotesComponent implements OnInit, OnDestroy {
120120
@ViewChild('deleteQuestion') deleteQuestion; //get template from HTML
121121
delete(id) {
122122
this.modalService.open(this.deleteQuestion).result.then((reallyDelete) => {
123-
if (reallyDelete)
124-
this.dataService.removeNote(id);
125-
//workaround because for some reason it wants to open the detail page, but doesn't do it on any other overview page
126-
this.location.back(); //TODO: fix this
127-
},
123+
if (reallyDelete)
124+
this.dataService.removeNote(id);
125+
//workaround because for some reason it wants to open the detail page, but doesn't do it on any other overview page
126+
this.location.back(); //TODO: fix this
127+
},
128128
(reason) => { //dismissed
129129
});
130130
}

src/app/pupil/pupil.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ <h4 class="modal-title">Wirklich löschen?</h4>
106106
<label class="control-label col-sm-4" for="class">Klasse:</label>
107107
<div class="col-sm-8">
108108
<select class="form-control" id="class" [(ngModel)]="model.classId" required>
109-
<option *ngFor="let class of dataService.getClasses()" [value]="class.id">{{class.name}}</option>
109+
<option *ngFor="let class of dataService.getClassesVisible()" [value]="class.id">{{class.name}}</option>
110110
</select>
111111
</div>
112112
</div>

0 commit comments

Comments
 (0)