Add survey questions with their options respectively
This commit is contained in:
		
							parent
							
								
									8e9a148b16
								
							
						
					
					
						commit
						5fa5cda7f2
					
				| 
						 | 
				
			
			@ -2,15 +2,20 @@ package org.datasurvey.web.rest;
 | 
			
		|||
 | 
			
		||||
import java.net.URI;
 | 
			
		||||
import java.net.URISyntaxException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Objects;
 | 
			
		||||
import java.util.Optional;
 | 
			
		||||
import java.util.stream.Collectors;
 | 
			
		||||
import java.util.stream.Stream;
 | 
			
		||||
import javax.validation.Valid;
 | 
			
		||||
import javax.validation.constraints.NotNull;
 | 
			
		||||
import org.datasurvey.domain.EPreguntaAbierta;
 | 
			
		||||
import org.datasurvey.domain.EPreguntaCerrada;
 | 
			
		||||
import org.datasurvey.domain.EPreguntaCerradaOpcion;
 | 
			
		||||
import org.datasurvey.domain.Encuesta;
 | 
			
		||||
import org.datasurvey.repository.EncuestaRepository;
 | 
			
		||||
import org.datasurvey.service.EncuestaQueryService;
 | 
			
		||||
import org.datasurvey.service.EncuestaService;
 | 
			
		||||
import org.datasurvey.service.*;
 | 
			
		||||
import org.datasurvey.service.criteria.EncuestaCriteria;
 | 
			
		||||
import org.datasurvey.web.rest.errors.BadRequestAlertException;
 | 
			
		||||
import org.slf4j.Logger;
 | 
			
		||||
