commit
						3e0be442c8
					
				| 
						 | 
				
			
			@ -80,6 +80,14 @@ public class EPreguntaCerradaOpcionResource {
 | 
			
		|||
            .body(result);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @PostMapping("/e-pregunta-cerrada-opcions/count/{id}")
 | 
			
		||||
    public ResponseEntity<EPreguntaCerradaOpcion> updateOpcionCount(@PathVariable(value = "id", required = true) final Long id) {
 | 
			
		||||
        EPreguntaCerradaOpcion updatedOpcion = getEPreguntaCerradaOpcion(id).getBody();
 | 
			
		||||
        int cantidad = updatedOpcion.getCantidad();
 | 
			
		||||
        updatedOpcion.setCantidad(cantidad += 1);
 | 
			
		||||
        return ResponseEntity.ok(updatedOpcion);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@code PUT  /e-pregunta-cerrada-opcions/:id} : Updates an existing ePreguntaCerradaOpcion.
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,7 @@ import { IEncuesta } from 'app/entities/encuesta/encuesta.model';
 | 
			
		|||
import { EncuestaService } from 'app/entities/encuesta/service/encuesta.service';
 | 
			
		||||
import { EstadoCategoria } from 'app/entities/enumerations/estado-categoria.model';
 | 
			
		||||
import { Observable } from 'rxjs';
 | 
			
		||||
import { finalize, map } from 'rxjs/operators';
 | 
			
		||||
import { finalize } from 'rxjs/operators';
 | 
			
		||||
 | 
			
		||||
import { Categoria, ICategoria } from '../categoria.model';
 | 
			
		||||
import { CategoriaService } from '../service/categoria.service';
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,10 @@ export class EPreguntaCerradaOpcionService {
 | 
			
		|||
 | 
			
		||||
  constructor(protected http: HttpClient, protected applicationConfigService: ApplicationConfigService) {}
 | 
			
		||||
 | 
			
		||||
  updateCount(id: any) {
 | 
			
		||||
    return this.http.post(`${this.resourceUrl}/count/${id}`, id, { observe: 'response' });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  create(ePreguntaCerradaOpcion: IEPreguntaCerradaOpcion, preguntaId?: number): Observable<EntityResponseType> {
 | 
			
		||||
    return this.http.post<IEPreguntaCerradaOpcion>(`${this.resourceUrl}/${preguntaId}`, ePreguntaCerradaOpcion, { observe: 'response' });
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,175 @@
 | 
			
		|||
<div class="container-fluid" *ngIf="encuesta">
 | 
			
		||||
  <div>
 | 
			
		||||
    <h2 id="page-heading" data-cy="EPreguntaCerradaHeading">
 | 
			
		||||
      <div class="d-flex align-items-center">
 | 
			
		||||
        <p class="ds-title">Vista previa de {{ encuesta!.nombre }}</p>
 | 
			
		||||
          <fa-icon class="ds-info--icon" [icon]="faQuestion" data-toggle="modal" data-target="#verParametros"></fa-icon>
 | 
			
		||||
      </div>
 | 
			
		||||
 | 
			
		||||
      <p class="ds-subtitle">Creada el día {{ encuesta!.fechaCreacion | formatShortDatetime | lowercase }}</p>
 | 
			
		||||
      <div class="d-flex justify-content-end">
 | 
			
		||||
        <button type="button" class="ds-btn ds-btn--secondary" (click)="previousState()">
 | 
			
		||||
          <fa-icon icon="arrow-left"></fa-icon>  <span jhiTranslate="entity.action.back">Back</span>
 | 
			
		||||
        </button>
 | 
			
		||||
      </div>
 | 
			
		||||
    </h2>
 | 
			
		||||
 | 
			
		||||
    <jhi-alert-error></jhi-alert-error>
 | 
			
		||||
 | 
			
		||||
    <div class="alert alert-warning" id="no-result" *ngIf="ePreguntas?.length === 0">
 | 
			
		||||
      <span>No se encontraron preguntas</span>
 | 
			
		||||
    </div>
 | 
			
		||||
 | 
			
		||||
    <div class="ds-survey preview-survey" id="entities" *ngIf="ePreguntas && ePreguntas.length > 0">
 | 
			
		||||
      <div class="ds-survey--all-question-wrapper col-8">
 | 
			
		||||
        <div class="ds-survey--question-wrapper card-encuesta lift" *ngFor="let ePregunta of ePreguntas; let i = index; trackBy: trackId">
 | 
			
		||||
          <div
 | 
			
		||||
            [attr.data-index]="ePregunta.id"
 | 
			
		||||
            [attr.data-tipo]="ePregunta.tipo"
 | 
			
		||||
            [attr.data-opcional]="ePregunta.opcional"
 | 
			
		||||
            class="ds-survey--question"
 | 
			
		||||
          >
 | 
			
		||||
            <div class="ds-survey--titulo">
 | 
			
		||||
              <span class="ds-survey--titulo--name">{{ i + 1 }}. {{ ePregunta.nombre }}</span>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div>
 | 
			
		||||
              <span *ngIf="ePregunta.tipo === 'SINGLE'" class="ds-subtitle"
 | 
			
		||||
                >Pregunta de respuesta {{ 'dataSurveyApp.PreguntaCerradaTipo.SINGLE' | translate | lowercase }}
 | 
			
		||||
                {{ ePregunta.opcional ? '(opcional)' : '' }}</span
 | 
			
		||||
              >
 | 
			
		||||
              <span *ngIf="ePregunta.tipo === 'MULTIPLE'" class="ds-subtitle"
 | 
			
		||||
                >Pregunta de respuesta {{ 'dataSurveyApp.PreguntaCerradaTipo.MULTIPLE' | translate | lowercase }}
 | 
			
		||||
                {{ ePregunta.opcional ? '(opcional)' : '' }}</span
 | 
			
		||||
              >
 | 
			
		||||
              <span *ngIf="!ePregunta.tipo" class="ds-subtitle"
 | 
			
		||||
                >Pregunta de respuesta abierta {{ ePregunta.opcional ? '(opcional)' : '' }}</span
 | 
			
		||||
              >
 | 
			
		||||
            </div>
 | 
			
		||||
            <ng-container *ngIf="ePregunta.tipo">
 | 
			
		||||
              <ng-container *ngFor="let ePreguntaOpcion of ePreguntasOpciones; let j = index; trackBy: trackId">
 | 
			
		||||
                <ng-container *ngFor="let ePreguntaOpcionFinal of ePreguntaOpcion">
 | 
			
		||||
                  <ng-container *ngIf="ePregunta.id === ePreguntaOpcionFinal.epreguntaCerrada.id">
 | 
			
		||||
                    <div
 | 
			
		||||
                      class="ds-survey--option ds-survey--option--base ds-survey--closed-option can-delete"
 | 
			
		||||
                      [attr.data-id]="ePreguntaOpcionFinal.id"
 | 
			
		||||
                    >
 | 
			
		||||
                      <div class="radio" *ngIf="ePregunta.tipo === 'SINGLE'">
 | 
			
		||||
                        <input
 | 
			
		||||
                          type="radio"
 | 
			
		||||
                          (change)="onCheck(ePreguntaOpcionFinal)"
 | 
			
		||||
                          [value]="ePreguntaOpcionFinal.id"
 | 
			
		||||
                          style="border-radius: 3px"
 | 
			
		||||
                          name="{{ 'radio' + ePregunta.id }}"
 | 
			
		||||
                          id="{{ 'radio' + ePreguntaOpcionFinal.id }}"
 | 
			
		||||
                        />
 | 
			
		||||
                        <label for="{{ 'radio' + ePreguntaOpcionFinal.id }}">{{ ePreguntaOpcionFinal.nombre }}</label>
 | 
			
		||||
                      </div>
 | 
			
		||||
                      <div class="checkbox" *ngIf="ePregunta.tipo === 'MULTIPLE'">
 | 
			
		||||
                        <input
 | 
			
		||||
                          (change)="toggleOption(ePreguntaOpcionFinal)"
 | 
			
		||||
                          type="checkbox"
 | 
			
		||||
                          style="border-radius: 3px"
 | 
			
		||||
                          id="{{ 'checkbox' + ePreguntaOpcionFinal.id }}"
 | 
			
		||||
                        />
 | 
			
		||||
                        <label for="{{ 'checkbox' + ePreguntaOpcionFinal.id }}">{{ ePreguntaOpcionFinal.nombre }}</label>
 | 
			
		||||
                      </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </ng-container>
 | 
			
		||||
                </ng-container>
 | 
			
		||||
              </ng-container>
 | 
			
		||||
            </ng-container>
 | 
			
		||||
            <div class="ds-survey--option ds-survey--option--base ds-survey--open-option" *ngIf="!ePregunta.tipo">
 | 
			
		||||
              <textarea id="{{ ePregunta.id }}" cols="33" rows="10"></textarea>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
        <button class="ds-btn ds-btn--primary" (click)="finish()">Terminar</button>
 | 
			
		||||
      </div>
 | 
			
		||||
      <div
 | 
			
		||||
        class="modal fade ds-modal"
 | 
			
		||||
        id="verParametros"
 | 
			
		||||
        tabindex="-1"
 | 
			
		||||
        role="dialog"
 | 
			
		||||
        aria-labelledby="exampleModalCenterTitle"
 | 
			
		||||
        aria-hidden="true"
 | 
			
		||||
      >
 | 
			
		||||
        <div class="modal-dialog modal-dialog-centered" role="document">
 | 
			
		||||
          <div class="modal-content">
 | 
			
		||||
            <div class="modal-header">
 | 
			
		||||
              <h1 class="modal-title" id="exampleModalLongTitle">Información de encuesta</h1>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <div class="modal-body">
 | 
			
		||||
              <div>
 | 
			
		||||
                <div class="mb-5">
 | 
			
		||||
                  <p style="font-size: 1.2em" class="ds-subtitle">Cantidad de preguntas</p>
 | 
			
		||||
                  <p>{{ ePreguntas?.length }}</p>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div class="mb-5">
 | 
			
		||||
                  <p class="ds-subtitle" jhiTranslate="dataSurveyApp.encuesta.acceso">Acceso</p>
 | 
			
		||||
                  <p jhiTranslate="{{ 'dataSurveyApp.AccesoEncuesta.' + encuesta.acceso }}">{{ encuesta.acceso }}</p>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div *ngIf="encuesta.acceso === 'PRIVATE'" class="mb-5">
 | 
			
		||||
                  <p class="ds-subtitle">Contraseña</p>
 | 
			
		||||
                  <p>{{ encuesta.contrasenna }}</p>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div class="mb-5">
 | 
			
		||||
                  <p class="ds-subtitle">Estado:</p>
 | 
			
		||||
                  <p jhiTranslate="{{ 'dataSurveyApp.EstadoEncuesta.' + encuesta.estado }}">{{ encuesta.estado }}</p>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div *ngIf="encuesta.categoria" class="mb-5">
 | 
			
		||||
                  <p class="ds-subtitle">Categoría</p>
 | 
			
		||||
                  <P> </P> {{ encuesta.categoria?.nombre }}
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div class="mb-5">
 | 
			
		||||
                  <p class="ds-subtitle">Fecha de publicación</p>
 | 
			
		||||
                  <P
 | 
			
		||||
                    >{{
 | 
			
		||||
                      encuesta.fechaPublicacion === undefined
 | 
			
		||||
                        ? 'Sin publicar'
 | 
			
		||||
                        : (encuesta.fechaPublicacion | formatShortDatetime | lowercase)
 | 
			
		||||
                    }}
 | 
			
		||||
                  </P>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div class="mb-5">
 | 
			
		||||
                  <p class="ds-subtitle">Fecha de finalización</p>
 | 
			
		||||
                  <P>
 | 
			
		||||
                    {{
 | 
			
		||||
                      encuesta.fechaFinalizada === undefined
 | 
			
		||||
                        ? 'Sin finalizar'
 | 
			
		||||
                        : (encuesta.fechaFinalizada | formatShortDatetime | lowercase)
 | 
			
		||||
                    }}
 | 
			
		||||
                  </P>
 | 
			
		||||
                </div>
 | 
			
		||||
 | 
			
		||||
                <div class="mb-5">
 | 
			
		||||
                  <p class="ds-subtitle">Calificación</p>
 | 
			
		||||
                  <div>
 | 
			
		||||
                    <fa-icon *ngFor="let i of [].constructor(encuesta.calificacion)" class="entity-icon--star" [icon]="faStar"></fa-icon
 | 
			
		||||
                    ><fa-icon
 | 
			
		||||
                      *ngFor="let i of [].constructor(5 - encuesta.calificacion!)"
 | 
			
		||||
                      class="entity-icon--star--off"
 | 
			
		||||
                      [icon]="faStar"
 | 
			
		||||
                    ></fa-icon>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
              </div>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <div class="modal-footer">
 | 
			
		||||
              <button id="cancelBtnVerParametros" type="button" class="ds-btn ds-btn--secondary" data-dismiss="modal">
 | 
			
		||||
                <fa-icon icon="arrow-left"></fa-icon>  <span>Volver</span>
 | 
			
		||||
              </button>
 | 
			
		||||
            </div>
 | 
			
		||||
          </div>
 | 
			
		||||
        </div>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
 | 
			
		||||
 | 
			
		||||
import { EncuestaCompleteComponent } from './complete.component';
 | 
			
		||||
 | 
			
		||||
describe('EncuestaCompleteComponent', () => {
 | 
			
		||||
  let component: EncuestaCompleteComponent;
 | 
			
		||||
  let fixture: ComponentFixture<EncuestaCompleteComponent>;
 | 
			
		||||
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await TestBed.configureTestingModule({
 | 
			
		||||
      declarations: [EncuestaCompleteComponent],
 | 
			
		||||
    }).compileComponents();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  beforeEach(() => {
 | 
			
		||||
    fixture = TestBed.createComponent(EncuestaCompleteComponent);
 | 
			
		||||
    component = fixture.componentInstance;
 | 
			
		||||
    fixture.detectChanges();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should create', () => {
 | 
			
		||||
    expect(component).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,229 @@
 | 
			
		|||
import { Component, OnInit } from '@angular/core';
 | 
			
		||||
import { FormBuilder } from '@angular/forms';
 | 
			
		||||
import { ActivatedRoute } from '@angular/router';
 | 
			
		||||
import { finalize } from 'rxjs/operators';
 | 
			
		||||
import { IEncuesta } from '../encuesta.model';
 | 
			
		||||
import { EncuestaService } from '../service/encuesta.service';
 | 
			
		||||
import { ICategoria } from 'app/entities/categoria/categoria.model';
 | 
			
		||||
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 { EPreguntaAbiertaService } from '../../e-pregunta-abierta/service/e-pregunta-abierta.service';
 | 
			
		||||
import { EPreguntaAbiertaRespuestaService } from '../../e-pregunta-abierta-respuesta/service/e-pregunta-abierta-respuesta.service';
 | 
			
		||||
import { EPreguntaCerradaOpcionService } from '../../e-pregunta-cerrada-opcion/service/e-pregunta-cerrada-opcion.service';
 | 
			
		||||
import { faStar, faQuestion } from '@fortawesome/free-solid-svg-icons';
 | 
			
		||||
import { AccesoEncuesta } from 'app/entities/enumerations/acceso-encuesta.model';
 | 
			
		||||
import { EncuestaPasswordDialogComponent } from '../encuesta-password-dialog/encuesta-password-dialog.component';
 | 
			
		||||
import { PreguntaCerradaTipo } from 'app/entities/enumerations/pregunta-cerrada-tipo.model';
 | 
			
		||||
import { EPreguntaAbiertaRespuesta } from 'app/entities/e-pregunta-abierta-respuesta/e-pregunta-abierta-respuesta.model';
 | 
			
		||||
import { Observable } from 'rxjs/internal/Observable';
 | 
			
		||||
import { HttpErrorResponse, HttpResponse } from '@angular/common/http';
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'jhi-complete',
 | 
			
		||||
  templateUrl: './complete.component.html',
 | 
			
		||||
})
 | 
			
		||||
export class EncuestaCompleteComponent implements OnInit {
 | 
			
		||||
  categoriasSharedCollection: ICategoria[] = [];
 | 
			
		||||
  usuarioExtrasSharedCollection: IUsuarioExtra[] = [];
 | 
			
		||||
  faStar = faStar;
 | 
			
		||||
  faQuestion = faQuestion;
 | 
			
		||||
  encuesta?: IEncuesta;
 | 
			
		||||
  isLoading = false;
 | 
			
		||||
  ePreguntas?: any[];
 | 
			
		||||
  ePreguntasOpciones?: any[];
 | 
			
		||||
  isLocked?: boolean;
 | 
			
		||||
  selectedOpenOptions: any;
 | 
			
		||||
  selectedSingleOptions: any;
 | 
			
		||||
  selectedMultiOptions: any;
 | 
			
		||||
  error: boolean;
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
    protected activatedRoute: ActivatedRoute,
 | 
			
		||||
    protected encuestaService: EncuestaService,
 | 
			
		||||
    protected usuarioExtraService: UsuarioExtraService,
 | 
			
		||||
    protected fb: FormBuilder,
 | 
			
		||||
    protected modalService: NgbModal,
 | 
			
		||||
    protected ePreguntaCerradaService: EPreguntaCerradaService,
 | 
			
		||||
    protected ePreguntaCerradaOpcionService: EPreguntaCerradaOpcionService,
 | 
			
		||||
    protected ePreguntaAbiertaService: EPreguntaAbiertaService,
 | 
			
		||||
    protected ePreguntaAbiertaRespuestaService: EPreguntaAbiertaRespuestaService
 | 
			
		||||
  ) {
 | 
			
		||||
    this.selectedOpenOptions = {};
 | 
			
		||||
    this.selectedSingleOptions = {};
 | 
			
		||||
    this.selectedMultiOptions = [];
 | 
			
		||||
    this.error = false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ngOnInit(): void {
 | 
			
		||||
    this.activatedRoute.data.subscribe(({ encuesta }) => {
 | 
			
		||||
      if (encuesta) {
 | 
			
		||||
        this.encuesta = encuesta;
 | 
			
		||||
      }
 | 
			
		||||
      this.isLocked = this.verifyPassword();
 | 
			
		||||
      if (this.isLocked) {
 | 
			
		||||
        this.previousState();
 | 
			
		||||
      } else {
 | 
			
		||||
        this.loadAll();
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
    for (let pregunta of this.ePreguntas!) {
 | 
			
		||||
      if (pregunta.tipo && pregunta.tipo === PreguntaCerradaTipo.SINGLE) {
 | 
			
		||||
        this.selectedSingleOptions[pregunta.id] = null;
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  verifyPassword(): boolean {
 | 
			
		||||
    if (this.encuesta!.acceso === AccesoEncuesta.PUBLIC) {
 | 
			
		||||
      return false;
 | 
			
		||||
    } else {
 | 
			
		||||
      const modalRef = this.modalService.open(EncuestaPasswordDialogComponent, { size: 'lg', backdrop: 'static' });
 | 
			
		||||
      modalRef.componentInstance.encuesta = this.encuesta;
 | 
			
		||||
      modalRef.closed.subscribe(reason => {
 | 
			
		||||
        return reason === 'success';
 | 
			
		||||
      });
 | 
			
		||||
    }
 | 
			
		||||
    return true;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ngAfterViewChecked(): void {
 | 
			
		||||
    this.initListeners();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  initListeners(): void {
 | 
			
		||||
    const questions = document.getElementsByClassName('ds-survey--question-wrapper');
 | 
			
		||||
    for (let i = 0; i < questions.length; i++) {
 | 
			
		||||
      if (questions[i].classList.contains('ds-survey--closed-option')) {
 | 
			
		||||
        questions[i].addEventListener('click', e => {
 | 
			
		||||
          if ((e.target as HTMLInputElement).checked) {
 | 
			
		||||
            (e.target as HTMLElement).offsetParent!.classList.add('ds-survey--closed-option--active');
 | 
			
		||||
            (e.target as HTMLElement).id;
 | 
			
		||||
          } 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!;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  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;
 | 
			
		||||
        }
 | 
			
		||||
      );
 | 
			
		||||
    if (this.ePreguntas!.length == 0) {
 | 
			
		||||
      this.previousState();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  previousState(): void {
 | 
			
		||||
    window.history.back();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  onCheck(preguntaOpcion: { epreguntaCerrada: any; id: any }): void {
 | 
			
		||||
    this.selectedSingleOptions[preguntaOpcion.epreguntaCerrada!.id!] = preguntaOpcion.id;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  toggleOption(ePreguntaOpcionFinal: { id: any }): void {
 | 
			
		||||
    if (this.selectedMultiOptions.includes(ePreguntaOpcionFinal.id)) {
 | 
			
		||||
      for (let i = 0; i < this.selectedMultiOptions.length; i++) {
 | 
			
		||||
        if (this.selectedMultiOptions[i] === ePreguntaOpcionFinal.id) {
 | 
			
		||||
          this.selectedMultiOptions.splice(i, 1);
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    } else {
 | 
			
		||||
      this.selectedMultiOptions.push(ePreguntaOpcionFinal.id);
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  finish(): void {
 | 
			
		||||
    this.getOpenQuestionAnswers();
 | 
			
		||||
    this.registerOpenQuestionAnswers();
 | 
			
		||||
    this.updateClosedOptionsCount();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  updateClosedOptionsCount() {
 | 
			
		||||
    for (let key in this.selectedSingleOptions) {
 | 
			
		||||
      this.subscribeToSaveResponse(this.ePreguntaCerradaOpcionService.updateCount(this.selectedSingleOptions[key]));
 | 
			
		||||
    }
 | 
			
		||||
    this.selectedMultiOptions.forEach((option: any) => {
 | 
			
		||||
      this.subscribeToSaveResponse(this.ePreguntaCerradaOpcionService.updateCount(option));
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  registerOpenQuestionAnswers() {
 | 
			
		||||
    for (let id in this.selectedOpenOptions) {
 | 
			
		||||
      let pregunta = this.ePreguntas!.find(p => {
 | 
			
		||||
        return p.id == id;
 | 
			
		||||
      });
 | 
			
		||||
      let newRespuesta = new EPreguntaAbiertaRespuesta(0, this.selectedOpenOptions[id], pregunta);
 | 
			
		||||
      this.subscribeToSaveResponse(this.ePreguntaAbiertaRespuestaService.create(newRespuesta));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected onSaveFinalize(): void {
 | 
			
		||||
    // this.isSaving = false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  processError(response: HttpErrorResponse): void {
 | 
			
		||||
    if (response.status === 400) {
 | 
			
		||||
      this.error = true;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected subscribeToSaveResponse(result: Observable<HttpResponse<any>>): void {
 | 
			
		||||
    result.pipe(finalize(() => this.onSaveFinalize())).subscribe(
 | 
			
		||||
      () => this.previousState(),
 | 
			
		||||
      response => this.processError(response)
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  getOpenQuestionAnswers() {
 | 
			
		||||
    this.ePreguntas!.forEach(pregunta => {
 | 
			
		||||
      if (!pregunta.tipo) {
 | 
			
		||||
        let textValue = (document.getElementById(pregunta.id) as HTMLInputElement).value;
 | 
			
		||||
        this.selectedOpenOptions[pregunta.id] = textValue;
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,28 @@
 | 
			
		|||
<form class="ds-form" [formGroup]="passwordForm" name="deleteForm" (ngSubmit)="submitPassword()">
 | 
			
		||||
  <div *ngIf="this.isWrong">
 | 
			
		||||
    <p>Contraseña incorrecta</p>
 | 
			
		||||
  </div>
 | 
			
		||||
  <div class="modal-body">
 | 
			
		||||
    <p class="ds-title--small" jhiTranslate="dataSurveyApp.encuesta.password.title">Enter password</p>
 | 
			
		||||
    <p class="ds-subtitle" id="jhi-delete-encuesta-heading" jhiTranslate="dataSurveyApp.encuesta.password.text">
 | 
			
		||||
      This survey is marked as private, please enter the password
 | 
			
		||||
    </p>
 | 
			
		||||
    <input [(ngModel)]="passwordInput" type="password" name="passwordInput" id="passwordInput" placeholder="qwerty..." />
 | 
			
		||||
  </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> <span jhiTranslate="entity.action.cancel">Cancel</span>
 | 
			
		||||
    </button>
 | 
			
		||||
 | 
			
		||||
    <button
 | 
			
		||||
      id="jhi-confirm-delete-option"
 | 
			
		||||
      data-cy="submit"
 | 
			
		||||
      type="submit"
 | 
			
		||||
      class="ds-btn ds-btn--primary"
 | 
			
		||||
      [disabled]="passwordForm.get('password')!.invalid"
 | 
			
		||||
    >
 | 
			
		||||
      <span jhiTranslate="entity.action.submit">Submit</span>
 | 
			
		||||
    </button>
 | 
			
		||||
  </div>
 | 
			
		||||
</form>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,4 @@
 | 
			
		|||
input {
 | 
			
		||||
  margin: 2%;
 | 
			
		||||
  width: 100%;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
 | 
			
		||||
 | 
			
		||||
import { EncuestaPasswordDialogComponent } from './encuesta-password-dialog.component';
 | 
			
		||||
 | 
			
		||||
describe('EncuestaPasswordDialogComponent', () => {
 | 
			
		||||
  let component: EncuestaPasswordDialogComponent;
 | 
			
		||||
  let fixture: ComponentFixture<EncuestaPasswordDialogComponent>;
 | 
			
		||||
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await TestBed.configureTestingModule({
 | 
			
		||||
      declarations: [EncuestaPasswordDialogComponent],
 | 
			
		||||
    }).compileComponents();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  beforeEach(() => {
 | 
			
		||||
    fixture = TestBed.createComponent(EncuestaPasswordDialogComponent);
 | 
			
		||||
    component = fixture.componentInstance;
 | 
			
		||||
    fixture.detectChanges();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should create', () => {
 | 
			
		||||
    expect(component).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
import { Component, OnInit } from '@angular/core';
 | 
			
		||||
import { FormBuilder, Validators } from '@angular/forms';
 | 
			
		||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
 | 
			
		||||
import { IEncuesta } from '../encuesta.model';
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'jhi-encuesta-password-dialog',
 | 
			
		||||
  templateUrl: './encuesta-password-dialog.component.html',
 | 
			
		||||
  styleUrls: ['./encuesta-password-dialog.component.scss'],
 | 
			
		||||
})
 | 
			
		||||
export class EncuestaPasswordDialogComponent implements OnInit {
 | 
			
		||||
  passwordForm = this.fb.group({
 | 
			
		||||
    password: [null, [Validators.required]],
 | 
			
		||||
  });
 | 
			
		||||
  encuesta?: IEncuesta;
 | 
			
		||||
  isWrong?: boolean;
 | 
			
		||||
  passwordInput?: string;
 | 
			
		||||
 | 
			
		||||
  constructor(protected activeModal: NgbActiveModal, protected fb: FormBuilder) {}
 | 
			
		||||
 | 
			
		||||
  ngOnInit(): void {}
 | 
			
		||||
 | 
			
		||||
  submitPassword() {
 | 
			
		||||
    const password = this.passwordForm.get(['password'])!.value;
 | 
			
		||||
 | 
			
		||||
    if (this.passwordForm.valid && password === this.encuesta!.contrasenna) {
 | 
			
		||||
      this.activeModal.close('success');
 | 
			
		||||
    } else {
 | 
			
		||||
      this.isWrong = true;
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  cancel(): void {
 | 
			
		||||
    this.activeModal.close('cancel');
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -10,9 +10,9 @@ import { EncuestaPublishDialogComponent } from './encuesta-publish-dialog/encues
 | 
			
		|||
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 { EncuestaCompartirDialogComponent } from './encuesta-compartir-dialog/encuesta-compartir-dialog.component';
 | 
			
		||||
 | 
			
		||||
import { EncuestaCompleteComponent } from './complete/complete.component';
 | 
			
		||||
import { EncuestaPasswordDialogComponent } from './encuesta-password-dialog/encuesta-password-dialog.component';
 | 
			
		||||
import { EncuestaFinalizarDialogComponent } from './encuesta-finalizar-dialog/encuesta-finalizar-dialog.component';
 | 
			
		||||
 | 
			
		||||
import { EncuestaDeleteColaboratorDialogComponent } from './encuesta-delete-colaborator-dialog/encuesta-delete-colaborator-dialog.component';
 | 
			
		||||
 | 
			
		||||
@NgModule({
 | 
			
		||||
| 
						 | 
				
			
			@ -26,6 +26,8 @@ import { EncuestaDeleteColaboratorDialogComponent } from './encuesta-delete-cola
 | 
			
		|||
    EncuestaDeleteQuestionDialogComponent,
 | 
			
		||||
    EncuestaDeleteOptionDialogComponent,
 | 
			
		||||
    EncuestaCompartirDialogComponent,
 | 
			
		||||
    EncuestaCompleteComponent,
 | 
			
		||||
    EncuestaPasswordDialogComponent,
 | 
			
		||||
    EncuestaFinalizarDialogComponent,
 | 
			
		||||
    EncuestaDeleteColaboratorDialogComponent,
 | 
			
		||||
  ],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ import { EncuestaComponent } from '../list/encuesta.component';
 | 
			
		|||
import { EncuestaDetailComponent } from '../detail/encuesta-detail.component';
 | 
			
		||||
import { EncuestaUpdateComponent } from '../update/encuesta-update.component';
 | 
			
		||||
import { EncuestaRoutingResolveService } from './encuesta-routing-resolve.service';
 | 
			
		||||
import { EncuestaCompleteComponent } from '../complete/complete.component';
 | 
			
		||||
 | 
			
		||||
const encuestaRoute: Routes = [
 | 
			
		||||
  {
 | 
			
		||||
| 
						 | 
				
			
			@ -37,6 +38,14 @@ const encuestaRoute: Routes = [
 | 
			
		|||
    },
 | 
			
		||||
    canActivate: [UserRouteAccessService],
 | 
			
		||||
  },
 | 
			
		||||
  {
 | 
			
		||||
    path: ':id/complete',
 | 
			
		||||
    component: EncuestaCompleteComponent,
 | 
			
		||||
    resolve: {
 | 
			
		||||
      encuesta: EncuestaRoutingResolveService,
 | 
			
		||||
    },
 | 
			
		||||
    canActivate: [UserRouteAccessService],
 | 
			
		||||
  },
 | 
			
		||||
];
 | 
			
		||||
 | 
			
		||||
@NgModule({
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -106,7 +106,9 @@
 | 
			
		|||
                      ></fa-icon>
 | 
			
		||||
                    </div>
 | 
			
		||||
                    <div class="entity-body--row m-2">
 | 
			
		||||
                      <button class="ds-btn btn-card"><fa-icon [icon]="faPollH"></fa-icon>  Completar encuesta</button>
 | 
			
		||||
                      <button (click)="completeEncuesta(encuesta)" class="ds-btn btn-card">
 | 
			
		||||
                        <fa-icon [icon]="faPollH"></fa-icon>  Completar encuesta
 | 
			
		||||
                      </button>
 | 
			
		||||
                    </div>
 | 
			
		||||
                  </div>
 | 
			
		||||
                </div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,6 +15,8 @@ import { Subject } from 'rxjs';
 | 
			
		|||
 | 
			
		||||
import { faPollH, faCalendarAlt, faStar, faListAlt, faFileAlt } from '@fortawesome/free-solid-svg-icons';
 | 
			
		||||
import { ICategoria } from '../entities/categoria/categoria.model';
 | 
			
		||||
import { AccesoEncuesta } from 'app/entities/enumerations/acceso-encuesta.model';
 | 
			
		||||
import { EncuestaPasswordDialogComponent } from 'app/entities/encuesta/encuesta-password-dialog/encuesta-password-dialog.component';
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'jhi-pagina-principal',
 | 
			
		||||
| 
						 | 
				
			
			@ -106,7 +108,21 @@ export class PaginaPrincipalComponent implements OnInit {
 | 
			
		|||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  trackId(index: number, item: IEncuesta): number {
 | 
			
		||||
  trackId(_index: number, item: IEncuesta): number {
 | 
			
		||||
    return item.id!;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  completeEncuesta(encuesta: IEncuesta): void {
 | 
			
		||||
    this.router.navigate(['/encuesta', encuesta.id, 'complete']);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  confirmPassword(encuesta: IEncuesta): void {
 | 
			
		||||
    const modalRef = this.modalService.open(EncuestaPasswordDialogComponent, { size: 'lg', backdrop: 'static' });
 | 
			
		||||
    modalRef.componentInstance.encuesta = encuesta;
 | 
			
		||||
    modalRef.closed.subscribe(isValid => {
 | 
			
		||||
      if (isValid) {
 | 
			
		||||
        // Load the survey
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -34,7 +34,11 @@
 | 
			
		|||
      "ePreguntaAbierta": "Pregunta Abierta",
 | 
			
		||||
      "ePreguntaCerrada": "Pregunta Cerrada",
 | 
			
		||||
      "categoria": "Categoría",
 | 
			
		||||
      "usuarioExtra": "Correo Usuario"
 | 
			
		||||
      "usuarioExtra": "Correo Usuario",
 | 
			
		||||
      "password": {
 | 
			
		||||
        "title": "Contraseña Requerida",
 | 
			
		||||
        "text": "Esta encuesta es privada, por lo que debe ingresar la contraseña"
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -130,7 +130,8 @@
 | 
			
		|||
      "enable": "Habilitar",
 | 
			
		||||
      "disable": "Deshabilitar",
 | 
			
		||||
      "toggleStatus": "Cambiar Estado",
 | 
			
		||||
      "publish": "Publicar"
 | 
			
		||||
      "publish": "Publicar",
 | 
			
		||||
      "submit": "Ingresar"
 | 
			
		||||
    },
 | 
			
		||||
    "detail": {
 | 
			
		||||
      "field": "Campo",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue