83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import { Component, OnInit, Input } from '@angular/core';
|
|
|
|
import { Router, ActivatedRoute } from '@angular/router';
|
|
|
|
import { EntriesService } from '../../services/entries.service';
|
|
import { PageEvent } from '@angular/material/paginator';
|
|
|
|
@Component({
|
|
selector: 'page-top',
|
|
templateUrl: './top.page.html'
|
|
})
|
|
export class PageTop implements OnInit {
|
|
|
|
|
|
@Input() entries: any;
|
|
boundRefresh: Function;
|
|
boundUpdate: Function;
|
|
init: boolean = true;
|
|
|
|
constructor(private entriesService: EntriesService, private router: Router, private route: ActivatedRoute) { }
|
|
|
|
ngOnInit(): void {
|
|
this.boundRefresh = this.refresh.bind(this);
|
|
this.boundUpdate = this.update.bind(this);
|
|
this.route.queryParams.subscribe(params => {
|
|
if (this.init) {
|
|
this.entries = {};
|
|
if (params[ 'p' ]) {
|
|
this.entries.number = +params[ 'p' ] - 1;
|
|
if (this.entries.number < 0) {
|
|
this.entries.number = 0;
|
|
}
|
|
}
|
|
|
|
if (params[ 's' ]) {
|
|
this.entries.size = +params[ 's' ];
|
|
}
|
|
|
|
this.refresh();
|
|
this.init = false;
|
|
}
|
|
});
|
|
}
|
|
|
|
refresh(): void {
|
|
if (!this.entries) {
|
|
this.entries = {};
|
|
}
|
|
|
|
this.entries.content = null;
|
|
this.entriesService.getPages(this.entries.number || 0, this.entries.size || 30).subscribe((data: any) => {
|
|
this.entries = data;
|
|
}, (error) => { })
|
|
|
|
}
|
|
|
|
update(event: PageEvent) {
|
|
this.entries.content = null;
|
|
const params: any = { p: null, s: null };
|
|
|
|
if (event.pageIndex != 0) {
|
|
params.p = event.pageIndex + 1;
|
|
}
|
|
|
|
if (event.pageSize != 30) {
|
|
params.s = event.pageSize;
|
|
}
|
|
|
|
this.router.navigate(
|
|
[],
|
|
{
|
|
relativeTo: this.route,
|
|
queryParams: params,
|
|
queryParamsHandling: 'merge'
|
|
});
|
|
|
|
this.entriesService.getPages(event.pageIndex, event.pageSize).subscribe((data: any) => {
|
|
this.entries = data;
|
|
}, (error) => { })
|
|
}
|
|
|
|
}
|