Shares #109

Merged
amigan merged 59 commits from shareUI into trunk 2025-02-14 00:25:03 -05:00
8 changed files with 63 additions and 12 deletions
Showing only changes of commit 04b0d0b5de - Show all commits

View file

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

View file

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