Compare commits

...

1 Commits

Author SHA1 Message Date
Mariela Bonilla 4246e31edb fix id survey y que cuando solo cuando sea un admin, cargue los users 2021-07-26 16:11:26 -06:00
2 changed files with 44 additions and 42 deletions

View File

@ -65,11 +65,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
account: Account | null = null; account: Account | null = null;
usuarioExtra: UsuarioExtra | null = null; usuarioExtra: UsuarioExtra | null = null;
estadoDeleted = EstadoEncuesta.DELETED; estadoDeleted = EstadoEncuesta.DELETED;
encuestas?: IEncuesta[]; encuestas?: IEncuesta[];
isLoading = false; isLoading = false;
selectedSurvey?: IEncuesta | null = null; selectedSurvey?: IEncuesta | null = null;
idEncuesta: number | null = null;
isSaving = false; isSaving = false;
categoriasSharedCollection: ICategoria[] = []; categoriasSharedCollection: ICategoria[] = [];
@ -83,6 +81,9 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
//public categoriaEncuesta: string; //public categoriaEncuesta: string;
public estadoEncuesta: string; public estadoEncuesta: string;
createAnother: Boolean = false;
selectedSurveyId: Number | null = null;
editForm = this.fb.group({ editForm = this.fb.group({
id: [], id: [],
nombre: [null, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]], nombre: [null, [Validators.required, Validators.minLength(1), Validators.maxLength(50)]],
@ -99,9 +100,6 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
// usuarioExtra: [], // usuarioExtra: [],
}); });
createAnother: Boolean = false;
selectedSurveyId: Number | null = null;
constructor( constructor(
protected encuestaService: EncuestaService, protected encuestaService: EncuestaService,
protected modalService: NgbModal, protected modalService: NgbModal,
@ -124,12 +122,16 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
loadAll(): void { loadAll(): void {
this.isLoading = true; this.isLoading = true;
if (this.isAdmin()) {
this.usuarioExtraService this.usuarioExtraService
.retrieveAllPublicUsers() .retrieveAllPublicUsers()
.pipe(finalize(() => this.loadPublicUser())) .pipe(finalize(() => this.loadPublicUser()))
.subscribe(res => { .subscribe(res => {
this.userSharedCollection = res; this.userSharedCollection = res;
}); });
} else {
this.loadEncuestas();
}
} }
loadPublicUser(): void { loadPublicUser(): void {
@ -144,8 +146,22 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
loadUserExtras() { loadUserExtras() {
this.usuarioExtraService this.usuarioExtraService
.query() .query()
.pipe( .pipe(finalize(() => this.loadEncuestas()))
finalize(() => .subscribe(
(res: HttpResponse<IUsuarioExtra[]>) => {
this.isLoading = false;
this.usuarioExtrasSharedCollection = res.body ?? [];
this.usuarioExtrasSharedCollection.forEach(uE => {
uE.user = this.userSharedCollection?.find(pU => pU.id == uE.user?.id);
});
},
() => {
this.isLoading = false;
}
);
}
loadEncuestas() {
this.encuestaService.query().subscribe( this.encuestaService.query().subscribe(
(res: HttpResponse<IEncuesta[]>) => { (res: HttpResponse<IEncuesta[]>) => {
this.isLoading = false; this.isLoading = false;
@ -165,20 +181,6 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
() => { () => {
this.isLoading = false; this.isLoading = false;
} }
)
)
)
.subscribe(
(res: HttpResponse<IUsuarioExtra[]>) => {
this.isLoading = false;
this.usuarioExtrasSharedCollection = res.body ?? [];
this.usuarioExtrasSharedCollection.forEach(uE => {
uE.user = this.userSharedCollection?.find(pU => pU.id == uE.user?.id);
});
},
() => {
this.isLoading = false;
}
); );
} }
@ -253,8 +255,8 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
} }
deleteSurvey(): void { deleteSurvey(): void {
if (this.idEncuesta != null) { if (this.selectedSurveyId != null) {
this.getEncuesta(this.idEncuesta) this.getEncuesta(this.selectedSurveyId)
.pipe( .pipe(
finalize(() => { finalize(() => {
const modalRef = this.modalService.open(EncuestaDeleteDialogComponent, { size: 'lg', backdrop: 'static' }); 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); return this.encuestaService.findEncuesta(id);
} }
@ -428,7 +430,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
} }
selectSurvey(event: any): void { 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 => { document.querySelectorAll('.ds-list--entity').forEach(e => {
e.classList.remove('active'); e.classList.remove('active');
}); });
@ -438,7 +440,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
} }
openPreview() { openPreview() {
const surveyId = this.idEncuesta; const surveyId = this.selectedSurveyId;
this.router.navigate(['/encuesta', surveyId, 'preview']); this.router.navigate(['/encuesta', surveyId, 'preview']);
} }
@ -480,7 +482,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
document.getElementById('contextmenu-delete--separator')!.style.display = 'none'; document.getElementById('contextmenu-delete--separator')!.style.display = 'none';
} else if ((event.target as HTMLElement).classList.contains('ds-list--entity')) { } else if ((event.target as HTMLElement).classList.contains('ds-list--entity')) {
this.selectedSurveyId = Number(event.target.dataset.id); this.selectedSurveyId = Number(event.target.dataset.id);
this.idEncuesta = Number(event.target.dataset.id);
event.target.classList.add('active'); event.target.classList.add('active');
let res = await this.encuestaService.find(this.selectedSurveyId).toPromise(); let res = await this.encuestaService.find(this.selectedSurveyId).toPromise();

View File

@ -45,7 +45,7 @@ export class EncuestaService {
.pipe(map((res: EntityResponseType) => this.convertDateFromServer(res))); .pipe(map((res: EntityResponseType) => this.convertDateFromServer(res)));
} }
findEncuesta(id: number): Observable<IEncuesta> { findEncuesta(id: Number): Observable<IEncuesta> {
return this.http.get<IEncuesta>(`${this.resourceUrl}/${id}`); return this.http.get<IEncuesta>(`${this.resourceUrl}/${id}`);
} }