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
>
</h1>
@if (!inShare) {
@if (share == null) {
<button mat-icon-button (click)="editIncident(incID)">
<mat-icon>edit</mat-icon>
</button>

View file

@ -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<IncidentRecord>();
inc$!: Observable<IncidentRecord>;
@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<IncidentRecord>;
if (this.route.component === this.constructor) {
// loaded by route

View file

@ -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<Share> {
return this.http.get<Share>(`/share/${id}`);

View file

@ -27,15 +27,24 @@ 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 fetchAll = new BehaviorSubject<Share|null>(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<string[]>('/api/talkgroup/tags');
}
getTalkgroups(share: Share | null): Observable<Talkgroup[]> {
return this.http.get<Talkgroup[]>('/api/talkgroup/');
getTalkgroups(share: Share|null): Observable<Talkgroup[]> {
return this.http.get<Talkgroup[]>(share ? `/share/${share.id}/talkgroups` : '/api/talkgroup/');
}
getTalkgroup(
@ -55,9 +64,6 @@ 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>();
@ -101,11 +107,7 @@ export class TalkgroupService {
return this.http.post<TalkgroupsPaginated>('/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) => {