|
@@ -1,25 +1,21 @@
|
|
|
-import { Component, ElementRef, Input, OnInit, QueryList, ViewChildren } from '@angular/core';
|
|
|
|
|
|
|
+import { Component, Input, OnInit, ViewChild } from '@angular/core';
|
|
|
import { FormControl, FormGroup, FormArray, FormBuilder } from '@angular/forms';
|
|
import { FormControl, FormGroup, FormArray, FormBuilder } from '@angular/forms';
|
|
|
import { faMinusSquare, faPlusSquare } from '@fortawesome/free-solid-svg-icons';
|
|
import { faMinusSquare, faPlusSquare } from '@fortawesome/free-solid-svg-icons';
|
|
|
-import { ServiceApiService } from '../../services/service-api.service';
|
|
|
|
|
|
|
+
|
|
|
import { deepCopy } from '../../../../../common/util/object-utils';
|
|
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({
|
|
@Component({
|
|
|
selector: 'app-service-check-form',
|
|
selector: 'app-service-check-form',
|
|
|
templateUrl: './service-check-form.component.html',
|
|
templateUrl: './service-check-form.component.html',
|
|
|
styleUrls: ['./service-check-form.component.scss']
|
|
styleUrls: ['./service-check-form.component.scss']
|
|
|
})
|
|
})
|
|
|
export class ServiceCheckFormComponent implements OnInit {
|
|
export class ServiceCheckFormComponent implements OnInit {
|
|
|
- @ViewChildren('checkInput')
|
|
|
|
|
- set checkRows(childs: QueryList<ElementRef<HTMLInputElement>>) {
|
|
|
|
|
- if (childs?.length && childs.get(0)?.nativeElement.value === '') {
|
|
|
|
|
- //new added children via addPattern without value gets focus
|
|
|
|
|
- childs.get(0)?.nativeElement.focus();
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ @ViewChild(ServiceCheckDisjunctionComponent) checkEditor!: ServiceCheckDisjunctionComponent;
|
|
|
|
|
|
|
|
- @Input()
|
|
|
|
|
- serviceCheck!: HttpCheckConfig;
|
|
|
|
|
|
|
+ @Input() serviceCheck!: HttpCheckConfig;
|
|
|
public fa = { plus: faPlusSquare, delete: faMinusSquare };
|
|
public fa = { plus: faPlusSquare, delete: faMinusSquare };
|
|
|
|
|
|
|
|
serviceCheckForm: FormGroup = this.formBuilder.group({
|
|
serviceCheckForm: FormGroup = this.formBuilder.group({
|
|
@@ -29,45 +25,24 @@ export class ServiceCheckFormComponent implements OnInit {
|
|
|
url: '', //constant for defaultValues
|
|
url: '', //constant for defaultValues
|
|
|
interval: 10, //constant for defaultValues
|
|
interval: 10, //constant for defaultValues
|
|
|
timeout: 10, //constant for defaultValuess
|
|
timeout: 10, //constant for defaultValuess
|
|
|
- checks: this.formBuilder.array([]),
|
|
|
|
|
notify: true,
|
|
notify: true,
|
|
|
notifyThreshold: 3
|
|
notifyThreshold: 3
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
constructor(private formBuilder: FormBuilder, private serviceApi: ServiceApiService) {}
|
|
constructor(private formBuilder: FormBuilder, private serviceApi: ServiceApiService) {}
|
|
|
|
|
|
|
|
- get checks(): FormArray {
|
|
|
|
|
- return this.serviceCheckForm.controls['checks'] as FormArray;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
ngOnInit(): void {
|
|
ngOnInit(): void {
|
|
|
- this.patchForm(this.serviceCheck);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- private patchForm(serviceCheck: HttpCheckConfig) {
|
|
|
|
|
- this.checks.controls = [];
|
|
|
|
|
- serviceCheck.checks.reverse().forEach(e => {
|
|
|
|
|
- this.checks.controls.push(new FormControl(e));
|
|
|
|
|
- });
|
|
|
|
|
- this.serviceCheckForm.patchValue(serviceCheck);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- addPattern() {
|
|
|
|
|
- this.checks.controls.unshift(new FormControl(''));
|
|
|
|
|
- //focus set via viewChildren setter, here is too early
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- removePattern(index: number) {
|
|
|
|
|
- this.checks.controls.splice(index, 1);
|
|
|
|
|
|
|
+ this.serviceCheckForm.patchValue(this.serviceCheck);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async save() {
|
|
async save() {
|
|
|
try {
|
|
try {
|
|
|
this.serviceCheckForm.updateValueAndValidity();
|
|
this.serviceCheckForm.updateValueAndValidity();
|
|
|
const copy = deepCopy(this.serviceCheckForm.value as HttpCheckConfig);
|
|
const copy = deepCopy(this.serviceCheckForm.value as HttpCheckConfig);
|
|
|
- copy.checks = this.checks.controls.map(e => e.value).reverse();
|
|
|
|
|
|
|
+ copy.checks = this.checkEditor.collect();
|
|
|
const savedCheck = await this.serviceApi.saveServiceCheck(this.serviceCheck.serverId as number, copy);
|
|
const savedCheck = await this.serviceApi.saveServiceCheck(this.serviceCheck.serverId as number, copy);
|
|
|
- this.patchForm(savedCheck);
|
|
|
|
|
|
|
+ this.serviceCheckForm.patchValue(savedCheck);
|
|
|
|
|
+ this.serviceCheck = savedCheck;
|
|
|
} catch (error: any) {
|
|
} catch (error: any) {
|
|
|
console.error(error);
|
|
console.error(error);
|
|
|
}
|
|
}
|