This commit is contained in:
Daniel Ponte 2025-01-31 09:03:46 -05:00
parent 632607cd0b
commit 1c0734f19d
5 changed files with 58 additions and 11 deletions

View file

@ -1,5 +1,5 @@
import { Component, inject, Sanitizer } from '@angular/core'; import { Component, inject, Input, input, Sanitizer } from '@angular/core';
import { tap } from 'rxjs/operators'; import { switchMap, tap } from 'rxjs/operators';
import { CommonModule, Location } from '@angular/common'; import { CommonModule, Location } from '@angular/common';
import { BehaviorSubject, merge, Subscription } from 'rxjs'; import { BehaviorSubject, merge, Subscription } from 'rxjs';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
@ -39,6 +39,8 @@ 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 { toObservable } from '@angular/core/rxjs-interop';
export interface EditDialogData { export interface EditDialogData {
incID: string; incID: string;
@ -153,6 +155,7 @@ export class IncidentEditDialogComponent {
export class IncidentComponent { export class IncidentComponent {
incPrime = new BehaviorSubject<IncidentRecord>(<IncidentRecord>{}); incPrime = new BehaviorSubject<IncidentRecord>(<IncidentRecord>{});
inc$!: Observable<IncidentRecord>; inc$!: Observable<IncidentRecord>;
@Input() incident?: Share;
subscriptions: Subscription = new Subscription(); subscriptions: Subscription = new Subscription();
dialog = inject(MatDialog); dialog = inject(MatDialog);
incID!: string; incID!: string;
@ -179,8 +182,18 @@ export class IncidentComponent {
saveIncName(ev: Event) {} saveIncName(ev: Event) {}
ngOnInit() { ngOnInit() {
this.incID = this.route.snapshot.paramMap.get('id')!; let incOb: Observable<IncidentRecord>;
this.inc$ = merge(this.incSvc.getIncident(this.incID), this.incPrime).pipe( if (this.route.component === this.constructor) { // loaded by route
this.incID = this.route.snapshot.paramMap.get('id')!;
incOb = this.incSvc.getIncident(this.incID);
} else {
if (!this.incident) {
return;
}
this.incID = (this.incident.share as IncidentRecord).id;
incOb = new BehaviorSubject(this.incident.share as IncidentRecord);
}
this.inc$ = merge(incOb, this.incPrime).pipe(
tap((inc) => { tap((inc) => {
if (inc.calls) { if (inc.calls) {
this.callsResult.data = inc.calls; this.callsResult.data = inc.calls;

View file

@ -1 +1,10 @@
<p>share works!</p> @let sh = share | async;
@if (sh == null) {
} @else if (sh.shareType == 'incident') {
<app-incident [incident]="sh"></app-incident>
} @else if (sh.shareType == 'call') {
} @else {
}

View file

@ -1,20 +1,37 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { ShareService } from './share.service'; import { Share, ShareService } from './share.service';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { Observable, Subscription, switchMap } from 'rxjs';
import { IncidentComponent } from '../incidents/incident/incident.component';
import { AsyncPipe } from '@angular/common';
@Component({ @Component({
selector: 'app-share', selector: 'app-share',
imports: [], imports: [
AsyncPipe,
IncidentComponent,
],
templateUrl: './share.component.html', templateUrl: './share.component.html',
styleUrl: './share.component.scss' styleUrl: './share.component.scss'
}) })
export class ShareComponent { export class ShareComponent {
shareID!: string;
share!: Observable<Share|null>;
constructor( constructor(
private route: ActivatedRoute, private route: ActivatedRoute,
private shareSvc: ShareService, private shareSvc: ShareService,
) {} ) {}
ngOnInit() { ngOnInit() {
let shareParam = this.route.snapshot.paramMap.get('id');
if (shareParam == null) {
// TODO: error
return;
}
this.shareID = shareParam;
this.share = this.shareSvc.getShare(this.shareID);
} }
} }

View file

@ -3,7 +3,11 @@ 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';
type Share = IncidentRecord | ArrayBuffer; type ShareType = IncidentRecord | ArrayBuffer;
export interface Share {
shareType: string;
share: ShareType;
}
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
}) })
@ -14,14 +18,14 @@ export class ShareService {
) { } ) { }
getShare(id: string): Observable<Share|null> { getShare(id: string): Observable<Share|null> {
return this.http.get<Share>(`/share/${id}`, {observe: 'response'}).pipe( return this.http.get<ShareType>(`/share/${id}`, {observe: 'response'}).pipe(
map((res) => { map((res) => {
let typ = res.headers.get('X-Share-Type'); let typ = res.headers.get('X-Share-Type');
switch(typ) { switch(typ) {
case 'call': case 'call':
return (res.body as ArrayBuffer); return <Share>{shareType: typ, share: (res.body as ArrayBuffer)};
case 'incident': case 'incident':
return (res.body as IncidentRecord); return <Share>{shareType: typ, share: (res.body as IncidentRecord)};
} }
return null; return null;
}) })

View file

@ -2,5 +2,9 @@
"/api": { "/api": {
"target": "http://xenon:3050", "target": "http://xenon:3050",
"secure": false "secure": false
},
"/share": {
"target": "http://xenon:3050",
"secure": false
} }
} }