From 3c133b092248560701b9f7659d4f191b4cbd9380 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 5 Jan 2025 17:22:09 -0500 Subject: [PATCH] New incident --- .../src/app/calls/calls.component.html | 8 ++- .../stillbox/src/app/calls/calls.component.ts | 45 +++++++++++++- .../incidents/incident/incident.component.ts | 59 ++++++++++--------- 3 files changed, 81 insertions(+), 31 deletions(-) diff --git a/client/stillbox/src/app/calls/calls.component.html b/client/stillbox/src/app/calls/calls.component.html index 4a599e0..100cc73 100644 --- a/client/stillbox/src/app/calls/calls.component.html +++ b/client/stillbox/src/app/calls/calls.component.html @@ -90,8 +90,12 @@ playlist_add - - + + diff --git a/client/stillbox/src/app/calls/calls.component.ts b/client/stillbox/src/app/calls/calls.component.ts index 4836f9a..ab7ac9b 100644 --- a/client/stillbox/src/app/calls/calls.component.ts +++ b/client/stillbox/src/app/calls/calls.component.ts @@ -1,4 +1,10 @@ -import { Component, Pipe, PipeTransform, ViewChild } from '@angular/core'; +import { + Component, + inject, + Pipe, + PipeTransform, + ViewChild, +} from '@angular/core'; import { CommonModule, AsyncPipe } from '@angular/common'; import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; import { MatTableModule } from '@angular/material/table'; @@ -31,6 +37,16 @@ import { ToolbarContextService } from '../navigation/toolbar-context.service'; import { MatSelectModule } from '@angular/material/select'; import { CallPlayerComponent } from './player/call-player/call-player.component'; import { MatMenuModule } from '@angular/material/menu'; +import { MatDialog } from '@angular/material/dialog'; +import { + EditDialogData, + IncidentEditDialogComponent, +} from '../incidents/incident/incident.component'; +import { + CallIncidentParams, + IncidentsService, +} from '../incidents/incidents.service'; +import { IncidentRecord } from '../incidents'; @Pipe({ name: 'grabDate', @@ -151,6 +167,7 @@ export class CallsComponent { callsResult = new BehaviorSubject(new Array(0)); @ViewChild('paginator') paginator!: MatPaginator; count = 0; + dialog = inject(MatDialog); page = 0; perPage = 25; pageSizeOptions = [25, 50, 75, 100, 200]; @@ -193,6 +210,7 @@ export class CallsComponent { private prefsSvc: PrefsService, public tcSvc: ToolbarContextService, public tgSvc: TalkgroupService, + public incSvc: IncidentsService, ) { this.tcSvc.showFilterButton(); } @@ -340,4 +358,29 @@ export class CallsComponent { this.form.controls['start'].setValue(this.lTime(new Date())); this.form.controls['duration'].setValue(0); } + + addToNewInc(ev: Event) { + const dialogRef = this.dialog.open(IncidentEditDialogComponent, { + data: { + incID: '', + new: true, + }, + }); + dialogRef.afterClosed().subscribe((res: IncidentRecord) => { + this.incSvc + .addRemoveCalls(res.id, { + add: this.selection.selected.map((s) => s.id), + }) + .subscribe({ + next: () => { + this.selection.clear(); + }, + error: (err) => { + alert(err); + }, + }); + }); + } + + addToExistingInc(ev: Event) {} } diff --git a/client/stillbox/src/app/incidents/incident/incident.component.ts b/client/stillbox/src/app/incidents/incident/incident.component.ts index 3779d44..823fee8 100644 --- a/client/stillbox/src/app/incidents/incident/incident.component.ts +++ b/client/stillbox/src/app/incidents/incident/incident.component.ts @@ -1,11 +1,7 @@ import { Component, inject } from '@angular/core'; import { tap } from 'rxjs/operators'; import { CommonModule } from '@angular/common'; -import { - BehaviorSubject, - merge, - Subscription, -} from 'rxjs'; +import { BehaviorSubject, merge, Subscription } from 'rxjs'; import { Observable } from 'rxjs'; import { ReactiveFormsModule, @@ -88,33 +84,40 @@ export class IncidentEditDialogComponent { this.form.patchValue(inc); }), ); + } else { + this.inc$ = new BehaviorSubject({}); } } save() { - this.incSvc - .updateIncident(this.data.incID, { - name: this.form.controls['name'].dirty - ? this.form.controls['name'].value - : null, - startTime: this.form.controls['start'].dirty - ? this.form.controls['start'].value - : null, - endTime: this.form.controls['end'].dirty - ? this.form.controls['end'].value - : null, - description: this.form.controls['description'].dirty - ? this.form.controls['description'].value - : null, - }) - .subscribe({ - next: (ok) => { - this.dialogRef.close(ok); - }, - error: (er) => { - alert(er); - }, - }); + let resObs: Observable; + let ir: IncidentRecord = { + name: this.form.controls['name'].dirty + ? this.form.controls['name'].value + : null, + startTime: this.form.controls['start'].dirty + ? this.form.controls['start'].value + : null, + endTime: this.form.controls['end'].dirty + ? this.form.controls['end'].value + : null, + description: this.form.controls['description'].dirty + ? this.form.controls['description'].value + : null, + }; + if (this.data.new) { + resObs = this.incSvc.createIncident(ir); + } else { + resObs = this.incSvc.updateIncident(this.data.incID, ir); + } + resObs.subscribe({ + next: (ok) => { + this.dialogRef.close(ok); + }, + error: (er) => { + alert(er); + }, + }); } cancel() {