From 56279f45b3d2d31f4bca49749a88054557b0c6e9 Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Sun, 5 Jan 2025 14:36:37 -0500 Subject: [PATCH] WIP: incident record description is never being marked as dirty, needs fix --- .../src/app/calls/calls.component.html | 7 +++ .../stillbox/src/app/calls/calls.component.ts | 2 + .../incident-editor-dialog.component.html | 2 +- .../incidents/incident/incident.component.ts | 48 +++++++++++++++---- 4 files changed, 49 insertions(+), 10 deletions(-) diff --git a/client/stillbox/src/app/calls/calls.component.html b/client/stillbox/src/app/calls/calls.component.html index a2b5857..8870ca3 100644 --- a/client/stillbox/src/app/calls/calls.component.html +++ b/client/stillbox/src/app/calls/calls.component.html @@ -83,6 +83,13 @@ + + + + + diff --git a/client/stillbox/src/app/calls/calls.component.ts b/client/stillbox/src/app/calls/calls.component.ts index 9113069..0a3c077 100644 --- a/client/stillbox/src/app/calls/calls.component.ts +++ b/client/stillbox/src/app/calls/calls.component.ts @@ -30,6 +30,7 @@ import { debounceTime } from 'rxjs/operators'; 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'; @Pipe({ name: 'grabDate', @@ -141,6 +142,7 @@ const reqPageSize = 200; MatProgressSpinnerModule, MatSelectModule, CallPlayerComponent, + MatMenuModule, ], templateUrl: './calls.component.html', styleUrl: './calls.component.scss', diff --git a/client/stillbox/src/app/incidents/incident/incident-editor-dialog.component.html b/client/stillbox/src/app/incidents/incident/incident-editor-dialog.component.html index 5ff7a2f..d939a2d 100644 --- a/client/stillbox/src/app/incidents/incident/incident-editor-dialog.component.html +++ b/client/stillbox/src/app/incidents/incident/incident-editor-dialog.component.html @@ -1,4 +1,4 @@ -

Edit Incident

+

{{ title }}

@let inc = inc$ | async; diff --git a/client/stillbox/src/app/incidents/incident/incident.component.ts b/client/stillbox/src/app/incidents/incident/incident.component.ts index a5278cb..5086abd 100644 --- a/client/stillbox/src/app/incidents/incident/incident.component.ts +++ b/client/stillbox/src/app/incidents/incident/incident.component.ts @@ -40,6 +40,11 @@ import { import { CallPlayerComponent } from '../../calls/player/call-player/call-player.component'; import { FmtDatePipe } from '../incidents.component'; +export interface EditDialogData { + incID: string; + new: boolean; +} + @Component({ selector: 'app-incident-editor', imports: [ @@ -61,7 +66,8 @@ import { FmtDatePipe } from '../incidents.component'; }) export class IncidentEditDialogComponent { dialogRef = inject(MatDialogRef); - incID = inject(MAT_DIALOG_DATA); + data = inject(MAT_DIALOG_DATA); + title = this.data.new ? 'New Incident' : 'Edit Incident'; inc$!: Observable; form = new FormGroup({ name: new FormControl(''), @@ -73,14 +79,36 @@ export class IncidentEditDialogComponent { constructor(private incSvc: IncidentsService) {} ngOnInit() { - this.inc$ = this.incSvc.getIncident(this.incID).pipe( - tap((inc) => { - this.form.patchValue(inc); - }), - ); + if (!this.data.new) { + this.inc$ = this.incSvc.getIncident(this.data.incID).pipe( + tap((inc) => { + this.form.patchValue(inc, { + onlySelf: false, + emitEvent: false, + } + ); + this.form.markAsPristine(); + }), + ); + } } - save() {} + save() { + console.log(this.form.value); + 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); + }, + }); + } cancel() { this.dialogRef.close(); @@ -145,7 +173,6 @@ export class IncidentComponent { .pipe( tap((inc) => { if (inc.calls) { - console.log(inc.calls); this.callsResult.data = inc.calls; } }), @@ -155,7 +182,10 @@ export class IncidentComponent { editIncident(incID: string) { const dialogRef = this.dialog.open(IncidentEditDialogComponent, { - data: incID, + data: { + incID: incID, + new: false, + }, }); dialogRef.afterClosed().subscribe((res) => {