ciyidogan commited on
Commit
d542ec7
·
verified ·
1 Parent(s): 44ece74

Update flare-ui/src/app/components/environment/environment.component.ts

Browse files
flare-ui/src/app/components/environment/environment.component.ts CHANGED
@@ -1,6 +1,6 @@
1
  import { Component, inject, OnInit } from '@angular/core';
2
  import { CommonModule } from '@angular/common';
3
- import { FormsModule } from '@angular/forms';
4
  import { MatCardModule } from '@angular/material/card';
5
  import { MatFormFieldModule } from '@angular/material/form-field';
6
  import { MatInputModule } from '@angular/material/input';
@@ -561,44 +561,18 @@ export class EnvironmentComponent implements OnInit {
561
  private apiService = inject(ApiService);
562
  private snackBar = inject(MatSnackBar);
563
  private environmentService = inject(EnvironmentService);
 
564
 
565
- environment: Environment = {
566
- work_mode: 'hfcloud',
567
- cloud_token: '',
568
- spark_endpoint: '',
569
- internal_prompt: '',
570
- tts_engine: 'no_tts',
571
- tts_engine_api_key: '',
572
- stt_engine: 'no_stt',
573
- stt_engine_api_key: '',
574
- stt_settings: {
575
- speech_timeout_ms: 2000,
576
- noise_reduction_level: 2,
577
- vad_sensitivity: 0.5,
578
- language: 'tr-TR',
579
- model: 'latest_long',
580
- use_enhanced: true,
581
- enable_punctuation: true,
582
- interim_results: true
583
- }
584
- };
585
 
586
  sttSettingsExpanded = false;
587
  loading = true;
588
  saving = false;
589
 
590
  ngOnInit() {
591
- console.log('EnvironmentComponent ngOnInit started');
592
- try {
593
- this.loadEnvironment();
594
- } catch (error) {
595
- console.error('Error in ngOnInit:', error);
596
- if (error instanceof Error) {
597
- console.error('Stack trace:', error.stack);
598
- } else {
599
- console.error('Unknown error type:', error);
600
- }
601
- }
602
  }
603
 
604
  ngAfterViewInit() {
@@ -607,6 +581,30 @@ export class EnvironmentComponent implements OnInit {
607
  console.log('STT settings:', this.environment.stt_settings);
608
  }
609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
610
  get sttSettings(): STTSettings {
611
  if (!this.environment.stt_settings) {
612
  this.environment.stt_settings = {
@@ -624,36 +622,30 @@ export class EnvironmentComponent implements OnInit {
624
  }
625
 
626
  loadEnvironment() {
627
- console.log('loadEnvironment called');
628
  this.loading = true;
629
-
630
  this.apiService.getEnvironment().subscribe({
631
  next: (env) => {
632
- console.log('Environment loaded from API:', env);
633
  this.environment = env;
634
 
635
- // Debug check
636
- console.log('Checking stt_settings:', this.environment.stt_settings);
637
-
638
- if (!this.environment.stt_settings) {
639
- console.log('No stt_settings found, creating defaults...');
640
- this.environment.stt_settings = {
641
- speech_timeout_ms: 2000,
642
- noise_reduction_level: 2,
643
- vad_sensitivity: 0.5,
644
- language: 'tr-TR',
645
- model: 'latest_long',
646
- use_enhanced: true,
647
- enable_punctuation: true,
648
- interim_results: true
649
- };
650
  }
651
 
652
- console.log('Final environment:', this.environment);
653
  this.loading = false;
654
  },
655
  error: (err) => {
656
- console.error('Error loading environment:', err);
657
  this.snackBar.open('Failed to load environment configuration', 'Close', {
658
  duration: 5000,
659
  panelClass: 'error-snackbar'
@@ -663,6 +655,17 @@ export class EnvironmentComponent implements OnInit {
663
  });
664
  }
665
 
 
 
 
 
 
 
 
 
 
 
 
666
  onSTTCredentialsFileSelected(event: any) {
667
  const file = event.target.files[0];
668
  if (file && file.type === 'application/json') {
 
1
  import { Component, inject, OnInit } from '@angular/core';
2
  import { CommonModule } from '@angular/common';
3
+ import { FormsModule, ReactiveFormsModule, FormBuilder, FormGroup } from '@angular/forms';
4
  import { MatCardModule } from '@angular/material/card';
5
  import { MatFormFieldModule } from '@angular/material/form-field';
6
  import { MatInputModule } from '@angular/material/input';
 
561
  private apiService = inject(ApiService);
562
  private snackBar = inject(MatSnackBar);
563
  private environmentService = inject(EnvironmentService);
564
+ private fb = inject(FormBuilder);
565
 
566
+ environmentForm!: FormGroup;
567
+ sttSettingsForm!: FormGroup;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
568
 
569
  sttSettingsExpanded = false;
570
  loading = true;
571
  saving = false;
572
 
573
  ngOnInit() {
574
+ this.initializeForms();
575
+ this.loadEnvironment();
 
 
 
 
 
 
 
 
 
576
  }
577
 
578
  ngAfterViewInit() {
 
581
  console.log('STT settings:', this.environment.stt_settings);
582
  }
583
 
584
+ initializeForms() {
585
+ this.environmentForm = this.fb.group({
586
+ work_mode: ['hfcloud'],
587
+ cloud_token: [''],
588
+ spark_endpoint: [''],
589
+ internal_prompt: [''],
590
+ tts_engine: ['no_tts'],
591
+ tts_engine_api_key: [''],
592
+ stt_engine: ['no_stt'],
593
+ stt_engine_api_key: ['']
594
+ });
595
+
596
+ this.sttSettingsForm = this.fb.group({
597
+ speech_timeout_ms: [2000],
598
+ noise_reduction_level: [2],
599
+ vad_sensitivity: [0.5],
600
+ language: ['tr-TR'],
601
+ model: ['latest_long'],
602
+ use_enhanced: [true],
603
+ enable_punctuation: [true],
604
+ interim_results: [true]
605
+ });
606
+ }
607
+
608
  get sttSettings(): STTSettings {
609
  if (!this.environment.stt_settings) {
610
  this.environment.stt_settings = {
 
622
  }
623
 
624
  loadEnvironment() {
 
625
  this.loading = true;
 
626
  this.apiService.getEnvironment().subscribe({
627
  next: (env) => {
 
628
  this.environment = env;
629
 
630
+ // Form'ları güncelle
631
+ this.environmentForm.patchValue({
632
+ work_mode: env.work_mode,
633
+ cloud_token: env.cloud_token,
634
+ spark_endpoint: env.spark_endpoint,
635
+ internal_prompt: env.internal_prompt,
636
+ tts_engine: env.tts_engine,
637
+ tts_engine_api_key: env.tts_engine_api_key,
638
+ stt_engine: env.stt_engine,
639
+ stt_engine_api_key: env.stt_engine_api_key
640
+ });
641
+
642
+ if (env.stt_settings) {
643
+ this.sttSettingsForm.patchValue(env.stt_settings);
 
644
  }
645
 
 
646
  this.loading = false;
647
  },
648
  error: (err) => {
 
649
  this.snackBar.open('Failed to load environment configuration', 'Close', {
650
  duration: 5000,
651
  panelClass: 'error-snackbar'
 
655
  });
656
  }
657
 
658
+ get environment(): Environment {
659
+ return {
660
+ ...this.environmentForm.value,
661
+ stt_settings: this.sttSettingsForm.value
662
+ };
663
+ }
664
+
665
+ set environment(value: Environment) {
666
+ // Form update için kullanılmıyor, sadece compat için
667
+ }
668
+
669
  onSTTCredentialsFileSelected(event: any) {
670
  const file = event.target.files[0];
671
  if (file && file.type === 'application/json') {