Add update survey
This commit is contained in:
		
							parent
							
								
									340bfbb67f
								
							
						
					
					
						commit
						300f20affd
					
				| 
						 | 
					@ -136,6 +136,31 @@ public class EncuestaResource {
 | 
				
			||||||
            .body(result);
 | 
					            .body(result);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @PutMapping("/encuestas/update/{id}")
 | 
				
			||||||
 | 
					    public ResponseEntity<Encuesta> updateEncuestaReal(
 | 
				
			||||||
 | 
					        @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);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return ResponseEntity
 | 
				
			||||||
 | 
					            .ok()
 | 
				
			||||||
 | 
					            .headers(HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, encuesta.getId().toString()))
 | 
				
			||||||
 | 
					            .body(result);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @PutMapping("/encuestas/publish/{id}")
 | 
					    @PutMapping("/encuestas/publish/{id}")
 | 
				
			||||||
    public ResponseEntity<Encuesta> publishEncuesta(
 | 
					    public ResponseEntity<Encuesta> publishEncuesta(
 | 
				
			||||||
        @PathVariable(value = "id", required = false) final Long id,
 | 
					        @PathVariable(value = "id", required = false) final Long id,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -33,6 +33,13 @@ export class EncuestaService {
 | 
				
			||||||
      .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
 | 
					      .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  updateSurvey(encuesta: IEncuesta): Observable<EntityResponseType> {
 | 
				
			||||||
 | 
					    const copy = this.convertDateFromClient(encuesta);
 | 
				
			||||||
 | 
					    return this.http
 | 
				
			||||||
 | 
					      .put<IEncuesta>(`${this.resourceUrl}/update/${getEncuestaIdentifier(encuesta) as number}`, copy, { observe: 'response' })
 | 
				
			||||||
 | 
					      .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  partialUpdate(encuesta: IEncuesta): Observable<EntityResponseType> {
 | 
					  partialUpdate(encuesta: IEncuesta): Observable<EntityResponseType> {
 | 
				
			||||||
    const copy = this.convertDateFromClient(encuesta);
 | 
					    const copy = this.convertDateFromClient(encuesta);
 | 
				
			||||||
    return this.http
 | 
					    return this.http
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,7 +1,7 @@
 | 
				
			||||||
<div>
 | 
					<div>
 | 
				
			||||||
  <h2 id="page-heading" data-cy="EPreguntaCerradaHeading">
 | 
					  <h2 id="page-heading" data-cy="EPreguntaCerradaHeading">
 | 
				
			||||||
    <div class="d-flex align-items-center">
 | 
					    <div class="d-flex align-items-center">
 | 
				
			||||||
      <p class="ds-title">{{ encuesta!.nombre }}</p>
 | 
					      <p class="ds-title ds-title--interactive" contenteditable="true" (blur)="updateSurveyName($event)">{{ encuesta!.nombre }}</p>
 | 
				
			||||||
        <fa-icon
 | 
					        <fa-icon
 | 
				
			||||||
        class="ds-info--icon"
 | 
					        class="ds-info--icon"
 | 
				
			||||||
        [icon]="faQuestion"
 | 
					        [icon]="faQuestion"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -160,7 +160,7 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  ngAfterViewChecked(): void {
 | 
					  ngAfterViewChecked(): void {
 | 
				
			||||||
    this.initListeners();
 | 
					    // this.initListeners();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  trackId(index: number, item: IEPreguntaCerrada): number {
 | 
					  trackId(index: number, item: IEPreguntaCerrada): number {
 | 
				
			||||||
| 
						 | 
					@ -178,18 +178,18 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  initListeners(): void {
 | 
					  // initListeners(): void {
 | 
				
			||||||
    const checkboxes = document.getElementsByClassName('ds-survey--checkbox');
 | 
					  //   const checkboxes = document.getElementsByClassName('ds-survey--checkbox');
 | 
				
			||||||
    for (let i = 0; i < checkboxes.length; i++) {
 | 
					  //   for (let i = 0; i < checkboxes.length; i++) {
 | 
				
			||||||
      checkboxes[i].addEventListener('click', e => {
 | 
					  //     checkboxes[i].addEventListener('click', e => {
 | 
				
			||||||
        if ((e.target as HTMLInputElement).checked) {
 | 
					  //       if ((e.target as HTMLInputElement).checked) {
 | 
				
			||||||
          (e.target as HTMLElement).offsetParent!.classList.add('ds-survey--closed-option--active');
 | 
					  //         (e.target as HTMLElement).offsetParent!.classList.add('ds-survey--closed-option--active');
 | 
				
			||||||
        } else {
 | 
					  //       } else {
 | 
				
			||||||
          (e.target as HTMLElement).offsetParent!.classList.remove('ds-survey--closed-option--active');
 | 
					  //         (e.target as HTMLElement).offsetParent!.classList.remove('ds-survey--closed-option--active');
 | 
				
			||||||
        }
 | 
					  //       }
 | 
				
			||||||
      });
 | 
					  //     });
 | 
				
			||||||
    }
 | 
					  //   }
 | 
				
			||||||
  }
 | 
					  // }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  previousState(): void {
 | 
					  previousState(): void {
 | 
				
			||||||
    window.history.back();
 | 
					    window.history.back();
 | 
				
			||||||
| 
						 | 
					@ -416,6 +416,21 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
 | 
				
			||||||
    this.isSavingQuestion = false;
 | 
					    this.isSavingQuestion = false;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  updateSurveyName(event: any) {
 | 
				
			||||||
 | 
					    const updatedSurveyName = event.target.innerText;
 | 
				
			||||||
 | 
					    if (updatedSurveyName !== this.encuesta?.nombre) {
 | 
				
			||||||
 | 
					      const survey = { ...this.encuesta };
 | 
				
			||||||
 | 
					      survey.nombre = updatedSurveyName;
 | 
				
			||||||
 | 
					      survey.usuarioExtra!.user = null;
 | 
				
			||||||
 | 
					      console.log(survey);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      this.encuestaService.updateSurvey(survey).subscribe(res => {
 | 
				
			||||||
 | 
					        console.log('UPDATED');
 | 
				
			||||||
 | 
					        console.log(res);
 | 
				
			||||||
 | 
					      });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // previousState(): void {
 | 
					  // previousState(): void {
 | 
				
			||||||
  //   window.history.back();
 | 
					  //   window.history.back();
 | 
				
			||||||
  // }
 | 
					  // }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,6 +9,20 @@
 | 
				
			||||||
  letter-spacing: 0.025rem;
 | 
					  letter-spacing: 0.025rem;
 | 
				
			||||||
  text-transform: uppercase;
 | 
					  text-transform: uppercase;
 | 
				
			||||||
  font-size: 1.2rem;
 | 
					  font-size: 1.2rem;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  &--interactive {
 | 
				
			||||||
 | 
					    border: 2.25px solid transparent;
 | 
				
			||||||
 | 
					    border-radius: 3px;
 | 
				
			||||||
 | 
					    outline: 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    &:hover {
 | 
				
			||||||
 | 
					      border: 2.25px solid #e5e5e5;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    &:focus {
 | 
				
			||||||
 | 
					      border: 2.25px solid #2962ff;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.ds-title--small {
 | 
					.ds-title--small {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue