From 2b1c62a0132353ed66d660a61917b9511a5f4d3f Mon Sep 17 00:00:00 2001 From: Pablo Bonilla Date: Mon, 26 Jul 2021 00:55:41 -0600 Subject: [PATCH] Add edit survey functionality in context menu --- .../encuesta/list/encuesta.component.html | 6 ++- .../encuesta/list/encuesta.component.ts | 38 +++++-------------- 2 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/main/webapp/app/entities/encuesta/list/encuesta.component.html b/src/main/webapp/app/entities/encuesta/list/encuesta.component.html index c0f3da5..5bd0ab6 100644 --- a/src/main/webapp/app/entities/encuesta/list/encuesta.component.html +++ b/src/main/webapp/app/entities/encuesta/list/encuesta.component.html @@ -97,11 +97,13 @@
  • - +
  • diff --git a/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts b/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts index 5d4bb97..4216f10 100644 --- a/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts +++ b/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts @@ -100,7 +100,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { }); createAnother: Boolean = false; - selectedSurveyId: Number | null = null; + selectedSurveyId: number | null = null; constructor( protected encuestaService: EncuestaService, @@ -423,8 +423,13 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } openSurvey(event: any): void { - const surveyId = event.target.getAttribute('data-id'); - this.router.navigate(['/encuesta', surveyId, 'edit']); + if (event === null) { + const surveyId = this.selectedSurveyId; + this.router.navigate(['/encuesta', surveyId, 'edit']); + } else { + const surveyId = event.target.dataset.id; + this.router.navigate(['/encuesta', surveyId, 'edit']); + } } selectSurvey(event: any): void { @@ -438,18 +443,10 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } openPreview() { - const surveyId = this.idEncuesta; + const surveyId = this.selectedSurveyId; this.router.navigate(['/encuesta', surveyId, 'preview']); } - counter(i: number) { - return new Array(i); - } - - testMe(something: any) { - return 5 - something; - } - async openContextMenu(event: any): Promise { if (event.type === 'contextmenu') { event.preventDefault(); @@ -457,22 +454,6 @@ export class EncuestaComponent implements OnInit, AfterViewInit { document.querySelectorAll('.ds-list--entity').forEach(e => { e.classList.remove('active'); }); - this.selectedSurveyId = Number(event.target.dataset.id); - - let res = await this.encuestaService.find(this.selectedSurveyId).toPromise(); - this.selectedSurvey = res.body; - this.isPublished = this.selectedSurvey!.estado === 'DRAFT'; // QUE SE LE MUESTRE CUANDO ESTE EN DRAFT - // } - - document.getElementById('contextmenu-create--separator')!.style.display = 'block'; - document.getElementById('contextmenu-edit--separator')!.style.display = 'block'; - document.getElementById('contextmenu-delete--separator')!.style.display = 'block'; - document.getElementById('contextmenu-edit')!.style.display = 'block'; - if (this.isPublished) { - document.getElementById('contextmenu-publish')!.style.display = 'block'; //cambiar - } - document.getElementById('contextmenu-preview')!.style.display = 'block'; - //document.getElementById('contextmenu-share')!.style.display = 'block'; if ((event.target as HTMLElement).classList.contains('ds-list')) { document.getElementById('contextmenu-create--separator')!.style.display = 'block'; @@ -480,7 +461,6 @@ export class EncuestaComponent implements OnInit, AfterViewInit { document.getElementById('contextmenu-delete--separator')!.style.display = 'none'; } else if ((event.target as HTMLElement).classList.contains('ds-list--entity')) { this.selectedSurveyId = Number(event.target.dataset.id); - this.idEncuesta = Number(event.target.dataset.id); event.target.classList.add('active'); let res = await this.encuestaService.find(this.selectedSurveyId).toPromise();