Add edit survey functionality in context menu

This commit is contained in:
Pablo Bonilla 2021-07-26 00:55:41 -06:00
parent d02a2fd267
commit 2b1c62a013
No known key found for this signature in database
GPG Key ID: 46877262B8DE47E2
2 changed files with 13 additions and 31 deletions

View File

@ -97,11 +97,13 @@
</div>
<div class="ds-contextmenu__divider ds-contextmenu__divider--separator-bottom" id="contextmenu-edit--separator">
<li class="d-justify justify-content-start">
<button type="button" id="contextmenu-edit"><fa-icon class="contextmenu__icon" [icon]="faEdit"></fa-icon>Editar</button>
<button type="button" (click)="openSurvey(null)" id="contextmenu-edit">
<fa-icon class="contextmenu__icon" [icon]="faEdit"></fa-icon>Editar
</button>
</li>
<li>
<button type="button" (click)="openPreview()" id="contextmenu-preview">
<fa-icon class="contextmenu__icon" [icon]="faPollH"></fa-icon>Ver Vista Previa
<fa-icon class="contextmenu__icon" [icon]="faPollH"></fa-icon>Ver vista previa
</button>
</li>
<li>

View File

@ -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<void> {
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();