2021-07-03 21:48:27 +00:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { HttpResponse } from '@angular/common/http';
|
|
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
|
|
|
|
|
|
|
import { ICategoria } from '../categoria.model';
|
|
|
|
import { CategoriaService } from '../service/categoria.service';
|
|
|
|
import { CategoriaDeleteDialogComponent } from '../delete/categoria-delete-dialog.component';
|
|
|
|
|
2021-07-26 04:48:33 +00:00
|
|
|
import { faExchangeAlt } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
|
2021-07-03 21:48:27 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'jhi-categoria',
|
|
|
|
templateUrl: './categoria.component.html',
|
|
|
|
})
|
|
|
|
export class CategoriaComponent implements OnInit {
|
2021-07-26 04:48:33 +00:00
|
|
|
faExchangeAlt = faExchangeAlt;
|
|
|
|
|
2021-07-03 21:48:27 +00:00
|
|
|
categorias?: ICategoria[];
|
|
|
|
isLoading = false;
|
2021-07-11 02:20:13 +00:00
|
|
|
public searchString: string;
|
2021-07-19 05:01:27 +00:00
|
|
|
success = false;
|
2021-07-03 21:48:27 +00:00
|
|
|
|
2021-07-11 02:20:13 +00:00
|
|
|
constructor(protected categoriaService: CategoriaService, protected modalService: NgbModal) {
|
|
|
|
this.searchString = '';
|
|
|
|
}
|
2021-07-03 21:48:27 +00:00
|
|
|
|
|
|
|
loadAll(): void {
|
|
|
|
this.isLoading = true;
|
|
|
|
|
|
|
|
this.categoriaService.query().subscribe(
|
|
|
|
(res: HttpResponse<ICategoria[]>) => {
|
|
|
|
this.isLoading = false;
|
|
|
|
this.categorias = res.body ?? [];
|
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.isLoading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-07-11 02:20:13 +00:00
|
|
|
this.searchString = '';
|
2021-07-03 21:48:27 +00:00
|
|
|
this.loadAll();
|
|
|
|
}
|
|
|
|
|
2021-07-15 03:11:34 +00:00
|
|
|
trackId(_index: number, item: ICategoria): number {
|
2021-07-03 21:48:27 +00:00
|
|
|
return item.id!;
|
|
|
|
}
|
|
|
|
|
2021-07-19 02:57:20 +00:00
|
|
|
toggleStatus(categoria: ICategoria): void {
|
2021-07-03 21:48:27 +00:00
|
|
|
const modalRef = this.modalService.open(CategoriaDeleteDialogComponent, { size: 'lg', backdrop: 'static' });
|
|
|
|
modalRef.componentInstance.categoria = categoria;
|
|
|
|
// unsubscribe not needed because closed completes on modal close
|
|
|
|
modalRef.closed.subscribe(reason => {
|
|
|
|
if (reason === 'deleted') {
|
2021-07-19 05:01:27 +00:00
|
|
|
this.success = true;
|
2021-07-03 21:48:27 +00:00
|
|
|
this.loadAll();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|