Browse Source

UI: Add unsubscribe to device profile transport type

pull/4651/head
Vladyslav_Prykhodko 5 years ago
parent
commit
1b2a259191
  1. 21
      ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.ts
  2. 17
      ui-ngx/src/app/modules/home/components/profile/device/device-profile-configuration.component.ts
  3. 25
      ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.ts
  4. 28
      ui-ngx/src/app/modules/home/components/profile/device/snmp-device-profile-transport-configuration.component.ts
  5. 2
      ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.ts

21
ui-ngx/src/app/modules/home/components/profile/device/coap-device-profile-transport-configuration.component.ts

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, forwardRef, Input, OnInit } from '@angular/core'; import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@app/core/core.state'; import { AppState } from '@app/core/core.state';
@ -33,6 +33,8 @@ import {
transportPayloadTypeTranslationMap, transportPayloadTypeTranslationMap,
} from '@shared/models/device.models'; } from '@shared/models/device.models';
import { isDefinedAndNotNull } from '@core/utils'; import { isDefinedAndNotNull } from '@core/utils';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({ @Component({
selector: 'tb-coap-device-profile-transport-configuration', selector: 'tb-coap-device-profile-transport-configuration',
@ -44,7 +46,7 @@ import { isDefinedAndNotNull } from '@core/utils';
multi: true multi: true
}] }]
}) })
export class CoapDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit { export class CoapDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, OnDestroy {
coapTransportDeviceTypes = Object.keys(CoapTransportDeviceType); coapTransportDeviceTypes = Object.keys(CoapTransportDeviceType);
@ -56,6 +58,7 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
coapDeviceProfileTransportConfigurationFormGroup: FormGroup; coapDeviceProfileTransportConfigurationFormGroup: FormGroup;
private destroy$ = new Subject();
private requiredValue: boolean; private requiredValue: boolean;
private transportPayloadTypeConfiguration = this.fb.group({ private transportPayloadTypeConfiguration = this.fb.group({
@ -99,15 +102,23 @@ export class CoapDeviceProfileTransportConfigurationComponent implements Control
}) })
} }
); );
this.coapDeviceProfileTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType') this.coapDeviceProfileTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').valueChanges.pipe(
.valueChanges.subscribe(coapDeviceType => { takeUntil(this.destroy$)
).subscribe(coapDeviceType => {
this.updateCoapDeviceTypeBasedControls(coapDeviceType, true); this.updateCoapDeviceTypeBasedControls(coapDeviceType, true);
}); });
this.coapDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { this.coapDeviceProfileTransportConfigurationFormGroup.valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe(() => {
this.updateModel(); this.updateModel();
}); });
} }
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
get coapDeviceTypeDefault(): boolean { get coapDeviceTypeDefault(): boolean {
const coapDeviceType = this.coapDeviceProfileTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').value; const coapDeviceType = this.coapDeviceProfileTransportConfigurationFormGroup.get('coapDeviceTypeConfiguration.coapDeviceType').value;
return coapDeviceType === CoapTransportDeviceType.DEFAULT; return coapDeviceType === CoapTransportDeviceType.DEFAULT;

17
ui-ngx/src/app/modules/home/components/profile/device/device-profile-configuration.component.ts

@ -14,13 +14,15 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, forwardRef, Input, OnInit } from '@angular/core'; import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@app/core/core.state'; import { AppState } from '@app/core/core.state';
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { DeviceProfileConfiguration, DeviceProfileType } from '@shared/models/device.models'; import { DeviceProfileConfiguration, DeviceProfileType } from '@shared/models/device.models';
import { deepClone } from '@core/utils'; import { deepClone } from '@core/utils';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({ @Component({
selector: 'tb-device-profile-configuration', selector: 'tb-device-profile-configuration',
@ -32,12 +34,14 @@ import { deepClone } from '@core/utils';
multi: true multi: true
}] }]
}) })
export class DeviceProfileConfigurationComponent implements ControlValueAccessor, OnInit { export class DeviceProfileConfigurationComponent implements ControlValueAccessor, OnInit, OnDestroy {
deviceProfileType = DeviceProfileType; deviceProfileType = DeviceProfileType;
deviceProfileConfigurationFormGroup: FormGroup; deviceProfileConfigurationFormGroup: FormGroup;
private destroy$ = new Subject();
private requiredValue: boolean; private requiredValue: boolean;
get required(): boolean { get required(): boolean {
return this.requiredValue; return this.requiredValue;
@ -69,11 +73,18 @@ export class DeviceProfileConfigurationComponent implements ControlValueAccessor
this.deviceProfileConfigurationFormGroup = this.fb.group({ this.deviceProfileConfigurationFormGroup = this.fb.group({
configuration: [null, Validators.required] configuration: [null, Validators.required]
}); });
this.deviceProfileConfigurationFormGroup.valueChanges.subscribe(() => { this.deviceProfileConfigurationFormGroup.valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe(() => {
this.updateModel(); this.updateModel();
}); });
} }
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
setDisabledState(isDisabled: boolean): void { setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled; this.disabled = isDisabled;
if (this.disabled) { if (this.disabled) {

25
ui-ngx/src/app/modules/home/components/profile/device/mqtt-device-profile-transport-configuration.component.ts

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, forwardRef, Input, OnInit } from '@angular/core'; import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core';
import { import {
ControlValueAccessor, ControlValueAccessor,
FormBuilder, FormBuilder,
@ -39,6 +39,8 @@ import {
transportPayloadTypeTranslationMap transportPayloadTypeTranslationMap
} from '@shared/models/device.models'; } from '@shared/models/device.models';
import { isDefinedAndNotNull } from '@core/utils'; import { isDefinedAndNotNull } from '@core/utils';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
@Component({ @Component({
selector: 'tb-mqtt-device-profile-transport-configuration', selector: 'tb-mqtt-device-profile-transport-configuration',
@ -50,7 +52,7 @@ import { isDefinedAndNotNull } from '@core/utils';
multi: true multi: true
}] }]
}) })
export class MqttDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit { export class MqttDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, OnDestroy {
transportPayloadTypes = Object.keys(TransportPayloadType); transportPayloadTypes = Object.keys(TransportPayloadType);
@ -58,6 +60,7 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control
mqttDeviceProfileTransportConfigurationFormGroup: FormGroup; mqttDeviceProfileTransportConfigurationFormGroup: FormGroup;
private destroy$ = new Subject();
private requiredValue: boolean; private requiredValue: boolean;
get required(): boolean { get required(): boolean {
@ -98,15 +101,23 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control
}) })
}, {validator: this.uniqueDeviceTopicValidator} }, {validator: this.uniqueDeviceTopicValidator}
); );
this.mqttDeviceProfileTransportConfigurationFormGroup.get('transportPayloadTypeConfiguration.transportPayloadType') this.mqttDeviceProfileTransportConfigurationFormGroup.get('transportPayloadTypeConfiguration.transportPayloadType').valueChanges.pipe(
.valueChanges.subscribe(payloadType => { takeUntil(this.destroy$)
).subscribe(payloadType => {
this.updateTransportPayloadBasedControls(payloadType, true); this.updateTransportPayloadBasedControls(payloadType, true);
}); });
this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe(() => {
this.updateModel(); this.updateModel();
}); });
} }
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
setDisabledState(isDisabled: boolean): void { setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled; this.disabled = isDisabled;
if (this.disabled) { if (this.disabled) {
@ -192,8 +203,8 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control
} }
private uniqueDeviceTopicValidator(control: FormGroup): { [key: string]: boolean } | null { private uniqueDeviceTopicValidator(control: FormGroup): { [key: string]: boolean } | null {
if (control.value) { if (control.getRawValue()) {
const formValue = control.value as MqttDeviceProfileTransportConfiguration; const formValue = control.getRawValue() as MqttDeviceProfileTransportConfiguration;
if (formValue.deviceAttributesTopic === formValue.deviceTelemetryTopic) { if (formValue.deviceAttributesTopic === formValue.deviceTelemetryTopic) {
return {unique: true}; return {unique: true};
} }

28
ui-ngx/src/app/modules/home/components/profile/device/snmp-device-profile-transport-configuration.component.ts

@ -14,17 +14,19 @@
/// limitations under the License. /// limitations under the License.
/// ///
import {Component, forwardRef, Input, OnInit} from '@angular/core'; import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core';
import {ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators} from '@angular/forms'; import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
import {Store} from '@ngrx/store'; import { Store } from '@ngrx/store';
import {AppState} from '@app/core/core.state'; import { AppState } from '@app/core/core.state';
import {coerceBooleanProperty} from '@angular/cdk/coercion'; import { coerceBooleanProperty } from '@angular/cdk/coercion';
import { import {
DeviceProfileTransportConfiguration, DeviceProfileTransportConfiguration,
DeviceTransportType, DeviceTransportType,
SnmpDeviceProfileTransportConfiguration SnmpDeviceProfileTransportConfiguration
} from '@shared/models/device.models'; } from '@shared/models/device.models';
import {isDefinedAndNotNull} from "@core/utils"; import { isDefinedAndNotNull } from '@core/utils';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
export interface OidMappingConfiguration { export interface OidMappingConfiguration {
isAttribute: boolean; isAttribute: boolean;
@ -44,8 +46,11 @@ export interface OidMappingConfiguration {
multi: true multi: true
}] }]
}) })
export class SnmpDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit { export class SnmpDeviceProfileTransportConfigurationComponent implements ControlValueAccessor, OnInit, OnDestroy {
snmpDeviceProfileTransportConfigurationFormGroup: FormGroup; snmpDeviceProfileTransportConfigurationFormGroup: FormGroup;
private destroy$ = new Subject();
private requiredValue: boolean; private requiredValue: boolean;
private configuration = []; private configuration = [];
@ -71,11 +76,18 @@ export class SnmpDeviceProfileTransportConfigurationComponent implements Control
this.snmpDeviceProfileTransportConfigurationFormGroup = this.fb.group({ this.snmpDeviceProfileTransportConfigurationFormGroup = this.fb.group({
configuration: [null, Validators.required] configuration: [null, Validators.required]
}); });
this.snmpDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { this.snmpDeviceProfileTransportConfigurationFormGroup.valueChanges.pipe(
takeUntil(this.destroy$)
).subscribe(() => {
this.updateModel(); this.updateModel();
}); });
} }
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
registerOnChange(fn: any): void { registerOnChange(fn: any): void {
this.propagateChange = fn; this.propagateChange = fn;
} }

2
ui-ngx/src/app/modules/home/pages/device-profile/device-profile-tabs.component.ts

@ -32,7 +32,7 @@ import {
}) })
export class DeviceProfileTabsComponent extends EntityTabsComponent<DeviceProfile> { export class DeviceProfileTabsComponent extends EntityTabsComponent<DeviceProfile> {
deviceTransportTypes = Object.keys(DeviceTransportType); deviceTransportTypes = Object.values(DeviceTransportType);
deviceTransportTypeTranslations = deviceTransportTypeTranslationMap; deviceTransportTypeTranslations = deviceTransportTypeTranslationMap;

Loading…
Cancel
Save