| 
						 | 
				
			
			@ -41,14 +46,26 @@ public class EncuestaResource {
 | 
			
		|||
 | 
			
		||||
    private final EncuestaQueryService encuestaQueryService;
 | 
			
		||||
 | 
			
		||||
    private final EPreguntaCerradaService ePreguntaCerradaService;
 | 
			
		||||
 | 
			
		||||
    private final EPreguntaAbiertaService ePreguntaAbiertaService;
 | 
			
		||||
 | 
			
		||||
    private final EPreguntaCerradaOpcionService ePreguntaCerradaOpcionService;
 | 
			
		||||
 | 
			
		||||
    public EncuestaResource(
 | 
			
		||||
        EncuestaService encuestaService,
 | 
			
		||||
        EncuestaRepository encuestaRepository,
 | 
			
		||||
        EncuestaQueryService encuestaQueryService
 | 
			
		||||
        EncuestaQueryService encuestaQueryService,
 | 
			
		||||
        EPreguntaCerradaService ePreguntaCerradaService,
 | 
			
		||||
        EPreguntaAbiertaService ePreguntaAbiertaService,
 | 
			
		||||
        EPreguntaCerradaOpcionService ePreguntaCerradaOpcionService
 | 
			
		||||
    ) {
 | 
			
		||||
        this.encuestaService = encuestaService;
 | 
			
		||||
        this.encuestaRepository = encuestaRepository;
 | 
			
		||||
        this.encuestaQueryService = encuestaQueryService;
 | 
			
		||||
        this.ePreguntaCerradaService = ePreguntaCerradaService;
 | 
			
		||||
        this.ePreguntaAbiertaService = ePreguntaAbiertaService;
 | 
			
		||||
        this.ePreguntaCerradaOpcionService = ePreguntaCerradaOpcionService;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +91,7 @@ public class EncuestaResource {
 | 
			
		|||
    /**
 | 
			
		||||
     * {@code PUT  /encuestas/:id} : Updates an existing encuesta.
 | 
			
		||||
     *
 | 
			
		||||
     * @param id the id of the encuesta to save.
 | 
			
		||||
     * @param id       the id of the encuesta to save.
 | 
			
		||||
     * @param encuesta the encuesta to update.
 | 
			
		||||
     * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated encuesta,
 | 
			
		||||
     * or with status {@code 400 (Bad Request)} if the encuesta is not valid,
 | 
			
		||||
| 
						 | 
				
			
			@ -108,7 +125,7 @@ public class EncuestaResource {
 | 
			
		|||
    /**
 | 
			
		||||
     * {@code PATCH  /encuestas/:id} : Partial updates given fields of an existing encuesta, field will ignore if it is null
 | 
			
		||||
     *
 | 
			
		||||
     * @param id the id of the encuesta to save.
 | 
			
		||||
     * @param id       the id of the encuesta to save.
 | 
			
		||||
     * @param encuesta the encuesta to update.
 | 
			
		||||
     * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated encuesta,
 | 
			
		||||
     * or with status {@code 400 (Bad Request)} if the encuesta is not valid,
 | 
			
		||||
| 
						 | 
				
			
			@ -154,6 +171,55 @@ public class EncuestaResource {
 | 
			
		|||
        return ResponseEntity.ok().body(entityList);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/encuestas/preguntas/{id}")
 | 
			
		||||
    public ResponseEntity<List<Object>> getPreguntasByIdEncuesta(@PathVariable Long id) {
 | 
			
		||||
        List<EPreguntaCerrada> preguntasCerradas = ePreguntaCerradaService.findAll();
 | 
			
		||||
        List<EPreguntaAbierta> preguntasAbiertas = ePreguntaAbiertaService.findAll();
 | 
			
		||||
        List<Object> preguntas = Stream.concat(preguntasCerradas.stream(), preguntasAbiertas.stream()).collect(Collectors.toList());
 | 
			
		||||
        List<Object> preguntasFiltered = new ArrayList<>();
 | 
			
		||||
 | 
			
		||||
        for (Object obj : preguntas) {
 | 
			
		||||
            if (obj.getClass() == EPreguntaCerrada.class) {
 | 
			
		||||
                if (((EPreguntaCerrada) obj).getEncuesta() != null) {
 | 
			
		||||
                    if (((EPreguntaCerrada) obj).getEncuesta().getId().equals(id)) {
 | 
			
		||||
                        preguntasFiltered.add(obj);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            } else if (obj.getClass() == EPreguntaAbierta.class) {
 | 
			
		||||
                if (((EPreguntaAbierta) obj).getEncuesta() != null) {
 | 
			
		||||
                    if (((EPreguntaAbierta) obj).getEncuesta().getId().equals(id)) {
 | 
			
		||||
                        preguntasFiltered.add(obj);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return ResponseEntity.ok().body(preguntasFiltered);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @GetMapping("/encuestas/preguntas-opciones/{id}")
 | 
			
		||||
    public ResponseEntity<List<List<EPreguntaCerradaOpcion>>> getPreguntaCerradaOpcionByIdEncuesta(@PathVariable Long id) {
 | 
			
		||||
        List<List<EPreguntaCerradaOpcion>> res = new ArrayList<>();
 | 
			
		||||
        List<EPreguntaCerrada> preguntasCerradas = ePreguntaCerradaService.findAll();
 | 
			
		||||
        List<EPreguntaCerrada> preguntasCerradasFiltered = preguntasCerradas
 | 
			
		||||
            .stream()
 | 
			
		||||
            .filter(p -> Objects.nonNull(p.getEncuesta()))
 | 
			
		||||
            .filter(p -> p.getEncuesta().getId().equals(id))
 | 
			
		||||
            .collect(Collectors.toList());
 | 
			
		||||
        List<EPreguntaCerradaOpcion> opciones = ePreguntaCerradaOpcionService.findAll();
 | 
			
		||||
 | 
			
		||||
        for (EPreguntaCerrada ePreguntaCerrada : preguntasCerradasFiltered) {
 | 
			
		||||
            long preguntaCerradaId = ePreguntaCerrada.getId();
 | 
			
		||||
            List<EPreguntaCerradaOpcion> opcionesFiltered = opciones
 | 
			
		||||
                .stream()
 | 
			
		||||
                .filter(o -> Objects.nonNull(o.getEPreguntaCerrada()))
 | 
			
		||||
                .filter(o -> o.getEPreguntaCerrada().getId().equals(preguntaCerradaId))
 | 
			
		||||
                .collect(Collectors.toList());
 | 
			
		||||
            res.add(opcionesFiltered);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return ResponseEntity.ok().body(res);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * {@code GET  /encuestas/count} : count all the encuestas.
 | 
			
		||||
     *
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -45,6 +45,18 @@ export class EncuestaService {
 | 
			
		|||
      .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  findQuestions(id: number): Observable<EntityResponseType> {
 | 
			
		||||
    return this.http
 | 
			
		||||
      .get<any>(`${this.resourceUrl}/preguntas/${id}`, { observe: 'response' })
 | 
			
		||||
      .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  findQuestionsOptions(id: number): Observable<EntityResponseType> {
 | 
			
		||||
    return this.http
 | 
			
		||||
      .get<any>(`${this.resourceUrl}/preguntas-opciones/${id}`, { observe: 'response' })
 | 
			
		||||
      .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  query(req?: any): Observable<EntityArrayResponseType> {
 | 
			
		||||
    const options = createRequestOption(req);
 | 
			
		||||
    return this.http
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,4 +1,115 @@
 | 
			
		|||
<div class="row justify-content-center">
 | 
			
		||||
<div>
 | 
			
		||||
  <h2 id="page-heading" data-cy="EPreguntaCerradaHeading">
 | 
			
		||||
    <span>{{ encuesta!.nombre }}</span>
 | 
			
		||||
 | 
			
		||||
    <div class="d-flex justify-content-end">
 | 
			
		||||
      <button class="btn btn-info mr-2" (click)="loadAll()" [disabled]="isLoading">
 | 
			
		||||
        <fa-icon icon="sync" [spin]="isLoading"></fa-icon>
 | 
			
		||||
        <span jhiTranslate="dataSurveyApp.ePreguntaCerrada.home.refreshListLabel">Refresh List</span>
 | 
			
		||||
      </button>
 | 
			
		||||
 | 
			
		||||
      <button
 | 
			
		||||
        id="jh-create-entity"
 | 
			
		||||
        data-cy="entityCreateButton"
 | 
			
		||||
        class="btn btn-primary jh-create-entity create-e-pregunta-cerrada"
 | 
			
		||||
        [routerLink]="['/e-pregunta-cerrada/new']"
 | 
			
		||||
      >
 | 
			
		||||
        <fa-icon icon="plus"></fa-icon>
 | 
			
		||||
        <span jhiTranslate="dataSurveyApp.ePreguntaCerrada.home.createLabel"> Create a new E Pregunta Cerrada </span>
 | 
			
		||||
      </button>
 | 
			
		||||
    </div>
 | 
			
		||||
  </h2>
 | 
			
		||||
 | 
			
		||||
  <jhi-alert-error></jhi-alert-error>
 | 
			
		||||
 | 
			
		||||
  <jhi-alert></jhi-alert>
 | 
			
		||||
 | 
			
		||||
  <div class="alert alert-warning" id="no-result" *ngIf="ePreguntas?.length === 0">
 | 
			
		||||
    <span>No se encontraron preguntas</span>
 | 
			
		||||
  </div>
 | 
			
		||||
 | 
			
		||||
  <div class="table-responsive" id="entities" *ngIf="ePreguntas && ePreguntas.length > 0">
 | 
			
		||||
    <div>
 | 
			
		||||
      <div *ngFor="let ePregunta of ePreguntas; let i = index; trackBy: trackId" [attr.data-index]="ePregunta.id">
 | 
			
		||||
        <span>{{ ePregunta.nombre }} | </span>
 | 
			
		||||
        <span>{{ ePregunta.tipo }} | </span>
 | 
			
		||||
        <span>{{ ePregunta.opcional }}</span>
 | 
			
		||||
 | 
			
		||||
        <ng-container *ngIf="ePregunta.tipo">
 | 
			
		||||
          <ng-container *ngFor="let ePreguntaOpcion of ePreguntasOpciones; let j = index; trackBy: trackId">
 | 
			
		||||
            <ng-container *ngIf="ePregunta.id == ePreguntaOpcion[j].epreguntaCerrada.id">
 | 
			
		||||
              <div *ngFor="let ePreguntaOpcion2 of ePreguntaOpcion; let k = index; trackBy: trackId">
 | 
			
		||||
                <span>--------- {{ ePreguntaOpcion2.nombre }}</span>
 | 
			
		||||
              </div>
 | 
			
		||||
            </ng-container>
 | 
			
		||||
          </ng-container>
 | 
			
		||||
        </ng-container>
 | 
			
		||||
        <textarea *ngIf="!ePregunta.tipo" name="" id="" cols="30" rows="10"></textarea>
 | 
			
		||||
      </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    <!-- <table class="table table-striped" aria-describedby="page-heading">
 | 
			
		||||
      <thead>
 | 
			
		||||
        <tr>
 | 
			
		||||
          <th scope="col"><span jhiTranslate="global.field.id">ID</span></th>
 | 
			
		||||
          <th scope="col"><span jhiTranslate="dataSurveyApp.ePreguntaCerrada.nombre">Nombre</span></th>
 | 
			
		||||
          <th scope="col"><span jhiTranslate="dataSurveyApp.ePreguntaCerrada.tipo">Tipo</span></th>
 | 
			
		||||
          <th scope="col"><span jhiTranslate="dataSurveyApp.ePreguntaCerrada.opcional">Opcional</span></th>
 | 
			
		||||
          <th scope="col"><span jhiTranslate="dataSurveyApp.ePreguntaCerrada.orden">Orden</span></th>
 | 
			
		||||
          <th scope="col"><span jhiTranslate="dataSurveyApp.ePreguntaCerrada.encuesta">Encuesta</span></th>
 | 
			
		||||
          <th scope="col"></th>
 | 
			
		||||
        </tr>
 | 
			
		||||
      </thead>
 | 
			
		||||
      <tbody>
 | 
			
		||||
        <tr *ngFor="let ePreguntaCerrada of ePreguntaCerradas; trackBy: trackId" data-cy="entityTable">
 | 
			
		||||
          <td>
 | 
			
		||||
            <a [routerLink]="['/e-pregunta-cerrada', ePreguntaCerrada.id, 'view']">{{ ePreguntaCerrada.id }}</a>
 | 
			
		||||
          </td>
 | 
			
		||||
          <td>{{ ePreguntaCerrada.nombre }}</td>
 | 
			
		||||
          <td *ngIf="ePreguntaCerrada.tipo != undefined" jhiTranslate="{{ 'dataSurveyApp.PreguntaCerradaTipo.' + ePreguntaCerrada.tipo }}">{{ ePreguntaCerrada.tipo }}</td>
 | 
			
		||||
          <td *ngIf="ePreguntaCerrada.tipo == undefined"></td>
 | 
			
		||||
          
 | 
			
		||||
          <td>{{ ePreguntaCerrada.opcional }}</td>
 | 
			
		||||
          <td>{{ ePreguntaCerrada.orden }}</td>
 | 
			
		||||
          <td>
 | 
			
		||||
            <div *ngIf="ePreguntaCerrada.encuesta">
 | 
			
		||||
              <a [routerLink]="['/encuesta', ePreguntaCerrada.encuesta?.id, 'view']">{{ ePreguntaCerrada.encuesta?.id }}</a>
 | 
			
		||||
            </div>
 | 
			
		||||
          </td>
 | 
			
		||||
          <td class="text-right">
 | 
			
		||||
            <div class="btn-group">
 | 
			
		||||
              <button
 | 
			
		||||
                type="submit"
 | 
			
		||||
                [routerLink]="['/e-pregunta-cerrada', ePreguntaCerrada.id, 'view']"
 | 
			
		||||
                class="btn btn-info btn-sm"
 | 
			
		||||
                data-cy="entityDetailsButton"
 | 
			
		||||
              >
 | 
			
		||||
                <fa-icon icon="eye"></fa-icon>
 | 
			
		||||
                <span class="d-none d-md-inline" jhiTranslate="entity.action.view">View</span>
 | 
			
		||||
              </button>
 | 
			
		||||
 | 
			
		||||
              <button
 | 
			
		||||
                type="submit"
 | 
			
		||||
                [routerLink]="['/e-pregunta-cerrada', ePreguntaCerrada.id, 'edit']"
 | 
			
		||||
                class="btn btn-primary btn-sm"
 | 
			
		||||
                data-cy="entityEditButton"
 | 
			
		||||
              >
 | 
			
		||||
                <fa-icon icon="pencil-alt"></fa-icon>
 | 
			
		||||
                <span class="d-none d-md-inline" jhiTranslate="entity.action.edit">Edit</span>
 | 
			
		||||
              </button>
 | 
			
		||||
 | 
			
		||||
              <button type="submit" (click)="delete(ePreguntaCerrada)" class="btn btn-danger btn-sm" data-cy="entityDeleteButton">
 | 
			
		||||
                <fa-icon icon="times"></fa-icon>
 | 
			
		||||
                <span class="d-none d-md-inline" jhiTranslate="entity.action.delete">Delete</span>
 | 
			
		||||
              </button>
 | 
			
		||||
            </div>
 | 
			
		||||
          </td>
 | 
			
		||||
        </tr>
 | 
			
		||||
      </tbody>
 | 
			
		||||
    </table> -->
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
 | 
			
		||||
<!-- <div class="row justify-content-center">
 | 
			
		||||
  <div class="col-8">
 | 
			
		||||
    <form name="editForm" role="form" novalidate (ngSubmit)="save()" [formGroup]="editForm">
 | 
			
		||||
      <h2 id="jhi-encuesta-heading" data-cy="EncuestaCreateUpdateHeading" jhiTranslate="dataSurveyApp.encuesta.home.createOrEditLabel">
 | 
			
		||||
| 
						 | 
				
			
			@ -259,4 +370,4 @@
 | 
			
		|||
      </div>
 | 
			
		||||
    </form>
 | 
			
		||||
  </div>
 | 
			
		||||
</div>
 | 
			
		||||
</div> -->
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -15,6 +15,11 @@ import { CategoriaService } from 'app/entities/categoria/service/categoria.servi
 | 
			
		|||
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';
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'jhi-encuesta-update',
 | 
			
		||||
  templateUrl: './encuesta-update.component.html',
 | 
			
		||||
| 
						 | 
				
			
			@ -41,147 +46,193 @@ export class EncuestaUpdateComponent implements OnInit {
 | 
			
		|||
    usuarioExtra: [],
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  ePreguntas?: any[];
 | 
			
		||||
  ePreguntasOpciones?: any[];
 | 
			
		||||
  encuesta: Encuesta | null = null;
 | 
			
		||||
 | 
			
		||||
  isLoading = false;
 | 
			
		||||
 | 
			
		||||
  constructor(
 | 
			
		||||
    protected encuestaService: EncuestaService,
 | 
			
		||||
    protected categoriaService: CategoriaService,
 | 
			
		||||
    protected usuarioExtraService: UsuarioExtraService,
 | 
			
		||||
    protected activatedRoute: ActivatedRoute,
 | 
			
		||||
    protected fb: FormBuilder
 | 
			
		||||
    protected fb: FormBuilder,
 | 
			
		||||
    protected modalService: NgbModal
 | 
			
		||||
  ) {}
 | 
			
		||||
 | 
			
		||||
  loadAll(): void {
 | 
			
		||||
    this.isLoading = true;
 | 
			
		||||
 | 
			
		||||
    this.encuestaService.findQuestions(this.encuesta?.id!).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;
 | 
			
		||||
      }
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ngOnInit(): void {
 | 
			
		||||
    this.activatedRoute.data.subscribe(({ encuesta }) => {
 | 
			
		||||
      console.log(this.activatedRoute.data);
 | 
			
		||||
      console.log(encuesta);
 | 
			
		||||
 | 
			
		||||
      if (encuesta.id === undefined) {
 | 
			
		||||
        const today = dayjs().startOf('day');
 | 
			
		||||
        encuesta.fechaCreacion = today;
 | 
			
		||||
        encuesta.fechaPublicacion = today;
 | 
			
		||||
        encuesta.fechaFinalizar = today;
 | 
			
		||||
        encuesta.fechaFinalizada = today;
 | 
			
		||||
      } else {
 | 
			
		||||
        this.encuesta = encuesta;
 | 
			
		||||
        this.loadAll();
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      this.updateForm(encuesta);
 | 
			
		||||
      // this.updateForm(encuesta);
 | 
			
		||||
 | 
			
		||||
      this.loadRelationshipsOptions();
 | 
			
		||||
      // this.loadRelationshipsOptions();
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  previousState(): void {
 | 
			
		||||
    window.history.back();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  save(): void {
 | 
			
		||||
    this.isSaving = true;
 | 
			
		||||
    const encuesta = this.createFromForm();
 | 
			
		||||
    if (encuesta.id !== undefined) {
 | 
			
		||||
      this.subscribeToSaveResponse(this.encuestaService.update(encuesta));
 | 
			
		||||
    } else {
 | 
			
		||||
      this.subscribeToSaveResponse(this.encuestaService.create(encuesta));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  trackCategoriaById(index: number, item: ICategoria): number {
 | 
			
		||||
  trackId(index: number, item: IEPreguntaCerrada): number {
 | 
			
		||||
    return item.id!;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  trackUsuarioExtraById(index: number, item: IUsuarioExtra): number {
 | 
			
		||||
    return item.id!;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected subscribeToSaveResponse(result: Observable<HttpResponse<IEncuesta>>): void {
 | 
			
		||||
    result.pipe(finalize(() => this.onSaveFinalize())).subscribe(
 | 
			
		||||
      () => this.onSaveSuccess(),
 | 
			
		||||
      () => this.onSaveError()
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected onSaveSuccess(): void {
 | 
			
		||||
    this.previousState();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected onSaveError(): void {
 | 
			
		||||
    // Api for inheritance.
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected onSaveFinalize(): void {
 | 
			
		||||
    this.isSaving = false;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected updateForm(encuesta: IEncuesta): void {
 | 
			
		||||
    this.editForm.patchValue({
 | 
			
		||||
      id: encuesta.id,
 | 
			
		||||
      nombre: encuesta.nombre,
 | 
			
		||||
      descripcion: encuesta.descripcion,
 | 
			
		||||
      fechaCreacion: encuesta.fechaCreacion ? encuesta.fechaCreacion.format(DATE_TIME_FORMAT) : null,
 | 
			
		||||
      fechaPublicacion: encuesta.fechaPublicacion ? encuesta.fechaPublicacion.format(DATE_TIME_FORMAT) : null,
 | 
			
		||||
      fechaFinalizar: encuesta.fechaFinalizar ? encuesta.fechaFinalizar.format(DATE_TIME_FORMAT) : null,
 | 
			
		||||
      fechaFinalizada: encuesta.fechaFinalizada ? encuesta.fechaFinalizada.format(DATE_TIME_FORMAT) : null,
 | 
			
		||||
      calificacion: encuesta.calificacion,
 | 
			
		||||
      acceso: encuesta.acceso,
 | 
			
		||||
      contrasenna: encuesta.contrasenna,
 | 
			
		||||
      estado: encuesta.estado,
 | 
			
		||||
      categoria: encuesta.categoria,
 | 
			
		||||
      usuarioExtra: encuesta.usuarioExtra,
 | 
			
		||||
  delete(ePreguntaCerrada: IEPreguntaCerrada): void {
 | 
			
		||||
    const modalRef = this.modalService.open(EPreguntaCerradaDeleteDialogComponent, { size: 'lg', backdrop: 'static' });
 | 
			
		||||
    modalRef.componentInstance.ePreguntaCerrada = ePreguntaCerrada;
 | 
			
		||||
    // unsubscribe not needed because closed completes on modal close
 | 
			
		||||
    modalRef.closed.subscribe(reason => {
 | 
			
		||||
      if (reason === 'deleted') {
 | 
			
		||||
        this.loadAll();
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    this.categoriasSharedCollection = this.categoriaService.addCategoriaToCollectionIfMissing(
 | 
			
		||||
      this.categoriasSharedCollection,
 | 
			
		||||
      encuesta.categoria
 | 
			
		||||
    );
 | 
			
		||||
    this.usuarioExtrasSharedCollection = this.usuarioExtraService.addUsuarioExtraToCollectionIfMissing(
 | 
			
		||||
      this.usuarioExtrasSharedCollection,
 | 
			
		||||
      encuesta.usuarioExtra
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  protected loadRelationshipsOptions(): void {
 | 
			
		||||
    this.categoriaService
 | 
			
		||||
      .query()
 | 
			
		||||
      .pipe(map((res: HttpResponse<ICategoria[]>) => res.body ?? []))
 | 
			
		||||
      .pipe(
 | 
			
		||||
        map((categorias: ICategoria[]) =>
 | 
			
		||||
          this.categoriaService.addCategoriaToCollectionIfMissing(categorias, this.editForm.get('categoria')!.value)
 | 
			
		||||
        )
 | 
			
		||||
      )
 | 
			
		||||
      .subscribe((categorias: ICategoria[]) => (this.categoriasSharedCollection = categorias));
 | 
			
		||||
  // previousState(): void {
 | 
			
		||||
  //   window.history.back();
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
    this.usuarioExtraService
 | 
			
		||||
      .query()
 | 
			
		||||
      .pipe(map((res: HttpResponse<IUsuarioExtra[]>) => res.body ?? []))
 | 
			
		||||
      .pipe(
 | 
			
		||||
        map((usuarioExtras: IUsuarioExtra[]) =>
 | 
			
		||||
          this.usuarioExtraService.addUsuarioExtraToCollectionIfMissing(usuarioExtras, this.editForm.get('usuarioExtra')!.value)
 | 
			
		||||
        )
 | 
			
		||||
      )
 | 
			
		||||
      .subscribe((usuarioExtras: IUsuarioExtra[]) => (this.usuarioExtrasSharedCollection = usuarioExtras));
 | 
			
		||||
  }
 | 
			
		||||
  // save(): void {
 | 
			
		||||
  //   this.isSaving = true;
 | 
			
		||||
  //   const encuesta = this.createFromForm();
 | 
			
		||||
  //   if (encuesta.id !== undefined) {
 | 
			
		||||
  //     this.subscribeToSaveResponse(this.encuestaService.update(encuesta));
 | 
			
		||||
  //   } else {
 | 
			
		||||
  //     this.subscribeToSaveResponse(this.encuestaService.create(encuesta));
 | 
			
		||||
  //   }
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  protected createFromForm(): IEncuesta {
 | 
			
		||||
    return {
 | 
			
		||||
      ...new Encuesta(),
 | 
			
		||||
      id: this.editForm.get(['id'])!.value,
 | 
			
		||||
      nombre: this.editForm.get(['nombre'])!.value,
 | 
			
		||||
      descripcion: this.editForm.get(['descripcion'])!.value,
 | 
			
		||||
      fechaCreacion: this.editForm.get(['fechaCreacion'])!.value
 | 
			
		||||
        ? dayjs(this.editForm.get(['fechaCreacion'])!.value, DATE_TIME_FORMAT)
 | 
			
		||||
        : undefined,
 | 
			
		||||
      fechaPublicacion: this.editForm.get(['fechaPublicacion'])!.value
 | 
			
		||||
        ? dayjs(this.editForm.get(['fechaPublicacion'])!.value, DATE_TIME_FORMAT)
 | 
			
		||||
        : undefined,
 | 
			
		||||
      fechaFinalizar: this.editForm.get(['fechaFinalizar'])!.value
 | 
			
		||||
        ? dayjs(this.editForm.get(['fechaFinalizar'])!.value, DATE_TIME_FORMAT)
 | 
			
		||||
        : undefined,
 | 
			
		||||
      fechaFinalizada: this.editForm.get(['fechaFinalizada'])!.value
 | 
			
		||||
        ? dayjs(this.editForm.get(['fechaFinalizada'])!.value, DATE_TIME_FORMAT)
 | 
			
		||||
        : undefined,
 | 
			
		||||
      calificacion: this.editForm.get(['calificacion'])!.value,
 | 
			
		||||
      acceso: this.editForm.get(['acceso'])!.value,
 | 
			
		||||
      contrasenna: this.editForm.get(['contrasenna'])!.value,
 | 
			
		||||
      estado: this.editForm.get(['estado'])!.value,
 | 
			
		||||
      categoria: this.editForm.get(['categoria'])!.value,
 | 
			
		||||
      usuarioExtra: this.editForm.get(['usuarioExtra'])!.value,
 | 
			
		||||
    };
 | 
			
		||||
  }
 | 
			
		||||
  // trackCategoriaById(index: number, item: ICategoria): number {
 | 
			
		||||
  //   return item.id!;
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // trackUsuarioExtraById(index: number, item: IUsuarioExtra): number {
 | 
			
		||||
  //   return item.id!;
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // protected subscribeToSaveResponse(result: Observable<HttpResponse<IEncuesta>>): void {
 | 
			
		||||
  //   result.pipe(finalize(() => this.onSaveFinalize())).subscribe(
 | 
			
		||||
  //     () => this.onSaveSuccess(),
 | 
			
		||||
  //     () => this.onSaveError()
 | 
			
		||||
  //   );
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // protected onSaveSuccess(): void {
 | 
			
		||||
  //   this.previousState();
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // protected onSaveError(): void {
 | 
			
		||||
  //   // Api for inheritance.
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // protected onSaveFinalize(): void {
 | 
			
		||||
  //   this.isSaving = false;
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // protected updateForm(encuesta: IEncuesta): void {
 | 
			
		||||
  //   this.editForm.patchValue({
 | 
			
		||||
  //     id: encuesta.id,
 | 
			
		||||
  //     nombre: encuesta.nombre,
 | 
			
		||||
  //     descripcion: encuesta.descripcion,
 | 
			
		||||
  //     fechaCreacion: encuesta.fechaCreacion ? encuesta.fechaCreacion.format(DATE_TIME_FORMAT) : null,
 | 
			
		||||
  //     fechaPublicacion: encuesta.fechaPublicacion ? encuesta.fechaPublicacion.format(DATE_TIME_FORMAT) : null,
 | 
			
		||||
  //     fechaFinalizar: encuesta.fechaFinalizar ? encuesta.fechaFinalizar.format(DATE_TIME_FORMAT) : null,
 | 
			
		||||
  //     fechaFinalizada: encuesta.fechaFinalizada ? encuesta.fechaFinalizada.format(DATE_TIME_FORMAT) : null,
 | 
			
		||||
  //     calificacion: encuesta.calificacion,
 | 
			
		||||
  //     acceso: encuesta.acceso,
 | 
			
		||||
  //     contrasenna: encuesta.contrasenna,
 | 
			
		||||
  //     estado: encuesta.estado,
 | 
			
		||||
  //     categoria: encuesta.categoria,
 | 
			
		||||
  //     usuarioExtra: encuesta.usuarioExtra,
 | 
			
		||||
  //   });
 | 
			
		||||
 | 
			
		||||
  //   this.categoriasSharedCollection = this.categoriaService.addCategoriaToCollectionIfMissing(
 | 
			
		||||
  //     this.categoriasSharedCollection,
 | 
			
		||||
  //     encuesta.categoria
 | 
			
		||||
  //   );
 | 
			
		||||
  //   this.usuarioExtrasSharedCollection = this.usuarioExtraService.addUsuarioExtraToCollectionIfMissing(
 | 
			
		||||
  //     this.usuarioExtrasSharedCollection,
 | 
			
		||||
  //     encuesta.usuarioExtra
 | 
			
		||||
  //   );
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // protected loadRelationshipsOptions(): void {
 | 
			
		||||
  //   this.categoriaService
 | 
			
		||||
  //     .query()
 | 
			
		||||
  //     .pipe(map((res: HttpResponse<ICategoria[]>) => res.body ?? []))
 | 
			
		||||
  //     .pipe(
 | 
			
		||||
  //       map((categorias: ICategoria[]) =>
 | 
			
		||||
  //         this.categoriaService.addCategoriaToCollectionIfMissing(categorias, this.editForm.get('categoria')!.value)
 | 
			
		||||
  //       )
 | 
			
		||||
  //     )
 | 
			
		||||
  //     .subscribe((categorias: ICategoria[]) => (this.categoriasSharedCollection = categorias));
 | 
			
		||||
 | 
			
		||||
  //   this.usuarioExtraService
 | 
			
		||||
  //     .query()
 | 
			
		||||
  //     .pipe(map((res: HttpResponse<IUsuarioExtra[]>) => res.body ?? []))
 | 
			
		||||
  //     .pipe(
 | 
			
		||||
  //       map((usuarioExtras: IUsuarioExtra[]) =>
 | 
			
		||||
  //         this.usuarioExtraService.addUsuarioExtraToCollectionIfMissing(usuarioExtras, this.editForm.get('usuarioExtra')!.value)
 | 
			
		||||
  //       )
 | 
			
		||||
  //     )
 | 
			
		||||
  //     .subscribe((usuarioExtras: IUsuarioExtra[]) => (this.usuarioExtrasSharedCollection = usuarioExtras));
 | 
			
		||||
  // }
 | 
			
		||||
 | 
			
		||||
  // protected createFromForm(): IEncuesta {
 | 
			
		||||
  //   return {
 | 
			
		||||
  //     ...new Encuesta(),
 | 
			
		||||
  //     id: this.editForm.get(['id'])!.value,
 | 
			
		||||
  //     nombre: this.editForm.get(['nombre'])!.value,
 | 
			
		||||
  //     descripcion: this.editForm.get(['descripcion'])!.value,
 | 
			
		||||
  //     fechaCreacion: this.editForm.get(['fechaCreacion'])!.value
 | 
			
		||||
  //       ? dayjs(this.editForm.get(['fechaCreacion'])!.value, DATE_TIME_FORMAT)
 | 
			
		||||
  //       : undefined,
 | 
			
		||||
  //     fechaPublicacion: this.editForm.get(['fechaPublicacion'])!.value
 | 
			
		||||
  //       ? dayjs(this.editForm.get(['fechaPublicacion'])!.value, DATE_TIME_FORMAT)
 | 
			
		||||
  //       : undefined,
 | 
			
		||||
  //     fechaFinalizar: this.editForm.get(['fechaFinalizar'])!.value
 | 
			
		||||
  //       ? dayjs(this.editForm.get(['fechaFinalizar'])!.value, DATE_TIME_FORMAT)
 | 
			
		||||
  //       : undefined,
 | 
			
		||||
  //     fechaFinalizada: this.editForm.get(['fechaFinalizada'])!.value
 | 
			
		||||
  //       ? dayjs(this.editForm.get(['fechaFinalizada'])!.value, DATE_TIME_FORMAT)
 | 
			
		||||
  //       : undefined,
 | 
			
		||||
  //     calificacion: this.editForm.get(['calificacion'])!.value,
 | 
			
		||||
  //     acceso: this.editForm.get(['acceso'])!.value,
 | 
			
		||||
  //     contrasenna: this.editForm.get(['contrasenna'])!.value,
 | 
			
		||||
  //     estado: this.editForm.get(['estado'])!.value,
 | 
			
		||||
  //     categoria: this.editForm.get(['categoria'])!.value,
 | 
			
		||||
  //     usuarioExtra: this.editForm.get(['usuarioExtra'])!.value,
 | 
			
		||||
  //   };
 | 
			
		||||
  // }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -75,7 +75,9 @@ $form-background: #f1f5f9;
 | 
			
		|||
  }
 | 
			
		||||
 | 
			
		||||
  label {
 | 
			
		||||
    font-size: 0.8rem;
 | 
			
		||||
    color: #757d94;
 | 
			
		||||
    margin-bottom: 0.5rem;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue