import works, needs error reporting

This commit is contained in:
Daniel 2024-11-20 11:43:07 -05:00
parent f5ffd54bdf
commit 54544200bc
5 changed files with 45 additions and 11 deletions

View file

@ -44,13 +44,16 @@ export interface Talkgroup {
metadata: Metadata|null;
tags: string[];
alert: boolean;
system?: System;
alert_config: AlertRule[];
system: System;
weight: number;
learned?: boolean;
selected?: boolean;
}
export interface TalkgroupUI extends Talkgroup {
selected?: boolean;
};
export interface TalkgroupUpdate {
id: number;
system_id: number;

View file

@ -9,14 +9,14 @@
></textarea>
<input type="number" class="input input-bordered" formControlName="systemID" id="systemID" />
<input type="submit" class="btn btn-primary" value="Preview" />
<button class="btn btn-secondary" (click)="save()">Save</button>
</form>
<button class="btn btn-secondary" (click)="save()">Save</button>
</div>
<div class="w-100 justify-center overflow-x-auto">
<table class="table">
<thead>
<tr>
<th><input type="checkbox" class="checkbox" [(ngModel)]="selectAll" name="selectAll" /></th>
<th><input type="checkbox" class="checkbox" [checked]="isAllSelected()" (change)="selectAllTGs($event)" [(ngModel)]="selectAll" name="selectAll" /></th>
<th>Sys</th>
<th>Sys ID</th>
<th>Group</th>
@ -31,8 +31,8 @@
<tr>
<td><input type="checkbox" class="checkbox" [(ngModel)]="tg.selected" value="{{tg.name}}" (change)="isAllSelected()">
</td>
<td>{{ tg.system.name }}</td>
<td>{{ tg.system.id }}</td>
<td>{{ tg.system?.name }}</td>
<td>{{ tg.system?.id }}</td>
<td>{{ tg.tg_group }}</td>
<td>{{ tg.alpha_tag }}</td>
<td>{{ tg.name }}</td>

View file

@ -1,6 +1,6 @@
import { Component, inject } from '@angular/core';
import { TalkgroupService } from '../talkgroups.service';
import { Talkgroup } from '../../talkgroup';
import { Talkgroup, TalkgroupUI, TalkgroupUpdate } from '../../talkgroup';
import { FormGroup, FormControl, ReactiveFormsModule, FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
import { Router, ActivatedRoute } from '@angular/router';
@ -16,7 +16,7 @@ import { catchError, of } from 'rxjs';
export class ImportComponent {
tgService: TalkgroupService = inject(TalkgroupService);
form!: FormGroup;
tgs!: Talkgroup[];
tgs!: TalkgroupUI[];
selectAll: boolean = false;
constructor(
@ -46,8 +46,32 @@ export class ImportComponent {
}
isAllSelected() {
return this.tgs.every(_ => _.selected);
}
selectAllTGs(ev: any) {
this.tgs.forEach(x => x.selected = ev.target.checked);
}
save() {
let toImport: TalkgroupUpdate[] = [];
let sysID = Number(this.form.controls['systemID'].value);
this.tgs.forEach((x) => {
if(x.selected) {
let ct: TalkgroupUpdate = x;
toImport.push(ct);
}
});
this.tgService.putTalkgroups(sysID, toImport).
pipe(
catchError(() => {
return of(null);
}),
)
.subscribe((event) => {
this.tgs = event!;
});
}
}

View file

@ -14,13 +14,13 @@
<tbody>
@for (tg of talkgroups$ | async; track tg.id) {
<tr>
<td>{{ tg.system.name }}</td>
<td>{{ tg.system.id }}</td>
<td>{{ tg.system?.name }}</td>
<td>{{ tg.system?.id }}</td>
<td>{{ tg.name }}</td>
<td>{{ tg.tgid }}</td>
<td>{{ tg?.learned ? 'Y' : '' }}</td>
<td>
<a routerLink="/talkgroups/{{ tg.system.id }}/{{ tg.tgid }}"
<a routerLink="/talkgroups/{{ tg.system?.id }}/{{ tg.tgid }}"
><ng-icon name="ionCreateOutline"></ng-icon
></a>
</td>

View file

@ -29,4 +29,11 @@ export class TalkgroupService {
tu,
);
}
putTalkgroups(sysID: Number, tgs: TalkgroupUpdate[]): Observable<Talkgroup[]> {
return this.http.put<Talkgroup[]>(
`/api/talkgroup/${sysID}`,
tgs,
);
}
}