Merge pull request #114 from Quantum-P3/feature/US-35

add desactivar/activar plantilla
This commit is contained in:
Eduardo Quiros 2021-08-08 07:52:17 +00:00 committed by GitHub
commit 3dbe2c5329
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 125 additions and 72 deletions

View File

@ -1,70 +0,0 @@
import { Plantilla } from '../plantilla.model';
import { ComponentFixture, fakeAsync, inject, TestBed, 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 { PlantillaService } from '../service/plantilla.service';
import { PlantillaDeleteDialogComponent } from './plantilla-delete-dialog.component';
import { EstadoPlantilla } from '../../enumerations/estado-plantilla.model';
jest.mock('@ng-bootstrap/ng-bootstrap');
describe('Component Tests', () => {
describe('Plantilla Management Delete Component', () => {
let comp: PlantillaDeleteDialogComponent;
let fixture: ComponentFixture<PlantillaDeleteDialogComponent>;
let service: PlantillaService;
let mockActiveModal: NgbActiveModal;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
declarations: [PlantillaDeleteDialogComponent],
providers: [NgbActiveModal],
})
.overrideTemplate(PlantillaDeleteDialogComponent, '')
.compileComponents();
fixture = TestBed.createComponent(PlantillaDeleteDialogComponent);
comp = fixture.componentInstance;
service = TestBed.inject(PlantillaService);
mockActiveModal = TestBed.inject(NgbActiveModal);
});
describe('confirmDelete', () => {
it('Should call delete service on confirmDelete', inject(
[],
fakeAsync(() => {
// GIVEN
jest.spyOn(service, 'delete').mockReturnValue(of(new HttpResponse({})));
const pPlantilla = new Plantilla();
pPlantilla.id = 123;
pPlantilla.estado = EstadoPlantilla.DELETED;
// WHEN
comp.confirmDelete(pPlantilla);
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();
});
});
});
});

View File

@ -67,7 +67,10 @@
> >
<span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span> <span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
</button> </button>
<button type="submit" (click)="cambiarEstado(plantilla)" class="ds-btn btn-warning btn-sm" data-cy="entityDeleteButton">
<fa-icon [icon]="faExchangeAlt"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="dataSurveyApp.plantilla.updated.buttonChangeEstado">Change status</span>
</button>
<button type="submit" (click)="delete(plantilla)" class="ds-btn ds-btn--danger btn-sm" data-cy="entityDeleteButton"> <button type="submit" (click)="delete(plantilla)" class="ds-btn ds-btn--danger btn-sm" data-cy="entityDeleteButton">
<fa-icon icon="times"></fa-icon> <fa-icon icon="times"></fa-icon>
<span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span> <span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>

View File

@ -17,6 +17,9 @@ import { CategoriaService } from 'app/entities/categoria/service/categoria.servi
import * as dayjs from 'dayjs'; import * as dayjs from 'dayjs';
import { DATE_TIME_FORMAT } from 'app/config/input.constants'; import { DATE_TIME_FORMAT } from 'app/config/input.constants';
import { PlantillaChangeStatusDialogComponent } from '../plantilla-change-status-dialog/plantilla-change-status-dialog.component';
import { faExchangeAlt } from '@fortawesome/free-solid-svg-icons';
@Component({ @Component({
selector: 'jhi-plantilla', selector: 'jhi-plantilla',
@ -39,6 +42,7 @@ export class PlantillaComponent implements OnInit {
categoria: [null, [Validators.required]], categoria: [null, [Validators.required]],
}); });
faExchangeAlt = faExchangeAlt;
constructor( constructor(
protected plantillaService: PlantillaService, protected plantillaService: PlantillaService,
protected modalService: NgbModal, protected modalService: NgbModal,
@ -82,6 +86,17 @@ export class PlantillaComponent implements OnInit {
}); });
} }
cambiarEstado(plantilla: IPlantilla): void {
const modalRef = this.modalService.open(PlantillaChangeStatusDialogComponent, { size: 'lg', backdrop: 'static' });
modalRef.componentInstance.plantilla = plantilla;
// unsubscribe not needed because closed completes on modal close
modalRef.closed.subscribe(reason => {
if (reason === 'updated') {
this.loadAll();
}
});
}
isAdmin(): boolean { isAdmin(): boolean {
return this.accountService.hasAnyAuthority('ROLE_ADMIN'); return this.accountService.hasAnyAuthority('ROLE_ADMIN');
} }

View File

@ -0,0 +1,32 @@
<form *ngIf="plantilla" class="ds-form" name="changeStatusForm" (ngSubmit)="confirmChangeStatus(plantilla)">
<div class="modal-body">
<p class="ds-title--small">Cambiar estado</p>
<p
*ngIf="plantilla.estado != 'DISABLED'"
class="ds-subtitle"
id="jhi-inactive-plantilla-heading"
jhiTranslate="dataSurveyApp.plantilla.desactivar.question"
>
Are you sure you want to delete this option?
</p>
<p
*ngIf="plantilla.estado == 'DISABLED'"
class="ds-subtitle"
id="jhi-active-plantilla-heading"
jhiTranslate="dataSurveyApp.plantilla.activar.question"
>
Are you sure you want to delete this option?
</p>
</div>
<div class="modal-footer">
<button type="button" class="ds-btn ds-btn--secondary" data-dismiss="modal" (click)="cancel()">
<fa-icon icon="arrow-left"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
</button>
<button id="jhi-confirm-change-status-option" data-cy="entityConfirmChangeButton" type="submit" class="ds-btn btn-warning">
<fa-icon [icon]="faExchangeAlt"></fa-icon
><span class="d-none d-md-inline" jhiTranslate="dataSurveyApp.plantilla.updated.buttonChangeEstado">Cambiar estado</span>
</button>
</div>
</form>

