Dialog WIP

This commit is contained in:
Daniel Ponte 2024-12-31 12:39:27 -05:00
parent 9d3c285947
commit 4db1cf3ce7
5 changed files with 62 additions and 26 deletions

View file

@ -43,14 +43,6 @@ export const routes: Routes = [
), ),
data: { title: 'Export Talkgroups' }, 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', path: 'calls',
loadComponent: () => loadComponent: () =>

View file

@ -1,5 +1,7 @@
<h2 mat-dialog-title>Edit {{tgid.sys}}:{{tgid.tg}}</h2>
<mat-dialog-content>
<div class="tgRecord"> <div class="tgRecord">
<form *ngIf="tg" [formGroup]="form" (ngSubmit)="submit()"> <form *ngIf="tg" [formGroup]="form" (ngSubmit)="save()">
<div> <div>
<mat-form-field> <mat-form-field>
<mat-label>Name</mat-label> <mat-label>Name</mat-label>
@ -99,6 +101,10 @@
<div class="alert"> <div class="alert">
<alert-rule-builder [rules]="tg.alert_config" /> <alert-rule-builder [rules]="tg.alert_config" />
</div> </div>
<button class="sbButton" type="submit">Save</button>
</form> </form>
</div> </div>
</mat-dialog-content>
<mat-dialog-actions>
<button class="sbButton" type="button" (click)="cancel()">Cancel</button>
<button class="sbButton" [mat-dialog-close]="save()" cdk-focus-initial>Save</button>
</mat-dialog-actions>

View file

