[8423429] | 1 | import {Component, OnInit} from '@angular/core';
|
---|
| 2 | import {StudentCourseService} from "../student-course.service";
|
---|
| 3 | import {StudentCourseInterface} from "../StudentCourseInterface";
|
---|
| 4 | import {LoginService} from "../login.service";
|
---|
| 5 | import {ProfessorCourseInterface} from "../ProfessorCourseInterface";
|
---|
| 6 | import {ActiveUserInterface} from "../ActiveUserInterface";
|
---|
| 7 | import {Router} from "@angular/router";
|
---|
| 8 |
|
---|
| 9 | @Component({
|
---|
| 10 | selector: 'app-student-course',
|
---|
| 11 | templateUrl: './student-course.component.html',
|
---|
| 12 | styleUrls: ['./student-course.component.css']
|
---|
| 13 | })
|
---|
| 14 | export class StudentCourseComponent implements OnInit {
|
---|
| 15 |
|
---|
| 16 | studentCourses: StudentCourseInterface[] = []
|
---|
| 17 | professorCourses: ProfessorCourseInterface[] = []
|
---|
| 18 | activeUser: ActiveUserInterface | undefined;
|
---|
| 19 |
|
---|
| 20 | constructor(private service: StudentCourseService,
|
---|
| 21 | private loginService: LoginService,
|
---|
| 22 | private router: Router) {
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | ngOnInit(): void {
|
---|
| 26 | this.activeUser = this.loginService.activeUser!!;
|
---|
| 27 | if (!this.activeUser) {
|
---|
| 28 | this.router.navigate(['/'])
|
---|
| 29 | }
|
---|
| 30 | // console.log("username", this.activeUser.username)
|
---|
| 31 | if (this.loginService.activeUser!!.userType == 'STUDENT')
|
---|
| 32 | this.service.getAllCoursesForActiveUserStudent(this.activeUser.username)
|
---|
| 33 | .subscribe(studentCourses => this.studentCourses = studentCourses);
|
---|
| 34 | if (this.activeUser.userType == 'PROFESSOR')
|
---|
| 35 | this.service.getAllCoursesForActiveUserProfessor(this.activeUser.username)
|
---|
| 36 | .subscribe(professorCourses => this.professorCourses = professorCourses);
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | saveCourseAsCurrent(id: number): void {
|
---|
| 40 | console.log("course id", id)
|
---|
| 41 | this.loginService.setCurrentCourse(id);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 |
|
---|
| 45 | }
|
---|