This commit is contained in:
Daniel Ponte 2024-11-25 16:36:15 -05:00
parent d99e8126dd
commit 02316cf365
2 changed files with 27 additions and 4 deletions

View file

@ -75,16 +75,29 @@ export class TalkgroupsComponent {
selectedId: number = 0;
talkgroups$!: Observable<Talkgroup[]>;
tgService: TalkgroupService = inject(TalkgroupService);
page: number = 1;
perPage: number = 20;
constructor(private route: ActivatedRoute) {}
ngOnInit() {
prevPage() {
if (this.page > 1) {
this.page--;
}
this.fetchTGs();
}
fetchTGs() {
this.talkgroups$ = this.route.paramMap.pipe(
switchMap((params) => {
this.selectedSys = Number(params.get('sys'));
this.selectedId = Number(params.get('tg'));
return this.tgService.getTalkgroups();
return this.tgService.getTalkgroups({page: this.page, perPage: perPage});
}),
);
}
ngOnInit() {
this.fetchTGs();
}
}

View file

@ -6,12 +6,22 @@ import { Talkgroup, TalkgroupUpdate } from '../talkgroup';
@Injectable({
providedIn: 'root',
})
export interface Pagination {
page: number;
perPage: number;
}
export class TalkgroupService {
loggedIn: boolean = false;
constructor(private http: HttpClient) {}
getTalkgroups(): Observable<Talkgroup[]> {
return this.http.get<Talkgroup[]>('/api/talkgroup/');
getTalkgroups(pagination?: Pagination): Observable<Talkgroup[]> {
if (pagination == null) {
return this.http.get<Talkgroup[]>('/api/talkgroup/');
}
return this.http.post<Talkgroup[]>('/api/talkgroup/', pagination);
}
getTalkgroup(sys: number, tg: number): Observable<Talkgroup> {