Merge pull request #123 from Quantum-P3/feature/US-46

agregar calificacion de encuesta
This commit is contained in:
Eduardo Quiros 2021-08-13 08:20:08 +00:00 committed by GitHub
commit 119ed8f2d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 1214 additions and 980 deletions

2102
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -22,7 +22,7 @@
<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 class="ds-survey--question-wrapper card-encuesta" *ngFor="let ePregunta of ePreguntas; let i = index; trackBy: trackId">
<div
[attr.data-index]="ePregunta.id"
[attr.data-tipo]="ePregunta.tipo"
@ -79,7 +79,25 @@
</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>
<textarea class="ds-survey--textarea" id="{{ ePregunta.id }}" cols="33" rows="10"></textarea>
</div>
</div>
</div>
<div class="ds-survey--question-wrapper card-encuesta">
<div class="ds-survey--question">
<div class="ds-survey--rating">
<div class="ds-survey--titulo">
<span class="ds-survey--titulo--name">Calificación</span>
</div>
<div class="ds-survey--option ds-survey--option--base">
<fa-icon
*ngFor="let starNumber of this.stars"
id="{{ 'star-' + starNumber }}"
class="entity-icon--star--off"
[icon]="faStar"
(click)="updateRating(starNumber)"
></fa-icon>
</div>
</div>
</div>
</div>
@ -139,21 +157,21 @@
<div class="mb-5">
<p class="ds-subtitle">Fecha de finalización</p>
<P>
<p>
{{
encuesta.fechaFinalizada === undefined
? 'Sin finalizar'
: (encuesta.fechaFinalizada | formatShortDatetime | lowercase)
}}
</P>
</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(this.avgCalificacion)" class="entity-icon--star" [icon]="faStar"></fa-icon
><fa-icon
*ngFor="let i of [].constructor(5 - encuesta.calificacion!)"
*ngFor="let i of [].constructor(5 - this.avgCalificacion)"
class="entity-icon--star--off"
[icon]="faStar"
></fa-icon>

View File

@ -39,6 +39,11 @@ export class EncuestaCompleteComponent implements OnInit {
selectedSingleOptions: any;
selectedMultiOptions: any;
error: boolean;
calificacion: number;
stars: number[] = [1, 2, 3, 4, 5];
cantidadCalificaciones: number = 0;
avgCalificacion: number = 0;
sumCalificacion: number = 0;
constructor(
protected activatedRoute: ActivatedRoute,
@ -55,12 +60,16 @@ export class EncuestaCompleteComponent implements OnInit {
this.selectedSingleOptions = {};
this.selectedMultiOptions = [];
this.error = false;
this.calificacion = 0;
}
ngOnInit(): void {
this.activatedRoute.data.subscribe(({ encuesta }) => {
if (encuesta) {
this.encuesta = encuesta;
this.avgCalificacion = parseInt(this.encuesta!.calificacion!.toString().split('.')[0]);
this.cantidadCalificaciones = parseInt(this.encuesta!.calificacion!.toString().split('.')[1]);
this.sumCalificacion = this.avgCalificacion * this.cantidadCalificaciones;
}
this.isLocked = this.verifyPassword();
if (this.isLocked) {
@ -177,17 +186,29 @@ export class EncuestaCompleteComponent implements OnInit {
}
finish(): void {
this.updateEncuestaRating();
this.getOpenQuestionAnswers();
this.registerOpenQuestionAnswers();
this.updateClosedOptionsCount();
}
updateEncuestaRating() {
if (this.calificacion !== 0) {
const newSumCalificacion = this.sumCalificacion + this.calificacion;
const newCantidadCalificacion = this.cantidadCalificaciones + 1;
const newAvgCalificacion = newSumCalificacion / newCantidadCalificacion;
const newRating = this.joinRatingValues(newAvgCalificacion, newCantidadCalificacion);
this.encuesta!.calificacion = Number(newRating);
this.encuestaService.updateSurvey(this.encuesta!);
}
}
updateClosedOptionsCount() {
for (let key in this.selectedSingleOptions) {
this.subscribeToSaveResponse(this.ePreguntaCerradaOpcionService.updateCount(this.selectedSingleOptions[key]));
this.ePreguntaCerradaOpcionService.updateCount(this.selectedSingleOptions[key]);
}
this.selectedMultiOptions.forEach((option: any) => {
this.subscribeToSaveResponse(this.ePreguntaCerradaOpcionService.updateCount(option));
this.ePreguntaCerradaOpcionService.updateCount(option);
});
}
@ -197,7 +218,7 @@ export class EncuestaCompleteComponent implements OnInit {
return p.id == id;
});
let newRespuesta = new EPreguntaAbiertaRespuesta(0, this.selectedOpenOptions[id], pregunta);
this.subscribeToSaveResponse(this.ePreguntaAbiertaRespuestaService.create(newRespuesta));
this.ePreguntaAbiertaRespuestaService.create(newRespuesta);
}
}
@ -226,4 +247,23 @@ export class EncuestaCompleteComponent implements OnInit {
}
});
}
joinRatingValues(totalValue: number, ratingCount: number): Number {
const result = totalValue.toString() + '.' + ratingCount.toString();
return parseFloat(result);
}
updateRating(value: number) {
this.calificacion = value;
this.stars.forEach(starNumber => {
let starElement = document.getElementById(`star-${starNumber}`);
if (starNumber > this.calificacion!) {
starElement!.classList.add('entity-icon--star--off');
starElement!.classList.remove('entity-icon--star');
} else {
starElement!.classList.add('entity-icon--star');
starElement!.classList.remove('entity-icon--star--off');
}
});
}
}

View File

@ -19,7 +19,6 @@ export class EncuestaFinalizarDialogComponent implements OnInit {
ngOnInit(): void {}
confirmFinalizar(encuesta: IEncuesta): void {
debugger;
const now = dayjs();
encuesta.estado = EstadoEncuesta.FINISHED;

View File

@ -107,7 +107,6 @@ export class EncuestaPublishDialogComponent implements OnInit {
fechaFinalizacionIsInvalid(fechaFinalizar: dayjs.Dayjs, fechaPublicacion: dayjs.Dayjs): boolean {
let numberDays: number;
debugger;
numberDays = fechaFinalizar?.diff(fechaPublicacion, 'days');

View File

@ -19,7 +19,6 @@ export class FacturaService {
constructor(protected http: HttpClient, protected applicationConfigService: ApplicationConfigService) {}
create(factura: IFactura): Observable<EntityResponseType> {
debugger;
const copy = this.convertDateFromClient(factura);
return this.http
.post<IFactura>(this.resourceUrl, copy, { observe: 'response' })

View File

@ -76,7 +76,7 @@
</ng-container>
</ng-container>
<div class="ds-survey--option ds-survey--option--base ds-survey--open-option" *ngIf="!pPregunta.tipo">
<textarea cols="30" rows="10" disabled></textarea>
<textarea class="ds-survey--textarea" cols="30" rows="10" disabled></textarea>
</div>
</div>
</div>

View File

@ -106,7 +106,6 @@ export class PaypalDialogComponent implements OnInit {
});
},
onClientAuthorization: data => {
debugger;
console.log('onClientAuthorization - you should probably inform your server about completed transaction at this point', data);
this.updateUser();
this.sendReceipt();
@ -119,7 +118,6 @@ export class PaypalDialogComponent implements OnInit {
}
getUser(): void {
debugger;
// Get jhi_user and usuario_extra information
if (this.account !== null) {
this.usuarioExtraService.find(this.account.id).subscribe(usuarioExtra => {
@ -138,7 +136,6 @@ export class PaypalDialogComponent implements OnInit {
sendReceipt(): void {
const now = dayjs();
debugger;
this.factura = {
nombreUsuario: String(this.usuarioExtra?.id!),
nombrePlantilla: this.plantilla?.nombre!,

View File

@ -6,7 +6,6 @@ import { Pipe, PipeTransform, Injectable } from '@angular/core';
@Injectable()
export class FilterPipe implements PipeTransform {
transform(items: any[], field: string, value: string): any[] {
debugger;
if (!items) {
return [];
}

View File

@ -99,7 +99,12 @@
}
}
.ds-survey--option {
.ds-survey--textarea {
width: 100% !important;
}
.ds-survey--option,
.ds-survey--rating {
@media screen and (max-width: 991px) {
width: 21rem !important;
}