From 079a3894749789e1a3d2f75c2ade10c551ad6a1f Mon Sep 17 00:00:00 2001
From: Artem Dychenko <s192441@student.pg.edu.pl>
Date: Thu, 27 Mar 2025 21:45:46 +0100
Subject: [PATCH] mod: change form initialization

---
 .../dashboard-settings.component.ts             | 17 ++++++-----------
 .../components/dashboard/dashboard.component.ts |  4 +---
 src/app/service/settings.service.ts             |  4 ----
 3 files changed, 7 insertions(+), 18 deletions(-)

diff --git a/src/app/components/dashboard-settings/dashboard-settings.component.ts b/src/app/components/dashboard-settings/dashboard-settings.component.ts
index 130f008..768be1a 100644
--- a/src/app/components/dashboard-settings/dashboard-settings.component.ts
+++ b/src/app/components/dashboard-settings/dashboard-settings.component.ts
@@ -43,20 +43,15 @@ export class DashboardSettingsComponent implements OnInit {
 
   ngOnInit() {
     this.settingsService.settings$.subscribe(settings => {
-      const protocols = Object.keys(settings.protocols);
-      this.form = this.settingsFormBuilder.createDefaultForm(protocols);
-
-      if (this.form) {
-        this.initializeForm();
-      }
+      this.initializeForm(settings);
     });
   }
 
-  initializeForm() {
-    const currentSettings = this.settingsService.getSettings();
-    if (this.form) {
-      this.form.patchValue(currentSettings);
-    }
+  initializeForm(settings: Settings) {
+    const protocols = Object.keys(settings.protocols);
+
+    this.form = this.settingsFormBuilder.createDefaultForm(protocols);
+    this.form.patchValue(settings);
   }
 
   onSubmit() {
diff --git a/src/app/components/dashboard/dashboard.component.ts b/src/app/components/dashboard/dashboard.component.ts
index 170da9b..9d0e380 100644
--- a/src/app/components/dashboard/dashboard.component.ts
+++ b/src/app/components/dashboard/dashboard.component.ts
@@ -42,9 +42,7 @@ export class DashboardComponent implements OnInit {
 
   ngOnInit() {
     this.configurationApi.fetchAppliedConfiguration().subscribe(config => {
-      if (config) {
-        this.settingsService.initSettings(config.protocols);
-      }
+      this.settingsService.initSettings(config.protocols);
     });
   }
 
diff --git a/src/app/service/settings.service.ts b/src/app/service/settings.service.ts
index 46b34db..8e9ee7e 100644
--- a/src/app/service/settings.service.ts
+++ b/src/app/service/settings.service.ts
@@ -39,8 +39,4 @@ export class SettingsService {
   updateSettings(settings: Settings) {
     this.settingsSubject.next(settings);
   }
-
-  getSettings(): Settings {
-    return this.settingsSubject.value;
-  }
 }
-- 
GitLab