-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy-courses.component.ts
More file actions
73 lines (64 loc) · 1.84 KB
/
my-courses.component.ts
File metadata and controls
73 lines (64 loc) · 1.84 KB
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
64
65
66
67
68
69
70
71
72
73
import { Component, OnInit } from "@angular/core";
import { Course } from "src/app/model/course";
import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
import { CourseEditModalComponent } from "./course-edit-modal/course-edit-modal.component";
import { CoursesStoreService } from "src/app/service/courses-store.service";
const DEBUG = false;
@Component({
selector: "app-my-courses",
templateUrl: "./my-courses.component.html",
styleUrls: ["./my-courses.component.css"]
})
export class MyCoursesComponent implements OnInit {
courses: Course[];
constructor(
private modalService: NgbModal,
private courseService: CoursesStoreService
) {
console.log(this.courses);
}
ngOnInit(): void {
this.courseService.getCourses().subscribe((newCourses: Course[]) => {
this.courses = newCourses;
console.log(this.courses);
});
if (DEBUG) {
setInterval(() => {
// this.courses.push(courseList[0]);
}, 2000);
}
}
onCreateCourse() {
this.openModal(
{
title: "",
description: "",
price: null
} as Course,
"Create course"
).then(
value => {
this.courseService.createCourse(value);
},
reason => console.log(reason)
);
}
onCourseEdit(course: Course) {
this.openModal(course, "Edit course").then(
modifiedCourse => {
console.log(modifiedCourse);
this.courseService.updateCourse(modifiedCourse);
},
reason => console.log(reason)
);
}
onCourseRemove(course: Course) {
this.courseService.deleteCourse(course);
}
private openModal(course: Course, title: string): Promise<any> {
const modalRef = this.modalService.open(CourseEditModalComponent);
modalRef.componentInstance.modalTitle = title;
modalRef.componentInstance.course = course;
return modalRef.result;
}
}