Shares #109
3 changed files with 55 additions and 0 deletions
|
@ -1,4 +1,6 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
import { ShareService } from './share.service';
|
||||||
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-share',
|
selector: 'app-share',
|
||||||
|
@ -7,5 +9,12 @@ import { Component } from '@angular/core';
|
||||||
styleUrl: './share.component.scss'
|
styleUrl: './share.component.scss'
|
||||||
})
|
})
|
||||||
export class ShareComponent {
|
export class ShareComponent {
|
||||||
|
constructor(
|
||||||
|
private route: ActivatedRoute,
|
||||||
|
private shareSvc: ShareService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
16
client/stillbox/src/app/share/share.service.spec.ts
Normal file
16
client/stillbox/src/app/share/share.service.spec.ts
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
import { TestBed } from '@angular/core/testing';
|
||||||
|
|
||||||
|
import { ShareService } from './share.service';
|
||||||
|
|
||||||
|
describe('ShareService', () => {
|
||||||
|
let service: ShareService;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({});
|
||||||
|
service = TestBed.inject(ShareService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be created', () => {
|
||||||
|
expect(service).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
30
client/stillbox/src/app/share/share.service.ts
Normal file
30
client/stillbox/src/app/share/share.service.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import { HttpClient } from '@angular/common/http';
|
||||||
|
import { Injectable } from '@angular/core';
|
||||||
|
import { map, Observable, switchMap } from 'rxjs';
|
||||||
|
import { IncidentRecord } from '../incidents';
|
||||||
|
|
||||||
|
type Share = IncidentRecord | ArrayBuffer;
|
||||||
|
@Injectable({
|
||||||
|
providedIn: 'root'
|
||||||
|
})
|
||||||
|
export class ShareService {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private http: HttpClient,
|
||||||
|
) { }
|
||||||
|
|
||||||
|
getShare(id: string): Observable<Share|null> {
|
||||||
|
return this.http.get<Share>(`/share/${id}`, {observe: 'response'}).pipe(
|
||||||
|
map((res) => {
|
||||||
|
let typ = res.headers.get('X-Share-Type');
|
||||||
|
switch(typ) {
|
||||||
|
case 'call':
|
||||||
|
return (res.body as ArrayBuffer);
|
||||||
|
case 'incident':
|
||||||
|
return (res.body as IncidentRecord);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue