import { Component, OnInit, OnDestroy } from '@angular/core'; import { HttpResponse, HttpHeaders } from '@angular/common/http'; import { NgbModal } from '@ng-bootstrap/ng-bootstrap'; import { Subscription, combineLatest } from 'rxjs'; import { ActivatedRoute, ParamMap, Router, Data } from '@angular/router'; import { JhiEventManager } from 'ng-jhipster'; import { ITEMS_PER_PAGE } from 'app/shared/constants/pagination.constants'; // import { AccountService } from 'app/core/auth/account.service'; // import { Account } from 'app/core/user/account.model'; import { TimeCardsReportingService } from './timecardsreporting.service'; import { TimeCardsReporting } from './timecardsreporting.model'; import { TimeCardsReportingDeleteDialogComponent } from './timecardsreporting-delete-dialog.component'; @Component({ selector: 'jhi-timecardsreporting', templateUrl: './timecardsreporting.component.html', }) export class TimeCardsReportingComponent implements OnInit, OnDestroy { // currentAccount: Account | null = null; timecardsreportings: TimeCardsReporting[] | null = null; timeCardsReportingListSubscription?: Subscription; totalItems = 0; itemsPerPage = ITEMS_PER_PAGE; page!: number; predicate!: string; ascending!: boolean; constructor( private timeCardsReportingService: TimeCardsReportingService, // private accountService: AccountService, private activatedRoute: ActivatedRoute, private router: Router, private eventManager: JhiEventManager, private modalService: NgbModal ) {} ngOnInit(): void { // this.accountService.identity().subscribe(account => (this.currentAccount = account)); this.timeCardsReportingListSubscription = this.eventManager.subscribe('timeCardsReportingListModification', () => this.loadAll()); this.handleNavigation(); } ngOnDestroy(): void { if (this.timeCardsReportingListSubscription) { this.eventManager.destroy(this.timeCardsReportingListSubscription); } } trackIdentity(index: number, item: TimeCardsReporting): any { return item.id; } deleteTimeCardsReporting(timeCardsReporting: TimeCardsReporting): void { const modalRef = this.modalService.open(TimeCardsReportingDeleteDialogComponent, { size: 'lg', backdrop: 'static' }); modalRef.componentInstance.timeCardsReporting = timeCardsReporting; } transition(): void { this.router.navigate(['./'], { relativeTo: this.activatedRoute.parent, queryParams: { page: this.page, sort: this.predicate + ',' + (this.ascending ? 'asc' : 'desc'), }, }); } private handleNavigation(): void { combineLatest(this.activatedRoute.data, this.activatedRoute.queryParamMap, (data: Data, params: ParamMap) => { const page = params.get('page'); this.page = page !== null ? +page : 1; const sort = (params.get('sort') ?? data['defaultSort']).split(','); this.predicate = sort[0]; this.ascending = sort[1] === 'asc'; this.loadAll(); }).subscribe(); } private loadAll(): void { this.timeCardsReportingService .query({ page: this.page - 1, size: this.itemsPerPage, sort: this.sort(), }) .subscribe((res: HttpResponse) => this.onSuccess(res.body, res.headers)); } private sort(): string[] { const result = [this.predicate + ',' + (this.ascending ? 'asc' : 'desc')]; if (this.predicate !== 'id') { result.push('id'); } return result; } private onSuccess(timecardsreportings: TimeCardsReporting[] | null, headers: HttpHeaders): void { this.totalItems = Number(headers.get('X-Total-Count')); this.timecardsreportings = timecardsreportings; } }