add Eliminar encuesta

This commit is contained in:
Mariela Bonilla 2021-07-22 02:49:12 -06:00
parent 593905bf01
commit 9f4f87ef41
6 changed files with 73 additions and 10 deletions

View File

@ -1,6 +1,6 @@
<form *ngIf="encuesta" name="deleteForm" (ngSubmit)="confirmDelete(encuesta.id!)"> <form class="ds-form" *ngIf="encuesta" name="deleteForm" (ngSubmit)="confirmDelete(encuesta!)">
<div class="modal-header"> <div class="modal-header">
<h4 class="modal-title" data-cy="encuestaDeleteDialogHeading" jhiTranslate="entity.delete.title">Confirm delete operation</h4> <h2 class="ds-title" data-cy="encuestaDeleteDialogHeading" jhiTranslate="entity.delete.title">Confirm delete operation</h2>
<button type="button" class="close" data-dismiss="modal" aria-hidden="true" (click)="cancel()">&times;</button> <button type="button" class="close" data-dismiss="modal" aria-hidden="true" (click)="cancel()">&times;</button>
</div> </div>
@ -14,11 +14,11 @@
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal" (click)="cancel()"> <button type="button" class="ds-btn ds-btn--secondary" data-dismiss="modal" (click)="cancel()">
<fa-icon icon="ban"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span> <fa-icon icon="arrow-left"></fa-icon>&nbsp;<span jhiTranslate="entity.action.cancel">Cancel</span>
</button> </button>
<button id="jhi-confirm-delete-encuesta" data-cy="entityConfirmDeleteButton" type="submit" class="btn btn-danger"> <button id="jhi-confirm-delete-encuesta" data-cy="entityConfirmDeleteButton" type="submit" class="ds-btn ds-btn--danger">
<fa-icon icon="times"></fa-icon>&nbsp;<span jhiTranslate="entity.action.delete">Delete</span> <fa-icon icon="times"></fa-icon>&nbsp;<span jhiTranslate="entity.action.delete">Delete</span>
</button> </button>
</div> </div>

View File

