|
|
@@ -14,13 +14,13 @@ import { NivelEducativo } from '../../../Administrador/interfaces/NivelEducativo
|
|
|
import { GradosEducativosService } from '../../../Administrador/services/grados-educativos.service';
|
|
|
import { GruposService } from '../../../Administrador/services/grupos.service';
|
|
|
import { MateriaService } from '../../../Administrador/services/materia.service';
|
|
|
-import { Editor } from 'ngx-editor';
|
|
|
-import Toolbar from 'quill/modules/toolbar';
|
|
|
+import { Editor, Toolbar } from 'ngx-editor';
|
|
|
import { forkJoin, tap } from 'rxjs';
|
|
|
import moment from 'moment';
|
|
|
|
|
|
import { v4 as uuidv4 } from 'uuid';
|
|
|
import { MAT_DATE_LOCALE, provideNativeDateAdapter } from '@angular/material/core';
|
|
|
+import { TareasService } from '../../services/tareas.service';
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
@@ -95,162 +95,162 @@ export class TareasComponent {
|
|
|
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
public allInfo: any;
|
|
|
public files: any;
|
|
|
-//Traer la información y mostrarla en la tabla
|
|
|
-getCirculares() {
|
|
|
- this.circularService.getAllCirculares().subscribe((response: any) => {
|
|
|
- this.isLoading = false;
|
|
|
+ //Traer la información y mostrarla en la tabla
|
|
|
+ getCirculares() {
|
|
|
+ this.circularService.getAllCirculares().subscribe((response: any) => {
|
|
|
+ this.isLoading = false;
|
|
|
|
|
|
- this.allInfo = response.map((circular: any) => {
|
|
|
+ this.allInfo = response.map((circular: any) => {
|
|
|
|
|
|
- if (circular.jsonAdjuntos) {
|
|
|
- circular.jsonAdjuntos = JSON.parse(circular.jsonAdjuntos);
|
|
|
+ if (circular.jsonAdjuntos) {
|
|
|
+ circular.jsonAdjuntos = JSON.parse(circular.jsonAdjuntos);
|
|
|
|
|
|
- } else {
|
|
|
- circular.jsonAdjuntos = [];
|
|
|
- }
|
|
|
- return circular;
|
|
|
- });
|
|
|
+ } else {
|
|
|
+ circular.jsonAdjuntos = [];
|
|
|
+ }
|
|
|
+ return circular;
|
|
|
+ });
|
|
|
|
|
|
- this.dataSource = new MatTableDataSource<any>(this.allInfo.filter((filtro: any) => filtro.estado === 'Activo'));
|
|
|
- this.dataSource.paginator = this.paginator;
|
|
|
- });
|
|
|
-}
|
|
|
+ this.dataSource = new MatTableDataSource<any>(this.allInfo.filter((filtro: any) => filtro.estado === 'Activo'));
|
|
|
+ this.dataSource.paginator = this.paginator;
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
-buscarArchivo(ruta: string) {
|
|
|
- window.open(ruta, '_blank');
|
|
|
-}
|
|
|
+ buscarArchivo(ruta: string) {
|
|
|
+ window.open(ruta, '_blank');
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
-deleteCircular(id: string) {
|
|
|
+ deleteCircular(id: string) {
|
|
|
|
|
|
- Swal.fire({
|
|
|
- icon: 'question',
|
|
|
- title: '¿Desea cambiar el estado de la circular?',
|
|
|
- showCancelButton: true,
|
|
|
- allowOutsideClick: false,
|
|
|
- allowEscapeKey: false,
|
|
|
- confirmButtonColor: '#3085d6',
|
|
|
- cancelButtonColor: '#d33',
|
|
|
- confirmButtonText: "Eliminar",
|
|
|
- }).then((result: any) => {
|
|
|
- /* Read more about isConfirmed, isDenied below */
|
|
|
- if (result.isConfirmed) {
|
|
|
- this.circularService.eliminarCircular(id).subscribe((response: any) => {
|
|
|
- Swal.fire({
|
|
|
- icon: 'success',
|
|
|
- title: `${response.mensaje}`,
|
|
|
- confirmButtonColor: 'rgb(237,46,56)',
|
|
|
- confirmButtonText: 'Ok',
|
|
|
- }).then((result: any) => {
|
|
|
-
|
|
|
- if (result.isConfirmed) {
|
|
|
- this._enviarInfo.notifyCambioTabla();
|
|
|
- Swal.close();
|
|
|
- }
|
|
|
- })
|
|
|
- }, (err: any) => {
|
|
|
- Swal.fire({
|
|
|
- icon: 'error',
|
|
|
- title: 'Error al eliminar',
|
|
|
- text: `${err.error.mensaje}`,
|
|
|
- })
|
|
|
+ Swal.fire({
|
|
|
+ icon: 'question',
|
|
|
+ title: '¿Desea cambiar el estado de la circular?',
|
|
|
+ showCancelButton: true,
|
|
|
+ allowOutsideClick: false,
|
|
|
+ allowEscapeKey: false,
|
|
|
+ confirmButtonColor: '#3085d6',
|
|
|
+ cancelButtonColor: '#d33',
|
|
|
+ confirmButtonText: "Eliminar",
|
|
|
+ }).then((result: any) => {
|
|
|
+ /* Read more about isConfirmed, isDenied below */
|
|
|
+ if (result.isConfirmed) {
|
|
|
+ this.circularService.eliminarCircular(id).subscribe((response: any) => {
|
|
|
+ Swal.fire({
|
|
|
+ icon: 'success',
|
|
|
+ title: `${response.mensaje}`,
|
|
|
+ confirmButtonColor: 'rgb(237,46,56)',
|
|
|
+ confirmButtonText: 'Ok',
|
|
|
+ }).then((result: any) => {
|
|
|
+
|
|
|
+ if (result.isConfirmed) {
|
|
|
+ this._enviarInfo.notifyCambioTabla();
|
|
|
+ Swal.close();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, (err: any) => {
|
|
|
+ Swal.fire({
|
|
|
+ icon: 'error',
|
|
|
+ title: 'Error al eliminar',
|
|
|
+ text: `${err.error.mensaje}`,
|
|
|
+ })
|
|
|
+ this._enviarInfo.notifyCambioTabla();
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } else if (result.dismiss == 'cancel') {
|
|
|
this._enviarInfo.notifyCambioTabla();
|
|
|
}
|
|
|
- )
|
|
|
- } else if (result.dismiss == 'cancel') {
|
|
|
- this._enviarInfo.notifyCambioTabla();
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
|
|
|
-}
|
|
|
+ }
|
|
|
|
|
|
-enableCircular(id: string) {
|
|
|
- Swal.fire({
|
|
|
- icon: 'question',
|
|
|
- title: '¿Desea habilitar la circular?',
|
|
|
- showCancelButton: true,
|
|
|
- allowOutsideClick: false,
|
|
|
- allowEscapeKey: false,
|
|
|
- confirmButtonColor: '#3085d6',
|
|
|
- cancelButtonColor: '#d33',
|
|
|
- confirmButtonText: "Habilitar",
|
|
|
- }).then((result: any) => {
|
|
|
-
|
|
|
- if (result.value) {
|
|
|
- this.circularService.habilitarCircular(id).subscribe((response: any) => {
|
|
|
- Swal.fire({
|
|
|
- icon: 'success',
|
|
|
- title: `${response.mensaje}`,
|
|
|
- confirmButtonColor: 'rgb(237,46,56)',
|
|
|
- confirmButtonText: 'Ok',
|
|
|
- }).then((result: any) => {
|
|
|
- if (result.isConfirmed) {
|
|
|
- Swal.close();
|
|
|
- this._enviarInfo.notifyCambioTabla();
|
|
|
- }
|
|
|
- })
|
|
|
- }, (err: any) => {
|
|
|
- Swal.fire({
|
|
|
- icon: 'error',
|
|
|
- title: 'Error al habilitar',
|
|
|
- text: `${err.error.message}`,
|
|
|
- })
|
|
|
+ enableCircular(id: string) {
|
|
|
+ Swal.fire({
|
|
|
+ icon: 'question',
|
|
|
+ title: '¿Desea habilitar la circular?',
|
|
|
+ showCancelButton: true,
|
|
|
+ allowOutsideClick: false,
|
|
|
+ allowEscapeKey: false,
|
|
|
+ confirmButtonColor: '#3085d6',
|
|
|
+ cancelButtonColor: '#d33',
|
|
|
+ confirmButtonText: "Habilitar",
|
|
|
+ }).then((result: any) => {
|
|
|
+
|
|
|
+ if (result.value) {
|
|
|
+ this.circularService.habilitarCircular(id).subscribe((response: any) => {
|
|
|
+ Swal.fire({
|
|
|
+ icon: 'success',
|
|
|
+ title: `${response.mensaje}`,
|
|
|
+ confirmButtonColor: 'rgb(237,46,56)',
|
|
|
+ confirmButtonText: 'Ok',
|
|
|
+ }).then((result: any) => {
|
|
|
+ if (result.isConfirmed) {
|
|
|
+ Swal.close();
|
|
|
+ this._enviarInfo.notifyCambioTabla();
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }, (err: any) => {
|
|
|
+ Swal.fire({
|
|
|
+ icon: 'error',
|
|
|
+ title: 'Error al habilitar',
|
|
|
+ text: `${err.error.message}`,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ )
|
|
|
+ } else if (result.dismiss == 'cancel') {
|
|
|
+ this._enviarInfo.notifyCambioTabla();
|
|
|
}
|
|
|
- )
|
|
|
- } else if (result.dismiss == 'cancel') {
|
|
|
- this._enviarInfo.notifyCambioTabla();
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
-option(event: string) {
|
|
|
- this.isLoading = true;
|
|
|
- let filteredData: any;
|
|
|
+ option(event: string) {
|
|
|
+ this.isLoading = true;
|
|
|
+ let filteredData: any;
|
|
|
|
|
|
- if (event === 'Activos') {
|
|
|
- filteredData = this.allInfo.filter((filtro: any) => filtro.estado === 'Activo');
|
|
|
- } else if (event === 'Eliminados') {
|
|
|
- filteredData = this.allInfo.filter((filtro: any) => filtro.estado === 'Eliminado');
|
|
|
- }
|
|
|
+ if (event === 'Activos') {
|
|
|
+ filteredData = this.allInfo.filter((filtro: any) => filtro.estado === 'Activo');
|
|
|
+ } else if (event === 'Eliminados') {
|
|
|
+ filteredData = this.allInfo.filter((filtro: any) => filtro.estado === 'Eliminado');
|
|
|
+ }
|
|
|
|
|
|
- this.dataSource = new MatTableDataSource<any>(filteredData);
|
|
|
- this.dataSource.paginator = this.paginator;
|
|
|
- this.isLoading = false;
|
|
|
-}
|
|
|
+ this.dataSource = new MatTableDataSource<any>(filteredData);
|
|
|
+ this.dataSource.paginator = this.paginator;
|
|
|
+ this.isLoading = false;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
-//filtro de búsqueda
|
|
|
-applyFilter(event: Event) {
|
|
|
- const filterValue = (event.target as HTMLInputElement).value;
|
|
|
- this.dataSource.filter = filterValue.trim().toLowerCase();
|
|
|
-}
|
|
|
+ //filtro de búsqueda
|
|
|
+ applyFilter(event: Event) {
|
|
|
+ const filterValue = (event.target as HTMLInputElement).value;
|
|
|
+ this.dataSource.filter = filterValue.trim().toLowerCase();
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-//exportar búsqueda a excel
|
|
|
-exportAsExcel() {
|
|
|
- const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(this.table.nativeElement);
|
|
|
- const wb: XLSX.WorkBook = XLSX.utils.book_new();
|
|
|
- XLSX.utils.book_append_sheet(wb, ws, 'COLEGIOABC-ConsultaCirculares');
|
|
|
- XLSX.writeFile(wb, 'Circulares.xlsx');
|
|
|
+ //exportar búsqueda a excel
|
|
|
+ exportAsExcel() {
|
|
|
+ const ws: XLSX.WorkSheet = XLSX.utils.table_to_sheet(this.table.nativeElement);
|
|
|
+ const wb: XLSX.WorkBook = XLSX.utils.book_new();
|
|
|
+ XLSX.utils.book_append_sheet(wb, ws, 'COLEGIOABC-ConsultaCirculares');
|
|
|
+ XLSX.writeFile(wb, 'Circulares.xlsx');
|
|
|
|
|
|
-}
|
|
|
-//exportar toda la data a excel
|
|
|
-exportAll() {
|
|
|
- const dataSource = this.dataSource.data;
|
|
|
- const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(dataSource);
|
|
|
- const wb: XLSX.WorkBook = XLSX.utils.book_new();
|
|
|
-
|
|
|
- XLSX.utils.book_append_sheet(wb, ws, 'COLEGIOABC-ConsultaCirculares');
|
|
|
- XLSX.writeFile(wb, 'Circulares.xlsx');
|
|
|
-}
|
|
|
+ }
|
|
|
+ //exportar toda la data a excel
|
|
|
+ exportAll() {
|
|
|
+ const dataSource = this.dataSource.data;
|
|
|
+ const ws: XLSX.WorkSheet = XLSX.utils.json_to_sheet(dataSource);
|
|
|
+ const wb: XLSX.WorkBook = XLSX.utils.book_new();
|
|
|
+
|
|
|
+ XLSX.utils.book_append_sheet(wb, ws, 'COLEGIOABC-ConsultaCirculares');
|
|
|
+ XLSX.writeFile(wb, 'Circulares.xlsx');
|
|
|
+ }
|
|
|
|
|
|
|
|
|
// openDialog(id: string) {
|
|
|
@@ -290,7 +290,7 @@ exportAll() {
|
|
|
|
|
|
// }
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
}
|
|
|
@@ -312,26 +312,29 @@ export class ModalTarea {
|
|
|
private gradoService: GradosEducativosService,
|
|
|
private grupoService: GruposService,
|
|
|
private materiaService: MateriaService,
|
|
|
+ private tareaService: TareasService
|
|
|
) {
|
|
|
// this.lista()
|
|
|
+ this.getTipoTareas();
|
|
|
+ this.getMaterias();
|
|
|
}
|
|
|
|
|
|
public todayDate: Date = new Date();
|
|
|
- valoresCombinados: any = {};
|
|
|
|
|
|
public info: any;
|
|
|
private userData = JSON.parse(localStorage.getItem('userData') || '');
|
|
|
+ private userDataS = JSON.parse(localStorage.getItem('userDataS') || '');
|
|
|
editor!: Editor;
|
|
|
- // toolbar: Toolbar = [
|
|
|
- // ['bold', 'italic'],
|
|
|
- // ['underline', 'strike'],
|
|
|
- // ['blockquote'],
|
|
|
- // ['ordered_list', 'bullet_list'],
|
|
|
- // [{ heading: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] }],
|
|
|
- // ['link', 'image'],
|
|
|
- // ['text_color', 'background_color'],
|
|
|
- // ['align_left', 'align_center', 'align_right', 'align_justify'],
|
|
|
- // ];
|
|
|
+ toolbar: Toolbar = [
|
|
|
+ ['bold', 'italic'],
|
|
|
+ ['underline', 'strike'],
|
|
|
+ ['blockquote'],
|
|
|
+ ['ordered_list', 'bullet_list'],
|
|
|
+ [{ heading: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'] }],
|
|
|
+ ['link', 'image'],
|
|
|
+ ['text_color', 'background_color'],
|
|
|
+ ['align_left', 'align_center', 'align_right', 'align_justify'],
|
|
|
+ ];
|
|
|
colorPresets = [
|
|
|
"#000000", // Negro
|
|
|
"#FF0000", // Rojo
|
|
|
@@ -355,9 +358,6 @@ export class ModalTarea {
|
|
|
|
|
|
ngOnInit(): void {
|
|
|
this.editor = new Editor();
|
|
|
- this.lista().subscribe(() => {
|
|
|
- this.originales = [...this.opciones]; // Guarda las opciones originales
|
|
|
- });
|
|
|
}
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
@@ -365,165 +365,38 @@ export class ModalTarea {
|
|
|
}
|
|
|
|
|
|
|
|
|
- audiencia = [
|
|
|
- { value: 'AL', audiencia: 'Alumnos' },
|
|
|
- { value: 'PF', audiencia: 'Padre de Familia' },
|
|
|
- { value: 'AD', audiencia: 'Administradores' },
|
|
|
- { value: 'PR', audiencia: 'Profesores' },
|
|
|
- { value: 'TD', audiencia: 'Todos los usuarios' },
|
|
|
- ]
|
|
|
-
|
|
|
- importancia = [
|
|
|
- { value: 'Alta', importancia: 'Alta' },
|
|
|
- { value: 'Normal', importancia: 'Normal' },
|
|
|
- { value: 'Baja', importancia: 'Baja' },
|
|
|
- ]
|
|
|
- public opciones: any;
|
|
|
- public roles = ['Administradores', 'Padres'];
|
|
|
- public originales: any;
|
|
|
-
|
|
|
- public selectedAudiencia: string[] = [];
|
|
|
-
|
|
|
- onAudienciaChange(value: string[]) {
|
|
|
- // Si selecciona TD → bloquear todo excepto TD
|
|
|
- if (value.includes('TD')) {
|
|
|
- this.form.get('audiencia')?.setValue(['TD']);
|
|
|
- this.selectedAudiencia = ['TD'];
|
|
|
- } else {
|
|
|
- // Si lo deselecciona, volver a habilitar todas
|
|
|
- this.selectedAudiencia = value;
|
|
|
- }
|
|
|
-
|
|
|
- // 🔹 Siempre resetear destinos al cambiar audiencia
|
|
|
- this.form.get('destinos')?.setValue([]);
|
|
|
- this.selectedDestino = [];
|
|
|
-
|
|
|
- console.log('Audiencia seleccionada:', this.selectedAudiencia);
|
|
|
-
|
|
|
- // 🔹 Tu lógica de opciones según audiencia
|
|
|
- let extra = {};
|
|
|
- switch (this.selectedAudiencia[0]) {
|
|
|
- case 'AL':
|
|
|
- extra = { name: 'Alumnos', grupo: [{ value: 'AL', Destino: 'todos', viewValue: 'Todos los Alumnos' }] };
|
|
|
- this.opciones = [extra, ...this.originales];
|
|
|
- break;
|
|
|
- case 'PF':
|
|
|
- extra = { name: 'Padres de Familia', grupo: [{ value: 'PF', Destino: 'todos', viewValue: 'Todos los Padres de Familia' }] };
|
|
|
- this.opciones = [extra, ...this.originales];
|
|
|
- break;
|
|
|
- case 'AD':
|
|
|
- extra = { name: 'Administradores', grupo: [{ value: 'AD', Destino: 'todos', viewValue: 'Todos los Administradores' }] };
|
|
|
- this.opciones = [extra];
|
|
|
- break;
|
|
|
- case 'PR':
|
|
|
- extra = { name: 'Profesores', grupo: [{ value: 'PR', Destino: 'todos', viewValue: 'Todos los Profesores' }] };
|
|
|
- this.opciones = [extra, ...this.originales];
|
|
|
- break;
|
|
|
- case 'TD':
|
|
|
- extra = { name: 'Todos', grupo: [{ value: 'TD', Destino: 'todos', viewValue: 'Todos los usuarios' }] };
|
|
|
- this.opciones = [extra];
|
|
|
- this.form.get('destinos')?.setValue(['TD']);
|
|
|
- break;
|
|
|
- default:
|
|
|
- this.opciones = [...this.originales];
|
|
|
- break;
|
|
|
- }
|
|
|
+ public tipoTareas: any = [];
|
|
|
+ public materias: any = [];
|
|
|
+ getMaterias() {
|
|
|
+ this.materiaService.getHabilitados().subscribe((response: any) => {
|
|
|
+ this.materias = response.filter((materia: any) => materia.estado === 'Activo');
|
|
|
+ console.log("🚀 ~ ModalTarea ~ getMaterias ~ response:", response)
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
+ getTipoTareas() {
|
|
|
+ this.tareaService.getTipoTareas().subscribe((response: any) => {
|
|
|
+ this.tipoTareas = response.filter((tarea: any) => tarea.estado === 'Activo');
|
|
|
+ console.log("🚀 ~ ModalTarea ~ getTipoTareas ~ this.tipoTareas:", this.tipoTareas)
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
|
|
|
- lista() {
|
|
|
- return forkJoin({
|
|
|
- niveles: this.nivelService.getHabilitados(),
|
|
|
- grados: this.gradoService.getHabilitados(),
|
|
|
- grupos: this.grupoService.getHabilitados(),
|
|
|
- materias: this.materiaService.getHabilitados(),
|
|
|
- }).pipe(
|
|
|
- tap(({ niveles, grados, grupos, materias }: any) => {
|
|
|
- this.opciones = [
|
|
|
- {
|
|
|
- name: 'Nivel Educativo',
|
|
|
- grupo: niveles.map((nivel: any) => ({
|
|
|
- value: nivel.idNivel,
|
|
|
- Destino: 'NivelEducativo',
|
|
|
- viewValue: nivel.nombreNivel,
|
|
|
- })),
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Grados',
|
|
|
- grupo: grados.map((grado: any) => ({
|
|
|
- value: grado.nombreGrado,
|
|
|
- Destino: 'Grado',
|
|
|
- viewValue: grado.nombreGrado,
|
|
|
- })),
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Grupos',
|
|
|
- grupo: grupos.map((grupo: any) => ({
|
|
|
- value: grupo.idGrupo,
|
|
|
- Destino: 'Grupo',
|
|
|
- viewValue: grupo.nombreGrupo,
|
|
|
- })),
|
|
|
- },
|
|
|
- {
|
|
|
- name: 'Materia',
|
|
|
- grupo: materias.map((materia: any) => ({
|
|
|
- value: materia.idMateria,
|
|
|
- Destino: 'Materias',
|
|
|
- viewValue: materia.nombreMateria,
|
|
|
- })),
|
|
|
- },
|
|
|
- ];
|
|
|
- })
|
|
|
- );
|
|
|
- }
|
|
|
+ public opciones: any;
|
|
|
+ public originales: any;
|
|
|
|
|
|
public form = new FormGroup({
|
|
|
- titulo: new FormControl<string>('', Validators.required),
|
|
|
- audiencia: new FormControl<string[]>([''], Validators.required),
|
|
|
- destinos: new FormControl<string[]>([''], Validators.required),
|
|
|
- contenido: new FormControl<string>('', Validators.required),
|
|
|
- importancia: new FormControl<string>('', Validators.required),
|
|
|
- fechaInicio: new FormControl<any>(null, [Validators.required, this.validateFechaInicio.bind(this)]),
|
|
|
- horaInicio: new FormControl<any>(null, Validators.required),
|
|
|
- fechaCaducidad: new FormControl<any>(null, [Validators.required, this.validatefechaCaducidad.bind(this)]),
|
|
|
- horaCaducidad: new FormControl<any>(null, Validators.required),
|
|
|
- link: new FormControl<string>('')
|
|
|
+ tituloTarea: new FormControl<string>('', Validators.required),
|
|
|
+ idMateriaTarea: new FormControl<string[]>([''], Validators.required),
|
|
|
+ idTipoTarea: new FormControl<string[]>([''], Validators.required),
|
|
|
+ descripcionTarea: new FormControl<string>('', Validators.required),
|
|
|
+ fechaPublicacion: new FormControl<any>(null, [Validators.required]),
|
|
|
+ horaPublicacion: new FormControl<any>(null, Validators.required),
|
|
|
+ fechaEntrega: new FormControl<any>(null, [Validators.required]),
|
|
|
+ horaEntrega: new FormControl<any>(null, Validators.required),
|
|
|
+ vinculoTarea: new FormControl<string>('')
|
|
|
});
|
|
|
|
|
|
- validateFechaInicio(control: AbstractControl): ValidationErrors | null {
|
|
|
- const fechaInicio = new Date(control.value);
|
|
|
- const today = new Date();
|
|
|
- today.setHours(0, 0, 0, 0);
|
|
|
-
|
|
|
- if (fechaInicio >= today) {
|
|
|
- this.form.get('fechaCaducidad')?.updateValueAndValidity();
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- return { fechaInvalida: true };
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- validatefechaCaducidad(control: AbstractControl): ValidationErrors | null {
|
|
|
- if (!this.form) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- const fechaInicioValue = this.form.get('fechaInicio')?.value;
|
|
|
- const fechaCaducidadValue = control.value;
|
|
|
-
|
|
|
- if (!fechaInicioValue || !fechaCaducidadValue) {
|
|
|
- return { fechaInvalida: true };
|
|
|
- }
|
|
|
-
|
|
|
- const fechaInicio = new Date(fechaInicioValue);
|
|
|
- const fechaCaducidad = new Date(fechaCaducidadValue);
|
|
|
-
|
|
|
- if (fechaCaducidad >= fechaInicio) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- return { fechaInvalida: true };
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
isValidField(field: string, errorType: string) {
|
|
|
const control = this.form.get(field);
|
|
|
@@ -533,93 +406,61 @@ export class ModalTarea {
|
|
|
public urls: any = []
|
|
|
|
|
|
addUrl() {
|
|
|
- const link = this.form.get('link')?.value;
|
|
|
- this.urls.push(link);
|
|
|
- this.form.get('link')?.setValue('');
|
|
|
+ const vinculoTarea = this.form.get('vinculoTarea')?.value;
|
|
|
+ this.urls.push(vinculoTarea);
|
|
|
+ this.form.get('vinculoTarea')?.setValue('');
|
|
|
console.log(this.urls);
|
|
|
}
|
|
|
|
|
|
|
|
|
- public selectedDestino: string[] = [];
|
|
|
|
|
|
- Evaluar(event: any) {
|
|
|
- const todosValores = ['AL', 'PF', 'AD', 'PR', 'TD'];
|
|
|
- let destinosActuales: any[] = this.form.get('destinos')?.value || [];
|
|
|
-
|
|
|
- if (todosValores.includes(event.value)) {
|
|
|
- // Caso: selecciona "Todos"
|
|
|
- if (destinosActuales.includes(event.value)) {
|
|
|
- // Si ya estaba seleccionado, lo quitamos y reactivamos los demás
|
|
|
- destinosActuales = destinosActuales.filter((d: any) => d !== event.value);
|
|
|
- this.selectedDestino = destinosActuales;
|
|
|
- this.form.get('destinos')?.setValue(destinosActuales);
|
|
|
- } else {
|
|
|
- // Si lo selecciona por primera vez → limpiar y dejar solo "Todos"
|
|
|
- this.selectedDestino = [event.value];
|
|
|
- this.form.get('destinos')?.setValue([event.value]);
|
|
|
- }
|
|
|
- } else {
|
|
|
- // Caso: selecciona normales
|
|
|
- this.selectedDestino = destinosActuales;
|
|
|
- }
|
|
|
-
|
|
|
- // Para tu combinación
|
|
|
- this.valoresCombinados = {
|
|
|
- Destino: event.Destino,
|
|
|
- id: event.value,
|
|
|
- };
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
convertToDatetime() {
|
|
|
// Obtener valores del formulario
|
|
|
- const fechaInicio: any = this.form.get('fechaInicio')?.value;
|
|
|
- const horaInicio: any = this.form.get('horaInicio')?.value;
|
|
|
- const fechaCaducidad: any = this.form.get('fechaCaducidad')?.value;
|
|
|
- const horaCaducidad: any = this.form.get('horaCaducidad')?.value;
|
|
|
+ const fechaPublicacion: any = this.form.get('fechaPublicacion')?.value;
|
|
|
+ const horaPublicacion: any = this.form.get('horaPublicacion')?.value;
|
|
|
+ const fechaEntrega: any = this.form.get('fechaEntrega')?.value;
|
|
|
+ const horaEntrega: any = this.form.get('horaEntrega')?.value;
|
|
|
|
|
|
- let fechaHoraInicio: string | undefined;
|
|
|
- let fechaHoraCaducidad: string | undefined;
|
|
|
+ let fechahoraPublicacion: string | undefined;
|
|
|
+ let fechahoraEntrega: string | undefined;
|
|
|
|
|
|
- if (fechaInicio && horaInicio) {
|
|
|
+ if (fechaPublicacion && horaPublicacion) {
|
|
|
// Formatear fecha en 'YYYY-MM-DD'
|
|
|
- var formattedDate = moment(fechaInicio).format("YYYY-MM-DD");
|
|
|
- fechaHoraInicio = `${formattedDate} ${horaInicio}`;
|
|
|
+ var formattedDate = moment(fechaPublicacion).format("YYYY-MM-DD");
|
|
|
+ fechahoraPublicacion = `${formattedDate} ${horaPublicacion}`;
|
|
|
|
|
|
} else {
|
|
|
console.error('Fecha de inicio o hora de inicio no válidas.');
|
|
|
}
|
|
|
|
|
|
- if (fechaCaducidad && horaCaducidad) {
|
|
|
+ if (fechaEntrega && horaEntrega) {
|
|
|
// Formatear fecha en 'YYYY-MM-DD'
|
|
|
- var formattedDate = moment(fechaCaducidad).format("YYYY-MM-DD");
|
|
|
- fechaHoraCaducidad = `${formattedDate} ${horaCaducidad}`;
|
|
|
+ var formattedDate = moment(fechaEntrega).format("YYYY-MM-DD");
|
|
|
+ fechahoraEntrega = `${formattedDate} ${horaEntrega}`;
|
|
|
|
|
|
} else {
|
|
|
console.error('Fecha de caducidad o hora de caducidad no válidas.');
|
|
|
}
|
|
|
|
|
|
this.info = {
|
|
|
- titulo: this.form.get('titulo')?.value,
|
|
|
- audiencia: this.form.get('audiencia')?.value,
|
|
|
- idReceptores: this.form.get('destinos')?.value,
|
|
|
- contenido: this.form.get('contenido')?.value,
|
|
|
- importancia: this.form.get('importancia')?.value,
|
|
|
- jsonAdjuntos: this.archivosData,
|
|
|
+ tituloTarea: this.form.get('tituloTarea')?.value,
|
|
|
+ idMateriaTarea: this.form.get('idMateriaTarea')?.value,
|
|
|
+ idTipoTarea: this.form.get('idTipoTarea')?.value,
|
|
|
+ descripcionTarea: this.form.get('descripcionTarea')?.value,
|
|
|
+ adjuntoTarea: this.archivosData,
|
|
|
bases64: this.bases64,
|
|
|
fechaCreacion: moment(new Date()).format('YYYY-MM-DD HH:mm:ss'),
|
|
|
- fechaPublicacion: fechaHoraInicio,
|
|
|
- fechaCaducidad: fechaHoraCaducidad,
|
|
|
- idUsuario: this.userData[0],
|
|
|
- urls: this.urls.join('||')
|
|
|
+ fechaPublicacion: fechahoraPublicacion,
|
|
|
+ fechaEntrega: fechahoraEntrega,
|
|
|
+ idUsuario: this.userDataS[0] ? this.userDataS[0] : this.userData[0],
|
|
|
+ vinculoTarea: this.urls.join('||')
|
|
|
};
|
|
|
|
|
|
|
|
|
- this.valoresCombinados = {
|
|
|
- Audiencia: this.form.get('audiencia')?.value,
|
|
|
- ...this.valoresCombinados
|
|
|
- }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -719,118 +560,66 @@ export class ModalTarea {
|
|
|
|
|
|
|
|
|
valoresCombinados2: any[] = [];
|
|
|
-
|
|
|
+
|
|
|
|
|
|
arregloCombinaciones: any[] = [];
|
|
|
idCircular: any;
|
|
|
|
|
|
- async crearCircular() {
|
|
|
- if (this.form.invalid) {
|
|
|
- return Object.values(this.form.controls).forEach(control => {
|
|
|
- control.markAllAsTouched();
|
|
|
- Swal.fire({
|
|
|
- icon: 'error',
|
|
|
- title: `Por favor, llene todos los campos obligatorios.`
|
|
|
- })
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- const audiencias = this.form.get('audiencia')?.value || [];
|
|
|
- const destinos = this.form.get('destinos')?.value || [];
|
|
|
-
|
|
|
- // Genera el arreglo de combinaciones
|
|
|
- this.arregloCombinaciones = [];
|
|
|
- audiencias.forEach((audiencia: string) => {
|
|
|
- destinos.forEach((destino: any) => {
|
|
|
- this.arregloCombinaciones.push({
|
|
|
- Audiencia: audiencia,
|
|
|
- Destino: destino.Destino,
|
|
|
- id: destino.value
|
|
|
- });
|
|
|
- });
|
|
|
- });
|
|
|
+ public alumnos:any = [];
|
|
|
|
|
|
+ crearTarea() {
|
|
|
this.convertToDatetime();
|
|
|
- this.info.audiencia = JSON.stringify(audiencias);
|
|
|
- this.info.idReceptores = JSON.stringify(destinos.map((d: any) => d.value));
|
|
|
- console.log('Combinaciones:', this.arregloCombinaciones);
|
|
|
- console.log('Info:', this.info);
|
|
|
+ console.log(this.info);
|
|
|
|
|
|
- // Loading
|
|
|
- Swal.fire({
|
|
|
- title: 'Cargando...',
|
|
|
- allowOutsideClick: false,
|
|
|
- didOpen: () => {
|
|
|
- Swal.showLoading();
|
|
|
+ this.tareaService.getAlumnos(this.info.idMateriaTarea).subscribe(
|
|
|
+ (response: any) => {
|
|
|
+ this.alumnos = response.map((alumno: any) => alumno.idUsuario);
|
|
|
+ console.log("🚀 ~ ModalTarea ~ crearTarea ~ alumnos:", this.alumnos)
|
|
|
+ },
|
|
|
+ (err) => {
|
|
|
+ console.error('Error al obtener los alumnos:', err);
|
|
|
+
|
|
|
}
|
|
|
- });
|
|
|
-
|
|
|
- // 1️⃣ Primero creamos la circular
|
|
|
- this.circularService.crearCircular(this.info).subscribe(
|
|
|
- async (response: any) => {
|
|
|
- console.log('Circular creada:', response);
|
|
|
- this.idCircular = response.idCircular;
|
|
|
-
|
|
|
- // 2️⃣ Obtener destinatarios únicos
|
|
|
- const destinatariosUnicos: Set<string> = new Set();
|
|
|
-
|
|
|
- for (const combinacion of this.arregloCombinaciones) {
|
|
|
- console.log('Obteniendo destinatarios para:', combinacion);
|
|
|
- await new Promise<void>((resolve) => {
|
|
|
- this.circularService.obtenerDestinatarios(combinacion).subscribe(
|
|
|
- (resp: any) => {
|
|
|
- if (resp.idUsuario && Array.isArray(resp.idUsuario)) {
|
|
|
- resp.idUsuario.forEach((id: string) => destinatariosUnicos.add(id));
|
|
|
- }
|
|
|
- resolve();
|
|
|
- },
|
|
|
- (err) => {
|
|
|
- console.error('Error al obtener destinatarios:', err);
|
|
|
- resolve();
|
|
|
- }
|
|
|
- );
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- console.log('Destinatarios únicos:', Array.from(destinatariosUnicos));
|
|
|
-
|
|
|
- // 3️⃣ Enviar circular a cada destinatario
|
|
|
- const valoresCombinados2: any[] = [];
|
|
|
- Array.from(destinatariosUnicos).forEach((idUsuario: string) => {
|
|
|
- valoresCombinados2.push({
|
|
|
- idUsuario,
|
|
|
- idCircular: this.idCircular
|
|
|
- });
|
|
|
- });
|
|
|
+ );
|
|
|
|
|
|
- for (let i = 0; i < valoresCombinados2.length; i++) {
|
|
|
- this.circularService.enviarCircular(valoresCombinados2[i]).subscribe(
|
|
|
- (resp: any) => console.log('Envío OK:', resp),
|
|
|
- (err) => console.error('Error en envío:', err)
|
|
|
+ this.tareaService.crearTarea(this.info).subscribe(
|
|
|
+ (response: any) => {
|
|
|
+ console.log('Tarea creada:', response);
|
|
|
+ // Swal.fire({
|
|
|
+ // icon: 'success',
|
|
|
+ // title: `${response.mensaje}`
|
|
|
+ // });
|
|
|
+
|
|
|
+ this.alumnos.forEach((alumno:any) => {
|
|
|
+ this.tareaService.asignarTarea({
|
|
|
+ idTarea: response.idTarea,
|
|
|
+ idUsuario: alumno
|
|
|
+ }).subscribe(
|
|
|
+ (res) => {
|
|
|
+ console.log('Tarea asignada al alumno:', res);
|
|
|
+ },
|
|
|
+ (err) => {
|
|
|
+ console.error('Error al asignar la tarea al alumno:', err);
|
|
|
+ }
|
|
|
);
|
|
|
- }
|
|
|
-
|
|
|
- Swal.close();
|
|
|
- Swal.fire({
|
|
|
- icon: 'success',
|
|
|
- title: `${response.mensaje}`
|
|
|
});
|
|
|
|
|
|
this.dialog.closeAll();
|
|
|
this._enviarInfoService.notifyCambioTabla();
|
|
|
},
|
|
|
(err) => {
|
|
|
- Swal.close();
|
|
|
- Swal.fire({
|
|
|
- icon: 'error',
|
|
|
- title: `${err.mensaje}`
|
|
|
- });
|
|
|
+ console.error('Error al crear la tarea:', err);
|
|
|
+ // Swal.fire({
|
|
|
+ // icon: 'error',
|
|
|
+ // title: `Error al crear la tarea: ${err.error.mensaje || err.message || 'Error desconocido'}`
|
|
|
+ // });
|
|
|
}
|
|
|
);
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
public horasDelDia: any = this.generarHorasDelDia();
|
|
|
generarHorasDelDia(): { hora24: string, hora12: string }[] {
|
|
|
const horas: { hora24: string, hora12: string }[] = [];
|