@ -6,6 +6,7 @@ import {
TalkgroupUpdate, TalkgroupUpdate,
IconMap, IconMap,
iconMapping, iconMapping,
TGID,
} from '../../talkgroup'; } from '../../talkgroup';
import { COMMA, ENTER } from '@angular/cdk/keycodes'; import { COMMA, ENTER } from '@angular/cdk/keycodes';
import { TalkgroupService } from '../talkgroups.service'; import { TalkgroupService } from '../talkgroups.service';
@ -26,12 +27,20 @@ import {
FormControl, FormControl,
FormsModule, FormsModule,
} from '@angular/forms'; } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router';
import { MatInputModule } from '@angular/material/input'; import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field'; import { MatFormFieldModule } from '@angular/material/form-field';
import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatChipInputEvent, MatChipsModule } from '@angular/material/chips'; import { MatChipInputEvent, MatChipsModule } from '@angular/material/chips';
import { MatIconModule } from '@angular/material/icon'; import { MatIconModule } from '@angular/material/icon';
import {
MAT_DIALOG_DATA,
MatDialog,
MatDialogActions,
MatDialogClose,
MatDialogContent,
MatDialogRef,
MatDialogTitle,
} from '@angular/material/dialog';
@Component({ @Component({
selector: 'talkgroup-record', selector: 'talkgroup-record',
@ -46,11 +55,17 @@ import { MatIconModule } from '@angular/material/icon';
MatChipsModule, MatChipsModule,
MatIconModule, MatIconModule,
MatAutocompleteModule, MatAutocompleteModule,
MatDialogTitle,
MatDialogContent,
MatDialogActions,
MatDialogClose,
], ],
templateUrl: './talkgroup-record.component.html', templateUrl: './talkgroup-record.component.html',
styleUrl: './talkgroup-record.component.scss', styleUrl: './talkgroup-record.component.scss',
}) })
export class TalkgroupRecordComponent { export class TalkgroupRecordComponent {
dialogRef = inject(MatDialogRef<TalkgroupRecordComponent>);
tgid = inject<TGID>(MAT_DIALOG_DATA);
tg!: Talkgroup; tg!: Talkgroup;
iconMapping: IconMap = iconMapping; iconMapping: IconMap = iconMapping;
tgService: TalkgroupService = inject(TalkgroupService); tgService: TalkgroupService = inject(TalkgroupService);
@ -83,8 +98,6 @@ export class TalkgroupRecordComponent {
subscriptions = new Subscription(); subscriptions = new Subscription();
constructor( constructor(
private route: ActivatedRoute,
private router: Router,
) { ) {
this._allTags = this.tgService.allTags().pipe(shareReplay()); this._allTags = this.tgService.allTags().pipe(shareReplay());
} }
@ -138,12 +151,9 @@ export class TalkgroupRecordComponent {
} }
ngOnInit() { ngOnInit() {
const sysId = this.route.snapshot.paramMap.get('sys');
const tgId = this.route.snapshot.paramMap.get('tg');
this.subscriptions.add( this.subscriptions.add(
this.tgService this.tgService
.getTalkgroup(Number(sysId), Number(tgId)) .getTalkgroup(Number(this.tgid.sys), Number(this.tgid.tg))
.subscribe((data: Talkgroup) => { .subscribe((data: Talkgroup) => {
this.tg = data; this.tg = data;
this.form.controls['name'].setValue(this.tg.name); this.form.controls['name'].setValue(this.tg.name);
@ -168,7 +178,7 @@ export class TalkgroupRecordComponent {
this.subscriptions.unsubscribe(); this.subscriptions.unsubscribe();
} }
submit() { save() {
let tgu: TalkgroupUpdate = <TalkgroupUpdate>{ let tgu: TalkgroupUpdate = <TalkgroupUpdate>{
system_id: this.tg.system_id, system_id: this.tg.system_id,
tgid: this.tg.tgid, tgid: this.tg.tgid,
@ -208,15 +218,19 @@ export class TalkgroupRecordComponent {
}); });
} }
} }
this.tgService this.subscriptions.add(this.tgService
.putTalkgroup(tgu) .putTalkgroup(tgu)
.pipe( .pipe(
catchError(() => { catchError(() => {
return of(null); return of(null);
}), }),
) )
.subscribe((event) => { .subscribe((newTG) => {
this.router.navigate(['/talkgroups/']); this.dialogRef.close(newTG);
}); }));
}
cancel() {
this.dialogRef.close();
} }
} }

View file

@ -64,8 +64,8 @@
</ng-container> </ng-container>
<ng-container matColumnDef="edit"> <ng-container matColumnDef="edit">
<th mat-header-cell *matHeaderCellDef>Edit</th> <th mat-header-cell *matHeaderCellDef>Edit</th>
<td mat-cell *matCellDef="let tg"> <td mat-cell *matCellDef="let tg; let i = index">
<a routerLink="/talkgroups/{{ tg.system?.id }}/{{ tg.tgid }}" <a (click)="editTG(i, tg.system?.id, tg.tgid)"
><mat-icon>edit</mat-icon> ><mat-icon>edit</mat-icon>
</a> </a>
</td> </td>

View file

@ -10,7 +10,7 @@ import {
} from '@angular/core'; } from '@angular/core';
import { toObservable } from '@angular/core/rxjs-interop'; import { toObservable } from '@angular/core/rxjs-interop';
import { TalkgroupService, TalkgroupsPaginated } from '../talkgroups.service'; import { TalkgroupService, TalkgroupsPaginated } from '../talkgroups.service';
import { Talkgroup, iconMapping } from '../../talkgroup'; import { TGID, Talkgroup, iconMapping } from '../../talkgroup';
import { ActivatedRoute } from '@angular/router'; import { ActivatedRoute } from '@angular/router';
import { RouterModule, RouterLink } from '@angular/router'; import { RouterModule, RouterLink } from '@angular/router';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
@ -27,6 +27,16 @@ import { MatChipsModule } from '@angular/material/chips';
import { SelectionModel } from '@angular/cdk/collections'; import { SelectionModel } from '@angular/cdk/collections';
import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatCheckboxModule } from '@angular/material/checkbox';
import { Observable, Subscription } from 'rxjs'; 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({ @Pipe({
standalone: true, standalone: true,
@ -59,7 +69,6 @@ export class SanitizeHtmlPipe implements PipeTransform {
selector: 'talkgroup-table', selector: 'talkgroup-table',
imports: [ imports: [
RouterModule, RouterModule,
RouterLink,
MatIconModule, MatIconModule,
CommonModule, CommonModule,
IconifyPipe, IconifyPipe,
@ -104,6 +113,7 @@ export class TalkgroupTableComponent {
@Input() resetPage!: Observable<void>; @Input() resetPage!: Observable<void>;
@ViewChild('paginator') paginator!: MatPaginator; @ViewChild('paginator') paginator!: MatPaginator;
suppress = false; suppress = false;
dialog = inject(MatDialog);
constructor(private route: ActivatedRoute) {} constructor(private route: ActivatedRoute) {}
@ -156,4 +166,18 @@ export class TalkgroupTableComponent {
? this.selection.clear() ? this.selection.clear()
: this.dataSource.data.forEach((row) => this.selection.select(row)); : this.dataSource.data.forEach((row) => this.selection.select(row));
} }
editTG(idx: number, sys: number, tg: number) {
const tgid = <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;
}
});
}
} }