broken
This commit is contained in:
parent
493913112d
commit
98a74c1a92
5 changed files with 58 additions and 11 deletions
|
@ -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<IncidentRecord>(<IncidentRecord>{});
|
||||
inc$!: Observable<IncidentRecord>;
|
||||
@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<IncidentRecord>;
|
||||
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;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -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<Share|null>;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Share|null> {
|
||||
return this.http.get<Share>(`/share/${id}`, {observe: 'response'}).pipe(
|
||||
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 (res.body as ArrayBuffer);
|
||||
return <Share>{shareType: typ, share: (res.body as ArrayBuffer)};
|
||||
case 'incident':
|
||||
return (res.body as IncidentRecord);
|
||||
return <Share>{shareType: typ, share: (res.body as IncidentRecord)};
|
||||
}
|
||||
return null;
|
||||
})
|
||||
|
|
|
@ -2,5 +2,9 @@
|
|||
"/api": {
|
||||
"target": "http://xenon:3050",
|
||||
"secure": false
|
||||
},
|
||||
"/share": {
|
||||
"target": "http://xenon:3050",
|
||||
"secure": false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue