|
|
@@ -11,11 +11,15 @@ import { ModalTarea } from '../../../Profesor/pages/tareas/tareas.component';
|
|
|
|
|
|
import * as XLSX from 'xlsx';
|
|
|
import { TareasService } from '../../services/tareas.service';
|
|
|
+import { MAT_DATE_LOCALE, provideNativeDateAdapter } from '@angular/material/core';
|
|
|
|
|
|
@Component({
|
|
|
selector: 'app-tareas',
|
|
|
templateUrl: './tareas.component.html',
|
|
|
- styleUrl: './tareas.component.css'
|
|
|
+ styleUrl: './tareas.component.css',
|
|
|
+ providers: [provideNativeDateAdapter(),
|
|
|
+ { provide: MAT_DATE_LOCALE, useValue: 'en-GB' }
|
|
|
+ ]
|
|
|
})
|
|
|
export class TareasComponent {
|
|
|
public checked = false;
|
|
|
@@ -23,7 +27,7 @@ export class TareasComponent {
|
|
|
public searchInput = new FormControl('');
|
|
|
public color: string = '';
|
|
|
public textColor: string = '';
|
|
|
- public columnas: string[] = ['titulo', 'materia', 'tipoTarea', 'fechaPub', 'fechaEntrega', 'enlaces' ,'adjuntos', 'acciones'];
|
|
|
+ public columnas: string[] = ['titulo', 'materia', 'tipoTarea', 'fechaPub', 'fechaEntrega', 'enlaces', 'adjuntos', 'acciones'];
|
|
|
public dataSource = new MatTableDataSource<any>();
|
|
|
private userData = JSON.parse(localStorage.getItem('userData') || '[]');
|
|
|
private userDataS = JSON.parse(localStorage.getItem('userDataS') || '[]');
|
|
|
@@ -102,7 +106,7 @@ export class TareasComponent {
|
|
|
public urls: any = [];
|
|
|
//Traer la información y mostrarla en la tabla
|
|
|
getTareas() {
|
|
|
- this.tareasService.getTareas(this.userDataS[0] ? this.userDataS[0] : this.userData[0] ).subscribe((response: any) => {
|
|
|
+ this.tareasService.getTareas(this.userDataS[0] ? this.userDataS[0] : this.userData[0]).subscribe((response: any) => {
|
|
|
this.isLoading = false;
|
|
|
|
|
|
this.allInfo = response.map((tarea: any) => {
|
|
|
@@ -114,16 +118,16 @@ export class TareasComponent {
|
|
|
} else {
|
|
|
tarea.vinculoTareaArray = [];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
if (tarea.adjuntoTarea) {
|
|
|
tarea.adjuntoTarea = JSON.parse(tarea.adjuntoTarea);
|
|
|
} else {
|
|
|
tarea.adjuntoTarea = [];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
return tarea;
|
|
|
});
|
|
|
-
|
|
|
+
|
|
|
|
|
|
this.dataSource = new MatTableDataSource<any>(this.allInfo);
|
|
|
this.dataSource.paginator = this.paginator;
|
|
|
@@ -141,8 +145,106 @@ export class TareasComponent {
|
|
|
this.dataSource.filter = filterValue.trim().toLowerCase();
|
|
|
}
|
|
|
|
|
|
+ filtroSeleccionado: string = '';
|
|
|
+ materias: any[] = [];
|
|
|
+ fechaSeleccionada: Date | null = null;
|
|
|
+ materiaSeleccionada: any = null;
|
|
|
+
|
|
|
+ onFiltroChange(valor: string): void {
|
|
|
+ // Actualiza el filtro seleccionado
|
|
|
+ this.filtroSeleccionado = valor;
|
|
|
+
|
|
|
+ // Limpia valores previos
|
|
|
+ this.fechaSeleccionada = null;
|
|
|
+ this.materiaSeleccionada = null;
|
|
|
+
|
|
|
+ // Limpia tabla (opcional)
|
|
|
+ this.dataSource.data = this.allInfo;
|
|
|
+
|
|
|
+ // Si se selecciona MAT, carga materias recientes
|
|
|
+ if (valor === 'MAT') {
|
|
|
+ this.cargarMaterias();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ cargarMaterias(): void {
|
|
|
+ const userId = this.userDataS[0] ? this.userDataS[0] : this.userData[0];
|
|
|
+
|
|
|
+ this.tareasService.getMaterias30Dias(userId).subscribe(
|
|
|
+ (response: any) => {
|
|
|
+ this.materias = response;
|
|
|
+ console.log('Materias de últimos 30 días:', this.materias);
|
|
|
+ },
|
|
|
+ (error) => {
|
|
|
+ console.error('Error al cargar materias:', error);
|
|
|
+ this.materias = []; // fallback
|
|
|
+ }
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ onFechaSeleccionada(event: any): void {
|
|
|
+
|
|
|
+ this.fechaSeleccionada = event.value;
|
|
|
+ if (!this.fechaSeleccionada) return;
|
|
|
+ const fechaFormateada = this.formatFecha(this.fechaSeleccionada);
|
|
|
+ console.log('📅 Fecha seleccionada:', fechaFormateada);
|
|
|
+
|
|
|
+ if (!this.filtroSeleccionado) return;
|
|
|
+
|
|
|
+ // Mostrar loader
|
|
|
+ this.isLoading = true;
|
|
|
+
|
|
|
+ // Llamar al servicio correspondiente
|
|
|
+ if (this.filtroSeleccionado === 'FE') {
|
|
|
+ // Fecha de entrega
|
|
|
+ this.tareasService.getByFechaEntrega(fechaFormateada, this.userDataS[0] ? this.userDataS[0] : this.userData[0]).subscribe((response: any) => {
|
|
|
+ this.actualizarTabla(response);
|
|
|
+ });
|
|
|
+ } else if (this.filtroSeleccionado === 'FA') {
|
|
|
+ // Fecha de asignación
|
|
|
+ this.tareasService.getByFechaAsignacion(fechaFormateada, this.userDataS[0] ? this.userDataS[0] : this.userData[0]).subscribe((response: any) => {
|
|
|
+ this.actualizarTabla(response);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ onMateriaSeleccionada(idMateria: any): void {
|
|
|
+ this.materiaSeleccionada = idMateria;
|
|
|
+ console.log('📘 Materia seleccionada:', idMateria);
|
|
|
+
|
|
|
+ if (!idMateria) return;
|
|
|
+
|
|
|
+ this.isLoading = true;
|
|
|
+ this.tareasService.getByMateria(idMateria).subscribe((response: any) => {
|
|
|
+ this.actualizarTabla(response);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private actualizarTabla(response: any): void {
|
|
|
+ this.isLoading = false;
|
|
|
+
|
|
|
+ this.dataSource = new MatTableDataSource<any>(
|
|
|
+ response.map((tarea: any) => {
|
|
|
+ tarea.vinculoTareaArray = tarea.vinculoTarea
|
|
|
+ ? tarea.vinculoTarea.split("||").map((url: string) => ({ nombre: url, url }))
|
|
|
+ : [];
|
|
|
+ tarea.adjuntoTarea = tarea.adjuntoTarea ? JSON.parse(tarea.adjuntoTarea) : [];
|
|
|
+ return tarea;
|
|
|
+ })
|
|
|
+ );
|
|
|
+ this.dataSource.paginator = this.paginator;
|
|
|
+ }
|
|
|
+
|
|
|
+ private formatFecha(fecha: Date): string {
|
|
|
+ // Devuelve formato YYYY-MM-DD
|
|
|
+ const year = fecha.getFullYear();
|
|
|
+ const month = String(fecha.getMonth() + 1).padStart(2, '0');
|
|
|
+ const day = String(fecha.getDate()).padStart(2, '0');
|
|
|
+ return `${year}-${month}-${day}`;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
-
|
|
|
|
|
|
// openDialog1(id: string) {
|
|
|
// const dialogRef = this.dialog.open(ModalCircular, {
|
|
|
@@ -182,6 +284,6 @@ export class TareasComponent {
|
|
|
imports: [MatIconModule, MatDialogContent, MatDialogActions, MatDialogClose]
|
|
|
})
|
|
|
export class TareaAlumComponent {
|
|
|
- constructor(@Inject(MAT_DIALOG_DATA) public data: any) {
|
|
|
+ constructor(@Inject(MAT_DIALOG_DATA) public data: any) {
|
|
|
}
|
|
|
}
|