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; metadata: Metadata|null;
tags: string[]; tags: string[];
alert: boolean; alert: boolean;
system?: System;
alert_config: AlertRule[]; alert_config: AlertRule[];
system: System;
weight: number; weight: number;
learned?: boolean; learned?: boolean;
selected?: boolean;
} }
export interface TalkgroupUI extends Talkgroup {
selected?: boolean;
};
export interface TalkgroupUpdate { export interface TalkgroupUpdate {
id: number; id: number;
system_id: number; system_id: number;

View file

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

View file

@ -1,6 +1,6 @@
import { Component, inject } from '@angular/core'; import { Component, inject } from '@angular/core';
import { TalkgroupService } from '../talkgroups.service'; import { TalkgroupService } from '../talkgroups.service';
import { Talkgroup } from '../../talkgroup'; import { Talkgroup, TalkgroupUI, TalkgroupUpdate } from '../../talkgroup';
import { FormGroup, FormControl, ReactiveFormsModule, FormsModule } from '@angular/forms'; import { FormGroup, FormControl, ReactiveFormsModule, FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
@ -16,7 +16,7 @@ import { catchError, of } from 'rxjs';
export class ImportComponent { export class ImportComponent {
tgService: TalkgroupService = inject(TalkgroupService); tgService: TalkgroupService = inject(TalkgroupService);
form!: FormGroup; form!: FormGroup;
tgs!: Talkgroup[]; tgs!: TalkgroupUI[];
selectAll: boolean = false; selectAll: boolean = false;
constructor( constructor(
@ -46,8 +46,32 @@ export class ImportComponent {
} }
isAllSelected() { isAllSelected() {
return this.tgs.every(_ => _.selected);
}
selectAllTGs(ev: any) {
this.tgs.forEach(x => x.selected = ev.target.checked);
} }
save() { 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> <tbody>
@for (tg of talkgroups$ | async; track tg.id) { @for (tg of talkgroups$ | async; track tg.id) {
<tr> <tr>
<td>{{ tg.system.name }}</td> <td>{{ tg.system?.name }}</td>
<td>{{ tg.system.id }}</td> <td>{{ tg.system?.id }}</td>
<td>{{ tg.name }}</td> <td>{{ tg.name }}</td>
<td>{{ tg.tgid }}</td> <td>{{ tg.tgid }}</td>
<td>{{ tg?.learned ? 'Y' : '' }}</td> <td>{{ tg?.learned ? 'Y' : '' }}</td>
<td> <td>
<a routerLink="/talkgroups/{{ tg.system.id }}/{{ tg.tgid }}" <a routerLink="/talkgroups/{{ tg.system?.id }}/{{ tg.tgid }}"
><ng-icon name="ionCreateOutline"></ng-icon ><ng-icon name="ionCreateOutline"></ng-icon
></a> ></a>
</td> </td>

View file

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