Added Dynamic value to alarm schedule
This commit is contained in:
parent
8f485010f0
commit
6875df9dab
@ -73,8 +73,44 @@
|
||||
</div>
|
||||
</section>
|
||||
<section *ngIf="alarmScheduleForm.get('type').value === alarmScheduleType.CUSTOM">
|
||||
<div class="tb-small" style="margin-bottom: 0.5em" translate>device-profile.schedule-days</div>
|
||||
|
||||
<mat-expansion-panel class="device-profile-alarm" fxFlex>
|
||||
<mat-expansion-panel-header>
|
||||
<div fxFlex fxLayout="row" fxLayoutAlign="start center">
|
||||
<mat-panel-title>
|
||||
<div fxLayout="row" fxFlex fxLayoutAlign="start center">
|
||||
{{'filter.dynamic-value' | translate}}
|
||||
</div>
|
||||
</mat-panel-title>
|
||||
<span fxFlex></span>
|
||||
</div>
|
||||
</mat-expansion-panel-header>
|
||||
<ng-template matExpansionPanelContent>
|
||||
<div fxFlex [formGroup] = "alarmScheduleForm.get('dynamicValue')" fxLayout="column">
|
||||
<div fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="8px">
|
||||
<div fxFlex="40" fxLayout="column">
|
||||
<mat-form-field floatLabel="always" hideRequiredMarker class="mat-block">
|
||||
<mat-label></mat-label>
|
||||
<mat-select formControlName="sourceType" placeholder="{{'filter.dynamic-source-type' | translate}}">
|
||||
<mat-option [value]="null">
|
||||
{{'filter.no-dynamic-value' | translate}}
|
||||
</mat-option>
|
||||
<mat-option *ngFor="let sourceType of dynamicValueSourceTypes" [value]="sourceType">
|
||||
{{dynamicValueSourceTypeTranslations.get(sourceType) | translate}}
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
<div fxFlex fxLayout="column">
|
||||
<mat-form-field floatLabel="always" hideRequiredMarker class="mat-block source-attribute">
|
||||
<mat-label></mat-label>
|
||||
<input matInput formControlName="sourceAttribute" placeholder="{{'filter.source-attribute' | translate}}">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</ng-template>
|
||||
</mat-expansion-panel>
|
||||
<div class="tb-small" style="margin-bottom: 0.5em; margin-top: 26px;" translate>device-profile.schedule-days</div>
|
||||
<div *ngFor="let day of allDays" fxLayout="column" formArrayName="items" fxLayoutGap="1em">
|
||||
<div fxLayout.xs="column" fxLayout="row" fxLayoutGap="8px" [formGroupName]="''+day" fxLayoutAlign="start center" fxLayoutAlign.xs="center start">
|
||||
<mat-checkbox formControlName="enabled" fxFlex="17" (change)="changeCustomScheduler($event, day)">
|
||||
|
||||
@ -40,6 +40,12 @@ import {
|
||||
import { isDefined, isDefinedAndNotNull } from '@core/utils';
|
||||
import { MatCheckboxChange } from '@angular/material/checkbox';
|
||||
import { getDefaultTimezone } from '@shared/models/time/time.models';
|
||||
import {
|
||||
DynamicValueSourceType,
|
||||
dynamicValueSourceTypeTranslationMap,
|
||||
getDynamicSourcesForAllowUser
|
||||
} from '@shared/models/query/query.models';
|
||||
import { emit } from 'cluster';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-alarm-schedule',
|
||||
@ -64,7 +70,8 @@ export class AlarmScheduleComponent implements ControlValueAccessor, Validator,
|
||||
alarmScheduleTypes = Object.keys(AlarmScheduleType);
|
||||
alarmScheduleType = AlarmScheduleType;
|
||||
alarmScheduleTypeTranslate = AlarmScheduleTypeTranslationMap;
|
||||
|
||||
dynamicValueSourceTypes: DynamicValueSourceType[] = getDynamicSourcesForAllowUser(false);
|
||||
dynamicValueSourceTypeTranslations = dynamicValueSourceTypeTranslationMap;
|
||||
dayOfWeekTranslationsArray = dayOfWeekTranslations;
|
||||
|
||||
allDays = Array(7).fill(0).map((x, i) => i);
|
||||
@ -91,8 +98,19 @@ export class AlarmScheduleComponent implements ControlValueAccessor, Validator,
|
||||
daysOfWeek: this.fb.array(new Array(7).fill(false), this.validateDayOfWeeks),
|
||||
startsOn: [0, Validators.required],
|
||||
endsOn: [0, Validators.required],
|
||||
items: this.fb.array(Array.from({length: 7}, (value, i) => this.defaultItemsScheduler(i)), this.validateItems)
|
||||
items: this.fb.array(Array.from({length: 7}, (value, i) => this.defaultItemsScheduler(i)), this.validateItems),
|
||||
dynamicValue: this.fb.group({
|
||||
sourceType: [null],
|
||||
sourceAttribute: [null]
|
||||
})
|
||||
});
|
||||
|
||||
this.alarmScheduleForm.get('dynamicValue.sourceType').valueChanges.subscribe((sourceType) => {
|
||||
if (!sourceType) {
|
||||
this.alarmScheduleForm.get('dynamicValue.sourceAttribute').patchValue('', {emitEvent:false});
|
||||
}
|
||||
})
|
||||
|
||||
this.alarmScheduleForm.get('type').valueChanges.subscribe((type) => {
|
||||
const defaultTimezone = getDefaultTimezone();
|
||||
this.alarmScheduleForm.reset({type, items: this.defaultItems, timezone: defaultTimezone}, {emitEvent: false});
|
||||
@ -177,7 +195,11 @@ export class AlarmScheduleComponent implements ControlValueAccessor, Validator,
|
||||
this.alarmScheduleForm.patchValue({
|
||||
type: this.modelValue.type,
|
||||
timezone: this.modelValue.timezone,
|
||||
items: alarmDays
|
||||
items: alarmDays,
|
||||
dynamicValue: {
|
||||
sourceAttribute: this.modelValue.dynamicValue.sourceAttribute,
|
||||
sourceType: this.modelValue.dynamicValue.sourceType
|
||||
}
|
||||
}, {emitEvent: false});
|
||||
}
|
||||
break;
|
||||
|
||||
@ -477,6 +477,10 @@ export const AlarmScheduleTypeTranslationMap = new Map<AlarmScheduleType, string
|
||||
);
|
||||
|
||||
export interface AlarmSchedule{
|
||||
dynamicValue?: {
|
||||
sourceAttribute: string,
|
||||
sourceType: string;
|
||||
};
|
||||
type: AlarmScheduleType;
|
||||
timezone?: string;
|
||||
daysOfWeek?: number[];
|
||||
|
||||
@ -2129,6 +2129,7 @@
|
||||
"current-device": "Current device",
|
||||
"default-value": "Default value",
|
||||
"dynamic-source-type": "Dynamic source type",
|
||||
"dynamic-value": "Dynamic value",
|
||||
"no-dynamic-value": "No dynamic value",
|
||||
"source-attribute": "Source attribute",
|
||||
"switch-to-dynamic-value": "Switch to dynamic value",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user