2021-07-03 21:48:27 +00:00
|
|
|
import { Component } from '@angular/core';
|
|
|
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
2021-07-17 02:18:33 +00:00
|
|
|
import { IEncuesta } from 'app/entities/encuesta/encuesta.model';
|
2021-07-17 00:23:03 +00:00
|
|
|
import { EncuestaService } from 'app/entities/encuesta/service/encuesta.service';
|
2021-07-15 02:49:19 +00:00
|
|
|
import { EstadoCategoria } from 'app/entities/enumerations/estado-categoria.model';
|
2021-07-03 21:48:27 +00:00
|
|
|
|
2021-07-17 02:20:15 +00:00
|
|
|
import { Categoria, ICategoria } from '../categoria.model';
|
2021-07-03 21:48:27 +00:00
|
|
|
import { CategoriaService } from '../service/categoria.service';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
templateUrl: './categoria-delete-dialog.component.html',
|
|
|
|
})
|
|
|
|
export class CategoriaDeleteDialogComponent {
|
|
|
|
categoria?: ICategoria;
|
2021-07-17 02:18:33 +00:00
|
|
|
encuestas?: IEncuesta[];
|
|
|
|
encuestasFiltradas?: IEncuesta[];
|
2021-07-03 21:48:27 +00:00
|
|
|
|
2021-07-17 00:23:03 +00:00
|
|
|
constructor(
|
|
|
|
protected categoriaService: CategoriaService,
|
|
|
|
protected activeModal: NgbActiveModal,
|
|
|
|
protected encuestaService: EncuestaService
|
2021-07-19 03:40:55 +00:00
|
|
|
) {
|
|
|
|
this.getEncuestas();
|
|
|
|
}
|
2021-07-03 21:48:27 +00:00
|
|
|
|
|
|
|
cancel(): void {
|
|
|
|
this.activeModal.dismiss();
|
|
|
|
}
|
|
|
|
|
2021-07-15 02:39:01 +00:00
|
|
|
confirmDelete(categoria: ICategoria): void {
|
2021-07-17 02:20:54 +00:00
|
|
|
const categoriaNula = new Categoria(0, 'Otra', EstadoCategoria.ACTIVE);
|
2021-07-19 03:41:26 +00:00
|
|
|
this.getEncuestas();
|
|
|
|
debugger;
|
2021-07-19 02:57:20 +00:00
|
|
|
if (categoria.estado == EstadoCategoria.INACTIVE) {
|
|
|
|
categoria.estado = EstadoCategoria.ACTIVE;
|
|
|
|
} else {
|
|
|
|
categoria.estado = EstadoCategoria.INACTIVE;
|
|
|
|
}
|
2021-07-15 02:49:19 +00:00
|
|
|
this.categoriaService.update(categoria).subscribe(() => {
|
2021-07-03 21:48:27 +00:00
|
|
|
this.activeModal.close('deleted');
|
|
|
|
});
|
|
|
|
}
|
2021-07-17 02:20:15 +00:00
|
|
|
|
2021-07-19 03:41:26 +00:00
|
|
|
getEncuestas(): void {
|
2021-07-17 02:18:33 +00:00
|
|
|
this.encuestaService.query().subscribe(res => {
|
|
|
|
this.encuestas = res.body ?? [];
|
|
|
|
});
|
|
|
|
if (this.encuestas) {
|
|
|
|
this.encuestasFiltradas = this.encuestas.filter(encuesta => {
|
|
|
|
encuesta.categoria!.id === categoria.id;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|