Merge pull request #39 from Quantum-P3/feature/US-16
agregar borrado logico de categorias
This commit is contained in:
commit
01066239c2
|
@ -1,7 +1,8 @@
|
|||
package org.datasurvey.repository;
|
||||
|
||||
import org.datasurvey.domain.Categoria;
|
||||
import org.springframework.data.jpa.repository.*;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,14 +1,13 @@
|
|||
import { NgModule } from '@angular/core';
|
||||
import { SharedModule } from 'app/shared/shared.module';
|
||||
import { CategoriaComponent } from './list/categoria.component';
|
||||
import { CategoriaDetailComponent } from './detail/categoria-detail.component';
|
||||
import { CategoriaUpdateComponent } from './update/categoria-update.component';
|
||||
import { CategoriaDeleteDialogComponent } from './delete/categoria-delete-dialog.component';
|
||||
import { CategoriaRoutingModule } from './route/categoria-routing.module';
|
||||
|
||||
@NgModule({
|
||||
imports: [SharedModule, CategoriaRoutingModule],
|
||||
declarations: [CategoriaComponent, CategoriaDetailComponent, CategoriaUpdateComponent, CategoriaDeleteDialogComponent],
|
||||
declarations: [CategoriaComponent, CategoriaUpdateComponent, CategoriaDeleteDialogComponent],
|
||||
entryComponents: [CategoriaDeleteDialogComponent],
|
||||
})
|
||||
export class CategoriaModule {}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<form class="ds-form" *ngIf="categoria" name="deleteForm" (ngSubmit)="confirmDelete(categoria.id!)">
|
||||
<form class="ds-form" *ngIf="categoria" name="deleteForm" (ngSubmit)="confirmDelete(categoria!)">
|
||||
<div class="modal-header">
|
||||
<h4 class="modal-title" data-cy="categoriaDeleteDialogHeading" jhiTranslate="entity.delete.title">Confirm delete operation</h4>
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
|||
<jhi-alert-error></jhi-alert-error>
|
||||
|
||||
<p id="jhi-delete-categoria-heading" jhiTranslate="dataSurveyApp.categoria.delete.question" [translateValues]="{ id: categoria.id }">
|
||||
Are you sure you want to delete this Categoria?
|
||||
Are you sure you want to delete this category?
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
jest.mock('@ng-bootstrap/ng-bootstrap');
|
||||
|
||||
import { ComponentFixture, TestBed, inject, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { HttpResponse } from '@angular/common/http';
|
||||
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
||||
import { of } from 'rxjs';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
|
||||
import { CategoriaService } from '../service/categoria.service';
|
||||
|
||||
import { CategoriaDeleteDialogComponent } from './categoria-delete-dialog.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('Categoria Management Delete Component', () => {
|
||||
let comp: CategoriaDeleteDialogComponent;
|
||||
let fixture: ComponentFixture<CategoriaDeleteDialogComponent>;
|
||||
let service: CategoriaService;
|
||||
let mockActiveModal: NgbActiveModal;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [HttpClientTestingModule],
|
||||
declarations: [CategoriaDeleteDialogComponent],
|
||||
providers: [NgbActiveModal],
|
||||
})
|
||||
.overrideTemplate(CategoriaDeleteDialogComponent, '')
|
||||
.compileComponents();
|
||||
fixture = TestBed.createComponent(CategoriaDeleteDialogComponent);
|
||||
comp = fixture.componentInstance;
|
||||
service = TestBed.inject(CategoriaService);
|
||||
mockActiveModal = TestBed.inject(NgbActiveModal);
|
||||
});
|
||||
|
||||
describe('confirmDelete', () => {
|
||||
it('Should call delete service on confirmDelete', inject(
|
||||
[],
|
||||
fakeAsync(() => {
|
||||
// GIVEN
|
||||
jest.spyOn(service, 'delete').mockReturnValue(of(new HttpResponse({})));
|
||||
|
||||
// WHEN
|
||||
comp.confirmDelete(123);
|
||||
tick();
|
||||
|
||||
// THEN
|
||||
expect(service.delete).toHaveBeenCalledWith(123);
|
||||
expect(mockActiveModal.close).toHaveBeenCalledWith('deleted');
|
||||
})
|
||||
));
|
||||
|
||||
it('Should not call delete service on clear', () => {
|
||||
// GIVEN
|
||||
jest.spyOn(service, 'delete');
|
||||
|
||||
// WHEN
|
||||
comp.cancel();
|
||||
|
||||
// THEN
|
||||
expect(service.delete).not.toHaveBeenCalled();
|
||||
expect(mockActiveModal.close).not.toHaveBeenCalled();
|
||||
expect(mockActiveModal.dismiss).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,7 +1,10 @@
|
|||
import { Component } from '@angular/core';
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { IEncuesta } from 'app/entities/encuesta/encuesta.model';
|
||||
import { EncuestaService } from 'app/entities/encuesta/service/encuesta.service';
|
||||
import { EstadoCategoria } from 'app/entities/enumerations/estado-categoria.model';
|
||||
|
||||
import { ICategoria } from '../categoria.model';
|
||||
import { Categoria, ICategoria } from '../categoria.model';
|
||||
import { CategoriaService } from '../service/categoria.service';
|
||||
|
||||
@Component({
|
||||
|
@ -9,16 +12,52 @@ import { CategoriaService } from '../service/categoria.service';
|
|||
})
|
||||
export class CategoriaDeleteDialogComponent {
|
||||
categoria?: ICategoria;
|
||||
encuestas?: IEncuesta[];
|
||||
encuestasFiltradas?: IEncuesta[];
|
||||
|
||||
constructor(protected categoriaService: CategoriaService, protected activeModal: NgbActiveModal) {}
|
||||
constructor(
|
||||
protected categoriaService: CategoriaService,
|
||||
protected activeModal: NgbActiveModal,
|
||||
protected encuestaService: EncuestaService
|
||||
) {}
|
||||
|
||||
cancel(): void {
|
||||
this.activeModal.dismiss();
|
||||
}
|
||||
|
||||
confirmDelete(id: number): void {
|
||||
this.categoriaService.delete(id).subscribe(() => {
|
||||
confirmDelete(categoria: ICategoria): void {
|
||||
this.ensureNulaExists();
|
||||
const categoriaNula = new Categoria(0, 'Otra', EstadoCategoria.ACTIVE);
|
||||
this.getEncuestas(categoria);
|
||||
if (this.encuestas) {
|
||||
this.encuestas!.forEach(encuesta => {
|
||||
encuesta.categoria = categoriaNula;
|
||||
this.encuestaService.update(encuesta);
|
||||
});
|
||||
}
|
||||
categoria.estado = EstadoCategoria.INACTIVE;
|
||||
this.categoriaService.update(categoria).subscribe(() => {
|
||||
this.activeModal.close('deleted');
|
||||
});
|
||||
}
|
||||
ensureNulaExists(): void {
|
||||
const categoriaNula = new Categoria(0, 'Otra', EstadoCategoria.ACTIVE);
|
||||
const categoria = this.categoriaService.find(0);
|
||||
if (categoria) {
|
||||
this.categoriaService.update(categoriaNula);
|
||||
} else {
|
||||
this.categoriaService.create(categoriaNula);
|
||||
}
|
||||
}
|
||||
|
||||
protected getEncuestas(categoria: ICategoria): void {
|
||||
this.encuestaService.query().subscribe(res => {
|
||||
this.encuestas = res.body ?? [];
|
||||
});
|
||||
if (this.encuestas) {
|
||||
this.encuestasFiltradas = this.encuestas.filter(encuesta => {
|
||||
encuesta.categoria!.id === categoria.id;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
<div class="row justify-content-center">
|
||||
<div class="col-8">
|
||||
<div *ngIf="categoria">
|
||||
<h2 data-cy="categoriaDetailsHeading"><span jhiTranslate="dataSurveyApp.categoria.detail.title">Categoria</span></h2>
|
||||
|
||||
<hr />
|
||||
|
||||
<jhi-alert-error></jhi-alert-error>
|
||||
|
||||
<jhi-alert></jhi-alert>
|
||||
|
||||
<dl class="row-md jh-entity-details">
|
||||
<dt><span jhiTranslate="global.field.id">ID</span></dt>
|
||||
<dd>
|
||||
<span>{{ categoria.id }}</span>
|
||||
</dd>
|
||||
<dt><span jhiTranslate="dataSurveyApp.categoria.nombre">Nombre</span></dt>
|
||||
<dd>
|
||||
<span>{{ categoria.nombre }}</span>
|
||||
</dd>
|
||||
<dt><span jhiTranslate="dataSurveyApp.categoria.estado">Estado</span></dt>
|
||||
<dd>
|
||||
<span jhiTranslate="{{ 'dataSurveyApp.EstadoCategoria.' + categoria.estado }}">{{ categoria.estado }}</span>
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
<button type="submit" (click)="previousState()" class="btn btn-ds btn-info" data-cy="entityDetailsBackButton">
|
||||
<fa-icon icon="arrow-left"></fa-icon> <span jhiTranslate="entity.action.back">Back</span>
|
||||
</button>
|
||||
|
||||
<button type="button" [routerLink]="['/categoria', categoria.id, 'edit']" class="btn btn-ds btn-ds-primary btn-primary">
|
||||
<fa-icon icon="pencil-alt"></fa-icon> <span jhiTranslate="entity.action.edit">Edit</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
|
@ -1,38 +0,0 @@
|
|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
import { CategoriaDetailComponent } from './categoria-detail.component';
|
||||
|
||||
describe('Component Tests', () => {
|
||||
describe('Categoria Management Detail Component', () => {
|
||||
let comp: CategoriaDetailComponent;
|
||||
let fixture: ComponentFixture<CategoriaDetailComponent>;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
declarations: [CategoriaDetailComponent],
|
||||
providers: [
|
||||
{
|
||||
provide: ActivatedRoute,
|
||||
useValue: { data: of({ categoria: { id: 123 } }) },
|
||||
},
|
||||
],
|
||||
})
|
||||
.overrideTemplate(CategoriaDetailComponent, '')
|
||||
.compileComponents();
|
||||
fixture = TestBed.createComponent(CategoriaDetailComponent);
|
||||
comp = fixture.componentInstance;
|
||||
});
|
||||
|
||||
describe('OnInit', () => {
|
||||
it('Should load categoria on init', () => {
|
||||
// WHEN
|
||||
comp.ngOnInit();
|
||||
|
||||
// THEN
|
||||
expect(comp.categoria).toEqual(expect.objectContaining({ id: 123 }));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -1,24 +0,0 @@
|
|||
import { Component, OnInit } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
|
||||
import { ICategoria } from '../categoria.model';
|
||||
|
||||
@Component({
|
||||
selector: 'jhi-categoria-detail',
|
||||
templateUrl: './categoria-detail.component.html',
|
||||
})
|
||||
export class CategoriaDetailComponent implements OnInit {
|
||||
categoria: ICategoria | null = null;
|
||||
|
||||
constructor(protected activatedRoute: ActivatedRoute) {}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.activatedRoute.data.subscribe(({ categoria }) => {
|
||||
this.categoria = categoria;
|
||||
});
|
||||
}
|
||||
|
||||
previousState(): void {
|
||||
window.history.back();
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@ export class CategoriaComponent implements OnInit {
|
|||
this.loadAll();
|
||||
}
|
||||
|
||||
trackId(index: number, item: ICategoria): number {
|
||||
trackId(_index: number, item: ICategoria): number {
|
||||
return item.id!;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ import { RouterModule, Routes } from '@angular/router';
|
|||
|
||||
import { UserRouteAccessService } from 'app/core/auth/user-route-access.service';
|
||||
import { CategoriaComponent } from '../list/categoria.component';
|
||||
import { CategoriaDetailComponent } from '../detail/categoria-detail.component';
|
||||
import { CategoriaUpdateComponent } from '../update/categoria-update.component';
|
||||
import { CategoriaRoutingResolveService } from './categoria-routing-resolve.service';
|
||||
|
||||
|
@ -13,14 +12,6 @@ const categoriaRoute: Routes = [
|
|||
component: CategoriaComponent,
|
||||
canActivate: [UserRouteAccessService],
|
||||
},
|
||||
{
|
||||
path: ':id/view',
|
||||
component: CategoriaDetailComponent,
|
||||
resolve: {
|
||||
categoria: CategoriaRoutingResolveService,
|
||||
},
|
||||
canActivate: [UserRouteAccessService],
|
||||
},
|
||||
{
|
||||
path: 'new',
|
||||
component: CategoriaUpdateComponent,
|
||||
|
|
|
@ -64,7 +64,7 @@ export class CategoriaUpdateComponent implements OnInit {
|
|||
|
||||
protected categoryExists(categoria: ICategoria): boolean {
|
||||
this.loadAll();
|
||||
var condicion = this.categorias!.some(cat => cat.nombre!.toLowerCase() === categoria.nombre!.toLowerCase());
|
||||
var condicion = this.categorias!.some(cat => cat.nombre!.toLowerCase() === categoria.nombre!.toLowerCase() && cat.id !== categoria.id);
|
||||
return condicion;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue