import { Component , OnDestroy , OnInit } from '@angular/core' ; import { SystemService } from '../../../../settings/system/system.service' ; import { FormControl , FormGroup , Validators } from '@angular/forms' ; import { Subscription } from 'rxjs' ; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap' ; @ Component ( { selector : 'cmdb-feedback-modal' , templateUrl : './feedback-modal.component.html' , styleUrls : [ './feedback-modal.component.scss' ] } ) export class FeedbackModalComponent implements OnInit , OnDestroy { public feedbackForm : FormGroup ; public formListener : Subscription ; public feedbackUrl : string = 'https://datagerry.com/feedback-v1/0/0/0/0/0/unknown/' ; constructor ( private systemService , public activeModal ) { this . feedbackForm = new FormGroup ( { happiness : new FormControl ( 0 ) , usability : new FormControl ( 0 ) , functionality : new FormControl ( 0 ) , performance : new FormControl ( 0 ) , stability : new FormControl ( 0 ) , version : new FormControl ( '' ) , email : new FormControl ( '' , [ Validators . email , Validators . pattern ( '^[a-z0-9._%+-]+@[a-z0-9.-]+\\.[a-z]{2,4}$' ) ] ) , } ) ; } public get emailController ( ) : FormControl { return this . feedbackForm . get ( 'email' ) as FormControl ; } public ngOnInit ( ) { this . systemService . getDatagerryInformation ( ) . subscribe ( ( infos ) => { this . feedbackForm . get ( 'version' ) . setValue ( infos . version ) ; } ) ; this . formListener = this . feedbackForm . valueChanges . subscribe ( value => { this . generateQRCode ( ) ; } ) ; } private generateQRCode ( ) { let url = 'https://datagerry.com/feedback-v1/' ; url = url + this . feedbackForm . get ( 'happiness' ) . value . toString ( ) + '/' + this . feedbackForm . get ( 'usability' ) . value . toString ( ) + '/' + this . feedbackForm . get ( 'functionality' ) . value . toString ( ) + '/' + this . feedbackForm . get ( 'performance' ) . value . toString ( ) + '/' + this . feedbackForm . get ( 'stability' ) . value . toString ( ) + '/' + this . feedbackForm . get ( 'version' ) . value . toString ( ) + '/' + this . feedbackForm . get ( 'email' ) . value . toString ( ) ; this . feedbackUrl = url ; } public ngOnDestroy ( ) { this . formListener . unsubscribe ( ) ; } }