improve share, tg

This commit is contained in:
Daniel Ponte 2025-02-03 08:10:54 -05:00
parent b262fbce0c
commit cea7704778
7 changed files with 51 additions and 35 deletions

View file

@ -1,6 +1,7 @@
export interface CallRecord { export interface CallRecord {
id: string; id: string;
call_date: Date; call_date: Date;
audioURL: string | null;
duration: number; duration: number;
system_id: number; system_id: number;
tgid: number; tgid: number;

View file

@ -39,7 +39,7 @@ import {
import { CallPlayerComponent } from '../../calls/player/call-player/call-player.component'; import { CallPlayerComponent } from '../../calls/player/call-player/call-player.component';
import { FmtDatePipe } from '../incidents.component'; import { FmtDatePipe } from '../incidents.component';
import { MatMenuModule } from '@angular/material/menu'; import { MatMenuModule } from '@angular/material/menu';
import { Share } from '../../share/share.service'; import { Share } from '../../shares';
export interface EditDialogData { export interface EditDialogData {
incID: string; incID: string;
@ -190,8 +190,8 @@ export class IncidentComponent {
if (!this.incident) { if (!this.incident) {
return; return;
} }
this.incID = (this.incident.share as IncidentRecord).id; this.incID = (this.incident.sharedItem as IncidentRecord).id;
incOb = new BehaviorSubject(this.incident.share as IncidentRecord); incOb = new BehaviorSubject(this.incident.sharedItem as IncidentRecord);
} }
this.inc$ = merge(incOb, this.incPrime).pipe( this.inc$ = merge(incOb, this.incPrime).pipe(
tap((inc) => { tap((inc) => {

View file

@ -1,9 +1,9 @@
@let sh = share | async; @let sh = share | async;
@if (sh == null) { @if (sh == null) {
<h1 class="error">Share invalid!</h1> <h1 class="error">Share invalid!</h1>
} @else if (sh.shareType == "incident") { } @else if (sh.type == "incident") {
<app-incident [incident]="sh"></app-incident> <app-incident [incident]="sh"></app-incident>
} @else if (sh.shareType == "call") { } @else if (sh.type == "call") {
} @else { } @else {
<h1 class="error">Share type {{sh.shareType}} unknown</h1> <h1 class="error">Share type {{ sh.type }} unknown</h1>
} }

View file

@ -1,5 +1,6 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { Share, ShareService } from './share.service'; import { ShareService } from './share.service';
import { Share } from '../shares';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Observable, Subscription, switchMap } from 'rxjs'; import { Observable, Subscription, switchMap } from 'rxjs';
import { IncidentComponent } from '../incidents/incident/incident.component'; import { IncidentComponent } from '../incidents/incident/incident.component';

View file

@ -2,35 +2,39 @@ import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { map, Observable, switchMap } from 'rxjs'; import { map, Observable, switchMap } from 'rxjs';
import { IncidentRecord } from '../incidents'; import { IncidentRecord } from '../incidents';
import { CallRecord } from '../calls';
import { Share, ShareType } from '../shares';
type ShareType = IncidentRecord | ArrayBuffer;
export interface Share {
shareType: string;
share: ShareType;
}
@Injectable({ @Injectable({
providedIn: 'root', providedIn: 'root',
}) })
export class ShareService { export class ShareService {
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
getShare(id: string): Observable<Share | null> { getShare(id: string): Observable<Share> {
return this.http return this.http.get<Share>(`/share/${id}`);
.get<ShareType>(`/share/${id}`, { observe: 'response' }) }
.pipe(
map((res) => { getSharedItem(s: Observable<Share>): Observable<ShareType> {
let typ = res.headers.get('X-Share-Type'); return s.pipe(
switch (typ) { map((res) => {
case 'call': switch (res.type) {
return <Share>{ shareType: typ, share: res.body as ArrayBuffer }; case 'call':
case 'incident': return <CallRecord>res.sharedItem;
return <Share>{ case 'incident':
shareType: typ, return <IncidentRecord>res.sharedItem;
share: res.body as IncidentRecord, }
};
} return null;
return null; }),
}), );
); }
getCallAudio(s: Observable<CallRecord>): Observable<ArrayBuffer> {
return s.pipe(
switchMap((res) => {
return this.http.get<ArrayBuffer>(res.audioURL!);
}),
);
} }
} }

View file

@ -0,0 +1,8 @@
import { IncidentRecord } from './incidents';
import { CallRecord } from './calls';
export type ShareType = IncidentRecord | CallRecord | null;
export interface Share {
id: string;
type: string;
sharedItem: ShareType;
}

View file

@ -2,7 +2,6 @@ import { Injectable } from '@angular/core';
import { HttpClient, HttpResponse } from '@angular/common/http'; import { HttpClient, HttpResponse } from '@angular/common/http';
import { import {
BehaviorSubject, BehaviorSubject,
concatMap,
Observable, Observable,
ReplaySubject, ReplaySubject,
shareReplay, shareReplay,
@ -32,7 +31,10 @@ export class TalkgroupService {
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())); 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(),
@ -45,11 +47,11 @@ export class TalkgroupService {
} }
getAllTags(): Observable<string[]> { getAllTags(): Observable<string[]> {
return this.http.get<string[]>('/api/talkgroup/tags').pipe(shareReplay()); return this.http.get<string[]>('/api/talkgroup/tags');
} }
getTalkgroups(): Observable<Talkgroup[]> { getTalkgroups(): Observable<Talkgroup[]> {
return this.http.get<Talkgroup[]>('/api/talkgroup/').pipe(shareReplay()); return this.http.get<Talkgroup[]>('/api/talkgroup/');
} }
getTalkgroup(sys: number, tg: number): Observable<Talkgroup> { getTalkgroup(sys: number, tg: number): Observable<Talkgroup> {