|
|
|
@ -15,39 +15,42 @@ |
|
|
|
///
|
|
|
|
|
|
|
|
import { Component, forwardRef, Input, OnInit } from '@angular/core'; |
|
|
|
import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; |
|
|
|
import { |
|
|
|
ControlValueAccessor, |
|
|
|
NG_VALIDATORS, |
|
|
|
NG_VALUE_ACCESSOR, |
|
|
|
UntypedFormBuilder, |
|
|
|
UntypedFormControl, |
|
|
|
UntypedFormGroup, |
|
|
|
ValidationErrors, |
|
|
|
Validator, |
|
|
|
Validators |
|
|
|
} from '@angular/forms'; |
|
|
|
import { Store } from '@ngrx/store'; |
|
|
|
import { AppState } from '@app/core/core.state'; |
|
|
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|
|
|
import { |
|
|
|
DefaultDeviceProfileTransportConfiguration, |
|
|
|
DeviceProfileTransportConfiguration, |
|
|
|
DeviceTransportType |
|
|
|
} from '@shared/models/device.models'; |
|
|
|
import { DefaultDeviceProfileTransportConfiguration, DeviceTransportType } from '@shared/models/device.models'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-default-device-profile-transport-configuration', |
|
|
|
templateUrl: './default-device-profile-transport-configuration.component.html', |
|
|
|
styleUrls: [], |
|
|
|
providers: [{ |
|
|
|
provide: NG_VALUE_ACCESSOR, |
|
|
|
useExisting: forwardRef(() => DefaultDeviceProfileTransportConfigurationComponent), |
|
|
|
multi: true |
|
|
|
}] |
|
|
|
providers: [ |
|
|
|
{ |
|
|
|
provide: NG_VALUE_ACCESSOR, |
|
|
|
useExisting: forwardRef(() => DefaultDeviceProfileTransportConfigurationComponent), |
|
|
|
multi: true |
|
|
|
}, |
|
|
|
{ |
|
|
|
provide: NG_VALIDATORS, |
|
|
|
useExisting: forwardRef(() => DefaultDeviceProfileTransportConfigurationComponent), |
|
|
|
multi: true |
|
|
|
} |
|
|
|
] |
|
|
|
}) |
|
|
|
export class DefaultDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit { |
|
|
|
export class DefaultDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, Validator { |
|
|
|
|
|
|
|
defaultDeviceProfileTransportConfigurationFormGroup: UntypedFormGroup; |
|
|
|
|
|
|
|
private requiredValue: boolean; |
|
|
|
get required(): boolean { |
|
|
|
return this.requiredValue; |
|
|
|
} |
|
|
|
@Input() |
|
|
|
set required(value: boolean) { |
|
|
|
this.requiredValue = coerceBooleanProperty(value); |
|
|
|
} |
|
|
|
|
|
|
|
@Input() |
|
|
|
disabled: boolean; |
|
|
|
|
|
|
|
@ -86,12 +89,17 @@ export class DefaultDeviceProfileTransportConfigurationComponent implements Cont |
|
|
|
this.defaultDeviceProfileTransportConfigurationFormGroup.patchValue({configuration: value}, {emitEvent: false}); |
|
|
|
} |
|
|
|
|
|
|
|
private updateModel() { |
|
|
|
let configuration: DeviceProfileTransportConfiguration = null; |
|
|
|
if (this.defaultDeviceProfileTransportConfigurationFormGroup.valid) { |
|
|
|
configuration = this.defaultDeviceProfileTransportConfigurationFormGroup.getRawValue().configuration; |
|
|
|
configuration.type = DeviceTransportType.DEFAULT; |
|
|
|
validate(c: UntypedFormControl): ValidationErrors | null { |
|
|
|
return (this.defaultDeviceProfileTransportConfigurationFormGroup.valid) ? null : { |
|
|
|
configuration: { |
|
|
|
valid: false |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private updateModel() { |
|
|
|
const configuration = this.defaultDeviceProfileTransportConfigurationFormGroup.getRawValue().configuration; |
|
|
|
configuration.type = DeviceTransportType.DEFAULT; |
|
|
|
this.propagateChange(configuration); |
|
|
|
} |
|
|
|
} |
|
|
|
|