2021-07-03 21:48:27 +00:00
|
|
|
import { Component, OnInit, OnDestroy } from '@angular/core';
|
2021-07-24 08:49:55 +00:00
|
|
|
import { HttpResponse } from '@angular/common/http';
|
2021-07-03 21:48:27 +00:00
|
|
|
import { Router } from '@angular/router';
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
import { takeUntil } from 'rxjs/operators';
|
2021-07-18 09:39:39 +00:00
|
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
|
2021-07-03 21:48:27 +00:00
|
|
|
|
2021-07-24 08:49:55 +00:00
|
|
|
import { IEncuesta } from 'app/entities/encuesta/encuesta.model';
|
|
|
|
import { EncuestaService } from 'app/entities/encuesta/service/encuesta.service';
|
|
|
|
import { FormBuilder } from '@angular/forms';
|
|
|
|
import { ActivatedRoute } from '@angular/router';
|
|
|
|
|
|
|
|
import { ICategoria } from 'app/entities/categoria/categoria.model';
|
|
|
|
import { CategoriaService } from 'app/entities/categoria/service/categoria.service';
|
|
|
|
import { IUsuarioExtra, UsuarioExtra } from 'app/entities/usuario-extra/usuario-extra.model';
|
|
|
|
import { UsuarioExtraService } from 'app/entities/usuario-extra/service/usuario-extra.service';
|
2021-07-03 21:48:27 +00:00
|
|
|
import { AccountService } from 'app/core/auth/account.service';
|
|
|
|
import { Account } from 'app/core/auth/account.model';
|
|
|
|
|
2021-07-24 09:40:14 +00:00
|
|
|
import { faPollH, faCalendarAlt, faStar } from '@fortawesome/free-solid-svg-icons';
|
2021-07-24 08:49:55 +00:00
|
|
|
|
|
|
|
import * as $ from 'jquery';
|
|
|
|
|
2021-07-03 21:48:27 +00:00
|
|
|
@Component({
|
|
|
|
selector: 'jhi-home',
|
|
|
|
templateUrl: './home.component.html',
|
|
|
|
styleUrls: ['./home.component.scss'],
|
|
|
|
})
|
|
|
|
export class HomeComponent implements OnInit, OnDestroy {
|
|
|
|
account: Account | null = null;
|
|
|
|
private readonly destroy$ = new Subject<void>();
|
|
|
|
|
2021-07-24 08:49:55 +00:00
|
|
|
usuarioExtra: UsuarioExtra | null = null;
|
|
|
|
encuestas?: IEncuesta[];
|
2021-07-24 20:36:13 +00:00
|
|
|
encuestasMostradas: IEncuesta[] = new Array(3);
|
2021-07-24 08:49:55 +00:00
|
|
|
isLoading = false;
|
|
|
|
|
|
|
|
faStar = faStar;
|
|
|
|
faCalendarAlt = faCalendarAlt;
|
|
|
|
faPollH = faPollH;
|
|
|
|
|
|
|
|
notAccount: boolean = true;
|
|
|
|
|
2021-07-24 09:40:14 +00:00
|
|
|
public searchEncuestaPublica: string;
|
|
|
|
|
2021-07-24 08:49:55 +00:00
|
|
|
constructor(
|
|
|
|
protected encuestaService: EncuestaService,
|
|
|
|
protected modalService: NgbModal,
|
|
|
|
protected categoriaService: CategoriaService,
|
|
|
|
protected usuarioExtraService: UsuarioExtraService,
|
|
|
|
protected activatedRoute: ActivatedRoute,
|
|
|
|
protected fb: FormBuilder,
|
|
|
|
protected accountService: AccountService,
|
|
|
|
protected router: Router
|
2021-07-24 09:40:14 +00:00
|
|
|
) {
|
|
|
|
this.searchEncuestaPublica = '';
|
|
|
|
}
|
2021-07-03 21:48:27 +00:00
|
|
|
|
|
|
|
ngOnInit(): void {
|
2021-07-24 09:40:14 +00:00
|
|
|
this.searchEncuestaPublica = '';
|
2021-07-03 21:48:27 +00:00
|
|
|
this.accountService
|
|
|
|
.getAuthenticationState()
|
|
|
|
.pipe(takeUntil(this.destroy$))
|
2021-07-24 08:49:55 +00:00
|
|
|
.subscribe(account => {
|
|
|
|
if (account !== null) {
|
|
|
|
this.account = account;
|
|
|
|
this.notAccount = false;
|
|
|
|
} else {
|
|
|
|
this.notAccount = true;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
this.loadAll();
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
login(): void {
|
|
|
|
this.router.navigate(['/login']);
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnDestroy(): void {
|
|
|
|
this.destroy$.next();
|
|
|
|
this.destroy$.complete();
|
|
|
|
}
|
2021-07-24 08:49:55 +00:00
|
|
|
|
|
|
|
ngAfterViewInit(): void {}
|
|
|
|
|
|
|
|
trackId(index: number, item: IEncuesta): number {
|
|
|
|
return item.id!;
|
|
|
|
}
|
|
|
|
|
|
|
|
loadAll(): void {
|
|
|
|
this.isLoading = true;
|
|
|
|
|
|
|
|
this.encuestaService.query().subscribe(
|
|
|
|
(res: HttpResponse<IEncuesta[]>) => {
|
|
|
|
this.isLoading = false;
|
|
|
|
const tmpEncuestas = res.body ?? [];
|
|
|
|
this.encuestas = tmpEncuestas.filter(e => e.estado === 'ACTIVE' && e.acceso === 'PUBLIC');
|
2021-07-24 20:36:13 +00:00
|
|
|
this.encuestasMostradas = this.encuestas.reverse().slice(0, 3);
|
2021-07-24 08:49:55 +00:00
|
|
|
},
|
|
|
|
() => {
|
|
|
|
this.isLoading = false;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
openSurvey(event: any): void {
|
|
|
|
const surveyId = event.target.getAttribute('data-id');
|
|
|
|
this.router.navigate(['/encuesta', surveyId, 'edit']);
|
|
|
|
}
|
|
|
|
|
|
|
|
selectSurvey(event: any): void {
|
|
|
|
document.querySelectorAll('.ds-list--entity').forEach(e => {
|
|
|
|
e.classList.remove('active');
|
|
|
|
});
|
|
|
|
if (event.target.classList.contains('ds-list--entity')) {
|
|
|
|
event.target.classList.add('active');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
counter(i: number) {
|
|
|
|
return new Array(i);
|
|
|
|
}
|
2021-07-03 21:48:27 +00:00
|
|
|
}
|