fix id survey y que cuando solo cuando sea un admin, cargue los users
This commit is contained in:
parent
1d6abd148c
commit
4246e31edb
|
@ -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;
|
||||||
|
|
||||||
this.usuarioExtraService
|
if (this.isAdmin()) {
|
||||||
.retrieveAllPublicUsers()
|
this.usuarioExtraService
|
||||||
.pipe(finalize(() => this.loadPublicUser()))
|
.retrieveAllPublicUsers()
|
||||||
.subscribe(res => {
|
.pipe(finalize(() => this.loadPublicUser()))
|
||||||
this.userSharedCollection = res;
|
.subscribe(res => {
|
||||||
});
|
this.userSharedCollection = res;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.loadEncuestas();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadPublicUser(): void {
|
loadPublicUser(): void {
|
||||||
|
@ -144,30 +146,7 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
||||||
loadUserExtras() {
|
loadUserExtras() {
|
||||||
this.usuarioExtraService
|
this.usuarioExtraService
|
||||||
.query()
|
.query()
|
||||||
.pipe(
|
.pipe(finalize(() => this.loadEncuestas()))
|
||||||
finalize(() =>
|
|
||||||
this.encuestaService.query().subscribe(
|
|
||||||
(res: HttpResponse<IEncuesta[]>) => {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(res: HttpResponse<IUsuarioExtra[]>) => {
|
(res: HttpResponse<IUsuarioExtra[]>) => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
@ -182,6 +161,29 @@ export class EncuestaComponent implements OnInit, AfterViewInit {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadEncuestas() {
|
||||||
|
this.encuestaService.query().subscribe(
|
||||||
|
(res: HttpResponse<IEncuesta[]>) => {
|
||||||
|
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 {
|
ngOnInit(): void {
|
||||||
this.searchString = '';
|
this.searchString = '';
|
||||||
this.accesoEncuesta = '';
|
this.accesoEncuesta = '';
|
||||||
|
@ -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();
|
||||||
|
|
|
@ -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}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue