@@ -46,6 +46,14 @@ export class DataService {
4646 { id : 2 , firstName : 'Schüler' , lastName : '3' , classId : 1 } ,
4747 { id : 3 , firstName : 'Schüler' , lastName : '4' , classId : 2 } ,
4848 { id : 4 , firstName : 'Schüler' , lastName : '5' , classId : 3 } ,
49+ ] ) ;
50+ this . saveLocalstorage ( 'notes' , [
51+ { id : 0 , pupilId : 0 , teacherId : 1 , text : "Hat Mitschüler geschlagen." , date : new Date ( 1505400000000 ) } ,
52+ { id : 1 , pupilId : 0 , teacherId : 2 , text : "Hat Hausaufgaben 3 Mal nicht gemacht." , date : new Date ( 1505300000000 ) } ,
53+ { id : 2 , pupilId : 1 , teacherId : 1 , text : "Hat Tafel mit Edding bemalt." , date : new Date ( 1505200000000 ) } ,
54+ { id : 3 , pupilId : 1 , teacherId : 2 , text : "Hat Druckschrift anstatt Schreibschrift geschrieben. Strafarbeit: 5 Seiten Schreibschrift mit Füller." , date : new Date ( 1505100000000 ) } ,
55+ { id : 4 , pupilId : 1 , teacherId : 1 , text : "Hat \"Hosenscheißer\" zu Mitschüler gesagt." , date : new Date ( 1505000000000 ) } ,
56+ { id : 5 , pupilId : 3 , teacherId : 3 , text : "Schlägt Mitschülerin ins Gesicht." , date : new Date ( 1504900000000 ) } ,
4957 ] )
5058 }
5159
@@ -121,7 +129,7 @@ export class DataService {
121129 updateTeacher ( id , fName , lName , mail ) {
122130 let t = this . getTeachers ( ) ;
123131 // password unset due to asynchronous encryption
124- t [ id ] = { id : id , firstName : fName , lastName : lName , mail : mail , pass : '' } ;
132+ t [ id ] = { id : + id , firstName : fName , lastName : lName , mail : mail , pass : '' } ;
125133 this . saveLocalstorage ( 'teachers' , t ) ;
126134 }
127135
@@ -161,7 +169,7 @@ export class DataService {
161169
162170 updateClass ( id , name , grade ) {
163171 let c = this . getClasses ( ) ;
164- c [ id ] = { id : id , name : name , grade : grade } ;
172+ c [ id ] = { id : + id , name : name , grade : grade } ;
165173 this . saveLocalstorage ( 'classes' , c ) ;
166174 }
167175
@@ -198,14 +206,14 @@ export class DataService {
198206 let pupils = this . getPupils ( ) ;
199207 let id = Math . max . apply ( this , pupils . map ( e => e . id ) ) + 1 ; //generate new id
200208 if ( id < 0 ) id = 0 ; //set id to zero, if no previous id was found
201- let p = { id : id , firstName : firstName , lastName : lastName , classId : classId } ;
209+ let p = { id : id , firstName : firstName , lastName : lastName , classId : + classId } ;
202210 pupils . push ( p ) ;
203211 this . saveLocalstorage ( 'pupils' , pupils ) ;
204212 }
205213
206214 updatePupil ( id , firstName , lastName , classId ) {
207215 let p = this . getPupils ( ) ;
208- p [ id ] = { id : id , firstName : firstName , lastName : lastName , classId : classId } ;
216+ p [ id ] = { id : + id , firstName : firstName , lastName : lastName , classId : + classId } ;
209217 this . saveLocalstorage ( 'pupils' , p ) ;
210218 }
211219
@@ -228,7 +236,8 @@ export class DataService {
228236 getNotes ( ) {
229237 let ret = this . getLocalstorage ( 'notes' ) ;
230238 if ( ! ret ) { //no data found in localstorage
231- return [ ] ;
239+ this . generateInitialData ( ) ;
240+ return this . getNotes ( ) ;
232241 }
233242 else {
234243 ret = ret . map ( elem => {
@@ -239,7 +248,6 @@ export class DataService {
239248 this . notes = ret ;
240249 return this . notes ;
241250 }
242-
243251 }
244252
245253 getNote ( id ) {
@@ -275,14 +283,14 @@ export class DataService {
275283 let notes = this . getNotes ( ) ;
276284 let id = Math . max . apply ( this , notes . map ( e => e . id ) ) + 1 ; //generate new id
277285 if ( id < 0 ) id = 0 ; //set id to zero, if no previous id was found
278- let n = { id : id , pupilId : pupilId , teacherId : teacherId , text : text , date : date } ;
286+ let n = { id : id , pupilId : + pupilId , teacherId : + teacherId , text : text , date : date } ;
279287 notes . push ( n ) ;
280288 this . saveLocalstorage ( 'notes' , notes ) ;
281289 }
282290
283291 updateNote ( id , pupilId , teacherId , text , date ) {
284292 let n = this . getNotes ( ) ;
285- n [ id ] = { id : id , pupilId : pupilId , teacherId : teacherId , text : text , date : date } ;
293+ n [ id ] = { id : + id , pupilId : + pupilId , teacherId : + teacherId , text : text , date : date } ;
286294 this . saveLocalstorage ( 'notes' , n ) ;
287295 }
288296
0 commit comments