Merge pull request 'Begin new alert rule builder' (#100) from alertRuleBuilder91 into trunk
Reviewed-on: #100
This commit is contained in:
commit
66dc6e4b78
12 changed files with 90 additions and 46 deletions
|
@ -169,7 +169,11 @@
|
|||
</td>
|
||||
</ng-container>
|
||||
<tr mat-header-row *matHeaderRowDef="columns; sticky: true"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: columns" [ngClass]="{'in-incident': row.incidents > 0}"></tr>
|
||||
<tr
|
||||
mat-row
|
||||
*matRowDef="let row; columns: columns"
|
||||
[ngClass]="{ 'in-incident': row.incidents > 0 }"
|
||||
></tr>
|
||||
</table>
|
||||
</div>
|
||||
<div class="pagFoot">
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
@let inc = inc$ | async;
|
||||
<mat-card class="incident" appearance="outlined">
|
||||
<div class="cardHdr">
|
||||
<h1>{{ inc?.name }}</h1>
|
||||
<h1>
|
||||
{{ inc?.name }}
|
||||
<a [href]="'/api/incident/' + incID + '.m3u'"
|
||||
><mat-icon>playlist_play</mat-icon></a
|
||||
>
|
||||
</h1>
|
||||
<button mat-icon-button (click)="editIncident(incID)">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
|
|
|
@ -15,12 +15,19 @@ export class AlertTime {
|
|||
}
|
||||
|
||||
export class AlertRule {
|
||||
times: AlertTime[];
|
||||
mult: number;
|
||||
times!: string[];
|
||||
mult!: number;
|
||||
|
||||
constructor(times: AlertTime[], mult: number) {
|
||||
this.times = times;
|
||||
this.mult = mult;
|
||||
public getTimes(): AlertTime[] {
|
||||
let timesProc = <AlertTime[]>[];
|
||||
this.times.forEach((tm) => {
|
||||
let sr = tm.split('+');
|
||||
timesProc.push(<AlertTime>{
|
||||
time: sr[0],
|
||||
duration: sr[1],
|
||||
});
|
||||
});
|
||||
return timesProc;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,6 +91,10 @@ export class Talkgroup {
|
|||
icon?: string,
|
||||
) {
|
||||
this.iconSvg = this.iconMap(this.metadata?.icon!);
|
||||
this.alert_rules = this.alert_rules.map((x) =>
|
||||
Object.assign(new AlertRule(), x),
|
||||
);
|
||||
console.log(this.alert_rules);
|
||||
}
|
||||
|
||||
iconMap(icon: string): string {
|
||||
|
|
|
@ -1,30 +1,21 @@
|
|||
<div class="container flex">
|
||||
@for (rule of rules; track $index) {
|
||||
<div class="">
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Start</td>
|
||||
<td>Duration</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (time of rule.times; track $index) {
|
||||
<tr>
|
||||
<td>
|
||||
{{ time.time }}
|
||||
</td>
|
||||
<td>
|
||||
{{ time.duration }}
|
||||
</td>
|
||||
</tr>
|
||||
} @empty {
|
||||
<tr>
|
||||
<td><em>No times</em></td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
<div class="rule">
|
||||
<table mat-table [dataSource]="rule | ruleTimes">
|
||||
<ng-container matColumnDef="time">
|
||||
<th mat-header-cell *matHeaderCellDef>Time</th>
|
||||
<td mat-cell *matCellDef="let time">{{ time.time }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="duration">
|
||||
<th mat-header-cell *matHeaderCellDef>Duration</th>
|
||||
<td mat-cell *matCellDef="let time">{{ time.duration }}</td>
|
||||
</ng-container>
|
||||
<ng-container matColumnDef="multiplier">
|
||||
<th mat-header-cell *matHeaderCellDef>Multiplier</th>
|
||||
<td mat-cell *matCellDef="let time">{{ rule.mult }}</td>
|
||||
</ng-container>
|
||||
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||
</table>
|
||||
</div>
|
||||
} @empty {
|
||||
|
|
|
@ -1,18 +1,43 @@
|
|||
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
||||
import { AlertRule } from '../../../talkgroup';
|
||||
import {
|
||||
Component,
|
||||
Input,
|
||||
Output,
|
||||
EventEmitter,
|
||||
Pipe,
|
||||
PipeTransform,
|
||||
} from '@angular/core';
|
||||
import { AlertRule, AlertTime } from '../../../talkgroup';
|
||||
import { MatTableModule } from '@angular/material/table';
|
||||
|
||||
@Pipe({
|
||||
name: 'ruleTimes',
|
||||
standalone: true,
|
||||
pure: true,
|
||||
})
|
||||
export class AlertRulePipe implements PipeTransform {
|
||||
transform(rule: AlertRule, args?: any): AlertTime[] {
|
||||
return rule.getTimes();
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'alert-rule-builder',
|
||||
imports: [],
|
||||
imports: [MatTableModule, AlertRulePipe],
|
||||
templateUrl: './alert-rule-builder.component.html',
|
||||
styleUrl: './alert-rule-builder.component.scss',
|
||||
})
|
||||
export class AlertRuleBuilderComponent {
|
||||
@Input() rules: AlertRule[] = [];
|
||||
@Input() rules!: AlertRule[];
|
||||
@Output() rulesChange: EventEmitter<AlertRule[]> = new EventEmitter<
|
||||
AlertRule[]
|
||||
>();
|
||||
|
||||
displayedColumns = ['time', 'duration', 'multiplier'];
|
||||
|
||||
ngOnInit() {
|
||||
this.rules = <AlertRule[]>this.rules;
|
||||
}
|
||||
|
||||
emit() {
|
||||
this.rulesChange.emit(this.rules);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
IconMap,
|
||||
iconMapping,
|
||||
TGID,
|
||||
AlertRule,
|
||||
} from '../../talkgroup';
|
||||
import { COMMA, ENTER } from '@angular/cdk/keycodes';
|
||||
import { TalkgroupService } from '../talkgroups.service';
|
||||
|
@ -157,6 +158,10 @@ export class TalkgroupRecordComponent {
|
|||
.getTalkgroup(Number(this.tgid.sys), Number(this.tgid.tg))
|
||||
.pipe(
|
||||
tap((tg) => {
|
||||
console.log('tap run');
|
||||
tg.alert_rules = tg.alert_rules
|
||||
? tg.alert_rules.map((x) => Object.assign(new AlertRule(), x))
|
||||
: [];
|
||||
this.form.patchValue(tg);
|
||||
this.form.controls['tagInput'].setValue('');
|
||||
this.form.controls['tagsControl'].setValue(this.tg?.tags ?? []);
|
||||
|
|
|
@ -33,7 +33,10 @@ export class TalkgroupService {
|
|||
private subscriptions = new Subscription();
|
||||
constructor(private http: HttpClient) {
|
||||
this.tgs$ = this.fetchAll.pipe(switchMap(() => this.getTalkgroups()));
|
||||
this.tags$ = this.fetchAll.pipe(switchMap(() => this.getAllTags()));
|
||||
this.tags$ = this.fetchAll.pipe(
|
||||
switchMap(() => this.getAllTags()),
|
||||
shareReplay(),
|
||||
);
|
||||
this.fillTgMap();
|
||||
}
|
||||
|
||||
|
@ -52,11 +55,8 @@ export class TalkgroupService {
|
|||
getTalkgroup(sys: number, tg: number): Observable<Talkgroup> {
|
||||
const key = this.tgKey(sys, tg);
|
||||
if (!this._getTalkgroup.get(key)) {
|
||||
return this.tgs$.pipe(
|
||||
switchMap((talkg) =>
|
||||
talkg.filter((tgv) => tgv.tgid == tg && tgv.system_id == sys),
|
||||
),
|
||||
);
|
||||
let rs = new ReplaySubject<Talkgroup>();
|
||||
this._getTalkgroup.set(key, rs);
|
||||
}
|
||||
return this._getTalkgroup.get(key)!;
|
||||
}
|
||||
|
|
|
@ -245,6 +245,7 @@ func (a *Auth) routeAuth(w http.ResponseWriter, r *http.Request) {
|
|||
Path: "/",
|
||||
HttpOnly: true,
|
||||
Secure: true,
|
||||
MaxAge: 60 * 60 * 24 * 30, // one month
|
||||
}
|
||||
|
||||
cookie.Domain = r.Host
|
||||
|
|
|
@ -180,6 +180,7 @@ FROM incidents_calls ic, LATERAL (
|
|||
FROM swept_calls sc WHERE sc.id = ic.swept_call_id
|
||||
) c
|
||||
WHERE ic.incident_id = $1
|
||||
ORDER BY ic.call_date ASC
|
||||
`
|
||||
|
||||
type GetIncidentCallsRow struct {
|
||||
|
|
|
@ -202,7 +202,7 @@ func (ia *incidentsAPI) getCallsM3U(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
b := new(bytes.Buffer)
|
||||
|
||||
callUrl := common.PtrTo(*ia.baseURL)
|
||||
|
||||
|
@ -220,7 +220,7 @@ func (ia *incidentsAPI) getCallsM3U(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
callUrl.Path = "/api/call/" + c.ID.String()
|
||||
|
||||
fmt.Fprintf(w, "#EXTINF:%d,%s%s (%s)\n%s\n\n",
|
||||
fmt.Fprintf(b, "#EXTINF:%d,%s%s (%s)\n%s\n\n",
|
||||
c.Duration.Seconds(),
|
||||
tg.StringTag(true),
|
||||
from,
|
||||
|
|
|
@ -141,7 +141,8 @@ FROM incidents_calls ic, LATERAL (
|
|||
sc.transcript
|
||||
FROM swept_calls sc WHERE sc.id = ic.swept_call_id
|
||||
) c
|
||||
WHERE ic.incident_id = @id;
|
||||
WHERE ic.incident_id = @id
|
||||
ORDER BY ic.call_date ASC;
|
||||
|
||||
-- name: GetIncident :one
|
||||
SELECT
|
||||
|
|
Loading…
Reference in a new issue