@ -3,6 +3,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
import { IEncuesta } from '../encuesta.model'; import { IEncuesta } from '../encuesta.model';
import { EncuestaService } from '../service/encuesta.service'; import { EncuestaService } from '../service/encuesta.service';
import { EstadoEncuesta } from 'app/entities/enumerations/estado-encuesta.model';
@Component({ @Component({
templateUrl: './encuesta-delete-dialog.component.html', templateUrl: './encuesta-delete-dialog.component.html',
@ -16,8 +17,9 @@ export class EncuestaDeleteDialogComponent {
this.activeModal.dismiss(); this.activeModal.dismiss();
} }
confirmDelete(id: number): void { confirmDelete(encuest: IEncuesta): void {
this.encuestaService.delete(id).subscribe(() => { encuest.estado = EstadoEncuesta.DELETED;
this.encuestaService.deleteEncuesta(encuest).subscribe(() => {
this.activeModal.close('deleted'); this.activeModal.close('deleted');
}); });
} }

View File

@ -71,7 +71,9 @@
</div> </div>
<div class="ds-contextmenu__divider" id="contextmenu-delete--separator"> <div class="ds-contextmenu__divider" id="contextmenu-delete--separator">
<li> <li>
<button type="button"><fa-icon class="contextmenu__icon" [icon]="faTrashAlt"></fa-icon>Eliminar</button> <button type="button" (click)="deleteSurvey()">
<fa-icon class="contextmenu__icon" [icon]="faTrashAlt"></fa-icon>Eliminar
</button>
</li> </li>
</div> </div>
</ul> </ul>
@ -82,6 +84,7 @@
*ngFor="let encuesta of encuestas; trackBy: trackId" *ngFor="let encuesta of encuestas; trackBy: trackId"
(dblclick)="openSurvey($event)" (dblclick)="openSurvey($event)"
(click)="selectSurvey($event)" (click)="selectSurvey($event)"
[hidden]="encuesta.estado == 'DELETED'"
[attr.data-id]="encuesta.id" [attr.data-id]="encuesta.id"
> >
<div class="entity-header"> <div class="entity-header">
@ -194,7 +197,7 @@
<fa-icon icon="pencil-alt"></fa-icon> <fa-icon icon="pencil-alt"></fa-icon>
<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)="delete(encuesta)" class="btn btn-danger btn-sm" data-cy="entityDeleteButton"> <button type="submit" (click)="delete(encuesta)" class="btn 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

@ -66,6 +66,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
categoriasSharedCollection: ICategoria[] = []; categoriasSharedCollection: ICategoria[] = [];
usuarioExtrasSharedCollection: IUsuarioExtra[] = []; usuarioExtrasSharedCollection: IUsuarioExtra[] = [];
selectedSurvey: number | null = null;
encuestaencontrada: IEncuesta | null = null;
editForm = this.fb.group({ editForm = this.fb.group({
id: [], id: [],
nombre: [null, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]], nombre: [null, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]],
@ -178,6 +181,49 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
}); });
} }
deleteSurvey(): void {
if (this.selectedSurvey != null) {
this.getEncuesta(this.selectedSurvey)
.pipe(
finalize(() => {
const modalRef = this.modalService.open(EncuestaDeleteDialogComponent, { size: 'lg', backdrop: 'static' });
modalRef.componentInstance.encuesta = this.encuestaencontrada;
modalRef.closed.subscribe(reason => {
if (reason === 'deleted') {
this.loadAll();
}
});
})
)
.subscribe(data => {
console.log(data);
this.encuestaencontrada = data;
});
/*const modalRef = this.modalService.open(EncuestaDeleteDialogComponent, { size: 'lg', backdrop: 'static' });
modalRef.componentInstance.encuesta = this.getEncuesta(this.selectedSurvey)
.pipe(finalize(() =>
modalRef.closed.subscribe(reason => {
if (reason === 'deleted') {
this.loadAll();
}
})
))
.subscribe(data=> {
console.log(data);
//this.encuestaencontrada = data;
});
*/
// unsubscribe not needed because closed completes on modal close
}
}
getEncuesta(id: number) {
return this.encuestaService.findEncuesta(id);
}
previousState(): void { previousState(): void {
window.history.back(); window.history.back();
} }
@ -350,6 +396,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
} else if ((event.target as HTMLElement).classList.contains('ds-list--entity')) { } else if ((event.target as HTMLElement).classList.contains('ds-list--entity')) {
event.target.classList.add('active'); event.target.classList.add('active');
document.getElementById('contextmenu-create--separator')!.style.display = 'none'; document.getElementById('contextmenu-create--separator')!.style.display = 'none';
this.selectedSurvey = Number(event.target.dataset.id);
//this.selectedSurvey = event.target.dataset.encuesta;
} }
document.getElementById('contextmenu')!.style.top = event.layerY + 'px'; document.getElementById('contextmenu')!.style.top = event.layerY + 'px';

View File

@ -45,6 +45,15 @@ export class EncuestaService {
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res))); .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
} }
findEncuesta(id: number): Observable<IEncuesta> {
return this.http.get<IEncuesta>(`${this.resourceUrl}/${id}`);
}
deleteEncuesta(encuesta: IEncuesta): Observable<EntityResponseType> {
//const copy = this.convertDateFromClient(encuesta);
return this.http.put<IEncuesta>(`${this.resourceUrl}/${getEncuestaIdentifier(encuesta) as number}`, encuesta, { observe: 'response' });
}
query(req?: any): Observable<EntityArrayResponseType> { query(req?: any): Observable<EntityArrayResponseType> {
const options = createRequestOption(req); const options = createRequestOption(req);
return this.http return this.http

View File

@ -136,7 +136,7 @@
"value": "Valor" "value": "Valor"
}, },
"delete": { "delete": {
"title": "Confirmar operación de borrado" "title": "Confirmar de operación"
}, },
"validation": { "validation": {
"required": "Este campo es obligatorio.", "required": "Este campo es obligatorio.",