Skip to content

Commit 9d68faf

Browse files
committed
implement sorting && fix duplication glitch
1 parent 807fefb commit 9d68faf

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

src/app/data.service.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ export class DataService {
8282
getTeacherList() {
8383
let t = this.getTeachers();
8484
t.shift(); //remove root user from List
85+
t = t.sort((a, b) => a.firstName.localeCompare(b.firstName));
86+
t = t.sort((a, b) => a.lastName.localeCompare(b.lastName));
8587
return t;
8688
}
8789

@@ -149,8 +151,10 @@ export class DataService {
149151
this.generateInitialData();
150152
return this.getClasses();
151153
}
152-
else
154+
else {
155+
ret.sort((a, b) => a.name.localeCompare(b.name));
153156
return ret;
157+
}
154158
}
155159

156160
getClass(id) {
@@ -188,8 +192,11 @@ export class DataService {
188192
this.generateInitialData();
189193
return this.getPupils();
190194
}
191-
else
195+
else {
196+
ret.sort((a, b) => a.firstName.localeCompare(b.firstName));
197+
ret.sort((a, b) => a.lastName.localeCompare(b.lastName));
192198
return ret;
199+
}
193200
}
194201

195202
getPupil(id) {
@@ -231,6 +238,12 @@ export class DataService {
231238

232239

233240
/******************** Notes **********************/
241+
dateSort(a, b) {
242+
a = new Date(a.date);
243+
b = new Date(b.date);
244+
return a > b ? -1 : a < b ? 1 : 0;
245+
}
246+
234247
notes = [];
235248

236249
getNotes() {
@@ -244,6 +257,7 @@ export class DataService {
244257
elem.date = new Date(elem.date); //convert date string back to date
245258
return elem;
246259
});
260+
ret.sort(this.dateSort);
247261
if (JSON.stringify(this.notes) !== JSON.stringify(ret))
248262
this.notes = ret;
249263
return this.notes;

src/app/notes/notes.component.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div *ngIf="overview()">
22
<div class="container">
3-
<h1 *ngIf="!pupilId">Einträgeübersicht</h1>
4-
<h1 *ngIf="pupilId" >Einträgeübersicht für {{dataService.getPupilName(pupilId)}}</h1>
3+
<h1 *ngIf="!pupilView()">Einträgeübersicht</h1>
4+
<h1 *ngIf="pupilView()" >Einträgeübersicht für {{dataService.getPupilName(pupilId)}}</h1>
55
<div class="row row-spacing">
66
<button class="btn btn-success" (click)="add()">
77
<i class="fa fa-plus" aria-hidden="true"></i>

src/app/notes/notes.component.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,16 @@ export class NotesComponent implements OnInit, OnDestroy {
4747
return isNaN(this.id);
4848
}
4949

50+
pupilView() {
51+
return !isNaN(this.pupilId);
52+
}
53+
5054
goBack() {
51-
this.location.back();
55+
if(this.pupilView()) {
56+
this.router.navigate(['/notes/pupil', this.pupilId]);
57+
}
58+
else
59+
this.router.navigate(['/notes']);
5260
}
5361

5462
dateToString(date) {
@@ -74,10 +82,6 @@ export class NotesComponent implements OnInit, OnDestroy {
7482
return !(m.pupilId >= 0 && m.teacherId >= 0 && m.text && m.date);
7583
}
7684

77-
log(l) {
78-
console.log(l);
79-
}
80-
8185
getNotes() {
8286
let n = this.dataService.getNotes();
8387
if (this.pupilId)
@@ -87,7 +91,7 @@ export class NotesComponent implements OnInit, OnDestroy {
8791
}
8892

8993
convertToModelDate(d) {
90-
this.model.datePicker = {year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDay() + 1};
94+
this.model.datePicker = {year: d.getFullYear(), month: d.getMonth() + 1, day: d.getDate()};
9195
this.model.time = {hour: d.getHours(), minute: d.getMinutes()};
9296
}
9397

0 commit comments

Comments
 (0)