|
1 | | -import { Component, OnInit, Renderer2, ViewChild, ElementRef } from '@angular/core'; |
| 1 | +import { Component, Renderer2, ViewChild, ElementRef, AfterViewInit } from '@angular/core'; |
2 | 2 | import { CategoryService } from '../../../services/category.service'; |
3 | 3 | import { ActivatedRoute, Params } from '@angular/router'; |
4 | 4 | import { CommunicationService } from '../shared/communication.service'; |
5 | 5 | import { log } from 'util'; |
| 6 | +import { UserService } from '../../../services/user.service'; |
| 7 | +import { CoursesService } from '../shared/courses.service'; |
6 | 8 |
|
7 | 9 | @Component({ |
8 | 10 | selector: 'courses', |
9 | 11 | templateUrl: './courses.component.html', |
10 | 12 | styleUrls: ['./courses.component.scss'] |
11 | 13 | }) |
12 | | -export class CoursesComponent implements OnInit { |
| 14 | +export class CoursesComponent implements AfterViewInit { |
13 | 15 |
|
14 | 16 | @ViewChild('backgroundElement') backgroundElement: ElementRef; |
15 | 17 |
|
16 | 18 | public dataIsAvailable: boolean = false; |
17 | 19 | public courses: Array<any>; |
| 20 | + public headerText: string = ""; |
| 21 | + public category: string = ""; |
18 | 22 |
|
19 | | - constructor(public categoryService: CategoryService, |
| 23 | + constructor( |
| 24 | + public categoryService: CategoryService, |
| 25 | + public userService: UserService, |
20 | 26 | private activatedRoute: ActivatedRoute, |
21 | 27 | public comService: CommunicationService, |
22 | | - public renderer: Renderer2) { |
23 | | - let localThis = this; |
24 | | - this.comService.getColor().subscribe(color => { |
25 | | - console.log(color); |
26 | | - this.renderer.addClass(this.backgroundElement.nativeElement, color); |
| 28 | + public coursesService: CoursesService, |
| 29 | + public renderer: Renderer2) {} |
| 30 | + |
| 31 | + ngAfterViewInit() { |
| 32 | + this.comService.getInfo().subscribe(response => { |
| 33 | + this.category = response.category; |
| 34 | + this.renderer.addClass(this.backgroundElement.nativeElement, response.color); |
27 | 35 | }); |
28 | | - } |
29 | 36 |
|
30 | | - ngOnInit() { |
31 | 37 | this.activatedRoute.params.subscribe((params: Params) => { |
32 | | - this.categoryService.getCoursesByCategoryId(params.courseId).subscribe(response =>{ |
33 | | - this.courses = response; |
34 | | - if(response.name != "HttpResponseError"){ |
35 | | - this.dataIsAvailable = true; |
36 | | - this.courses = response; |
37 | | - } |
| 38 | + if(params.id == "me"){ |
| 39 | + this.requestCoursesByUser(); |
| 40 | + } |
| 41 | + else{ |
| 42 | + this.requestCoursesByCategory(params.id); |
| 43 | + } |
| 44 | + }); |
| 45 | + } |
| 46 | + |
| 47 | + requestCoursesByUser():void{ |
| 48 | + this.headerText = "Meine"; |
| 49 | + this.userService.getCoursesByUser().subscribe(response =>{ |
| 50 | + response.forEach(element => { |
| 51 | + this.courses = []; |
| 52 | + this.coursesService.getCoursesByCourseId(element.ANM_KURS_ID).subscribe(response => { |
| 53 | + response.ANM_DATUM = element.ANM_DATUM; |
| 54 | + this.courses.push(response); |
| 55 | + }); |
38 | 56 | }); |
| 57 | + if(response.name != "HttpResponseError"){ |
| 58 | + this.dataIsAvailable = true; |
| 59 | + } |
| 60 | + }); |
| 61 | + } |
| 62 | + |
| 63 | + requestCoursesByCategory(courseId: string):void{ |
| 64 | + this.headerText = this.category; |
| 65 | + this.categoryService.getCoursesByCategoryId(courseId).subscribe(response =>{ |
| 66 | + this.courses = response; |
| 67 | + if(response.name != "HttpResponseError"){ |
| 68 | + this.dataIsAvailable = true; |
| 69 | + this.courses = response; |
| 70 | + } |
39 | 71 | }); |
40 | 72 | } |
41 | 73 |
|
|
0 commit comments