This commit is contained in:
Daniel Ponte 2025-02-04 18:51:18 -05:00
parent f14e50d258
commit 04b0d0b5de
8 changed files with 63 additions and 12 deletions

View file

@ -76,6 +76,12 @@ export const routes: Routes = [
import('./alerts/alerts.component').then((m) => m.AlertsComponent),
data: { title: 'Alerts' },
},
{
path: 'shares',
loadComponent: () =>
import('./shares/shares.component').then((m) => m.SharesComponent),
data: { title: 'Shares' },
},
],
},
];

View file

@ -11,7 +11,7 @@ import { PrefsService } from '../prefs/prefs.service';
import { MatIconModule } from '@angular/material/icon';
import { SelectionModel } from '@angular/cdk/collections';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { BehaviorSubject, Subscription } from 'rxjs';
import { BehaviorSubject, Subject, Subscription } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import {
CallsListParams,
@ -115,9 +115,7 @@ export class CallsComponent {
subscriptions = new Subscription();
pageWindow = 0;
fetchCalls = new BehaviorSubject<CallsListParams>(
this.buildParams(this.curPage, this.curPage.pageIndex),
);
fetchCalls = new Subject<CallsListParams>();
constructor(
private callsSvc: CallsService,
@ -180,6 +178,7 @@ export class CallsComponent {
}
setPage(p: PageEvent, force?: boolean) {
console.log("setpage")
this.selection.clear();
this.curPage = p;
if (p && p!.pageSize != this.perPage) {
@ -195,16 +194,19 @@ export class CallsComponent {
}
getCalls(p: PageEvent, force?: boolean) {
console.log("getcalls")
const pageStart = p.pageIndex * p.pageSize;
const serverPage = Math.floor(pageStart / reqPageSize) + 1;
this.pageWindow = pageStart % reqPageSize;
if (serverPage == this.currentServerPage && !force && this.currentSet) {
console.log("currentset");
this.callsResult.next(
this.callsResult
? this.currentSet.slice(this.pageWindow, this.pageWindow + p.pageSize)
: [],
);
} else {
console.log("not currentset");
this.currentServerPage = serverPage;
this.fetchCalls.next(this.buildParams(p, serverPage));
}
@ -243,6 +245,7 @@ export class CallsComponent {
this.fetchCalls
.pipe(
switchMap((params) => {
console.log("gc switchmap");
return this.callsSvc.getCalls(params);
}),
)

View file

@ -101,6 +101,11 @@ export class NavigationComponent {
url: '/alerts',
icon: 'notifications',
},
{
name: 'Shares',
url: '/shares',
icon: 'share',
},
];
toggleFilterPanel() {

View file

@ -0,0 +1 @@
<p>shares works!</p>

View file

@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { SharesComponent } from './shares.component';
describe('SharesComponent', () => {
let component: SharesComponent;
let fixture: ComponentFixture<SharesComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [SharesComponent]
})
.compileComponents();
fixture = TestBed.createComponent(SharesComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View file

@ -0,0 +1,11 @@
import { Component } from '@angular/core';
@Component({
selector: 'app-shares',
imports: [],
templateUrl: './shares.component.html',
styleUrl: './shares.component.scss'
})
export class SharesComponent {
}

View file

@ -27,20 +27,15 @@ export interface TalkgroupsPaginated {
})
export class TalkgroupService {
private readonly _getTalkgroup = new Map<string, ReplaySubject<Talkgroup>>();
private tgs$: Observable<Talkgroup[]>;
private tgs$!: Observable<Talkgroup[]>;
private tags$!: Observable<string[]>;
private fetchAll = new BehaviorSubject<'fetch'>('fetch');
private subscriptions = new Subscription();
constructor(private http: HttpClient) {
this.tgs$ = this.fetchAll.pipe(
switchMap(() => this.getTalkgroups()),
shareReplay(),
);
this.tags$ = this.fetchAll.pipe(
switchMap(() => this.getAllTags()),
shareReplay(),
);
this.fillTgMap();
}
ngOnDestroy() {
@ -51,7 +46,7 @@ export class TalkgroupService {
return this.http.get<string[]>('/api/talkgroup/tags');
}
getTalkgroups(): Observable<Talkgroup[]> {
getTalkgroups(share: Share | null): Observable<Talkgroup[]> {
return this.http.get<Talkgroup[]>('/api/talkgroup/');
}
@ -60,6 +55,9 @@ export class TalkgroupService {
tg: number,
share: Share | null = null,
): Observable<Talkgroup> {
if (this._getTalkgroup.size < 1) {
this.fillTgMap(share);
}
const key = this.tgKey(sys, tg);
if (!this._getTalkgroup.get(key)) {
let rs = new ReplaySubject<Talkgroup>();
@ -103,7 +101,11 @@ export class TalkgroupService {
return this.http.post<TalkgroupsPaginated>('/api/talkgroup/', pagination);
}
fillTgMap() {
fillTgMap(share: Share | null) {
this.tgs$ = this.fetchAll.pipe(
switchMap(() => this.getTalkgroups(share)),
shareReplay(),
);
this.subscriptions.add(
this.tgs$.subscribe((tgs) => {
tgs.forEach((tg) => {