-
Notifications
You must be signed in to change notification settings - Fork 394
/
Copy pathhome.component.ts
67 lines (46 loc) · 1.77 KB
/
home.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import {Component, OnInit} from '@angular/core';
import {Course, sortCoursesBySeqNo} from '../model/course';
import { Observable } from 'rxjs';
import { finalize, map } from 'rxjs/operators';
import {HttpClient} from '@angular/common/http';
import {MatDialog, MatDialogConfig} from '@angular/material/dialog';
import {CourseDialogComponent} from '../course-dialog/course-dialog.component';
import { CoursesService } from '../services/courses.service';
import { LoadingService } from '../services/loading.service';
@Component({
selector: 'home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
beginnerCourses$: Observable<Course[]>;
advancedCourses$: Observable<Course[]>;
constructor(private http: HttpClient, private dialog: MatDialog, private coursesService: CoursesService, private loadingService: LoadingService) {}
ngOnInit() {
this.reloadCourses();
}
reloadCourses() {
this.loadingService.loadingOn();
const courses$ = this.coursesService.loadAllCourses()
.pipe(
map(courses => courses.sort(sortCoursesBySeqNo)),
finalize(() => this.loadingService.loadingOff())
)
this.beginnerCourses$ = courses$
.pipe(
map(courses => courses.filter(course => course.category === "BEGINNER"))
)
this.advancedCourses$ = courses$
.pipe(
map(courses => courses.filter(course => course.category === "ADVANCED"))
)
}
editCourse(course: Course) {
const dialogConfig = new MatDialogConfig();
dialogConfig.disableClose = true;
dialogConfig.autoFocus = true;
dialogConfig.width = "400px";
dialogConfig.data = course;
const dialogRef = this.dialog.open(CourseDialogComponent, dialogConfig);
}
}