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 }
0 commit comments