- conexion supabase
- autenticacion solo correos glm
- pantalla gestor empleados
This commit is contained in:
2026-09-05 12:42:29 -04:00
parent bb6757b492
commit c45182012c
27 changed files with 803 additions and 143 deletions
@@ -1,4 +1,4 @@
import { Component, ChangeDetectorRef } from '@angular/core';
import { Component, ChangeDetectorRef, OnInit } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AssignedRouteComponent } from './assigned-route/assigned-route.component';
@@ -10,21 +10,25 @@ import { ExcelPreviewService, PreviewResult } from '../../shared/services/excel-
import { Subscription } from 'rxjs';
import { PlanningKpisComponent } from './planning-kpis/planning-kpis.component';
import { PlanningInputService } from '../../core/services/planning-input.service';
import { RouterLink } from '@angular/router';
import { EmployeeService } from '../../core/services/employee.service';
@Component({
standalone: true,
selector: 'app-home',
imports: [CommonModule, FormsModule, AssignedRouteComponent, NoAssignedRouteComponent, PlanningKpisComponent],
imports: [CommonModule, FormsModule, RouterLink, AssignedRouteComponent, NoAssignedRouteComponent, PlanningKpisComponent],
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent {
export class HomeComponent implements OnInit {
pdvFile: File | null = null;
usuariosFile: File | null = null;
pdvPreview: PreviewResult | null = null;
usuariosPreview: PreviewResult | null = null;
pdvPreviewLoading = false;
usuariosPreviewLoading = false;
activeEmployees = 0;
employeesLoading = true;
uploadError: string | null = null;
isLoading = false;
private calcSub: Subscription | null = null;
@@ -34,9 +38,26 @@ export class HomeComponent {
private routeState: RouteState,
private previewService: ExcelPreviewService,
private planningInput: PlanningInputService,
private employeesService: EmployeeService,
private cdr: ChangeDetectorRef
) {}
ngOnInit(): void {
void this.loadEmployees();
}
private async loadEmployees(): Promise<void> {
this.employeesLoading = true;
try {
this.activeEmployees = (await this.employeesService.list()).filter(employee => employee.activo).length;
} catch {
this.activeEmployees = 0;
} finally {
this.employeesLoading = false;
this.cdr.detectChanges();
}
}
async onPdvFileChange(event: Event) {
const input = event.target as HTMLInputElement;
if (input.files && input.files.length > 0) {
@@ -132,23 +153,22 @@ export class HomeComponent {
}
get canSubmit(): boolean {
if (!this.pdvFile || !this.usuariosFile) return false;
if (this.pdvPreviewLoading || this.usuariosPreviewLoading) return false;
if (!this.pdvFile || !this.activeEmployees) return false;
if (this.pdvPreviewLoading || this.employeesLoading) return false;
if (this.isLoading) return false;
if (this.uploadError) return false;
// Require valid previews before enabling submit
if (this.pdvPreview && !this.pdvPreview.valid) return false;
if (this.usuariosPreview && !this.usuariosPreview.valid) return false;
// Previews must exist (file was parsed)
if (!this.pdvPreview || !this.usuariosPreview) return false;
if (!this.pdvPreview) return false;
return true;
}
get submitDisabledReason(): string | null {
if (!this.pdvFile || !this.usuariosFile) return 'Sube ambos archivos';
if (this.pdvPreviewLoading || this.usuariosPreviewLoading) return 'Validando archivos...';
if (!this.pdvFile) return 'Sube el archivo PDV';
if (this.employeesLoading) return 'Cargando empleados...';
if (!this.activeEmployees) return 'No hay empleados activos. Regístralos en Gestionar empleados.';
if (this.pdvPreviewLoading) return 'Validando archivo PDV...';
if (this.pdvPreview && !this.pdvPreview.valid) return 'Corrige los errores del archivo PDV';
if (this.usuariosPreview && !this.usuariosPreview.valid) return 'Corrige los errores del archivo Usuarios';
return null;
}
@@ -168,11 +188,20 @@ export class HomeComponent {
this.cdr.detectChanges();
return;
}
this.planningInput.setFiles(pdvForOptimizer, this.usuariosFile!);
let employeesFile: File;
try {
employeesFile = await this.employeesService.activeEmployeesFile();
} catch {
this.uploadError = 'No se pudieron obtener los empleados activos.';
this.routeState.setLoading(false);
this.isLoading = false;
return;
}
this.planningInput.setFiles(pdvForOptimizer, employeesFile);
const formData = new FormData();
formData.append('pdv_file', pdvForOptimizer, pdvForOptimizer.name);
formData.append('usuarios_file', this.usuariosFile!, this.usuariosFile!.name);
formData.append('usuarios_file', employeesFile, employeesFile.name);
this.calcSub?.unsubscribe();
this.calcSub = this.rutasService.calcularRutas(formData).subscribe({