admin-service-checks-page.component.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Component, ViewChild } from '@angular/core';
  2. import { faAngleRight, faPlus, faSave, faServer } from '@fortawesome/free-solid-svg-icons';
  3. import { ServiceCheckFormComponent } from 'src/app/components/service-check-form/service-check-form.component';
  4. import { ServiceApiService } from 'src/app/services/service-api.service';
  5. import { ServerApiService } from 'src/app/services/server-api.service';
  6. @Component({
  7. selector: 'app-admin-service-checks-page',
  8. templateUrl: './admin-service-checks-page.component.html',
  9. styleUrls: ['./admin-service-checks-page.component.scss'],
  10. host: { class: 'd-flex flex-column h-100' }
  11. })
  12. export class AdminServiceChecksPageComponent {
  13. @ViewChild(ServiceCheckFormComponent) formRef!: ServiceCheckFormComponent;
  14. public serverConfigs: ServerConfig[] = [];
  15. public serviceChecks: HttpCheckConfig[] = [];
  16. public fa = { save: faSave, server: faServer, angleRight: faAngleRight, plus: faPlus };
  17. public activeId = 0;
  18. constructor(private serviceApi: ServiceApiService, apiService: ServerApiService) {
  19. apiService.serverConfigs$.subscribe(data => {
  20. this.serverConfigs = data;
  21. if (data.length > 0) {
  22. this.fetchServiceChecks(data[this.activeId].id);
  23. }
  24. });
  25. }
  26. ngOnInit(): void {}
  27. async fetchServiceChecks(serverId: number) {
  28. try {
  29. this.serviceChecks = await this.serviceApi.loadServiceChecks(serverId);
  30. } catch (error: any) {
  31. console.error(error);
  32. }
  33. }
  34. saveServiceCheck(event: Event) {
  35. event.stopPropagation();
  36. this.formRef?.save();
  37. }
  38. addServiceCheck(serverId: number) {
  39. this.serviceChecks.unshift({ serverId, checks: [] as string[] } as HttpCheckConfig);
  40. }
  41. }