import { Component, Input, OnInit, ViewChild } from '@angular/core'; import { FormControl, FormGroup, FormArray, FormBuilder } from '@angular/forms'; import { faMinusSquare, faPlusSquare } from '@fortawesome/free-solid-svg-icons'; import { deepCopy } from '../../../../../common/util/object-utils'; import { ServiceCheckDisjunctionComponent } from 'src/app/components/service-check-editor/service-check-disjunction/service-check-disjunction.component'; import { ServiceApiService } from 'src/app/services/service-api.service'; @Component({ selector: 'app-service-check-form', templateUrl: './service-check-form.component.html', styleUrls: ['./service-check-form.component.scss'] }) export class ServiceCheckFormComponent implements OnInit { @ViewChild(ServiceCheckDisjunctionComponent) checkEditor!: ServiceCheckDisjunctionComponent; @Input() serviceCheck!: HttpCheckConfig; public fa = { plus: faPlusSquare, delete: faMinusSquare }; serviceCheckForm: FormGroup = this.formBuilder.group({ id: -1, //constant for defaultValues title: '', //constant for defaultValues active: undefined, //constant for defaultValues url: '', //constant for defaultValues interval: 10, //constant for defaultValues timeout: 10, //constant for defaultValuess notify: true, notifyThreshold: 3 }); constructor(private formBuilder: FormBuilder, private serviceApi: ServiceApiService) {} ngOnInit(): void { this.serviceCheckForm.patchValue(this.serviceCheck); } async save() { try { this.serviceCheckForm.updateValueAndValidity(); const copy = deepCopy(this.serviceCheckForm.value as HttpCheckConfig); copy.checks = this.checkEditor.collect(); const savedCheck = await this.serviceApi.saveServiceCheck(this.serviceCheck.serverId as number, copy); this.serviceCheckForm.patchValue(savedCheck); this.serviceCheck = savedCheck; } catch (error: any) { console.error(error); } } }