11import { Component , OnInit , ViewChild , Renderer2 , ElementRef } from '@angular/core' ;
2- import { Router } from '@angular/router' ;
2+ import { Router , ActivatedRoute , Params } from '@angular/router' ;
33import { ContactService } from '../shared/contact.service' ;
4+ import { log } from 'util' ;
5+ import { CoursesService } from '../shared/courses.service' ;
46
57@Component ( {
68 selector : 'contact' ,
79 templateUrl : './contact.component.html' ,
810 styleUrls : [ './contact.component.scss' ]
911} )
10- export class ContactComponent {
12+ export class ContactComponent implements OnInit {
1113 public dataIsAvailable : boolean = false ;
12- public button_text : string = "Feedback senden"
14+ public button_text : string = "Feedback senden" ;
15+ public headerText : string = "Kontakt" ;
16+ public course_feedback : boolean = false ;
17+ public single_course ;
1318 public contactMessage : any = {
1419 text : "" ,
1520 bewertung : null ,
@@ -20,14 +25,39 @@ export class ContactComponent {
2025 constructor (
2126 private router : Router ,
2227 private renderer : Renderer2 ,
23- private contactService : ContactService ) { }
28+ private contactService : ContactService ,
29+ private activatedRoute : ActivatedRoute ,
30+ private coursesService :CoursesService ) { }
2431
25- submit ( ) :void {
26- this . contactService . postContactFeedback ( this . contactMessage ) . subscribe ( response => {
27- if ( response . name != "HttpResponseError" ) {
28- this . renderer . addClass ( this . sendButton . nativeElement , 'is-primary-save' ) ;
29- this . button_text = 'Senden erfolgreich' ;
30- }
32+ ngOnInit ( ) {
33+ this . activatedRoute . params . subscribe ( ( params : Params ) => {
34+ if ( params . id ) {
35+ this . coursesService . getCoursesByCourseId ( params . id ) . subscribe ( response => {
36+ this . single_course = response ;
37+ this . course_feedback = true ;
38+ this . headerText = "Bewertung: " + this . single_course . KURS_NAME ;
39+ } ) ;
40+ }
3141 } ) ;
3242 }
43+
44+ submit ( ) :void {
45+ if ( this . course_feedback ) {
46+ this . coursesService . postFeedbackByCourse ( this . contactMessage , this . single_course . KURS_ID ) . subscribe ( response => {
47+ console . log ( response ) ;
48+ if ( response . name != "HttpResponseError" ) {
49+ this . renderer . addClass ( this . sendButton . nativeElement , 'is-primary-save' ) ;
50+ this . button_text = 'Senden erfolgreich' ;
51+ }
52+ } ) ;
53+ }
54+ else {
55+ this . contactService . postContactFeedback ( this . contactMessage ) . subscribe ( response => {
56+ if ( response . name != "HttpResponseError" ) {
57+ this . renderer . addClass ( this . sendButton . nativeElement , 'is-primary-save' ) ;
58+ this . button_text = 'Senden erfolgreich' ;
59+ }
60+ } ) ;
61+ }
62+ }
3363}
0 commit comments