diff --git a/src/main/java/org/datasurvey/service/MailService.java b/src/main/java/org/datasurvey/service/MailService.java index a14a8e8..23ee9fe 100644 --- a/src/main/java/org/datasurvey/service/MailService.java +++ b/src/main/java/org/datasurvey/service/MailService.java @@ -158,4 +158,9 @@ public class MailService { log.debug("Sending reactivated account mail to '{}'", user.getUser().getEmail()); sendEmailFromTemplate(user.getUser(), "mail/encuestaPublicaEmail", "email.public.title"); } + + public void sendEncuestaDeleted(UsuarioExtra user) { + log.debug("Sending encuesta deletion notification mail to '{}'", user.getUser().getEmail()); + sendEmailFromTemplate(user.getUser(), "mail/encuestaDeletedEmail", "email.encuestaDeleted.title"); + } } diff --git a/src/main/java/org/datasurvey/web/rest/EncuestaResource.java b/src/main/java/org/datasurvey/web/rest/EncuestaResource.java index e3e4b11..e7825d3 100644 --- a/src/main/java/org/datasurvey/web/rest/EncuestaResource.java +++ b/src/main/java/org/datasurvey/web/rest/EncuestaResource.java @@ -125,6 +125,31 @@ public class EncuestaResource { Encuesta result = encuestaService.save(encuesta); + return ResponseEntity + .ok() + .headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, encuesta.getId().toString())) + .body(result); + } + + @PutMapping("/encuestas/publish/{id}") + public ResponseEntity publishEncuesta( + @PathVariable(value = "id", required = false) final Long id, + @Valid @RequestBody Encuesta encuesta + ) throws URISyntaxException { + log.debug("REST request to update Encuesta : {}, {}", id, encuesta); + if (encuesta.getId() == null) { + throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); + } + if (!Objects.equals(id, encuesta.getId())) { + throw new BadRequestAlertException("Invalid ID", ENTITY_NAME, "idinvalid"); + } + + if (!encuestaRepository.existsById(id)) { + throw new BadRequestAlertException("Entity not found", ENTITY_NAME, "idnotfound"); + } + + Encuesta result = encuestaService.save(encuesta); + if (result.getAcceso().equals(AccesoEncuesta.PRIVATE)) { mailService.sendPublishedPrivateMail(result.getUsuarioExtra(), result.getContrasenna()); } else { @@ -274,4 +299,11 @@ public class EncuestaResource { .headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, id.toString())) .build(); } + + @DeleteMapping("encuestas/notify/{id}") + public ResponseEntity notifyEncuestaDeleted(@PathVariable Long id, @Valid @RequestBody Encuesta encuesta) { + log.debug("REST request to notify {} of deleted Encuesta", encuesta.getUsuarioExtra().getUser().getEmail()); + mailService.sendEncuestaDeleted(encuesta.getUsuarioExtra()); + return ResponseEntity.noContent().build(); + } } diff --git a/src/main/resources/i18n/messages_es.properties b/src/main/resources/i18n/messages_es.properties index cab4f1d..dafa1db 100644 --- a/src/main/resources/i18n/messages_es.properties +++ b/src/main/resources/i18n/messages_es.properties @@ -52,3 +52,9 @@ email.private.title=Su encuesta ha sido publicada de manera privada email.private.greeting=¡Felicidades {0}! email.private.text1=Su encuesta ha sdo publicada de manera privada. Su contraseña de acceso es: {0} email.private.text2=Saludos, + +#DeletedEncuesta +email.encuestaDeleted.title=Su encuesta ha sido eliminada +email.encuestaDeleted.greeting=Estimado {0} +email.encuestaDeleted.text1=Su encuesta ha sido eliminada por un administrador +email.encuestaDeleted.text2=Saludos, diff --git a/src/main/resources/templates/mail/activationEmail.html b/src/main/resources/templates/mail/activationEmail.html index 673edc0..34a97d2 100644 --- a/src/main/resources/templates/mail/activationEmail.html +++ b/src/main/resources/templates/mail/activationEmail.html @@ -244,7 +244,7 @@ diff --git a/src/main/resources/templates/mail/creationEmail.html b/src/main/resources/templates/mail/creationEmail.html index e46861a..70fe68f 100644 --- a/src/main/resources/templates/mail/creationEmail.html +++ b/src/main/resources/templates/mail/creationEmail.html @@ -244,7 +244,7 @@ diff --git a/src/main/resources/templates/mail/encuestaDeletedEmail.html b/src/main/resources/templates/mail/encuestaDeletedEmail.html new file mode 100644 index 0000000..207f19a --- /dev/null +++ b/src/main/resources/templates/mail/encuestaDeletedEmail.html @@ -0,0 +1,310 @@ + + + + + + + + + + + Encuesta Eliminada + + + + + + + +
+
+ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌  +
+ +
+ + diff --git a/src/main/resources/templates/mail/encuestaPrivadaEmail.html b/src/main/resources/templates/mail/encuestaPrivadaEmail.html index b017e8b..4acd28a 100644 --- a/src/main/resources/templates/mail/encuestaPrivadaEmail.html +++ b/src/main/resources/templates/mail/encuestaPrivadaEmail.html @@ -244,7 +244,7 @@ diff --git a/src/main/resources/templates/mail/encuestaPublicaEmail.html b/src/main/resources/templates/mail/encuestaPublicaEmail.html index f4a1dda..67a14a9 100644 --- a/src/main/resources/templates/mail/encuestaPublicaEmail.html +++ b/src/main/resources/templates/mail/encuestaPublicaEmail.html @@ -244,7 +244,7 @@ diff --git a/src/main/resources/templates/mail/passwordResetEmail.html b/src/main/resources/templates/mail/passwordResetEmail.html index 1742a3f..8c6b549 100644 --- a/src/main/resources/templates/mail/passwordResetEmail.html +++ b/src/main/resources/templates/mail/passwordResetEmail.html @@ -244,7 +244,7 @@ diff --git a/src/main/resources/templates/mail/passwordRestoredEmail.html b/src/main/resources/templates/mail/passwordRestoredEmail.html index 6dcebd1..5374e25 100644 --- a/src/main/resources/templates/mail/passwordRestoredEmail.html +++ b/src/main/resources/templates/mail/passwordRestoredEmail.html @@ -244,7 +244,7 @@ diff --git a/src/main/resources/templates/mail/reactivatedAccountEmail.html b/src/main/resources/templates/mail/reactivatedAccountEmail.html index 8226a4d..f0b0767 100644 --- a/src/main/resources/templates/mail/reactivatedAccountEmail.html +++ b/src/main/resources/templates/mail/reactivatedAccountEmail.html @@ -244,7 +244,7 @@ diff --git a/src/main/resources/templates/mail/suspendedAccountEmail.html b/src/main/resources/templates/mail/suspendedAccountEmail.html index 5cc146b..217aedf 100644 --- a/src/main/resources/templates/mail/suspendedAccountEmail.html +++ b/src/main/resources/templates/mail/suspendedAccountEmail.html @@ -244,7 +244,7 @@ diff --git a/src/main/webapp/app/account/settings/settings.component.html b/src/main/webapp/app/account/settings/settings.component.html index 738b1c0..a840991 100644 --- a/src/main/webapp/app/account/settings/settings.component.html +++ b/src/main/webapp/app/account/settings/settings.component.html @@ -1,172 +1,3 @@ - -
diff --git a/src/main/webapp/app/entities/categoria/delete/categoria-delete-dialog.component.html b/src/main/webapp/app/entities/categoria/delete/categoria-delete-dialog.component.html index ceb258b..d1ad4e4 100644 --- a/src/main/webapp/app/entities/categoria/delete/categoria-delete-dialog.component.html +++ b/src/main/webapp/app/entities/categoria/delete/categoria-delete-dialog.component.html @@ -2,24 +2,25 @@ diff --git a/src/main/webapp/app/entities/categoria/delete/categoria-delete-dialog.component.ts b/src/main/webapp/app/entities/categoria/delete/categoria-delete-dialog.component.ts index df89d70..8d665e3 100644 --- a/src/main/webapp/app/entities/categoria/delete/categoria-delete-dialog.component.ts +++ b/src/main/webapp/app/entities/categoria/delete/categoria-delete-dialog.component.ts @@ -10,10 +10,13 @@ import { finalize, map } from 'rxjs/operators'; import { Categoria, ICategoria } from '../categoria.model'; import { CategoriaService } from '../service/categoria.service'; +import { faExchangeAlt } from '@fortawesome/free-solid-svg-icons'; @Component({ templateUrl: './categoria-delete-dialog.component.html', }) export class CategoriaDeleteDialogComponent { + faExchangeAlt = faExchangeAlt; + categoria?: ICategoria; encuestas?: IEncuesta[]; encuestasFiltradas?: IEncuesta[]; diff --git a/src/main/webapp/app/entities/categoria/list/categoria.component.html b/src/main/webapp/app/entities/categoria/list/categoria.component.html index 7fb1898..a268f84 100644 --- a/src/main/webapp/app/entities/categoria/list/categoria.component.html +++ b/src/main/webapp/app/entities/categoria/list/categoria.component.html @@ -64,7 +64,8 @@ Edit -
diff --git a/src/main/webapp/app/entities/categoria/list/categoria.component.ts b/src/main/webapp/app/entities/categoria/list/categoria.component.ts index 10caf63..869e3c8 100644 --- a/src/main/webapp/app/entities/categoria/list/categoria.component.ts +++ b/src/main/webapp/app/entities/categoria/list/categoria.component.ts @@ -6,11 +6,15 @@ import { ICategoria } from '../categoria.model'; import { CategoriaService } from '../service/categoria.service'; import { CategoriaDeleteDialogComponent } from '../delete/categoria-delete-dialog.component'; +import { faExchangeAlt } from '@fortawesome/free-solid-svg-icons'; + @Component({ selector: 'jhi-categoria', templateUrl: './categoria.component.html', }) export class CategoriaComponent implements OnInit { + faExchangeAlt = faExchangeAlt; + categorias?: ICategoria[]; isLoading = false; public searchString: string; diff --git a/src/main/webapp/app/entities/categoria/update/categoria-update.component.html b/src/main/webapp/app/entities/categoria/update/categoria-update.component.html index 827ff29..0ad506f 100644 --- a/src/main/webapp/app/entities/categoria/update/categoria-update.component.html +++ b/src/main/webapp/app/entities/categoria/update/categoria-update.component.html @@ -46,10 +46,10 @@ type="button" id="cancel-save" data-cy="entityCreateCancelButton" - class="btn btn-secondary ds-btn ds-btn-secondary" + class="ds-btn ds-btn--secondary" (click)="previousState()" > -  Cancel +   Cancel diff --git a/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.html b/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.html index a21389e..8fd4065 100644 --- a/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.html +++ b/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.html @@ -6,9 +6,13 @@
diff --git a/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.ts b/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.ts index 713e0bb..1476438 100644 --- a/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.ts +++ b/src/main/webapp/app/entities/encuesta/delete/encuesta-delete-dialog.component.ts @@ -3,12 +3,14 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { IEncuesta } from '../encuesta.model'; import { EncuestaService } from '../service/encuesta.service'; import { EstadoEncuesta } from 'app/entities/enumerations/estado-encuesta.model'; +import { IUsuarioExtra } from 'app/entities/usuario-extra/usuario-extra.model'; @Component({ templateUrl: './encuesta-delete-dialog.component.html', }) export class EncuestaDeleteDialogComponent { encuesta?: IEncuesta; + usuarioExtra?: IUsuarioExtra; constructor(protected encuestaService: EncuestaService, protected activeModal: NgbActiveModal) {} @@ -16,10 +18,11 @@ export class EncuestaDeleteDialogComponent { this.activeModal.dismiss(); } - confirmDelete(encuest: IEncuesta): void { - encuest.estado = EstadoEncuesta.DELETED; - this.encuestaService.deleteEncuesta(encuest).subscribe(() => { + confirmDelete(encuesta: IEncuesta): void { + encuesta.estado = EstadoEncuesta.DELETED; + this.encuestaService.deleteEncuesta(encuesta).subscribe(() => { this.activeModal.close('deleted'); }); + this.encuestaService.deletedNotification(encuesta); } } diff --git a/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.html b/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.html index 6873d16..0b5bbed 100644 --- a/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.html +++ b/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.html @@ -1,4 +1,4 @@ -
+ + +
+
+

+

Vista previa de {{ encuesta!.nombre }}

+

Creada el día {{ encuesta!.fechaCreacion | formatShortDatetime | lowercase }}

+
+ + + + +
+

+ + + + + + +
+ No se encontraron preguntas +
+ +
+
+
+
+
+ {{ i + 1 }}. {{ ePregunta.nombre }} +
+
+ Pregunta de respuesta {{ 'dataSurveyApp.PreguntaCerradaTipo.SINGLE' | translate | lowercase }} + {{ ePregunta.opcional ? '(opcional)' : '' }} + Pregunta de respuesta {{ 'dataSurveyApp.PreguntaCerradaTipo.MULTIPLE' | translate | lowercase }} + {{ ePregunta.opcional ? '(opcional)' : '' }} + Pregunta de respuesta abierta {{ ePregunta.opcional ? '(opcional)' : '' }} +
+ + + + +
+
+ + + +
+
+ + + +
+
+
+
+
+
+
+ +
+
+
+
+
+

Cantidad de preguntas: {{ ePreguntas?.length }}

+ +
+
Acceso
+
+ - + {{ encuesta.acceso }} +
+
+
+
Contrasenna
+
+ - {{ encuesta.contrasenna }} +
+
+
+
Estado
+
+ - {{ encuesta.estado }} +
+
+
+
Categoria
+
+ - {{ encuesta.categoria?.nombre }} +
+
+
+
Fecha Publicacion
+
+ - + {{ + encuesta.fechaPublicacion === undefined ? 'Sin publicar' : (encuesta.fechaFinalizada | formatShortDatetime | lowercase) + }} +
+
+
+
Fecha Finalizar
+
+ + - + {{ + encuesta.fechaFinalizar === undefined + ? 'Sin fecha de finalización' + : (encuesta.fechaFinalizada | formatShortDatetime | lowercase) + }} +
+
+
+
Fecha Finalizada
+
+ + - + {{ + encuesta.fechaFinalizada === undefined ? 'Sin finalizar' : (encuesta.fechaFinalizada | formatShortDatetime | lowercase) + }} +
+
+
+
Calificacion
+
+ +
+
+
+
+
diff --git a/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.spec.ts b/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.tmpSpec.ts similarity index 100% rename from src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.spec.ts rename to src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.tmpSpec.ts diff --git a/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.ts b/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.ts index f04d377..7696f76 100644 --- a/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.ts +++ b/src/main/webapp/app/entities/encuesta/detail/encuesta-detail.component.ts @@ -1,20 +1,159 @@ import { Component, OnInit } from '@angular/core'; +import { HttpResponse } from '@angular/common/http'; +import { FormBuilder, Validators } from '@angular/forms'; import { ActivatedRoute } from '@angular/router'; +import { EstadoEncuesta } from 'app/entities/enumerations/estado-encuesta.model'; -import { IEncuesta } from '../encuesta.model'; +import { Observable } from 'rxjs'; +import { finalize, map } from 'rxjs/operators'; + +import * as dayjs from 'dayjs'; +import { DATE_TIME_FORMAT } from 'app/config/input.constants'; + +import { IEncuesta, Encuesta } from '../encuesta.model'; +import { EncuestaService } from '../service/encuesta.service'; +import { ICategoria } from 'app/entities/categoria/categoria.model'; +import { CategoriaService } from 'app/entities/categoria/service/categoria.service'; +import { IUsuarioExtra } from 'app/entities/usuario-extra/usuario-extra.model'; +import { UsuarioExtraService } from 'app/entities/usuario-extra/service/usuario-extra.service'; + +import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; +import { IEPreguntaCerrada } from 'app/entities/e-pregunta-cerrada/e-pregunta-cerrada.model'; +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 { IEPreguntaAbierta } from '../../e-pregunta-abierta/e-pregunta-abierta.model'; +import { EPreguntaCerrada } from '../../e-pregunta-cerrada/e-pregunta-cerrada.model'; +import { EPreguntaCerradaOpcion, IEPreguntaCerradaOpcion } from '../../e-pregunta-cerrada-opcion/e-pregunta-cerrada-opcion.model'; +import { EPreguntaAbiertaService } from '../../e-pregunta-abierta/service/e-pregunta-abierta.service'; +import { EPreguntaCerradaOpcionService } from '../../e-pregunta-cerrada-opcion/service/e-pregunta-cerrada-opcion.service'; +import { PreguntaCerradaTipo } from 'app/entities/enumerations/pregunta-cerrada-tipo.model'; + +import { faTimes, faPlus, faStar } from '@fortawesome/free-solid-svg-icons'; +import { EncuestaPublishDialogComponent } from '../encuesta-publish-dialog/encuesta-publish-dialog.component'; @Component({ selector: 'jhi-encuesta-detail', templateUrl: './encuesta-detail.component.html', }) export class EncuestaDetailComponent implements OnInit { + categoriasSharedCollection: ICategoria[] = []; + usuarioExtrasSharedCollection: IUsuarioExtra[] = []; + faTimes = faTimes; + faPlus = faPlus; + faStar = faStar; encuesta: IEncuesta | null = null; + isLoading = false; + successPublished = false; + ePreguntas?: any[]; + ePreguntasOpciones?: any[]; - constructor(protected activatedRoute: ActivatedRoute) {} + constructor( + protected activatedRoute: ActivatedRoute, + protected encuestaService: EncuestaService, + protected categoriaService: CategoriaService, + protected usuarioExtraService: UsuarioExtraService, + protected fb: FormBuilder, + protected modalService: NgbModal, + protected ePreguntaCerradaService: EPreguntaCerradaService, + protected ePreguntaCerradaOpcionService: EPreguntaCerradaOpcionService, + protected ePreguntaAbiertaService: EPreguntaAbiertaService + ) {} ngOnInit(): void { this.activatedRoute.data.subscribe(({ encuesta }) => { - this.encuesta = encuesta; + if (encuesta) { + this.encuesta = encuesta; + this.loadAll(); + } else { + this.previousState(); + } + }); + } + + ngAfterViewChecked(): void { + this.initListeners(); + } + + initListeners(): void { + const checkboxes = document.getElementsByClassName('ds-survey--checkbox'); + for (let i = 0; i < checkboxes.length; i++) { + checkboxes[i].addEventListener('click', e => { + if ((e.target as HTMLInputElement).checked) { + (e.target as HTMLElement).offsetParent!.classList.add('ds-survey--closed-option--active'); + } else { + (e.target as HTMLElement).offsetParent!.classList.remove('ds-survey--closed-option--active'); + } + }); + } + } + + trackId(index: number, item: IEPreguntaCerrada): number { + return item.id!; + } + + trackEPreguntaCerradaById(index: number, item: IEPreguntaCerrada): number { + return item.id!; + } + + trackCategoriaById(index: number, item: ICategoria): number { + return item.id!; + } + + trackUsuarioExtraById(index: number, item: IUsuarioExtra): number { + return item.id!; + } + + getEncuesta(id: number) { + return this.encuestaService.findEncuesta(id); + } + + loadAll(): void { + this.isLoading = true; + + this.encuestaService + .findQuestions(this.encuesta?.id!) + .pipe( + finalize(() => + this.encuestaService.findQuestionsOptions(this.encuesta?.id!).subscribe( + (res: any) => { + this.isLoading = false; + this.ePreguntasOpciones = res.body ?? []; + }, + () => { + this.isLoading = false; + } + ) + ) + ) + .subscribe( + (res: any) => { + this.isLoading = false; + this.ePreguntas = res.body ?? []; + }, + () => { + this.isLoading = false; + } + ); + + /* this.encuestaService.findQuestionsOptions(this.encuesta?.id!).subscribe( + (res: any) => { + this.isLoading = false; + this.ePreguntasOpciones = res.body ?? []; + }, + () => { + this.isLoading = false; + } + );*/ + } + publishSurvey(): void { + const modalRef = this.modalService.open(EncuestaPublishDialogComponent, { size: 'lg', backdrop: 'static' }); + modalRef.componentInstance.encuesta = this.encuesta; + // unsubscribe not needed because closed completes on modal close + modalRef.closed.subscribe(reason => { + if (reason === 'published') { + this.successPublished = true; + this.loadAll(); + } }); } diff --git a/src/main/webapp/app/entities/encuesta/encuesta-delete-option-dialog/encuesta-delete-option-dialog.component.html b/src/main/webapp/app/entities/encuesta/encuesta-delete-option-dialog/encuesta-delete-option-dialog.component.html index 40356a0..2845052 100644 --- a/src/main/webapp/app/entities/encuesta/encuesta-delete-option-dialog/encuesta-delete-option-dialog.component.html +++ b/src/main/webapp/app/entities/encuesta/encuesta-delete-option-dialog/encuesta-delete-option-dialog.component.html @@ -1,24 +1,23 @@ -
+ diff --git a/src/main/webapp/app/entities/encuesta/encuesta-delete-question-dialog/encuesta-delete-question-dialog.component.html b/src/main/webapp/app/entities/encuesta/encuesta-delete-question-dialog/encuesta-delete-question-dialog.component.html index fd2c58c..d6eb620 100644 --- a/src/main/webapp/app/entities/encuesta/encuesta-delete-question-dialog/encuesta-delete-question-dialog.component.html +++ b/src/main/webapp/app/entities/encuesta/encuesta-delete-question-dialog/encuesta-delete-question-dialog.component.html @@ -1,24 +1,23 @@ - + diff --git a/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.html b/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.html index f150f0a..0baeb1f 100644 --- a/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.html +++ b/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.html @@ -44,8 +44,8 @@
  • @@ -207,92 +206,6 @@ >
  • - - @@ -301,7 +214,7 @@ Nombre - Fecha Creacion + Fecha Creación Acceso Estado Categoria @@ -323,7 +236,8 @@ {{ encuesta.estado }}
    - {{ encuesta.categoria?.nombre }} + + {{ encuesta.categoria?.nombre }}
    @@ -333,7 +247,7 @@
    - + --> - + -->
    - - - - diff --git a/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts b/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts index 510efd8..5d4bb97 100644 --- a/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts +++ b/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts @@ -37,6 +37,7 @@ import { faPlus, faStar, faUpload, + faPollH, } from '@fortawesome/free-solid-svg-icons'; import * as $ from 'jquery'; @@ -58,8 +59,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit { faPlus = faPlus; faStar = faStar; faUpload = faUpload; - isPublished = false; + isPublished: Boolean = false; successPublished = false; + faPollH = faPollH; account: Account | null = null; usuarioExtra: UsuarioExtra | null = null; estadoDeleted = EstadoEncuesta.DELETED; @@ -67,13 +69,13 @@ export class EncuestaComponent implements OnInit, AfterViewInit { encuestas?: IEncuesta[]; isLoading = false; selectedSurvey?: IEncuesta | null = null; + idEncuesta: number | null = null; isSaving = false; categoriasSharedCollection: ICategoria[] = []; usuarioExtrasSharedCollection: IUsuarioExtra[] = []; userSharedCollection: IUser[] = []; - selectedIdSurvey: number | null = null; encuestaencontrada: IEncuesta | null = null; public searchString: string; @@ -98,7 +100,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { }); createAnother: Boolean = false; - selectedSurveyId: Number = 0; + selectedSurveyId: Number | null = null; constructor( protected encuestaService: EncuestaService, @@ -124,7 +126,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { this.usuarioExtraService .retrieveAllPublicUsers() - .pipe(finalize(() => this.loadUserExtras())) + .pipe(finalize(() => this.loadPublicUser())) .subscribe(res => { this.userSharedCollection = res; }); @@ -251,8 +253,8 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } deleteSurvey(): void { - if (this.selectedIdSurvey != null) { - this.getEncuesta(this.selectedIdSurvey) + if (this.idEncuesta != null) { + this.getEncuesta(this.idEncuesta) .pipe( finalize(() => { const modalRef = this.modalService.open(EncuestaDeleteDialogComponent, { size: 'lg', backdrop: 'static' }); @@ -426,6 +428,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } selectSurvey(event: any): void { + this.idEncuesta = event.target.getAttribute('data-id'); document.querySelectorAll('.ds-list--entity').forEach(e => { e.classList.remove('active'); }); @@ -434,6 +437,11 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } } + openPreview() { + const surveyId = this.idEncuesta; + this.router.navigate(['/encuesta', surveyId, 'preview']); + } + counter(i: number) { return new Array(i); } @@ -443,38 +451,55 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } async openContextMenu(event: any): Promise { - document.querySelectorAll('.ds-list--entity').forEach(e => { - e.classList.remove('active'); - }); - if (event.type === 'contextmenu') { event.preventDefault(); - this.selectedSurveyId = event.target.dataset.id; + if (event.target === null) return; + 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'; - document.getElementById('contextmenu-duplicate')!.style.display = 'block'; - if (this.isPublished) { document.getElementById('contextmenu-publish')!.style.display = 'block'; //cambiar } - document.getElementById('contextmenu-share')!.style.display = 'block'; + 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'; document.getElementById('contextmenu-edit--separator')!.style.display = 'none'; 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'); - document.getElementById('contextmenu-create--separator')!.style.display = 'none'; - this.selectedIdSurvey = Number(event.target.dataset.id); - //this.selectedSurvey = event.target.dataset.encuesta; + let res = await this.encuestaService.find(this.selectedSurveyId).toPromise(); + this.selectedSurvey = res.body; + this.isPublished = this.selectedSurvey!.estado === 'ACTIVE' || this.selectedSurvey!.estado === 'FINISHED'; // QUE SE LE MUESTRE CUANDO ESTE EN DRAFT + + document.getElementById('contextmenu-create--separator')!.style.display = 'none'; + document.getElementById('contextmenu-edit--separator')!.style.display = 'block'; + document.getElementById('contextmenu-delete--separator')!.style.display = 'block'; + document.getElementById('contextmenu-edit')!.style.display = 'block'; + document.getElementById('contextmenu-preview')!.style.display = 'block'; + + if (!this.isPublished) { + document.getElementById('contextmenu-publish')!.style.display = 'block'; + } else { + document.getElementById('contextmenu-publish')!.style.display = 'none'; + } + // document.getElementById('contextmenu-share')!.style.display = 'block'; + document.getElementById('contextmenu-create--separator')!.style.display = 'none'; } document.getElementById('contextmenu')!.style.top = event.layerY + 'px'; diff --git a/src/main/webapp/app/entities/encuesta/route/encuesta-routing.module.ts b/src/main/webapp/app/entities/encuesta/route/encuesta-routing.module.ts index 56c3558..df9a23d 100644 --- a/src/main/webapp/app/entities/encuesta/route/encuesta-routing.module.ts +++ b/src/main/webapp/app/entities/encuesta/route/encuesta-routing.module.ts @@ -14,7 +14,7 @@ const encuestaRoute: Routes = [ canActivate: [UserRouteAccessService], }, { - path: ':id/view', + path: ':id/preview', component: EncuestaDetailComponent, resolve: { encuesta: EncuestaRoutingResolveService, diff --git a/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts b/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts index 430f8ea..3fb18da 100644 --- a/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts +++ b/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts @@ -45,6 +45,10 @@ export class EncuestaService { .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res))); } + findEncuesta(id: number): Observable { + return this.http.get(`${this.resourceUrl}/${id}`); + } + findQuestions(id: number): Observable { return this.http .get(`${this.resourceUrl}/preguntas/${id}`, { observe: 'response' }) @@ -57,8 +61,11 @@ export class EncuestaService { .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res))); } - findEncuesta(id: number): Observable { - return this.http.get(`${this.resourceUrl}/${id}`); + publishEncuesta(encuesta: IEncuesta): Observable { + //const copy = this.convertDateFromClient(encuesta); + return this.http.put(`${this.resourceUrl}/publish/${getEncuestaIdentifier(encuesta) as number}`, encuesta, { + observe: 'response', + }); } deleteEncuesta(encuesta: IEncuesta): Observable { @@ -77,6 +84,10 @@ export class EncuestaService { return this.http.delete(`${this.resourceUrl}/${id}`, { observe: 'response' }); } + deletedNotification(encuesta: IEncuesta): Observable> { + return this.http.delete(`${this.resourceUrl}/notify/${encuesta.id}`, { observe: 'response' }); + } + addEncuestaToCollectionIfMissing(encuestaCollection: IEncuesta[], ...encuestasToCheck: (IEncuesta | null | undefined)[]): IEncuesta[] { const encuestas: IEncuesta[] = encuestasToCheck.filter(isPresent); if (encuestas.length > 0) { diff --git a/src/main/webapp/app/entities/encuesta/update/encuesta-update.component.html b/src/main/webapp/app/entities/encuesta/update/encuesta-update.component.html index 8565e93..6eb2590 100644 --- a/src/main/webapp/app/entities/encuesta/update/encuesta-update.component.html +++ b/src/main/webapp/app/entities/encuesta/update/encuesta-update.component.html @@ -1,18 +1,29 @@

    -

    {{ encuesta!.nombre }}

    +
    +

    {{ encuesta!.nombre }}

    +    +
    +

    Creada el día {{ encuesta!.fechaCreacion | formatShortDatetime | lowercase }}

    + + @@ -33,146 +47,100 @@ -
    + + +
    -
    -
    -
    - {{ i + 1 }}. {{ ePregunta.nombre }} - -
    -
    - Pregunta de respuesta {{ 'dataSurveyApp.PreguntaCerradaTipo.SINGLE' | translate | lowercase }} - {{ ePregunta.opcional ? '(opcional)' : '' }} - Pregunta de respuesta {{ 'dataSurveyApp.PreguntaCerradaTipo.MULTIPLE' | translate | lowercase }} - {{ ePregunta.opcional ? '(opcional)' : '' }} - Pregunta de respuesta abierta {{ ePregunta.opcional ? '(opcional)' : '' }} -
    - - - - -
    - - - -
    -
    -
    -
    -
    + +

    Encuesta en progreso

    +

    No puede modificar la encuesta debido a que esta ya está en progreso.

    +
    + +

    Encuesta finalizada

    +

    No puede modificar la encuesta debido a que esta ya ha concluido.

    +
    + +

    Encuesta vacía

    +

    Inicie creando preguntas y opciones para su encuesta.

    +
    + +
    +
    +
    + {{ i + 1 }}. {{ ePregunta.nombre }} - Añadir opción
    - -
    - +
    + Pregunta de respuesta {{ 'dataSurveyApp.PreguntaCerradaTipo.SINGLE' | translate | lowercase }} + {{ ePregunta.opcional ? '(opcional)' : '' }} + Pregunta de respuesta {{ 'dataSurveyApp.PreguntaCerradaTipo.MULTIPLE' | translate | lowercase }} + {{ ePregunta.opcional ? '(opcional)' : '' }} + Pregunta de respuesta abierta {{ ePregunta.opcional ? '(opcional)' : '' }} +
    + + + + +
    + + + +
    +
    +
    +
    +
    + + Añadir opción +
    +
    +
    + +
    -
    +
    - -
    @@ -264,7 +232,7 @@ [formGroup]="editFormQuestion" >