View File

@ -0,0 +1,24 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { PlantillaChangeStatusDialogComponent } from './plantilla-change-status-dialog.component';
describe('PlantillaChangeStatusDialogComponent', () => {
let component: PlantillaChangeStatusDialogComponent;
let fixture: ComponentFixture<PlantillaChangeStatusDialogComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [PlantillaChangeStatusDialogComponent],
}).compileComponents();
});
beforeEach(() => {
fixture = TestBed.createComponent(PlantillaChangeStatusDialogComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,36 @@
import { Component } from '@angular/core';
import { PlantillaService } from '../service/plantilla.service';
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { EstadoPlantilla } from '../../enumerations/estado-plantilla.model';
import { IPlantilla } from '../plantilla.model';
import { faExchangeAlt } from '@fortawesome/free-solid-svg-icons';
@Component({
selector: 'jhi-plantilla-change-status-dialog',
templateUrl: './plantilla-change-status-dialog.component.html',
styleUrls: ['./plantilla-change-status-dialog.component.scss'],
})
export class PlantillaChangeStatusDialogComponent {
plantilla?: IPlantilla;
faExchangeAlt = faExchangeAlt;
constructor(protected plantillaService: PlantillaService, protected activeModal: NgbActiveModal) {}
cancel(): void {
this.activeModal.dismiss();
}
confirmChangeStatus(pPlantilla: IPlantilla) {
if (this.plantilla) {
if (pPlantilla.estado === EstadoPlantilla.DISABLED) {
this.plantilla.estado = EstadoPlantilla.DRAFT;
} else {
this.plantilla.estado = EstadoPlantilla.DISABLED;
}
this.plantillaService.update(this.plantilla).subscribe(() => {
this.activeModal.close('updated');
});
}
}
}

View File

@ -10,6 +10,7 @@ import { PlantillaDeleteQuestionDialogComponent } from './plantilla-delete-quest
import { PlantillaDeleteOptionDialogComponent } from './plantilla-delete-option-dialog/plantilla-delete-option-dialog.component'; import { PlantillaDeleteOptionDialogComponent } from './plantilla-delete-option-dialog/plantilla-delete-option-dialog.component';
import { PlantillaPublishStoreDialogComponent } from './plantilla-publish-store-dialog/plantilla-publish-store-dialog.component'; import { PlantillaPublishStoreDialogComponent } from './plantilla-publish-store-dialog/plantilla-publish-store-dialog.component';
import { PlantillaDeleteStoreDialogComponent } from './plantilla-delete-store-dialog/plantilla-delete-store-dialog.component'; import { PlantillaDeleteStoreDialogComponent } from './plantilla-delete-store-dialog/plantilla-delete-store-dialog.component';
import { PlantillaChangeStatusDialogComponent } from './plantilla-change-status-dialog/plantilla-change-status-dialog.component';
@NgModule({ @NgModule({
imports: [SharedModule, PlantillaRoutingModule, FontAwesomeModule], imports: [SharedModule, PlantillaRoutingModule, FontAwesomeModule],
@ -22,6 +23,7 @@ import { PlantillaDeleteStoreDialogComponent } from './plantilla-delete-store-di
PlantillaDeleteOptionDialogComponent, PlantillaDeleteOptionDialogComponent,
PlantillaPublishStoreDialogComponent, PlantillaPublishStoreDialogComponent,
PlantillaDeleteStoreDialogComponent, PlantillaDeleteStoreDialogComponent,
PlantillaChangeStatusDialogComponent,
], ],
entryComponents: [PlantillaDeleteDialogComponent], entryComponents: [PlantillaDeleteDialogComponent],
}) })

View File

@ -9,7 +9,10 @@
"notFound": "No se encontró ninguna plantilla" "notFound": "No se encontró ninguna plantilla"
}, },
"created": "Una nueva plantilla ha sido creada con el identificador {{ param }}", "created": "Una nueva plantilla ha sido creada con el identificador {{ param }}",
"updated": "Una plantilla ha sido actualizada con el identificador {{ param }}", "updated": {
"detail": "Una plantilla ha sido actualizada con el identificador {{ param }}",
"buttonChangeEstado": "Cambiar estado"
},
"deleted": "Una plantilla ha sido eliminada con el identificador {{ param }}", "deleted": "Una plantilla ha sido eliminada con el identificador {{ param }}",
"delete": { "delete": {
"question": "¿Seguro que quiere eliminar esta plantilla?", "question": "¿Seguro que quiere eliminar esta plantilla?",
@ -21,6 +24,14 @@
"detail": { "detail": {
"title": "Plantilla" "title": "Plantilla"
}, },
"desactivar": {
"titulo": "Desactivar plantilla",
"question": "¿Seguro que quiere desactivar la plantilla?"
},
"activar": {
"titulo": "Activar plantilla",
"question": "¿Seguro que quiere activar la plantilla?. Esta será activada en estado de 'Borrador'"
},
"id": "ID", "id": "ID",
"nombre": "Nombre", "nombre": "Nombre",
"descripcion": "Descripción", "descripcion": "Descripción",