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; selectedId: number = 0;
talkgroups$!: Observable<Talkgroup[]>; talkgroups$!: Observable<Talkgroup[]>;
tgService: TalkgroupService = inject(TalkgroupService); tgService: TalkgroupService = inject(TalkgroupService);
page: number = 1;
perPage: number = 20;
constructor(private route: ActivatedRoute) {} constructor(private route: ActivatedRoute) {}
ngOnInit() { prevPage() {
if (this.page > 1) {
this.page--;
}
this.fetchTGs();
}
fetchTGs() {
this.talkgroups$ = this.route.paramMap.pipe( this.talkgroups$ = this.route.paramMap.pipe(
switchMap((params) => { switchMap((params) => {
this.selectedSys = Number(params.get('sys')); this.selectedSys = Number(params.get('sys'));
this.selectedId = Number(params.get('tg')); 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({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export interface Pagination {
page: number;
perPage: number;
}
export class TalkgroupService { export class TalkgroupService {
loggedIn: boolean = false; loggedIn: boolean = false;
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
getTalkgroups(): Observable<Talkgroup[]> { getTalkgroups(pagination?: Pagination): Observable<Talkgroup[]> {
return this.http.get<Talkgroup[]>('/api/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> { getTalkgroup(sys: number, tg: number): Observable<Talkgroup> {