import { AfterViewChecked, Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; import { FormBuilder } from '@angular/forms'; import { ConfiguratorParameter } from '../../../../shared/models/configurator-parameter.interface'; import { ConfiguratorService } from "../../../../shared/services/administration/configurator.service"; import { Category } from "../../../../shared/models/category.interface"; import { Router } from "@angular/router"; import { NotificationsHandlingService } from 'src/app/shared/services/notifications-handling/notifications-handling.service'; import { AuthService } from 'src/app/shared/services/auth.service'; import { USER_RIGHTS } from 'src/app/shared/enums/USER_RIGHTS.enum'; import { environment } from 'src/environments/environment'; @Component({ selector: 'app-configurator-form', templateUrl: './configurator-form.component.html', styleUrls: ['./configurator-form.component.scss'] }) export class ConfiguratorFormComponent implements OnInit { @Input() dialogLayout: boolean = false; // Controls .scss classes to allow for better dispay in a dialog. @Input() displayValidationMessagesEvenIfPristine: boolean = false; // Serves for manually treating the controls as dirty. @Input() editableParameter: ConfiguratorParameter; @Output() valueChange = new EventEmitter(); /* * Reactive Form */ configuratorForm = this.fb.group({ parameterName: null, parameterType: null, parameterValue: null }); constructor(private fb: FormBuilder, private configuratorService: ConfiguratorService, private router: Router, private notificationService: NotificationsHandlingService, private authService: AuthService) { } ngOnInit(): void { } ngOnChanges(): void { } public formValue(): ConfiguratorParameter { let formValue: ConfiguratorParameter = { configurationId: this.editableParameter.configurationId, configurationVariable: this.editableParameter.configurationVariable, variableType: this.editableParameter.variableType, integerValue: this.editableParameter.variableType === 'Integer' ? Number(this.configuratorForm.get('parameterValue').value) : null, stringValue: this.editableParameter.variableType === 'String' ? String(this.configuratorForm.get('parameterValue').value) : null }; return formValue; } updateButtonClicked(): void { if (this.editableParameter.configurationId !== null) { this.configuratorService.updateConfiguratorParameter(this.formValue()).subscribe(result => { this.valueChange.emit(this.formValue()); this.notificationService.showUpdateConfiguratorParameterSuccess(); }, error => { }); } } canEditParameterValue(): boolean { return this.authService.userHasRightForClient(USER_RIGHTS.J01, environment.globalRightsClientID) && this.editableParameter.configurationVariable != null; } }