From 1c0734f19da8cce688648ba0d997328083db9899 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Fri, 31 Jan 2025 09:03:46 -0500 Subject: [PATCH] broken --- .../incidents/incident/incident.component.ts | 21 +++++++++++++++---- .../src/app/share/share.component.html | 11 +++++++++- .../stillbox/src/app/share/share.component.ts | 21 +++++++++++++++++-- .../stillbox/src/app/share/share.service.ts | 12 +++++++---- client/stillbox/src/proxy.conf.json | 4 ++++ 5 files changed, 58 insertions(+), 11 deletions(-) diff --git a/client/stillbox/src/app/incidents/incident/incident.component.ts b/client/stillbox/src/app/incidents/incident/incident.component.ts index ad5cdcc..cd1d21a 100644 --- a/client/stillbox/src/app/incidents/incident/incident.component.ts +++ b/client/stillbox/src/app/incidents/incident/incident.component.ts @@ -1,5 +1,5 @@ -import { Component, inject, Sanitizer } from '@angular/core'; -import { tap } from 'rxjs/operators'; +import { Component, inject, Input, input, Sanitizer } from '@angular/core'; +import { switchMap, tap } from 'rxjs/operators'; import { CommonModule, Location } from '@angular/common'; import { BehaviorSubject, merge, Subscription } from 'rxjs'; import { Observable } from 'rxjs'; @@ -39,6 +39,8 @@ 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 { toObservable } from '@angular/core/rxjs-interop'; export interface EditDialogData { incID: string; @@ -153,6 +155,7 @@ export class IncidentEditDialogComponent { export class IncidentComponent { incPrime = new BehaviorSubject({}); inc$!: Observable; + @Input() incident?: Share; subscriptions: Subscription = new Subscription(); dialog = inject(MatDialog); incID!: string; @@ -179,8 +182,18 @@ export class IncidentComponent { saveIncName(ev: Event) {} ngOnInit() { - this.incID = this.route.snapshot.paramMap.get('id')!; - this.inc$ = merge(this.incSvc.getIncident(this.incID), this.incPrime).pipe( + let incOb: Observable; + 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) => { if (inc.calls) { this.callsResult.data = inc.calls; diff --git a/client/stillbox/src/app/share/share.component.html b/client/stillbox/src/app/share/share.component.html index 5ca71b6..8a7eaf6 100644 --- a/client/stillbox/src/app/share/share.component.html +++ b/client/stillbox/src/app/share/share.component.html @@ -1 +1,10 @@ -

share works!

+@let sh = share | async; +@if (sh == null) { + +} @else if (sh.shareType == 'incident') { + +} @else if (sh.shareType == 'call') { + +} @else { + +} \ No newline at end of file diff --git a/client/stillbox/src/app/share/share.component.ts b/client/stillbox/src/app/share/share.component.ts index 2f28cfc..127f62e 100644 --- a/client/stillbox/src/app/share/share.component.ts +++ b/client/stillbox/src/app/share/share.component.ts @@ -1,20 +1,37 @@ import { Component } from '@angular/core'; -import { ShareService } from './share.service'; +import { Share, ShareService } from './share.service'; import { ActivatedRoute } from '@angular/router'; +import { Observable, Subscription, switchMap } from 'rxjs'; +import { IncidentComponent } from '../incidents/incident/incident.component'; +import { AsyncPipe } from '@angular/common'; + @Component({ selector: 'app-share', - imports: [], + imports: [ + AsyncPipe, + IncidentComponent, + ], templateUrl: './share.component.html', styleUrl: './share.component.scss' }) export class ShareComponent { + shareID!: string; + share!: Observable; constructor( private route: ActivatedRoute, private shareSvc: ShareService, ) {} 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); } } diff --git a/client/stillbox/src/app/share/share.service.ts b/client/stillbox/src/app/share/share.service.ts index 4ea55f0..82433dd 100644 --- a/client/stillbox/src/app/share/share.service.ts +++ b/client/stillbox/src/app/share/share.service.ts @@ -3,7 +3,11 @@ import { Injectable } from '@angular/core'; import { map, Observable, switchMap } from 'rxjs'; import { IncidentRecord } from '../incidents'; -type Share = IncidentRecord | ArrayBuffer; +type ShareType = IncidentRecord | ArrayBuffer; +export interface Share { + shareType: string; + share: ShareType; +} @Injectable({ providedIn: 'root' }) @@ -14,14 +18,14 @@ export class ShareService { ) { } getShare(id: string): Observable { - return this.http.get(`/share/${id}`, {observe: 'response'}).pipe( + return this.http.get(`/share/${id}`, {observe: 'response'}).pipe( map((res) => { let typ = res.headers.get('X-Share-Type'); switch(typ) { case 'call': - return (res.body as ArrayBuffer); + return {shareType: typ, share: (res.body as ArrayBuffer)}; case 'incident': - return (res.body as IncidentRecord); + return {shareType: typ, share: (res.body as IncidentRecord)}; } return null; }) diff --git a/client/stillbox/src/proxy.conf.json b/client/stillbox/src/proxy.conf.json index 96af567..67915a8 100644 --- a/client/stillbox/src/proxy.conf.json +++ b/client/stillbox/src/proxy.conf.json @@ -2,5 +2,9 @@ "/api": { "target": "http://xenon:3050", "secure": false + }, + "/share": { + "target": "http://xenon:3050", + "secure": false } }