datasurvey/src/main/webapp/app/home/home.component.ts

124 lines
3.6 KiB
TypeScript
Raw Normal View History

2021-07-03 21:48:27 +00:00
import { Component, OnInit, OnDestroy } from '@angular/core';
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
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';
import { faPollH, faCalendarAlt, faStar } from '@fortawesome/free-solid-svg-icons';
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>();
usuarioExtra: UsuarioExtra | null = null;
encuestas?: IEncuesta[];
encuestasMostradas: IEncuesta[] = new Array(3);
isLoading = false;
faStar = faStar;
faCalendarAlt = faCalendarAlt;
faPollH = faPollH;
notAccount: boolean = true;
public searchEncuestaPublica: string;
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
) {
this.searchEncuestaPublica = '';
}
2021-07-03 21:48:27 +00:00
ngOnInit(): void {
this.searchEncuestaPublica = '';
2021-07-03 21:48:27 +00:00
this.accountService
.getAuthenticationState()
.pipe(takeUntil(this.destroy$))
.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();
}
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');
this.encuestasMostradas = this.encuestas.reverse().slice(0, 3);
},
() => {
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
}