2021-07-24 04:50:40 +00:00
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
|
import { IEncuesta } from '../encuesta.model';
|
|
|
|
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
|
|
|
|
import { EncuestaService } from '../service/encuesta.service';
|
|
|
|
import { EstadoEncuesta } from '../../enumerations/estado-encuesta.model';
|
2021-07-25 04:53:38 +00:00
|
|
|
import { AccesoEncuesta } from '../../enumerations/acceso-encuesta.model';
|
|
|
|
import { passwordResetFinishRoute } from '../../../account/password-reset/finish/password-reset-finish.route';
|
2021-07-24 04:50:40 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'jhi-encuesta-publish-dialog',
|
|
|
|
templateUrl: './encuesta-publish-dialog.component.html',
|
|
|
|
styleUrls: ['./encuesta-publish-dialog.component.scss'],
|
|
|
|
})
|
|
|
|
export class EncuestaPublishDialogComponent implements OnInit {
|
|
|
|
encuesta?: IEncuesta;
|
2021-07-26 01:20:07 +00:00
|
|
|
fechaFinalizar?: Date;
|
|
|
|
fechaFinalizarInvalid?: boolean;
|
2021-07-24 04:50:40 +00:00
|
|
|
|
|
|
|
constructor(protected encuestaService: EncuestaService, protected activeModal: NgbActiveModal) {}
|
|
|
|
|
|
|
|
cancel(): void {
|
|
|
|
this.activeModal.dismiss();
|
|
|
|
}
|
|
|
|
|
|
|
|
confirmPublish(encuesta: IEncuesta): void {
|
|
|
|
debugger;
|
|
|
|
if (encuesta.estado === 'DRAFT') {
|
|
|
|
encuesta.estado = EstadoEncuesta.ACTIVE;
|
|
|
|
}
|
|
|
|
|
2021-07-25 04:53:38 +00:00
|
|
|
if (encuesta.acceso === AccesoEncuesta.PRIVATE) {
|
|
|
|
encuesta.contrasenna = this.generatePassword();
|
|
|
|
}
|
|
|
|
|
2021-07-24 04:50:40 +00:00
|
|
|
this.encuestaService.update(encuesta).subscribe(() => {
|
|
|
|
this.activeModal.close('published');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-07-26 01:20:07 +00:00
|
|
|
fechaFinalizarIsInvalid(): void {
|
|
|
|
const now = new Date();
|
|
|
|
debugger;
|
|
|
|
this.fechaFinalizarInvalid = now < this.fechaFinalizar!;
|
|
|
|
}
|
|
|
|
|
2021-07-25 04:53:38 +00:00
|
|
|
generatePassword(): string {
|
|
|
|
debugger;
|
|
|
|
const alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
|
|
|
|
|
|
|
|
let password = '';
|
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
password += alpha.charAt(Math.floor(Math.random() * alpha.length));
|
|
|
|
}
|
|
|
|
return password;
|
|
|
|
}
|
|
|
|
|
2021-07-26 01:20:07 +00:00
|
|
|
ngOnInit(): void {
|
|
|
|
this.fechaFinalizar = new Date();
|
|
|
|
this.fechaFinalizarInvalid = false;
|
|
|
|
}
|
2021-07-24 04:50:40 +00:00
|
|
|
}
|