Merge pull request #77 from Quantum-P3/fix/edit-duplicate-survey

Add duplicate functionality in context menu
This commit is contained in:
Eduardo Quiros 2021-07-26 22:59:53 +00:00 committed by GitHub
commit 1ade085444
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 141 additions and 87 deletions

View File

@ -2,6 +2,7 @@ package org.datasurvey.web.rest;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@ -306,4 +307,71 @@ public class EncuestaResource {
mailService.sendEncuestaDeleted(encuesta.getUsuarioExtra());
return ResponseEntity.noContent().build();
}
@GetMapping("/encuestas/duplicate/{id}")
public ResponseEntity<Encuesta> getAllEncuestas(@PathVariable Long id) {
Optional<Encuesta> encuesta = encuestaService.findOne(id);
Encuesta newEncuesta = new Encuesta();
if (encuesta.isPresent()) {
// Encuesta
newEncuesta.setNombre(encuesta.get().getNombre());
newEncuesta.setDescripcion(encuesta.get().getDescripcion());
newEncuesta.setFechaCreacion(ZonedDateTime.now());
newEncuesta.setCalificacion(5d);
newEncuesta.setAcceso(encuesta.get().getAcceso());
newEncuesta.setEstado(encuesta.get().getEstado());
newEncuesta.setCategoria(encuesta.get().getCategoria());
newEncuesta.setUsuarioExtra(encuesta.get().getUsuarioExtra());
Encuesta encuestaCreated = encuestaService.save(newEncuesta);
// Preguntas cerradas
List<EPreguntaCerrada> preguntasCerradas = ePreguntaCerradaService.findAll();
for (EPreguntaCerrada ePreguntaCerrada : preguntasCerradas) {
if (ePreguntaCerrada.getEncuesta().getId().equals(id)) {
EPreguntaCerrada newEPreguntaCerrada = new EPreguntaCerrada();
newEPreguntaCerrada.setNombre(ePreguntaCerrada.getNombre());
newEPreguntaCerrada.setTipo(ePreguntaCerrada.getTipo());
newEPreguntaCerrada.setOpcional(ePreguntaCerrada.getOpcional());
newEPreguntaCerrada.setOrden(ePreguntaCerrada.getOrden());
newEPreguntaCerrada.setEncuesta(encuestaCreated);
ePreguntaCerradaService.save(newEPreguntaCerrada);
// Opciones de preguntas cerradas
List<EPreguntaCerradaOpcion> opciones = ePreguntaCerradaOpcionService.findAll();
for (EPreguntaCerradaOpcion ePreguntaCerradaOpcion : opciones) {
if (ePreguntaCerradaOpcion.getEPreguntaCerrada().getId().equals(ePreguntaCerrada.getId())) {
EPreguntaCerradaOpcion newEPreguntaCerradaOpcion = new EPreguntaCerradaOpcion();
newEPreguntaCerradaOpcion.setNombre(ePreguntaCerradaOpcion.getNombre());
newEPreguntaCerradaOpcion.setOrden(ePreguntaCerradaOpcion.getOrden());
newEPreguntaCerradaOpcion.setCantidad(0);
newEPreguntaCerradaOpcion.setEPreguntaCerrada(newEPreguntaCerrada);
ePreguntaCerradaOpcionService.save(newEPreguntaCerradaOpcion);
}
}
}
}
// Preguntas abiertas
List<EPreguntaAbierta> preguntasAbiertas = ePreguntaAbiertaService.findAll();
for (EPreguntaAbierta ePreguntaAbierta : preguntasAbiertas) {
if (ePreguntaAbierta.getEncuesta().getId().equals(id)) {
EPreguntaAbierta newEPreguntaAbierta = new EPreguntaAbierta();
newEPreguntaAbierta.setNombre(ePreguntaAbierta.getNombre());
newEPreguntaAbierta.setOpcional(ePreguntaAbierta.getOpcional());
newEPreguntaAbierta.setOrden(ePreguntaAbierta.getOrden());
newEPreguntaAbierta.setEncuesta(encuestaCreated);
ePreguntaAbiertaService.save(newEPreguntaAbierta);
}
}
return ResponseEntity.ok().body(encuestaCreated);
}
return ResponseEntity.ok().body(null);
}
}

View File

@ -1,6 +1,9 @@
<div>
<h2 id="page-heading" data-cy="CategoriaHeading">
<span jhiTranslate="dataSurveyApp.categoria.home.title">Categorias</span>
<div>
<span class="ds-title" jhiTranslate="dataSurveyApp.categoria.home.title">Categorias</span>
<p class="ds-subtitle">Categorice las encuestas de la aplicación</p>
</div>
<div class="d-flex justify-content-end">
<button

View File

@ -96,23 +96,19 @@
</li>
</div>
<div class="ds-contextmenu__divider ds-contextmenu__divider--separator-bottom" id="contextmenu-edit--separator">
<li class="d-justify justify-content-start">
<button type="button" id="contextmenu-edit"><fa-icon class="contextmenu__icon" [icon]="faEdit"></fa-icon>Editar</button>
<li class="d-justify justify-content-start" id="contextmenu-edit">
<button type="button" (click)="openSurvey(null)"><fa-icon class="contextmenu__icon" [icon]="faEdit"></fa-icon>Editar</button>
</li>
<li>
<button type="button" (click)="openPreview()" id="contextmenu-preview">
<fa-icon class="contextmenu__icon" [icon]="faPollH"></fa-icon>Ver Vista Previa
<li id="contextmenu-preview">
<button type="button" (click)="openPreview()">
<fa-icon class="contextmenu__icon" [icon]="faPollH"></fa-icon>Ver vista previa
</button>
</li>
<li>
<button
type="button"
id="contextmenu-publish"
type="button"
(click)="publish()"
data-toggle="modal"
data-target="#publicarEncuesta"
>
<li id="contextmenu-duplicate">
<button type="button" (click)="duplicateSurvey()"><fa-icon class="contextmenu__icon" [icon]="faCopy"></fa-icon>Duplicar</button>
</li>
<li id="contextmenu-publish">
<button type="button" (click)="publish()" data-toggle="modal" data-target="#publicarEncuesta">
<!--Agarrar el id de la encuesta -->
<fa-icon class="contextmenu__icon" [icon]="faUpload"></fa-icon>Publicar
</button>

View File

@ -100,7 +100,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
});
createAnother: Boolean = false;
selectedSurveyId: Number | null = null;
selectedSurveyId: number | null = null;
constructor(
protected encuestaService: EncuestaService,
@ -253,8 +253,8 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
}
deleteSurvey(): void {
if (this.idEncuesta != null) {
this.getEncuesta(this.idEncuesta)
if (this.selectedSurveyId != null) {
this.getEncuesta(this.selectedSurveyId)
.pipe(
finalize(() => {
const modalRef = this.modalService.open(EncuestaDeleteDialogComponent, { size: 'lg', backdrop: 'static' });
@ -423,8 +423,13 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
}
openSurvey(event: any): void {
const surveyId = event.target.getAttribute('data-id');
this.router.navigate(['/encuesta', surveyId, 'edit']);
if (event === null) {
const surveyId = this.selectedSurveyId;
this.router.navigate(['/encuesta', surveyId, 'edit']);
} else {
const surveyId = event.target.dataset.id;
this.router.navigate(['/encuesta', surveyId, 'edit']);
}
}
selectSurvey(event: any): void {
@ -438,18 +443,10 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
}
openPreview() {
const surveyId = this.idEncuesta;
const surveyId = this.selectedSurveyId;
this.router.navigate(['/encuesta', surveyId, 'preview']);
}
counter(i: number) {
return new Array(i);
}
testMe(something: any) {
return 5 - something;
}
async openContextMenu(event: any): Promise<void> {
if (event.type === 'contextmenu') {
event.preventDefault();
@ -457,22 +454,6 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
document.querySelectorAll('.ds-list--entity').forEach(e => {
e.classList.remove('active');
});
this.selectedSurveyId = Number(event.target.dataset.id);
let res = await this.encuestaService.find(this.selectedSurveyId).toPromise();
this.selectedSurvey = res.body;
this.isPublished = this.selectedSurvey!.estado === 'DRAFT'; // QUE SE LE MUESTRE CUANDO ESTE EN DRAFT
// }
document.getElementById('contextmenu-create--separator')!.style.display = 'block';
document.getElementById('contextmenu-edit--separator')!.style.display = 'block';
document.getElementById('contextmenu-delete--separator')!.style.display = 'block';
document.getElementById('contextmenu-edit')!.style.display = 'block';
if (this.isPublished) {
document.getElementById('contextmenu-publish')!.style.display = 'block'; //cambiar
}
document.getElementById('contextmenu-preview')!.style.display = 'block';
//document.getElementById('contextmenu-share')!.style.display = 'block';
if ((event.target as HTMLElement).classList.contains('ds-list')) {
document.getElementById('contextmenu-create--separator')!.style.display = 'block';
@ -480,7 +461,6 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
document.getElementById('contextmenu-delete--separator')!.style.display = 'none';
} else if ((event.target as HTMLElement).classList.contains('ds-list--entity')) {
this.selectedSurveyId = Number(event.target.dataset.id);
this.idEncuesta = Number(event.target.dataset.id);
event.target.classList.add('active');
let res = await this.encuestaService.find(this.selectedSurveyId).toPromise();
@ -495,8 +475,10 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
if (!this.isPublished) {
document.getElementById('contextmenu-publish')!.style.display = 'block';
document.getElementById('contextmenu-duplicate')!.style.display = 'block';
} else {
document.getElementById('contextmenu-publish')!.style.display = 'none';
document.getElementById('contextmenu-duplicate')!.style.display = 'none';
}
// document.getElementById('contextmenu-share')!.style.display = 'block';
document.getElementById('contextmenu-create--separator')!.style.display = 'none';
@ -521,4 +503,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
}
});
}
async duplicateSurvey(): Promise<void> {
const res = await this.encuestaService.duplicate(this.selectedSurveyId!).toPromise();
this.loadAll();
}
}

View File

@ -61,6 +61,10 @@ export class EncuestaService {
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
}
duplicate(id: number): Observable<EntityResponseType> {
return this.http.get<any>(`${this.resourceUrl}/duplicate/${id}`, { observe: 'response' });
}
publishEncuesta(encuesta: IEncuesta): Observable<EntityResponseType> {
//const copy = this.convertDateFromClient(encuesta);
return this.http.put<IEncuesta>(`${this.resourceUrl}/publish/${getEncuestaIdentifier(encuesta) as number}`, encuesta, {

View File

@ -9,6 +9,7 @@
data-target="#verParametros"
(click)="loadAplicationParameters()"
></fa-icon>
&nbsp;&nbsp;<fa-icon class="ds-info--icon" [icon]="faEye" (click)="openPreview()"></fa-icon>
</div>
<p class="ds-subtitle">Creada el día {{ encuesta!.fechaCreacion | formatShortDatetime | lowercase }}</p>
@ -31,15 +32,6 @@
>
<fa-icon icon="sync" [icon]="faPlus"></fa-icon>&nbsp;&nbsp;<span>Crear pregunta</span>
</button>
<button type="button" class="ds-btn ds-btn--success" (click)="openPreview()" [disabled]="isLoading">
<fa-icon [icon]="faPollH"></fa-icon>&nbsp;&nbsp;<span>Ver vista previa</span>
</button>
<ng-container *ngIf="encuesta!.estado === 'DRAFT'">
<button type="button" class="ds-btn ds-btn--primary" (click)="publishSurvey()">Publicar encuesta</button>
</ng-container>
<ng-container *ngIf="encuesta!.estado === 'ACTIVE'">
<button type="button" class="ds-btn ds-btn--danger" (click)="finishSurvey()">Finalizar encuesta</button>
</ng-container>
</div>
</h2>

View File

@ -25,7 +25,7 @@ import { IEPreguntaCerrada } from 'app/entities/e-pregunta-cerrada/e-pregunta-ce
import { EPreguntaCerradaService } from 'app/entities/e-pregunta-cerrada/service/e-pregunta-cerrada.service';
import { EPreguntaCerradaDeleteDialogComponent } from 'app/entities/e-pregunta-cerrada/delete/e-pregunta-cerrada-delete-dialog.component';
import { faTimes, faPlus, faQuestion, faPollH } from '@fortawesome/free-solid-svg-icons';
import { faTimes, faPlus, faQuestion, faPollH, faEye } from '@fortawesome/free-solid-svg-icons';
import { PreguntaCerradaTipo } from 'app/entities/enumerations/pregunta-cerrada-tipo.model';
import { EncuestaDeleteQuestionDialogComponent } from '../encuesta-delete-question-dialog/encuesta-delete-question-dialog.component';
import { EncuestaDeleteOptionDialogComponent } from '../encuesta-delete-option-dialog/encuesta-delete-option-dialog.component';
@ -43,6 +43,7 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
faPlus = faPlus;
faPollH = faPollH;
faQuestion = faQuestion;
faEye = faEye;
isSaving = false;
isSavingQuestion = false;

View File

@ -1,6 +1,9 @@
<div>
<h2 id="page-heading" data-cy="UsuarioExtraHeading">
<span jhiTranslate="dataSurveyApp.usuarioExtra.home.title">Usuarios</span>
<div>
<span class="ds-title" jhiTranslate="dataSurveyApp.usuarioExtra.home.title">Usuarios</span>
<p class="ds-subtitle">Administre los usuarios registrados en la aplicación</p>
</div>
<div class="d-flex justify-content-end">
<button id="jh-create-entity" data-cy="entityCreateButton" class="ds-btn ds-btn--primary" [routerLink]="['/usuario-extra/new']">

View File

@ -16,24 +16,24 @@ export interface ChildrenItems {
}
export const ADMIN_ROUTES: RouteInfo[] = [
{
path: '/dashboard',
title: 'Dashboard',
type: 'link',
icontype: 'nc-icon nc-chart-bar-32',
},
// {
// path: '/dashboard',
// title: 'Dashboard',
// type: 'link',
// icontype: 'nc-icon nc-chart-bar-32',
// },
{
path: '/encuesta',
title: 'Encuestas',
type: 'link',
icontype: 'nc-icon nc-paper',
},
{
path: '/plantilla',
title: 'Plantillas',
type: 'link',
icontype: 'nc-icon nc-album-2',
},
// {
// path: '/plantilla',
// title: 'Plantillas',
// type: 'link',
// icontype: 'nc-icon nc-album-2',
// },
{
path: '/categoria',
title: 'Categorías',
@ -61,22 +61,22 @@ export const USER_ROUTES: RouteInfo[] = [
type: 'link',
icontype: 'nc-icon nc-paper',
},
{
path: '/tienda',
title: 'Tienda',
type: 'link',
icontype: 'nc-icon nc-cart-simple',
},
{
path: '/plantilla',
title: 'Plantillas',
type: 'link',
icontype: 'nc-icon nc-album-2',
},
{
path: '/colaboraciones',
title: 'Colaboraciones',
type: 'link',
icontype: 'nc-icon nc-world-2',
},
// {
// path: '/tienda',
// title: 'Tienda',
// type: 'link',
// icontype: 'nc-icon nc-cart-simple',
// },
// {
// path: '/plantilla',
// title: 'Plantillas',
// type: 'link',
// icontype: 'nc-icon nc-album-2',
// },
// {
// path: '/colaboraciones',
// title: 'Colaboraciones',
// type: 'link',
// icontype: 'nc-icon nc-world-2',
// },
];