diff --git a/client/stillbox/src/app/incidents/incident/incident.component.html b/client/stillbox/src/app/incidents/incident/incident.component.html index 0bd0390..cd132ea 100644 --- a/client/stillbox/src/app/incidents/incident/incident.component.html +++ b/client/stillbox/src/app/incidents/incident/incident.component.html @@ -7,7 +7,7 @@ >playlist_play - @if (!inShare) { + @if (share == null) { diff --git a/client/stillbox/src/app/incidents/incident/incident.component.ts b/client/stillbox/src/app/incidents/incident/incident.component.ts index a92f01c..a868c8a 100644 --- a/client/stillbox/src/app/incidents/incident/incident.component.ts +++ b/client/stillbox/src/app/incidents/incident/incident.component.ts @@ -9,7 +9,7 @@ import { FormControl, FormsModule, } from '@angular/forms'; -import { ActivatedRoute, Router } from '@angular/router'; +import { ActivatedRoute } from '@angular/router'; import { MatInputModule } from '@angular/material/input'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatCheckboxModule } from '@angular/material/checkbox'; @@ -41,6 +41,7 @@ import { FmtDatePipe } from '../incidents.component'; import { MatMenuModule } from '@angular/material/menu'; import { Share } from '../../shares'; import { ShareService } from '../../share/share.service'; +import { TalkgroupService } from '../../talkgroups/talkgroups.service'; export interface EditDialogData { incID: string; @@ -153,7 +154,6 @@ export class IncidentEditDialogComponent { styleUrl: './incident.component.scss', }) export class IncidentComponent { - inShare = false; incPrime = new Subject(); inc$!: Observable; @Input() share?: Share; @@ -176,15 +176,17 @@ export class IncidentComponent { constructor( private route: ActivatedRoute, - private shareSvc: ShareService, private incSvc: IncidentsService, private location: Location, + private tgSvc: TalkgroupService, ) {} saveIncName(ev: Event) {} ngOnInit() { - this.inShare = this.shareSvc.isInShare(); + if (this.share) { + this.tgSvc.setShare(this.share); + } let incOb: Observable; if (this.route.component === this.constructor) { // loaded by route diff --git a/client/stillbox/src/app/share/share.service.ts b/client/stillbox/src/app/share/share.service.ts index 9a1723d..d13d118 100644 --- a/client/stillbox/src/app/share/share.service.ts +++ b/client/stillbox/src/app/share/share.service.ts @@ -4,17 +4,12 @@ import { map, Observable, switchMap } from 'rxjs'; import { IncidentRecord } from '../incidents'; import { CallRecord } from '../calls'; import { Share, ShareType } from '../shares'; -import { Router } from '@angular/router'; @Injectable({ providedIn: 'root', }) export class ShareService { - constructor(private http: HttpClient, private router: Router) {} - - isInShare(): boolean { - return this.router.url.startsWith('/s/'); - } + constructor(private http: HttpClient) {} getShare(id: string): Observable { return this.http.get(`/share/${id}`); diff --git a/client/stillbox/src/app/talkgroups/talkgroups.service.ts b/client/stillbox/src/app/talkgroups/talkgroups.service.ts index 9eb25f8..4c14a19 100644 --- a/client/stillbox/src/app/talkgroups/talkgroups.service.ts +++ b/client/stillbox/src/app/talkgroups/talkgroups.service.ts @@ -27,15 +27,24 @@ export interface TalkgroupsPaginated { }) export class TalkgroupService { private readonly _getTalkgroup = new Map>(); - private tgs$!: Observable; + private tgs$: Observable; private tags$!: Observable; - private fetchAll = new BehaviorSubject<'fetch'>('fetch'); + private fetchAll = new BehaviorSubject(null); private subscriptions = new Subscription(); constructor(private http: HttpClient) { + this.tgs$ = this.fetchAll.pipe( + switchMap((share) => this.getTalkgroups(share)), + shareReplay(), + ); this.tags$ = this.fetchAll.pipe( switchMap(() => this.getAllTags()), shareReplay(), ); + this.fillTgMap(); + } + + setShare(share: Share) { + this.fetchAll.next(share); } ngOnDestroy() { @@ -46,8 +55,8 @@ export class TalkgroupService { return this.http.get('/api/talkgroup/tags'); } - getTalkgroups(share: Share | null): Observable { - return this.http.get('/api/talkgroup/'); + getTalkgroups(share: Share|null): Observable { + return this.http.get(share ? `/share/${share.id}/talkgroups` : '/api/talkgroup/'); } getTalkgroup( @@ -55,9 +64,6 @@ export class TalkgroupService { tg: number, share: Share | null = null, ): Observable { - if (this._getTalkgroup.size < 1) { - this.fillTgMap(share); - } const key = this.tgKey(sys, tg); if (!this._getTalkgroup.get(key)) { let rs = new ReplaySubject(); @@ -101,11 +107,7 @@ export class TalkgroupService { return this.http.post('/api/talkgroup/', pagination); } - fillTgMap(share: Share | null) { - this.tgs$ = this.fetchAll.pipe( - switchMap(() => this.getTalkgroups(share)), - shareReplay(), - ); + fillTgMap() { this.subscriptions.add( this.tgs$.subscribe((tgs) => { tgs.forEach((tg) => {