1 | import {Component, ViewChild} from '@angular/core';
|
---|
2 | import {SubjectInterface} from "../subjectInterface";
|
---|
3 | import {SubjectService} from "../subject.service";
|
---|
4 | import {ActiveUserInterface} from "../ActiveUserInterface";
|
---|
5 | import {LoginService} from "../login.service";
|
---|
6 | import {AllCoursesComponent} from "../all-courses/all-courses.component";
|
---|
7 | import {Router} from "@angular/router";
|
---|
8 |
|
---|
9 | @Component({
|
---|
10 | selector: 'app-subject',
|
---|
11 | templateUrl: './subject.component.html',
|
---|
12 | styleUrls: ['./subject.component.css']
|
---|
13 | })
|
---|
14 | export class SubjectComponent {
|
---|
15 |
|
---|
16 | subjects: SubjectInterface[] = [];
|
---|
17 | subjectId: number | undefined;
|
---|
18 | activeUser: ActiveUserInterface | undefined;
|
---|
19 | @ViewChild(AllCoursesComponent) child!: AllCoursesComponent;
|
---|
20 |
|
---|
21 | constructor(private service: SubjectService,
|
---|
22 | private loginService: LoginService,
|
---|
23 | private router: Router) {
|
---|
24 | }
|
---|
25 |
|
---|
26 | ngOnInit(): void {
|
---|
27 | this.activeUser = this.loginService.activeUser!!;
|
---|
28 | if (!this.activeUser) {
|
---|
29 | this.router.navigate(['/'])
|
---|
30 | }
|
---|
31 | this.service.getAllSubjects()
|
---|
32 | .subscribe(subjects => this.subjects = subjects);
|
---|
33 | }
|
---|
34 |
|
---|
35 | onChange({event, id}: { event: any, id: any }) {
|
---|
36 | if (event.target.checked) {
|
---|
37 | // @ts-ignore
|
---|
38 | this.subjectId = id
|
---|
39 | this.child.loadCourses(id.id);
|
---|
40 | } else {
|
---|
41 | // @ts-ignore
|
---|
42 | this.subjectId = null;
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | }
|
---|