agregar boton y dialog de finalizar encuesta
This commit is contained in:
		
							parent
							
								
									ba7b12fbdc
								
							
						
					
					
						commit
						9d310922e2
					
				| 
						 | 
				
			
			@ -0,0 +1,19 @@
 | 
			
		|||
<form *ngIf="encuesta" name="deleteForm" (ngSubmit)="confirmFinalizar(encuesta!)">
 | 
			
		||||
  <div class="modal-header">
 | 
			
		||||
    <h4 class="ds-title--small" data-cy="encuestaDeleteDialogHeading">Finalizar encuesta</h4>
 | 
			
		||||
  </div>
 | 
			
		||||
 | 
			
		||||
  <div class="modal-body">
 | 
			
		||||
    <p class="ds-subtitle" id="jhi-delete-encuesta-heading">¿Está seguro de querer finalizar la encuesta?</p>
 | 
			
		||||
  </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-encuesta" data-cy="entityConfirmDeleteButton" type="submit" class="ds-btn ds-btn--danger">
 | 
			
		||||
       <span>Finalizar</span>
 | 
			
		||||
    </button>
 | 
			
		||||
  </div>
 | 
			
		||||
</form>
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,24 @@
 | 
			
		|||
import { ComponentFixture, TestBed } from '@angular/core/testing';
 | 
			
		||||
 | 
			
		||||
import { EncuestaFinalizarDialogComponent } from './encuesta-finalizar-dialog.component';
 | 
			
		||||
 | 
			
		||||
describe('EncuestaFinalizarDialogComponent', () => {
 | 
			
		||||
  let component: EncuestaFinalizarDialogComponent;
 | 
			
		||||
  let fixture: ComponentFixture<EncuestaFinalizarDialogComponent>;
 | 
			
		||||
 | 
			
		||||
  beforeEach(async () => {
 | 
			
		||||
    await TestBed.configureTestingModule({
 | 
			
		||||
      declarations: [EncuestaFinalizarDialogComponent],
 | 
			
		||||
    }).compileComponents();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  beforeEach(() => {
 | 
			
		||||
    fixture = TestBed.createComponent(EncuestaFinalizarDialogComponent);
 | 
			
		||||
    component = fixture.componentInstance;
 | 
			
		||||
    fixture.detectChanges();
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  it('should create', () => {
 | 
			
		||||
    expect(component).toBeTruthy();
 | 
			
		||||
  });
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,36 @@
 | 
			
		|||
import { Component, OnInit } from '@angular/core';
 | 
			
		||||
import { IEncuesta } from '../encuesta.model';
 | 
			
		||||
import { EstadoEncuesta } from '../../enumerations/estado-encuesta.model';
 | 
			
		||||
import { EncuestaService } from '../service/encuesta.service';
 | 
			
		||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
 | 
			
		||||
import * as dayjs from 'dayjs';
 | 
			
		||||
import { DATE_TIME_FORMAT } from '../../../config/input.constants';
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'jhi-encuesta-finalizar-dialog',
 | 
			
		||||
  templateUrl: './encuesta-finalizar-dialog.component.html',
 | 
			
		||||
  styleUrls: ['./encuesta-finalizar-dialog.component.scss'],
 | 
			
		||||
})
 | 
			
		||||
export class EncuestaFinalizarDialogComponent implements OnInit {
 | 
			
		||||
  encuesta?: IEncuesta;
 | 
			
		||||
 | 
			
		||||
  constructor(protected encuestaService: EncuestaService, protected activeModal: NgbActiveModal) {}
 | 
			
		||||
 | 
			
		||||
  ngOnInit(): void {}
 | 
			
		||||
 | 
			
		||||
  confirmFinalizar(encuesta: IEncuesta): void {
 | 
			
		||||
    debugger;
 | 
			
		||||
    const now = dayjs();
 | 
			
		||||
 | 
			
		||||
    encuesta.estado = EstadoEncuesta.FINISHED;
 | 
			
		||||
    encuesta.fechaFinalizada = dayjs(now, DATE_TIME_FORMAT);
 | 
			
		||||
 | 
			
		||||
    this.encuestaService.updateSurvey(encuesta).subscribe(() => {
 | 
			
		||||
      this.activeModal.close('finalized');
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  cancel(): void {
 | 
			
		||||
    this.activeModal.dismiss();
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -10,6 +10,7 @@ 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 { EncuestaFinalizarDialogComponent } from './encuesta-finalizar-dialog/encuesta-finalizar-dialog.component';
 | 
			
		||||
 | 
			
		||||
@NgModule({
 | 
			
		||||
  imports: [SharedModule, EncuestaRoutingModule, FontAwesomeModule],
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +23,7 @@ import { EncuestaCompartirDialogComponent } from './encuesta-compartir-dialog/en
 | 
			
		|||
    EncuestaDeleteQuestionDialogComponent,
 | 
			
		||||
    EncuestaDeleteOptionDialogComponent,
 | 
			
		||||
    EncuestaCompartirDialogComponent,
 | 
			
		||||
    EncuestaFinalizarDialogComponent,
 | 
			
		||||
  ],
 | 
			
		||||
  entryComponents: [EncuestaDeleteDialogComponent],
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,6 +26,7 @@ export class EncuestaService {
 | 
			
		|||
      .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  //update para publicar
 | 
			
		||||
  update(encuesta: IEncuesta): Observable<EntityResponseType> {
 | 
			
		||||
    const copy = this.convertDateFromClient(encuesta);
 | 
			
		||||
    return this.http
 | 
			
		||||
| 
						 | 
				
			
			@ -33,6 +34,7 @@ export class EncuestaService {
 | 
			
		|||
      .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  //update normal
 | 
			
		||||
  updateSurvey(encuesta: IEncuesta): Observable<EntityResponseType> {
 | 
			
		||||
    const copy = this.convertDateFromClient(encuesta);
 | 
			
		||||
    return this.http
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -40,6 +40,9 @@
 | 
			
		|||
    </div>
 | 
			
		||||
 | 
			
		||||
    <p class="ds-subtitle">Creada el día {{ encuesta!.fechaCreacion | formatShortDatetime | lowercase }}</p>
 | 
			
		||||
    <button type="button" class="ds-btn ds-btn--danger" (click)="finalizar()" *ngIf="encuesta!.estado === 'ACTIVE'">
 | 
			
		||||
      <fa-icon icon="sync" [icon]="faTimes"></fa-icon>  <span>Finalizar</span>
 | 
			
		||||
    </button>
 | 
			
		||||
 | 
			
		||||
    <div class="d-flex justify-content-end">
 | 
			
		||||
      <button type="button" class="ds-btn ds-btn--secondary" (click)="previousState()">
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +59,7 @@
 | 
			
		|||
        [disabled]="isLoading"
 | 
			
		||||
        data-toggle="modal"
 | 
			
		||||
        data-target="#crearPregunta"
 | 
			
		||||
        *ngIf="encuesta!.estado !== 'FINISHED'"
 | 
			
		||||
      >
 | 
			
		||||
        <fa-icon icon="sync" [icon]="faPlus"></fa-icon>  <span>Crear pregunta</span>
 | 
			
		||||
      </button>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,6 +39,8 @@ import { IUsuarioEncuesta } from '../../usuario-encuesta/usuario-encuesta.model'
 | 
			
		|||
import { RolColaborador } from '../../enumerations/rol-colaborador.model';
 | 
			
		||||
import { Account } from '../../../core/auth/account.model';
 | 
			
		||||
import { AccountService } from 'app/core/auth/account.service';
 | 
			
		||||
import { EncuestaPublishDialogComponent } from '../encuesta-publish-dialog/encuesta-publish-dialog.component';
 | 
			
		||||
import { EncuestaFinalizarDialogComponent } from '../encuesta-finalizar-dialog/encuesta-finalizar-dialog.component';
 | 
			
		||||
 | 
			
		||||
@Component({
 | 
			
		||||
  selector: 'jhi-encuesta-update',
 | 
			
		||||
| 
						 | 
				
			
			@ -54,6 +56,7 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
 | 
			
		|||
  isSaving = false;
 | 
			
		||||
  isSavingQuestion = false;
 | 
			
		||||
  isSavingCollab = false;
 | 
			
		||||
  finalizada = false;
 | 
			
		||||
  public rolSeleccionado: RolColaborador | undefined = undefined;
 | 
			
		||||
  categoriasSharedCollection: ICategoria[] = [];
 | 
			
		||||
  usuarioExtrasSharedCollection: IUsuarioExtra[] = [];
 | 
			
		||||
| 
						 | 
				
			
			@ -662,4 +665,16 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
 | 
			
		|||
  isAutor() {
 | 
			
		||||
    return this.usuarioExtra?.id == this.encuesta?.usuarioExtra?.id;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  finalizar(): void {
 | 
			
		||||
    const modalRef = this.modalService.open(EncuestaFinalizarDialogComponent, { size: 'lg', backdrop: 'static' });
 | 
			
		||||
    modalRef.componentInstance.encuesta = this.encuesta;
 | 
			
		||||
    // unsubscribe not needed because closed completes on modal close
 | 
			
		||||
    modalRef.closed.subscribe(reason => {
 | 
			
		||||
      if (reason === 'finalized') {
 | 
			
		||||
        this.finalizada = true;
 | 
			
		||||
        this.loadAll();
 | 
			
		||||
      }
 | 
			
		||||
    });
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue