import { Component } from '@angular/core'; import {HttpClient} from "@angular/common/http"; import {ToastrService} from "ngx-toastr"; @Component({ selector: 'app-env-vars', templateUrl: './env-vars.component.html', styleUrl: './env-vars.component.css' }) export class EnvVarsComponent { baseUrl: string = import.meta.env.NG_APP_BASE_API_URL; envVars: { name: string; value: string }[] = []; displayedColumns: string[] = ['name', 'value']; private apiUrl = `${this.baseUrl}/env-vars`; constructor( private http: HttpClient, private toastService: ToastrService, ) {} ngOnInit(): void { this.loadEnvVars(); } loadEnvVars(): void { this.http.get<{ vars: Record }>(this.apiUrl).subscribe({ next: (response) => { this.envVars = Object.entries(response.vars).map(([name, value]) => ({ name, value })); }, error: (err) => { console.error('Error al cargar las variables de entorno:', err); this.toastService.error('No se pudieron cargar las variables de entorno.'); } }); } saveEnvVars(): void { const vars = this.envVars.reduce((acc, variable) => { acc[variable.name] = variable.value; return acc; }, {} as Record); this.http.post(this.apiUrl, { vars }).subscribe({ next: () => { this.toastService.success('Variables de entorno guardadas correctamente.'); }, error: (err) => { console.error('Error al guardar las variables de entorno:', err); this.toastService.error('No se pudieron cargar las variables de entorno.'); } }); } }