Mat table alert rule builder wip
This commit is contained in:
parent
ce9f466410
commit
7e667d81ab
6 changed files with 48 additions and 41 deletions
|
@ -169,7 +169,11 @@
|
||||||
</td>
|
</td>
|
||||||
</ng-container>
|
</ng-container>
|
||||||
<tr mat-header-row *matHeaderRowDef="columns; sticky: true"></tr>
|
<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>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="pagFoot">
|
<div class="pagFoot">
|
||||||
|
|
|
@ -15,21 +15,19 @@ export class AlertTime {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AlertRule {
|
export class AlertRule {
|
||||||
times: string[];
|
times!: string[];
|
||||||
timesProc: AlertTime[];
|
mult!: number;
|
||||||
mult: number;
|
|
||||||
|
|
||||||
constructor(times: string[], mult: number) {
|
public getTimes(): AlertTime[] {
|
||||||
this.times = times;
|
let timesProc = <AlertTime[]>[];
|
||||||
this.timesProc = <AlertTime[]>[];
|
this.times.forEach((tm) => {
|
||||||
times.forEach((tm) => {
|
|
||||||
let sr = tm.split('+');
|
let sr = tm.split('+');
|
||||||
this.timesProc.push(<AlertTime>{
|
timesProc.push(<AlertTime>{
|
||||||
time: sr[0],
|
time: sr[0],
|
||||||
duration: sr[1],
|
duration: sr[1],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
this.mult = mult;
|
return timesProc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,6 +91,10 @@ export class Talkgroup {
|
||||||
icon?: string,
|
icon?: string,
|
||||||
) {
|
) {
|
||||||
this.iconSvg = this.iconMap(this.metadata?.icon!);
|
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 {
|
iconMap(icon: string): string {
|
||||||
|
|
|
@ -1,30 +1,21 @@
|
||||||
<div class="container flex">
|
<div class="container flex">
|
||||||
@for (rule of rules; track $index) {
|
@for (rule of rules; track $index) {
|
||||||
<div class="">
|
<div class="rule">
|
||||||
<table class="table">
|
<table mat-table [dataSource]="rule | ruleTimes">
|
||||||
<thead>
|
<ng-container matColumnDef="time">
|
||||||
<tr>
|
<th mat-header-cell *matHeaderCellDef>Time</th>
|
||||||
<td>Start</td>
|
<td mat-cell *matCellDef="let time">{{ time.time }}</td>
|
||||||
<td>Duration</td>
|
</ng-container>
|
||||||
<td></td>
|
<ng-container matColumnDef="duration">
|
||||||
</tr>
|
<th mat-header-cell *matHeaderCellDef>Duration</th>
|
||||||
</thead>
|
<td mat-cell *matCellDef="let time">{{ time.duration }}</td>
|
||||||
<tbody>
|
</ng-container>
|
||||||
@for (time of rule | ruleProc; track $index) {
|
<ng-container matColumnDef="multiplier">
|
||||||
<tr>
|
<th mat-header-cell *matHeaderCellDef>Multiplier</th>
|
||||||
<td>
|
<td mat-cell *matCellDef="let time">{{ rule.mult }}</td>
|
||||||
{{ time.time }}
|
</ng-container>
|
||||||
</td>
|
<tr mat-header-row *matHeaderRowDef="displayedColumns"></tr>
|
||||||
<td>
|
<tr mat-row *matRowDef="let row; columns: displayedColumns"></tr>
|
||||||
{{ time.duration }}
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
} @empty {
|
|
||||||
<tr>
|
|
||||||
<td><em>No times</em></td>
|
|
||||||
</tr>
|
|
||||||
}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
} @empty {
|
} @empty {
|
||||||
|
|
|
@ -7,31 +7,37 @@ import {
|
||||||
PipeTransform,
|
PipeTransform,
|
||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { AlertRule, AlertTime } from '../../../talkgroup';
|
import { AlertRule, AlertTime } from '../../../talkgroup';
|
||||||
|
import { MatTableModule } from '@angular/material/table';
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'ruleProc',
|
name: 'ruleTimes',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
pure: true,
|
pure: true,
|
||||||
})
|
})
|
||||||
export class AlertRulePipe implements PipeTransform {
|
export class AlertRulePipe implements PipeTransform {
|
||||||
transform(rule: AlertRule, args?: any): AlertTime[] {
|
transform(rule: AlertRule, args?: any): AlertTime[] {
|
||||||
let tm = new AlertRule(rule.times, rule.mult);
|
return rule.getTimes();
|
||||||
return tm.timesProc;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'alert-rule-builder',
|
selector: 'alert-rule-builder',
|
||||||
imports: [AlertRulePipe],
|
imports: [MatTableModule, AlertRulePipe],
|
||||||
templateUrl: './alert-rule-builder.component.html',
|
templateUrl: './alert-rule-builder.component.html',
|
||||||
styleUrl: './alert-rule-builder.component.scss',
|
styleUrl: './alert-rule-builder.component.scss',
|
||||||
})
|
})
|
||||||
export class AlertRuleBuilderComponent {
|
export class AlertRuleBuilderComponent {
|
||||||
@Input() rules: AlertRule[] = [];
|
@Input() rules!: AlertRule[];
|
||||||
@Output() rulesChange: EventEmitter<AlertRule[]> = new EventEmitter<
|
@Output() rulesChange: EventEmitter<AlertRule[]> = new EventEmitter<
|
||||||
AlertRule[]
|
AlertRule[]
|
||||||
>();
|
>();
|
||||||
|
|
||||||
|
displayedColumns = ['time', 'duration', 'multiplier'];
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.rules = <AlertRule[]>this.rules;
|
||||||
|
}
|
||||||
|
|
||||||
emit() {
|
emit() {
|
||||||
this.rulesChange.emit(this.rules);
|
this.rulesChange.emit(this.rules);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
IconMap,
|
IconMap,
|
||||||
iconMapping,
|
iconMapping,
|
||||||
TGID,
|
TGID,
|
||||||
|
AlertRule,
|
||||||
} 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';
|
||||||
|
@ -157,6 +158,9 @@ export class TalkgroupRecordComponent {
|
||||||
.getTalkgroup(Number(this.tgid.sys), Number(this.tgid.tg))
|
.getTalkgroup(Number(this.tgid.sys), Number(this.tgid.tg))
|
||||||
.pipe(
|
.pipe(
|
||||||
tap((tg) => {
|
tap((tg) => {
|
||||||
|
tg.alert_rules = tg.alert_rules.map((x) =>
|
||||||
|
Object.assign(new AlertRule(), x),
|
||||||
|
);
|
||||||
this.form.patchValue(tg);
|
this.form.patchValue(tg);
|
||||||
this.form.controls['tagInput'].setValue('');
|
this.form.controls['tagInput'].setValue('');
|
||||||
this.form.controls['tagsControl'].setValue(this.tg?.tags ?? []);
|
this.form.controls['tagsControl'].setValue(this.tg?.tags ?? []);
|
||||||
|
|
Loading…
Reference in a new issue