improve share, tg
This commit is contained in:
parent
b262fbce0c
commit
cea7704778
7 changed files with 51 additions and 35 deletions
|
@ -1,6 +1,7 @@
|
|||
export interface CallRecord {
|
||||
id: string;
|
||||
call_date: Date;
|
||||
audioURL: string | null;
|
||||
duration: number;
|
||||
system_id: number;
|
||||
tgid: number;
|
||||
|
|
|
@ -39,7 +39,7 @@ import {
|
|||
import { CallPlayerComponent } from '../../calls/player/call-player/call-player.component';
|
||||
import { FmtDatePipe } from '../incidents.component';
|
||||
import { MatMenuModule } from '@angular/material/menu';
|
||||
import { Share } from '../../share/share.service';
|
||||
import { Share } from '../../shares';
|
||||
|
||||
export interface EditDialogData {
|
||||
incID: string;
|
||||
|
@ -190,8 +190,8 @@ export class IncidentComponent {
|
|||
if (!this.incident) {
|
||||
return;
|
||||
}
|
||||
this.incID = (this.incident.share as IncidentRecord).id;
|
||||
incOb = new BehaviorSubject(this.incident.share as IncidentRecord);
|
||||
this.incID = (this.incident.sharedItem as IncidentRecord).id;
|
||||
incOb = new BehaviorSubject(this.incident.sharedItem as IncidentRecord);
|
||||
}
|
||||
this.inc$ = merge(incOb, this.incPrime).pipe(
|
||||
tap((inc) => {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
@let sh = share | async;
|
||||
@if (sh == null) {
|
||||
<h1 class="error">Share invalid!</h1>
|
||||
} @else if (sh.shareType == "incident") {
|
||||
} @else if (sh.type == "incident") {
|
||||
<app-incident [incident]="sh"></app-incident>
|
||||
} @else if (sh.shareType == "call") {
|
||||
} @else if (sh.type == "call") {
|
||||
} @else {
|
||||
<h1 class="error">Share type {{sh.shareType}} unknown</h1>
|
||||
<h1 class="error">Share type {{ sh.type }} unknown</h1>
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
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 { Observable, Subscription, switchMap } from 'rxjs';
|
||||
import { IncidentComponent } from '../incidents/incident/incident.component';
|
||||
|
|
|
@ -2,35 +2,39 @@ import { HttpClient } from '@angular/common/http';
|
|||
import { Injectable } from '@angular/core';
|
||||
import { map, Observable, switchMap } from 'rxjs';
|
||||
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({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ShareService {
|
||||
constructor(private http: HttpClient) {}
|
||||
|
||||
getShare(id: string): Observable<Share | null> {
|
||||
return this.http
|
||||
.get<ShareType>(`/share/${id}`, { observe: 'response' })
|
||||
.pipe(
|
||||
map((res) => {
|
||||
let typ = res.headers.get('X-Share-Type');
|
||||
switch (typ) {
|
||||
case 'call':
|
||||
return <Share>{ shareType: typ, share: res.body as ArrayBuffer };
|
||||
case 'incident':
|
||||
return <Share>{
|
||||
shareType: typ,
|
||||
share: res.body as IncidentRecord,
|
||||
};
|
||||
getShare(id: string): Observable<Share> {
|
||||
return this.http.get<Share>(`/share/${id}`);
|
||||
}
|
||||
|
||||
getSharedItem(s: Observable<Share>): Observable<ShareType> {
|
||||
return s.pipe(
|
||||
map((res) => {
|
||||
switch (res.type) {
|
||||
case 'call':
|
||||
return <CallRecord>res.sharedItem;
|
||||
case 'incident':
|
||||
return <IncidentRecord>res.sharedItem;
|
||||
}
|
||||
|
||||
return null;
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getCallAudio(s: Observable<CallRecord>): Observable<ArrayBuffer> {
|
||||
return s.pipe(
|
||||
switchMap((res) => {
|
||||
return this.http.get<ArrayBuffer>(res.audioURL!);
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
8
client/stillbox/src/app/shares.ts
Normal file
8
client/stillbox/src/app/shares.ts
Normal 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;
|
||||
}
|
|
@ -2,7 +2,6 @@ import { Injectable } from '@angular/core';
|
|||
import { HttpClient, HttpResponse } from '@angular/common/http';
|
||||
import {
|
||||
BehaviorSubject,
|
||||
concatMap,
|
||||
Observable,
|
||||
ReplaySubject,
|
||||
shareReplay,
|
||||
|
@ -32,7 +31,10 @@ export class TalkgroupService {
|
|||
private fetchAll = new BehaviorSubject<'fetch'>('fetch');
|
||||
private subscriptions = new Subscription();
|
||||
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(
|
||||
switchMap(() => this.getAllTags()),
|
||||
shareReplay(),
|
||||
|
@ -45,11 +47,11 @@ export class TalkgroupService {
|
|||
}
|
||||
|
||||
getAllTags(): Observable<string[]> {
|
||||
return this.http.get<string[]>('/api/talkgroup/tags').pipe(shareReplay());
|
||||
return this.http.get<string[]>('/api/talkgroup/tags');
|
||||
}
|
||||
|
||||
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> {
|
||||
|
|
Loading…
Add table
Reference in a new issue