WIP: incident record

description is never being marked as dirty, needs fix
This commit is contained in:
Daniel Ponte 2025-01-05 14:36:37 -05:00
parent 2f8df69d1d
commit 56279f45b3
4 changed files with 49 additions and 10 deletions

View file

@ -83,6 +83,13 @@
<button class="sbButton" (click)="refresh()"> <button class="sbButton" (click)="refresh()">
<mat-icon>refresh</mat-icon> <mat-icon>refresh</mat-icon>
</button> </button>
<button [ngClass]="{ sbButton: true, hidden: !selection.hasValue() }" [matMenuTriggerFor]="callMenu">
<mat-icon>playlist_add</mat-icon>
</button>
<mat-menu #callMenu="matMenu">
<button mat-menu-item>Add to new incident...</button>
<button mat-menu-item>Add to existing incident...</button>
</mat-menu>
</div> </div>
</form> </form>
</div> </div>

View file

@ -30,6 +30,7 @@ import { debounceTime } from 'rxjs/operators';
import { ToolbarContextService } from '../navigation/toolbar-context.service'; import { ToolbarContextService } from '../navigation/toolbar-context.service';
import { MatSelectModule } from '@angular/material/select'; import { MatSelectModule } from '@angular/material/select';
import { CallPlayerComponent } from './player/call-player/call-player.component'; import { CallPlayerComponent } from './player/call-player/call-player.component';
import {MatMenuModule} from '@angular/material/menu';
@Pipe({ @Pipe({
name: 'grabDate', name: 'grabDate',
@ -141,6 +142,7 @@ const reqPageSize = 200;
MatProgressSpinnerModule, MatProgressSpinnerModule,
MatSelectModule, MatSelectModule,
CallPlayerComponent, CallPlayerComponent,
MatMenuModule,
], ],
templateUrl: './calls.component.html', templateUrl: './calls.component.html',
styleUrl: './calls.component.scss', styleUrl: './calls.component.scss',

View file

@ -1,4 +1,4 @@
<h2 mat-dialog-title>Edit Incident</h2> <h2 mat-dialog-title>{{ title }}</h2>
<mat-dialog-content> <mat-dialog-content>
<div class="incRecord"> <div class="incRecord">
@let inc = inc$ | async; @let inc = inc$ | async;

View file

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