From 4246e31edba7832060fe82ffd817f9fb049e9f8d Mon Sep 17 00:00:00 2001 From: Mariela Bonilla Date: Mon, 26 Jul 2021 16:11:26 -0600 Subject: [PATCH] fix id survey y que cuando solo cuando sea un admin, cargue los users --- .../encuesta/list/encuesta.component.ts | 84 ++++++++++--------- .../encuesta/service/encuesta.service.ts | 2 +- 2 files changed, 44 insertions(+), 42 deletions(-) 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..9f67460 100644 --- a/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts +++ b/src/main/webapp/app/entities/encuesta/list/encuesta.component.ts @@ -65,11 +65,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit { account: Account | null = null; usuarioExtra: UsuarioExtra | null = null; estadoDeleted = EstadoEncuesta.DELETED; - encuestas?: IEncuesta[]; isLoading = false; selectedSurvey?: IEncuesta | null = null; - idEncuesta: number | null = null; isSaving = false; categoriasSharedCollection: ICategoria[] = []; @@ -83,6 +81,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit { //public categoriaEncuesta: string; public estadoEncuesta: string; + createAnother: Boolean = false; + selectedSurveyId: Number | null = null; + editForm = this.fb.group({ id: [], nombre: [null, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]], @@ -99,9 +100,6 @@ export class EncuestaComponent implements OnInit, AfterViewInit { // usuarioExtra: [], }); - createAnother: Boolean = false; - selectedSurveyId: Number | null = null; - constructor( protected encuestaService: EncuestaService, protected modalService: NgbModal, @@ -124,12 +122,16 @@ export class EncuestaComponent implements OnInit, AfterViewInit { loadAll(): void { this.isLoading = true; - this.usuarioExtraService - .retrieveAllPublicUsers() - .pipe(finalize(() => this.loadPublicUser())) - .subscribe(res => { - this.userSharedCollection = res; - }); + if (this.isAdmin()) { + this.usuarioExtraService + .retrieveAllPublicUsers() + .pipe(finalize(() => this.loadPublicUser())) + .subscribe(res => { + this.userSharedCollection = res; + }); + } else { + this.loadEncuestas(); + } } loadPublicUser(): void { @@ -144,30 +146,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { loadUserExtras() { this.usuarioExtraService .query() - .pipe( - finalize(() => - this.encuestaService.query().subscribe( - (res: HttpResponse) => { - this.isLoading = false; - const tmpEncuestas = res.body ?? []; - if (this.isAdmin()) { - this.encuestas = tmpEncuestas.filter(e => e.estado !== EstadoEncuesta.DELETED); - - this.encuestas.forEach(e => { - e.usuarioExtra = this.usuarioExtrasSharedCollection?.find(pU => pU.id == e.usuarioExtra?.id); - }); - } else { - this.encuestas = tmpEncuestas - .filter(e => e.usuarioExtra?.id === this.usuarioExtra?.id) - .filter(e => e.estado !== EstadoEncuesta.DELETED); - } - }, - () => { - this.isLoading = false; - } - ) - ) - ) + .pipe(finalize(() => this.loadEncuestas())) .subscribe( (res: HttpResponse) => { this.isLoading = false; @@ -182,6 +161,29 @@ export class EncuestaComponent implements OnInit, AfterViewInit { ); } + loadEncuestas() { + this.encuestaService.query().subscribe( + (res: HttpResponse) => { + this.isLoading = false; + const tmpEncuestas = res.body ?? []; + if (this.isAdmin()) { + this.encuestas = tmpEncuestas.filter(e => e.estado !== EstadoEncuesta.DELETED); + + this.encuestas.forEach(e => { + e.usuarioExtra = this.usuarioExtrasSharedCollection?.find(pU => pU.id == e.usuarioExtra?.id); + }); + } else { + this.encuestas = tmpEncuestas + .filter(e => e.usuarioExtra?.id === this.usuarioExtra?.id) + .filter(e => e.estado !== EstadoEncuesta.DELETED); + } + }, + () => { + this.isLoading = false; + } + ); + } + ngOnInit(): void { this.searchString = ''; this.accesoEncuesta = ''; @@ -253,8 +255,8 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } deleteSurvey(): void { - if (this.idEncuesta != null) { - this.getEncuesta(this.idEncuesta) + if (this.selectedSurveyId != null) { + this.getEncuesta(this.selectedSurveyId) .pipe( finalize(() => { const modalRef = this.modalService.open(EncuestaDeleteDialogComponent, { size: 'lg', backdrop: 'static' }); @@ -290,7 +292,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } } - getEncuesta(id: number) { + getEncuesta(id: Number) { return this.encuestaService.findEncuesta(id); } @@ -428,7 +430,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } selectSurvey(event: any): void { - this.idEncuesta = event.target.getAttribute('data-id'); + this.selectedSurveyId = event.target.getAttribute('data-id'); document.querySelectorAll('.ds-list--entity').forEach(e => { e.classList.remove('active'); }); @@ -438,7 +440,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit { } openPreview() { - const surveyId = this.idEncuesta; + const surveyId = this.selectedSurveyId; this.router.navigate(['/encuesta', surveyId, 'preview']); } @@ -480,7 +482,7 @@ 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(); diff --git a/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts b/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts index 3fb18da..fe20097 100644 --- a/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts +++ b/src/main/webapp/app/entities/encuesta/service/encuesta.service.ts @@ -45,7 +45,7 @@ export class EncuestaService { .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res))); } - findEncuesta(id: number): Observable { + findEncuesta(id: Number): Observable { return this.http.get(`${this.resourceUrl}/${id}`); }