From 4db1cf3ce70525db224bfba909e146ae0e67f63e Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Tue, 31 Dec 2024 12:39:27 -0500 Subject: [PATCH] Dialog WIP --- client/stillbox/src/app/app.routes.ts | 8 ---- .../talkgroup-record.component.html | 10 ++++- .../talkgroup-record.component.ts | 38 +++++++++++++------ .../talkgroup-table.component.html | 4 +- .../talkgroup-table.component.ts | 28 +++++++++++++- 5 files changed, 62 insertions(+), 26 deletions(-) diff --git a/client/stillbox/src/app/app.routes.ts b/client/stillbox/src/app/app.routes.ts index 6bd9e8d..9898a2e 100644 --- a/client/stillbox/src/app/app.routes.ts +++ b/client/stillbox/src/app/app.routes.ts @@ -43,14 +43,6 @@ export const routes: Routes = [ ), data: { title: 'Export Talkgroups' }, }, - { - path: 'talkgroups/:sys/:tg', - loadComponent: () => - import( - './talkgroups/talkgroup-record/talkgroup-record.component' - ).then((m) => m.TalkgroupRecordComponent), - data: { title: 'Edit Talkgroup' }, - }, { path: 'calls', loadComponent: () => diff --git a/client/stillbox/src/app/talkgroups/talkgroup-record/talkgroup-record.component.html b/client/stillbox/src/app/talkgroups/talkgroup-record/talkgroup-record.component.html index ba66d42..b919226 100644 --- a/client/stillbox/src/app/talkgroups/talkgroup-record/talkgroup-record.component.html +++ b/client/stillbox/src/app/talkgroups/talkgroup-record/talkgroup-record.component.html @@ -1,5 +1,7 @@ +

Edit {{tgid.sys}}:{{tgid.tg}}

+
-
+
Name @@ -99,6 +101,10 @@
-
+ + + + + \ No newline at end of file diff --git a/client/stillbox/src/app/talkgroups/talkgroup-record/talkgroup-record.component.ts b/client/stillbox/src/app/talkgroups/talkgroup-record/talkgroup-record.component.ts index 3469bd0..b591f7d 100644 --- a/client/stillbox/src/app/talkgroups/talkgroup-record/talkgroup-record.component.ts +++ b/client/stillbox/src/app/talkgroups/talkgroup-record/talkgroup-record.component.ts @@ -6,6 +6,7 @@ import { TalkgroupUpdate, IconMap, iconMapping, + TGID, } from '../../talkgroup'; import { COMMA, ENTER } from '@angular/cdk/keycodes'; import { TalkgroupService } from '../talkgroups.service'; @@ -26,12 +27,20 @@ import { FormControl, FormsModule, } from '@angular/forms'; -import { Router, ActivatedRoute } from '@angular/router'; import { MatInputModule } from '@angular/material/input'; import { MatFormFieldModule } from '@angular/material/form-field'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatChipInputEvent, MatChipsModule } from '@angular/material/chips'; import { MatIconModule } from '@angular/material/icon'; +import { + MAT_DIALOG_DATA, + MatDialog, + MatDialogActions, + MatDialogClose, + MatDialogContent, + MatDialogRef, + MatDialogTitle, +} from '@angular/material/dialog'; @Component({ selector: 'talkgroup-record', @@ -46,11 +55,17 @@ import { MatIconModule } from '@angular/material/icon'; MatChipsModule, MatIconModule, MatAutocompleteModule, + MatDialogTitle, + MatDialogContent, + MatDialogActions, + MatDialogClose, ], templateUrl: './talkgroup-record.component.html', styleUrl: './talkgroup-record.component.scss', }) export class TalkgroupRecordComponent { + dialogRef = inject(MatDialogRef); + tgid = inject(MAT_DIALOG_DATA); tg!: Talkgroup; iconMapping: IconMap = iconMapping; tgService: TalkgroupService = inject(TalkgroupService); @@ -83,8 +98,6 @@ export class TalkgroupRecordComponent { subscriptions = new Subscription(); constructor( - private route: ActivatedRoute, - private router: Router, ) { this._allTags = this.tgService.allTags().pipe(shareReplay()); } @@ -138,12 +151,9 @@ export class TalkgroupRecordComponent { } ngOnInit() { - const sysId = this.route.snapshot.paramMap.get('sys'); - const tgId = this.route.snapshot.paramMap.get('tg'); - this.subscriptions.add( this.tgService - .getTalkgroup(Number(sysId), Number(tgId)) + .getTalkgroup(Number(this.tgid.sys), Number(this.tgid.tg)) .subscribe((data: Talkgroup) => { this.tg = data; this.form.controls['name'].setValue(this.tg.name); @@ -168,7 +178,7 @@ export class TalkgroupRecordComponent { this.subscriptions.unsubscribe(); } - submit() { + save() { let tgu: TalkgroupUpdate = { system_id: this.tg.system_id, tgid: this.tg.tgid, @@ -208,15 +218,19 @@ export class TalkgroupRecordComponent { }); } } - this.tgService + this.subscriptions.add(this.tgService .putTalkgroup(tgu) .pipe( catchError(() => { return of(null); }), ) - .subscribe((event) => { - this.router.navigate(['/talkgroups/']); - }); + .subscribe((newTG) => { + this.dialogRef.close(newTG); + })); + } + + cancel() { + this.dialogRef.close(); } } diff --git a/client/stillbox/src/app/talkgroups/talkgroup-table/talkgroup-table.component.html b/client/stillbox/src/app/talkgroups/talkgroup-table/talkgroup-table.component.html index 505dcf0..780f1b3 100644 --- a/client/stillbox/src/app/talkgroups/talkgroup-table/talkgroup-table.component.html +++ b/client/stillbox/src/app/talkgroups/talkgroup-table/talkgroup-table.component.html @@ -64,8 +64,8 @@ Edit - - + edit diff --git a/client/stillbox/src/app/talkgroups/talkgroup-table/talkgroup-table.component.ts b/client/stillbox/src/app/talkgroups/talkgroup-table/talkgroup-table.component.ts index d95f529..4463081 100644 --- a/client/stillbox/src/app/talkgroups/talkgroup-table/talkgroup-table.component.ts +++ b/client/stillbox/src/app/talkgroups/talkgroup-table/talkgroup-table.component.ts @@ -10,7 +10,7 @@ import { } from '@angular/core'; import { toObservable } from '@angular/core/rxjs-interop'; import { TalkgroupService, TalkgroupsPaginated } from '../talkgroups.service'; -import { Talkgroup, iconMapping } from '../../talkgroup'; +import { TGID, Talkgroup, iconMapping } from '../../talkgroup'; import { ActivatedRoute } from '@angular/router'; import { RouterModule, RouterLink } from '@angular/router'; import { CommonModule } from '@angular/common'; @@ -27,6 +27,16 @@ import { MatChipsModule } from '@angular/material/chips'; import { SelectionModel } from '@angular/cdk/collections'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { Observable, Subscription } from 'rxjs'; +import { + MAT_DIALOG_DATA, + MatDialog, + MatDialogActions, + MatDialogClose, + MatDialogContent, + MatDialogRef, + MatDialogTitle, +} from '@angular/material/dialog'; +import { TalkgroupRecordComponent } from '../talkgroup-record/talkgroup-record.component'; @Pipe({ standalone: true, @@ -59,7 +69,6 @@ export class SanitizeHtmlPipe implements PipeTransform { selector: 'talkgroup-table', imports: [ RouterModule, - RouterLink, MatIconModule, CommonModule, IconifyPipe, @@ -104,6 +113,7 @@ export class TalkgroupTableComponent { @Input() resetPage!: Observable; @ViewChild('paginator') paginator!: MatPaginator; suppress = false; + dialog = inject(MatDialog); constructor(private route: ActivatedRoute) {} @@ -156,4 +166,18 @@ export class TalkgroupTableComponent { ? this.selection.clear() : this.dataSource.data.forEach((row) => this.selection.select(row)); } + + editTG(idx: number, sys: number, tg: number) { + const tgid = {sys: sys, tg: tg}; + const dialogRef = this.dialog.open(TalkgroupRecordComponent, { + data: tgid, + }); + + dialogRef.afterClosed().subscribe((res) => + { + if (res !== undefined) { + this.dataSource.data[idx] = res; + } + }); + } }