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 7c205b5..f38805c 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/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/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..2c28a4d 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,14 @@ 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'); }); + if (encuesta.usuarioExtra != undefined) { + const userEmail = encuesta.usuarioExtra!.user!.login; + this.encuestaService.deletedNotification(userEmail!); + } } } diff --git a/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.ts b/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.ts index dae745d..b7202cb 100644 --- a/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.ts +++ b/src/main/webapp/app/entities/encuesta/encuesta-publish-dialog/encuesta-publish-dialog.component.ts @@ -21,7 +21,6 @@ export class EncuestaPublishDialogComponent implements OnInit { } confirmPublish(encuesta: IEncuesta): void { - debugger; if (encuesta.estado === 'DRAFT') { encuesta.estado = EstadoEncuesta.ACTIVE; } @@ -30,13 +29,12 @@ export class EncuestaPublishDialogComponent implements OnInit { encuesta.contrasenna = this.generatePassword(); } - this.encuestaService.update(encuesta).subscribe(() => { + this.encuestaService.publishEncuesta(encuesta).subscribe(() => { this.activeModal.close('published'); }); } generatePassword(): string { - debugger; const alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'; let password = ''; diff --git a/src/main/webapp/app/entities/encuesta/list/encuesta.component.html b/src/main/webapp/app/entities/encuesta/list/encuesta.component.html index 07a8a57..4dc3a46 100644 --- a/src/main/webapp/app/entities/encuesta/list/encuesta.component.html +++ b/src/main/webapp/app/entities/encuesta/list/encuesta.component.html @@ -85,14 +85,8 @@
    -
  • -
  • @@ -114,15 +108,14 @@ (click)="publish()" data-toggle="modal" data-target="#publicarEncuesta" - *ngIf="isPublished" > Publicar -
  • +
  • @@ -303,7 +296,7 @@ Nombre - Fecha Creacion + Fecha Creación Acceso Estado Categoria 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 160f426..21944a5 100644 --- a/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts +++ b/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts @@ -59,7 +59,7 @@ 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; @@ -75,7 +75,6 @@ export class EncuestaComponent implements OnInit, AfterViewInit { usuarioExtrasSharedCollection: IUsuarioExtra[] = []; userSharedCollection: IUser[] = []; - selectedIdSurvey: number | null = null; encuestaencontrada: IEncuesta | null = null; public searchString: string; @@ -100,7 +99,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { }); createAnother: Boolean = false; - selectedSurveyId: Number = 0; + selectedSurveyId: number | null = null; constructor( protected encuestaService: EncuestaService, @@ -126,7 +125,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { this.usuarioExtraService .retrieveAllPublicUsers() - .pipe(finalize(() => this.loadUserExtras())) + .pipe(finalize(() => this.loadPublicUser())) .subscribe(res => { this.userSharedCollection = res; }); @@ -253,8 +252,8 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } deleteSurvey(): void { - if (this.selectedIdSurvey != null) { - this.getEncuesta(this.selectedIdSurvey) + if (this.selectedSurveyId != null) { + this.getEncuesta(this.selectedSurveyId) .pipe( finalize(() => { const modalRef = this.modalService.open(EncuestaDeleteDialogComponent, { size: 'lg', backdrop: 'static' }); @@ -450,13 +449,12 @@ 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'); + }); let res = await this.encuestaService.find(this.selectedSurveyId).toPromise(); this.selectedSurvey = res.body; @@ -473,14 +471,31 @@ export class EncuestaComponent implements OnInit, AfterViewInit { document.getElementById('contextmenu-share')!.style.display = 'block'; if ((event.target as HTMLElement).classList.contains('ds-list')) { + document; + 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); 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-duplicate')!.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/service/encuesta.service.ts b/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts index 3bcf8e2..2e8dce2 100644 --- a/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts +++ b/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts @@ -61,6 +61,13 @@ export class EncuestaService { .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res))); } + 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 { //const copy = this.convertDateFromClient(encuesta); return this.http.put(`${this.resourceUrl}/${getEncuestaIdentifier(encuesta) as number}`, encuesta, { observe: 'response' }); @@ -77,6 +84,10 @@ export class EncuestaService { return this.http.delete(`${this.resourceUrl}/${id}`, { observe: 'response' }); } + deletedNotification(email: string): Observable> { + return this.http.delete(`${this.resourceUrl}/${email}`, { 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 cabb0c1..8cc121a 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,6 +1,16 @@

    -

    {{ encuesta!.nombre }}

    +
    +

    {{ encuesta!.nombre }}

    +    +
    +

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

    @@ -13,7 +23,7 @@ + -->

    @@ -37,147 +48,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 +
    +
    +
    + +
    -
    +
    - -
    @@ -400,265 +364,48 @@ - + --> +
    + + diff --git a/src/main/webapp/app/entities/encuesta/update/encuesta-update.component.ts b/src/main/webapp/app/entities/encuesta/update/encuesta-update.component.ts index a04dc89..00c8b66 100644 --- a/src/main/webapp/app/entities/encuesta/update/encuesta-update.component.ts +++ b/src/main/webapp/app/entities/encuesta/update/encuesta-update.component.ts @@ -25,11 +25,13 @@ 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, faPollH } from '@fortawesome/free-solid-svg-icons'; +import { faTimes, faPlus, faQuestion, faPollH } 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'; +import { ParametroAplicacionService } from './../../parametro-aplicacion/service/parametro-aplicacion.service'; +import { IParametroAplicacion } from './../../parametro-aplicacion/parametro-aplicacion.model'; import { Router } from '@angular/router'; @Component({ @@ -40,6 +42,7 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked { faTimes = faTimes; faPlus = faPlus; faPollH = faPollH; + faQuestion = faQuestion; isSaving = false; isSavingQuestion = false; @@ -82,6 +85,7 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked { ePreguntas?: any[]; ePreguntasOpciones?: any[]; encuesta: Encuesta | null = null; + parametrosAplicacion?: IParametroAplicacion | null = null; isLoading = false; @@ -99,6 +103,8 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked { protected ePreguntaCerradaService: EPreguntaCerradaService, protected ePreguntaCerradaOpcionService: EPreguntaCerradaOpcionService, protected ePreguntaAbiertaService: EPreguntaAbiertaService, + protected parametroAplicacionService: ParametroAplicacionService, + protected ePreguntaAbiertaService: EPreguntaAbiertaService, protected router: Router ) {} @@ -127,6 +133,12 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked { ); } + async loadAplicationParameters(): Promise { + const params = await this.parametroAplicacionService.find(1).toPromise(); + this.parametrosAplicacion = params.body; + console.log(this.parametrosAplicacion); + } + ngOnInit(): void { this.activatedRoute.data.subscribe(({ encuesta }) => { if (encuesta.id === undefined) { @@ -138,6 +150,7 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked { } else { this.encuesta = encuesta; this.loadAll(); + this.loadAplicationParameters(); } // this.updateForm(encuesta); diff --git a/src/main/webapp/content/scss/paper-dashboard/_datasurvey-global.scss b/src/main/webapp/content/scss/paper-dashboard/_datasurvey-global.scss index da1c023..db81bbd 100644 --- a/src/main/webapp/content/scss/paper-dashboard/_datasurvey-global.scss +++ b/src/main/webapp/content/scss/paper-dashboard/_datasurvey-global.scss @@ -19,3 +19,22 @@ p { margin: 0 !important; } + +.ds-info--icon { + border-radius: 50%; + background-color: #f1f5f9; + cursor: pointer; + transition: background-color 0.2s ease-in-out; + width: 20px; + height: 20px; + font-size: 0.7rem; + color: #313747; + pointer-events: visible !important; + display: flex; + align-items: center; + justify-content: center; + + &:hover { + background-color: #e3e6e9; + } +}