Merge pull request #3733 from vvlladd28/improvement/device-profile/alarm-type/validation
UI: Added unique alarm type validation in alarm rule
This commit is contained in:
commit
566f24f429
@ -41,6 +41,9 @@
|
||||
<mat-error *ngIf="alarmFormGroup.get('alarmType').hasError('required')">
|
||||
{{ 'device-profile.alarm-type-required' | translate }}
|
||||
</mat-error>
|
||||
<mat-error *ngIf="alarmFormGroup.get('alarmType').hasError('unique')">
|
||||
{{ 'device-profile.alarm-type-unique' | translate }}
|
||||
</mat-error>
|
||||
<mat-hint *ngIf="!disabled"
|
||||
innerHTML="{{ 'device-profile.alarm-type-pattern-hint' | translate }}"></mat-hint>
|
||||
</mat-form-field>
|
||||
|
||||
@ -133,6 +133,19 @@ export class DeviceProfileAlarmComponent implements ControlValueAccessor, OnInit
|
||||
}
|
||||
|
||||
public validate(c: FormControl) {
|
||||
if (c.parent) {
|
||||
const alarmType = c.value.alarmType;
|
||||
const profileAlarmsType = [];
|
||||
c.parent.getRawValue().forEach((alarm: DeviceProfileAlarm) => {
|
||||
profileAlarmsType.push(alarm.alarmType);
|
||||
}
|
||||
);
|
||||
if (profileAlarmsType.filter(profileAlarmType => profileAlarmType === alarmType).length > 1) {
|
||||
this.alarmFormGroup.get('alarmType').setErrors({
|
||||
unique: true
|
||||
});
|
||||
}
|
||||
}
|
||||
return (this.alarmFormGroup.valid) ? null : {
|
||||
alarm: {
|
||||
valid: false,
|
||||
|
||||
@ -38,7 +38,7 @@ import {
|
||||
} from '@shared/models/device.models';
|
||||
import { EntityType } from '@shared/models/entity-type.models';
|
||||
import { RuleChainId } from '@shared/models/id/rule-chain-id';
|
||||
import {ServiceType} from "@shared/models/queue.models";
|
||||
import { ServiceType } from '@shared/models/queue.models';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-device-profile',
|
||||
@ -176,10 +176,10 @@ export class DeviceProfileComponent extends EntityComponent<DeviceProfile> {
|
||||
transportConfiguration: entity.profileData?.transportConfiguration,
|
||||
alarms: entity.profileData?.alarms,
|
||||
provisionConfiguration: deviceProvisionConfiguration
|
||||
}});
|
||||
this.entityForm.patchValue({defaultRuleChainId: entity.defaultRuleChainId ? entity.defaultRuleChainId.id : null});
|
||||
this.entityForm.patchValue({defaultQueueName: entity.defaultQueueName});
|
||||
this.entityForm.patchValue({description: entity.description});
|
||||
}}, {emitEvent: false});
|
||||
this.entityForm.patchValue({defaultRuleChainId: entity.defaultRuleChainId ? entity.defaultRuleChainId.id : null}, {emitEvent: false});
|
||||
this.entityForm.patchValue({defaultQueueName: entity.defaultQueueName}, {emitEvent: false});
|
||||
this.entityForm.patchValue({description: entity.description}, {emitEvent: false});
|
||||
}
|
||||
|
||||
prepareFormValue(formValue: any): any {
|
||||
|
||||
@ -909,6 +909,7 @@
|
||||
"edit-alarm-rule": "Edit alarm rule",
|
||||
"alarm-type": "Alarm type",
|
||||
"alarm-type-required": "Alarm type is required.",
|
||||
"alarm-type-unique": "Alarm type must be unique within the device profile alarm rules.",
|
||||
"alarm-type-pattern-hint": "Alarm type pattern, use <code>${metaKeyName}</code> to substitute variables from metadata",
|
||||
"create-alarm-pattern": "Create <b>{{alarmType}}</b> alarm",
|
||||
"create-alarm-rules": "Create alarm rules",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user