This commit is contained in:
Daniel Ponte 2025-02-06 20:51:30 -05:00
parent f5e969cea3
commit 3e3d39332c
4 changed files with 22 additions and 23 deletions

View file

@ -7,7 +7,7 @@
><mat-icon>playlist_play</mat-icon></a ><mat-icon>playlist_play</mat-icon></a
> >
</h1> </h1>
@if (!inShare) { @if (share == null) {
<button mat-icon-button (click)="editIncident(incID)"> <button mat-icon-button (click)="editIncident(incID)">
<mat-icon>edit</mat-icon> <mat-icon>edit</mat-icon>
</button> </button>

View file

@ -9,7 +9,7 @@ import {
FormControl, FormControl,
FormsModule, FormsModule,
} from '@angular/forms'; } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatCheckboxModule } from '@angular/material/checkbox';
@ -41,6 +41,7 @@ import { FmtDatePipe } from '../incidents.component';
import { MatMenuModule } from '@angular/material/menu'; import { MatMenuModule } from '@angular/material/menu';
import { Share } from '../../shares'; import { Share } from '../../shares';
import { ShareService } from '../../share/share.service'; import { ShareService } from '../../share/share.service';
import { TalkgroupService } from '../../talkgroups/talkgroups.service';
export interface EditDialogData { export interface EditDialogData {
incID: string; incID: string;
@ -153,7 +154,6 @@ export class IncidentEditDialogComponent {
styleUrl: './incident.component.scss', styleUrl: './incident.component.scss',
}) })
export class IncidentComponent { export class IncidentComponent {
inShare = false;
incPrime = new Subject<IncidentRecord>(); incPrime = new Subject<IncidentRecord>();
inc$!: Observable<IncidentRecord>; inc$!: Observable<IncidentRecord>;
@Input() share?: Share; @Input() share?: Share;
@ -176,15 +176,17 @@ export class IncidentComponent {
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private shareSvc: ShareService,
private incSvc: IncidentsService, private incSvc: IncidentsService,
private location: Location, private location: Location,
private tgSvc: TalkgroupService,
) {} ) {}
saveIncName(ev: Event) {} saveIncName(ev: Event) {}
ngOnInit() { ngOnInit() {
this.inShare = this.shareSvc.isInShare(); if (this.share) {
this.tgSvc.setShare(this.share);
}
let incOb: Observable<IncidentRecord>; let incOb: Observable<IncidentRecord>;
if (this.route.component === this.constructor) { if (this.route.component === this.constructor) {
// loaded by route // loaded by route

View file

@ -4,17 +4,12 @@ import { map, Observable, switchMap } from 'rxjs';
import { IncidentRecord } from '../incidents'; import { IncidentRecord } from '../incidents';
import { CallRecord } from '../calls'; import { CallRecord } from '../calls';
import { Share, ShareType } from '../shares'; import { Share, ShareType } from '../shares';
import { Router } from '@angular/router';
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class ShareService { export class ShareService {
constructor(private http: HttpClient, private router: Router) {} constructor(private http: HttpClient) {}
isInShare(): boolean {
return this.router.url.startsWith('/s/');
}
getShare(id: string): Observable<Share> { getShare(id: string): Observable<Share> {
return this.http.get<Share>(`/share/${id}`); return this.http.get<Share>(`/share/${id}`);

View file

@ -27,15 +27,24 @@ 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<Share|null>(null);
private subscriptions = new Subscription(); private subscriptions = new Subscription();
constructor(private http: HttpClient) { constructor(private http: HttpClient) {
this.tgs$ = this.fetchAll.pipe(
switchMap((share) => this.getTalkgroups(share)),
shareReplay(),
);
this.tags$ = this.fetchAll.pipe( this.tags$ = this.fetchAll.pipe(
switchMap(() => this.getAllTags()), switchMap(() => this.getAllTags()),
shareReplay(), shareReplay(),
); );
this.fillTgMap();
}
setShare(share: Share) {
this.fetchAll.next(share);
} }
ngOnDestroy() { ngOnDestroy() {
@ -46,8 +55,8 @@ export class TalkgroupService {
return this.http.get<string[]>('/api/talkgroup/tags'); return this.http.get<string[]>('/api/talkgroup/tags');
} }
getTalkgroups(share: Share | null): Observable<Talkgroup[]> { getTalkgroups(share: Share|null): Observable<Talkgroup[]> {
return this.http.get<Talkgroup[]>('/api/talkgroup/'); return this.http.get<Talkgroup[]>(share ? `/share/${share.id}/talkgroups` : '/api/talkgroup/');
} }
getTalkgroup( getTalkgroup(
@ -55,9 +64,6 @@ 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>();
@ -101,11 +107,7 @@ export class TalkgroupService {
return this.http.post<TalkgroupsPaginated>('/api/talkgroup/', pagination); return this.http.post<TalkgroupsPaginated>('/api/talkgroup/', pagination);
} }
fillTgMap(share: Share | null) { fillTgMap() {
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) => {