thingsboard/ui-ngx/src/app/modules/home/components/sms/smpp-sms-provider-configuration.component.ts

138 lines
4.1 KiB
TypeScript
Raw Normal View History

2022-03-03 21:36:40 +02:00
///
2023-01-31 10:43:56 +02:00
/// Copyright © 2016-2023 The Thingsboard Authors
2022-03-03 21:36:40 +02:00
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
2022-01-28 12:17:21 +02:00
import { Component, forwardRef, Input, OnInit } from '@angular/core';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
import {
AwsSnsSmsProviderConfiguration,
BindTypes,
bindTypesTranslationMap,
CodingSchemes,
codingSchemesMap,
NumberingPlanIdentification,
numberingPlanIdentificationMap,
SmppSmsProviderConfiguration,
smppVersions,
2022-01-28 12:17:21 +02:00
SmsProviderConfiguration,
SmsProviderType,
TypeOfNumber,
typeOfNumberMap
2022-01-28 12:17:21 +02:00
} from '@shared/models/settings.models';
import { isDefinedAndNotNull } from '@core/utils';
import { coerceBooleanProperty } from '@angular/cdk/coercion';
@Component({
selector: 'tb-smpp-sms-provider-configuration',
templateUrl: './smpp-sms-provider-configuration.component.html',
styleUrls: [],
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => SmppSmsProviderConfigurationComponent),
multi: true
}]
})
2022-01-28 12:17:21 +02:00
export class SmppSmsProviderConfigurationComponent implements ControlValueAccessor, OnInit{
constructor(private fb: FormBuilder) {
}
private requiredValue: boolean;
get required(): boolean {
return this.requiredValue;
}
@Input()
set required(value: boolean) {
this.requiredValue = coerceBooleanProperty(value);
}
@Input()
disabled: boolean;
smppSmsProviderConfigurationFormGroup: FormGroup;
smppVersions = smppVersions;
2022-01-28 12:17:21 +02:00
bindTypes = Object.keys(BindTypes);
bindTypesTranslation = bindTypesTranslationMap;
2022-01-28 12:17:21 +02:00
typeOfNumber = Object.keys(TypeOfNumber);
typeOfNumberMap = typeOfNumberMap;
2022-01-28 12:17:21 +02:00
numberingPlanIdentification = Object.keys(NumberingPlanIdentification);
numberingPlanIdentificationMap = numberingPlanIdentificationMap;
2022-01-28 12:17:21 +02:00
codingSchemes = Object.keys(CodingSchemes);
codingSchemesMap = codingSchemesMap;
2022-01-28 12:17:21 +02:00
private propagateChange = (v: any) => { };
ngOnInit(): void {
this.smppSmsProviderConfigurationFormGroup = this.fb.group({
protocolVersion: [null, [Validators.required]],
host: [null, [Validators.required]],
port: [null, [Validators.required]],
systemId: [null, [Validators.required]],
password: [null, [Validators.required]],
systemType: [null],
bindType: [null, []],
serviceType: [null, []],
sourceAddress: [null, []],
sourceTon: [null, []],
sourceNpi: [null, []],
destinationTon: [null, []],
destinationNpi: [null, []],
addressRange: [null, []],
codingScheme: [null, []],
});
this.smppSmsProviderConfigurationFormGroup.valueChanges.subscribe(() => {
this.updateValue();
});
}
registerOnChange(fn: any): void {
this.propagateChange = fn;
}
registerOnTouched(fn: any): void {
}
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
if (this.disabled) {
this.smppSmsProviderConfigurationFormGroup.disable({emitEvent: false});
} else {
this.smppSmsProviderConfigurationFormGroup.enable({emitEvent: false});
}
}
writeValue(value: AwsSnsSmsProviderConfiguration | null): void {
if (isDefinedAndNotNull(value)) {
this.smppSmsProviderConfigurationFormGroup.patchValue(value, {emitEvent: false});
}
}
private updateValue() {
let configuration: SmppSmsProviderConfiguration = null;
if (this.smppSmsProviderConfigurationFormGroup.valid) {
configuration = this.smppSmsProviderConfigurationFormGroup.value;
(configuration as SmsProviderConfiguration).type = SmsProviderType.SMPP;
}
this.propagateChange(configuration);
}
}