Fix bug in list of survey questions and options

This commit is contained in:
Pablo Bonilla 2021-07-23 23:58:25 -06:00
parent 2302a615b9
commit 0af94cd9f2
No known key found for this signature in database
GPG Key ID: 46877262B8DE47E2
2 changed files with 18 additions and 18 deletions

View File

@ -58,21 +58,20 @@
</div> </div>
<ng-container *ngIf="ePregunta.tipo"> <ng-container *ngIf="ePregunta.tipo">
<ng-container *ngFor="let ePreguntaOpcion of ePreguntasOpciones; let j = index; trackBy: trackId"> <ng-container *ngFor="let ePreguntaOpcion of ePreguntasOpciones; let j = index; trackBy: trackId">
<ng-container *ngIf="ePreguntaOpcion[j] !== undefined"> <ng-container *ngFor="let ePreguntaOpcionFinal of ePreguntaOpcion">
<ng-container *ngIf="ePregunta.id == ePreguntaOpcion[j].epreguntaCerrada.id"> <ng-container *ngIf="ePregunta.id === ePreguntaOpcionFinal.epreguntaCerrada.id">
<div <div
class="ds-survey--option ds-survey--option--base ds-survey--closed-option" class="ds-survey--option ds-survey--option--base ds-survey--closed-option can-delete"
*ngFor="let ePreguntaOpcion2 of ePreguntaOpcion; let k = index; trackBy: trackId" [attr.data-id]="ePreguntaOpcionFinal.id"
[attr.data-id]="ePreguntaOpcion2.id"
> >
<!-- <input class="ds-survey--checkbox" id="{{ ePregunta.id }}-{{ ePreguntaOpcion2.id }}" type="checkbox" disabled /> --> <input class="ds-survey--checkbox" id="{{ ePregunta.id }}-{{ ePreguntaOpcionFinal.id }}" type="checkbox" disabled />
<label for="{{ ePregunta.id }}-{{ ePreguntaOpcion2.id }}">{{ ePreguntaOpcion2.nombre }}</label> <label for="{{ ePregunta.id }}-{{ ePreguntaOpcionFinal.id }}">{{ ePreguntaOpcionFinal.nombre }}</label>
<fa-icon <fa-icon
*ngIf="encuesta!.estado === 'DRAFT'" *ngIf="encuesta!.estado === 'DRAFT'"
class="ds-survey--titulo--icon ds-survey--titulo--icon--small" class="ds-survey--titulo--icon ds-survey--titulo--icon--small"
[icon]="faTimes" [icon]="faTimes"
(click)="deleteOption($event)" (click)="deleteOption($event)"
[attr.data-optionid]="ePreguntaOpcion2.id" [attr.data-optionid]="ePreguntaOpcionFinal.id"
></fa-icon> ></fa-icon>
</div> </div>
</ng-container> </ng-container>

View File

@ -150,7 +150,6 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
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 => {
console.log(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 {
@ -176,7 +175,6 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
const id = event.target.dataset.id; const id = event.target.dataset.id;
this.ePreguntaCerradaService.find(id).subscribe(e => { this.ePreguntaCerradaService.find(id).subscribe(e => {
this.selectedQuestionToCreateOption = e.body; this.selectedQuestionToCreateOption = e.body;
console.log(this.selectedQuestionToCreateOption);
}); });
} }
} }
@ -193,22 +191,27 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
if (e.nodeName !== 'DIV') return; if (e.nodeName !== 'DIV') return;
if (i === 0) return; if (i === 0) return;
if ((e as HTMLElement).dataset.id === undefined) return; if ((e as HTMLElement).dataset.id === undefined) return;
if (!(e as HTMLElement).classList.contains('can-delete')) return;
let optionId = (e as HTMLElement).dataset.id; let optionId = (e as HTMLElement).dataset.id;
optionIdsToDelete.push(+optionId!); optionIdsToDelete.push(+optionId!);
}); });
// Delete question options if (optionIdsToDelete.length === 0) {
this.ePreguntaCerradaOpcionService.deleteMany(optionIdsToDelete).subscribe(e => {
// Delete question
this.ePreguntaCerradaService.delete(id).subscribe(e => { this.ePreguntaCerradaService.delete(id).subscribe(e => {
console.log('DELETED CLOSED QUESTION: ' + id);
this.loadAll(); this.loadAll();
}); });
}); } else {
// Delete question options
this.ePreguntaCerradaOpcionService.deleteMany(optionIdsToDelete).subscribe(e => {
// Delete question
this.ePreguntaCerradaService.delete(id).subscribe(e => {
this.loadAll();
});
});
}
} else { } else {
// Delete open question // Delete open question
this.ePreguntaAbiertaService.delete(id).subscribe(e => { this.ePreguntaAbiertaService.delete(id).subscribe(e => {
console.log('DELETED OPEN QUESTION: ' + id);
this.loadAll(); this.loadAll();
}); });
} }
@ -266,8 +269,6 @@ export class EncuestaUpdateComponent implements OnInit, AfterViewChecked {
} }
protected createFromForm(): IEPreguntaCerradaOpcion { protected createFromForm(): IEPreguntaCerradaOpcion {
console.log(this.selectedQuestionToCreateOption);
return { return {
// ...new EPreguntaCerradaOpcion(), // ...new EPreguntaCerradaOpcion(),
id: undefined, id: undefined,