From 8794f3f37ef30fd7977785baa829ecdeeac150a6 Mon Sep 17 00:00:00 2001 From: fe-dev Date: Fri, 24 Jun 2022 10:32:54 +0300 Subject: [PATCH 1/2] UI: change loading lib and fix bugs --- .../components/phone-input.component.html | 3 +- .../components/phone-input.component.scss | 7 ++ .../components/phone-input.component.ts | 66 +++++++++++++------ .../src/app/shared/models/country.models.ts | 8 +-- 4 files changed, 60 insertions(+), 24 deletions(-) diff --git a/ui-ngx/src/app/shared/components/phone-input.component.html b/ui-ngx/src/app/shared/components/phone-input.component.html index 83db450d70..da727bed90 100644 --- a/ui-ngx/src/app/shared/components/phone-input.component.html +++ b/ui-ngx/src/app/shared/components/phone-input.component.html @@ -19,7 +19,8 @@
- {{ flagIcon }} + {{ flagIcon }} + {{country.flag}} diff --git a/ui-ngx/src/app/shared/components/phone-input.component.scss b/ui-ngx/src/app/shared/components/phone-input.component.scss index acca75f560..432c9d21f2 100644 --- a/ui-ngx/src/app/shared/components/phone-input.component.scss +++ b/ui-ngx/src/app/shared/components/phone-input.component.scss @@ -15,6 +15,13 @@ */ :host ::ng-deep { + .flag-loader { + position: absolute; + top: 50%; + left: 0; + transform: translate(0, -50%); + } + .phone-input-container { display: flex; align-items: center; diff --git a/ui-ngx/src/app/shared/components/phone-input.component.ts b/ui-ngx/src/app/shared/components/phone-input.component.ts index 47bdf8741c..5fae7c0d0f 100644 --- a/ui-ngx/src/app/shared/components/phone-input.component.ts +++ b/ui-ngx/src/app/shared/components/phone-input.component.ts @@ -30,7 +30,6 @@ import { import { TranslateService } from '@ngx-translate/core'; import { Country, CountryData } from '@shared/models/country.models'; import examples from 'libphonenumber-js/examples.mobile.json'; -import { CountryCode, getExampleNumber, parsePhoneNumberFromString } from 'libphonenumber-js'; import { phoneNumberPattern } from '@shared/models/settings.models'; import { Subscription } from 'rxjs'; import { FloatLabelType, MatFormFieldAppearance } from '@angular/material/form-field/form-field'; @@ -59,7 +58,7 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida disabled: boolean; @Input() - defaultCountry: CountryCode = 'US'; + defaultCountry = 'US'; @Input() enableFlagsSelect = true; @@ -80,13 +79,29 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida label = 'phone-input.phone-input-label'; allCountries: Array = this.countryCodeData.allCountries; - phonePlaceholder: string; + phonePlaceholder = '+12015550123'; flagIcon: string; phoneFormGroup: FormGroup; phoneNumberPattern = phoneNumberPattern; + private isLoading = true; + get isLoad(): boolean { + return this.isLoading; + } + + set isLoad(value) { + if (this.isLoading) { + this.isLoading = value; + if (this.phoneFormGroup) { + this.defineCountryFromNumber(this.phoneFormGroup.get('phoneNumber').value); + } + } + } + + private getExampleNumber; + private parsePhoneNumberFromString; private baseCode = 127397; - private countryCallingCode: string; + private countryCallingCode = '+'; private modelValue: string; private valueChange$: Subscription = null; private propagateChange = (v: any) => { }; @@ -94,6 +109,10 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida constructor(private translate: TranslateService, private fb: FormBuilder, private countryCodeData: CountryData) { + import('libphonenumber-js/max').then((libphonenubmer) => { + this.parsePhoneNumberFromString = libphonenubmer.parsePhoneNumberFromString; + this.getExampleNumber = libphonenubmer.getExampleNumber; + }).then(() => this.isLoad = false); } ngOnInit(): void { @@ -108,13 +127,7 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida this.valueChange$ = this.phoneFormGroup.get('phoneNumber').valueChanges.subscribe(value => { this.updateModel(); - if (value) { - const parsedPhoneNumber = parsePhoneNumberFromString(value); - const country = this.phoneFormGroup.get('country').value; - if (parsedPhoneNumber?.country && parsedPhoneNumber?.country !== country) { - this.phoneFormGroup.get('country').patchValue(parsedPhoneNumber.country, {emitEvent: true}); - } - } + this.defineCountryFromNumber(value); }); this.phoneFormGroup.get('country').valueChanges.subscribe(value => { @@ -155,9 +168,11 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida } private getPhoneNumberData(country): void { - const phoneData = getExampleNumber(country, examples); - this.phonePlaceholder = phoneData.number; - this.countryCallingCode = '+' + phoneData.countryCallingCode; + if (this.getExampleNumber) { + const phoneData = this.getExampleNumber(country, examples); + this.phonePlaceholder = phoneData.number; + this.countryCallingCode = `+${this.enableFlagsSelect ? phoneData.countryCallingCode : ''}`; + } } private getFlagIcon(countryCode) { @@ -167,8 +182,8 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida validatePhoneNumber(): ValidatorFn { return (c: FormControl) => { const phoneNumber = c.value; - if (phoneNumber) { - const parsedPhoneNumber = parsePhoneNumberFromString(phoneNumber); + if (phoneNumber && this.parsePhoneNumberFromString) { + const parsedPhoneNumber = this.parsePhoneNumberFromString(phoneNumber); if (!parsedPhoneNumber?.isValid() || !parsedPhoneNumber?.isPossible()) { return { invalidPhoneNumber: { @@ -181,6 +196,16 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida }; } + private defineCountryFromNumber(phoneNumber) { + if (phoneNumber && this.parsePhoneNumberFromString) { + const parsedPhoneNumber = this.parsePhoneNumberFromString(phoneNumber); + const country = this.phoneFormGroup.get('country').value; + if (parsedPhoneNumber?.country && parsedPhoneNumber?.country !== country) { + this.phoneFormGroup.get('country').patchValue(parsedPhoneNumber.country, {emitEvent: true}); + } + } + } + validate(): ValidationErrors | null { return this.phoneFormGroup.get('phoneNumber').valid ? null : { phoneFormGroup: false @@ -205,8 +230,11 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida writeValue(phoneNumber): void { this.modelValue = phoneNumber; - const country = phoneNumber ? parsePhoneNumberFromString(phoneNumber)?.country : this.defaultCountry; - this.getFlagAndPhoneNumberData(country); + let country = this.defaultCountry; + if (this.parsePhoneNumberFromString) { + country = phoneNumber ? this.parsePhoneNumberFromString(phoneNumber)?.country : this.defaultCountry; + this.getFlagAndPhoneNumberData(country); + } this.phoneFormGroup.patchValue({phoneNumber, country}, {emitEvent: !phoneNumber}); } @@ -215,7 +243,7 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida if (phoneNumber.valid && phoneNumber.value) { this.modelValue = phoneNumber.value; this.propagateChange(this.modelValue); - } else { + } else if (phoneNumber.invalid && phoneNumber.value) { this.propagateChange(null); } } diff --git a/ui-ngx/src/app/shared/models/country.models.ts b/ui-ngx/src/app/shared/models/country.models.ts index d4895fada7..afba058c6d 100644 --- a/ui-ngx/src/app/shared/models/country.models.ts +++ b/ui-ngx/src/app/shared/models/country.models.ts @@ -357,7 +357,7 @@ export class CountryData { {name: 'Gibraltar', iso2: CountryISO.Gibraltar, dialCode: '350', flag: '๐Ÿ‡ฌ๐Ÿ‡ฎ'}, {name: 'Greece', iso2: CountryISO.Greece, dialCode: '30', flag: '๐Ÿ‡ฌ๐Ÿ‡ท'}, {name: 'Greenland', iso2: CountryISO.Greenland, dialCode: '299', flag: '๐Ÿ‡ฌ๐Ÿ‡ฑ'}, - {name: 'Grenada', iso2: CountryISO.Grenada, dialCode: '1473', flag: '๐Ÿ‡ฌ๐Ÿ‡ฉ'}, + {name: 'Grenada', iso2: CountryISO.Grenada, dialCode: '1', flag: '๐Ÿ‡ฌ๐Ÿ‡ฉ'}, {name: 'Guadeloupe', iso2: CountryISO.Guadeloupe, dialCode: '590', flag: '๐Ÿ‡ฌ๐Ÿ‡ต'}, {name: 'Guam', iso2: CountryISO.Guam, dialCode: '1', flag: '๐Ÿ‡ฌ๐Ÿ‡บ'}, {name: 'Guatemala', iso2: CountryISO.Guatemala, dialCode: '502', flag: '๐Ÿ‡ฌ๐Ÿ‡น'}, @@ -432,7 +432,7 @@ export class CountryData { {name: 'Niue', iso2: CountryISO.Niue, dialCode: '683', flag: '๐Ÿ‡ณ๐Ÿ‡บ'}, {name: 'Norfolk Island', iso2: CountryISO.NorfolkIsland, dialCode: '672', flag: '๐Ÿ‡ณ๐Ÿ‡ซ'}, {name: 'North Korea', iso2: CountryISO.NorthKorea, dialCode: '850', flag: '๐Ÿ‡ฐ๐Ÿ‡ต'}, - {name: 'Northern Mariana Islands', iso2: CountryISO.NorthernMarianaIslands, dialCode: '1670', flag: '๐Ÿ‡ฒ๐Ÿ‡ต'}, + {name: 'Northern Mariana Islands', iso2: CountryISO.NorthernMarianaIslands, dialCode: '1', flag: '๐Ÿ‡ฒ๐Ÿ‡ต'}, {name: 'Norway', iso2: CountryISO.Norway, dialCode: '47', flag: '๐Ÿ‡ณ๐Ÿ‡ด'}, {name: 'Oman', iso2: CountryISO.Oman, dialCode: '968', flag: '๐Ÿ‡ด๐Ÿ‡ฒ'}, {name: 'Pakistan', iso2: CountryISO.Pakistan, dialCode: '92', flag: '๐Ÿ‡ต๐Ÿ‡ฐ'}, @@ -453,7 +453,7 @@ export class CountryData { {name: 'Rwanda', iso2: CountryISO.Rwanda, dialCode: '250', flag: '๐Ÿ‡ท๐Ÿ‡ผ'}, {name: 'Saint Barthรฉlemy', iso2: CountryISO.SaintBarthรฉlemy, dialCode: '590', flag: '๐Ÿ‡ง๐Ÿ‡ฑ'}, {name: 'Saint Helena', iso2: CountryISO.SaintHelena, dialCode: '290', flag: '๐Ÿ‡ธ๐Ÿ‡ญ'}, - {name: 'Saint Kitts and Nevis', iso2: CountryISO.SaintKittsAndNevis, dialCode: '1869', flag: '๐Ÿ‡ฐ๐Ÿ‡ณ'}, + {name: 'Saint Kitts and Nevis', iso2: CountryISO.SaintKittsAndNevis, dialCode: '1', flag: '๐Ÿ‡ฐ๐Ÿ‡ณ'}, {name: 'Saint Lucia', iso2: CountryISO.SaintLucia, dialCode: '1', flag: '๐Ÿ‡ฑ๐Ÿ‡จ'}, {name: 'Saint Martin', iso2: CountryISO.SaintMartin, dialCode: '590', flag: '๐Ÿ‡ฒ๐Ÿ‡ซ'}, {name: 'Saint Pierre and Miquelon', iso2: CountryISO.SaintPierreAndMiquelon, dialCode: '508', flag: '๐Ÿ‡ต๐Ÿ‡ฒ'}, @@ -496,7 +496,7 @@ export class CountryData { {name: 'Tunisia', iso2: CountryISO.Tunisia, dialCode: '216', flag: '๐Ÿ‡น๐Ÿ‡ณ'}, {name: 'Turkey', iso2: CountryISO.Turkey, dialCode: '90', flag: '๐Ÿ‡น๐Ÿ‡ท'}, {name: 'Turkmenistan', iso2: CountryISO.Turkmenistan, dialCode: '993', flag: '๐Ÿ‡น๐Ÿ‡ฒ'}, - {name: 'Turks and Caicos Islands', iso2: CountryISO.TurksAndCaicosIslands, dialCode: '1649', flag: '๐Ÿ‡น๐Ÿ‡จ'}, + {name: 'Turks and Caicos Islands', iso2: CountryISO.TurksAndCaicosIslands, dialCode: '1', flag: '๐Ÿ‡น๐Ÿ‡จ'}, {name: 'Tuvalu', iso2: CountryISO.Tuvalu, dialCode: '688', flag: '๐Ÿ‡น๐Ÿ‡ป'}, {name: 'U.S. Virgin Islands', iso2: CountryISO.USVirginIslands, dialCode: '1', flag: '๐Ÿ‡ป๐Ÿ‡ฎ'}, {name: 'Uganda', iso2: CountryISO.Uganda, dialCode: '256', flag: '๐Ÿ‡บ๐Ÿ‡ฌ'}, From 24e856516ff6d9b96112287968b5e350ed38a4b7 Mon Sep 17 00:00:00 2001 From: Andrii Shvaika Date: Mon, 27 Jun 2022 12:33:02 +0300 Subject: [PATCH 2/2] Fix integration test --- .../sync/ie/importing/impl/DeviceProfileImportService.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/thingsboard/server/service/sync/ie/importing/impl/DeviceProfileImportService.java b/application/src/main/java/org/thingsboard/server/service/sync/ie/importing/impl/DeviceProfileImportService.java index 2c27f6941f..b1189412f3 100644 --- a/application/src/main/java/org/thingsboard/server/service/sync/ie/importing/impl/DeviceProfileImportService.java +++ b/application/src/main/java/org/thingsboard/server/service/sync/ie/importing/impl/DeviceProfileImportService.java @@ -19,6 +19,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.EntityType; +import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.exception.ThingsboardException; import org.thingsboard.server.common.data.id.DeviceProfileId; @@ -69,7 +70,8 @@ public class DeviceProfileImportService extends BaseEntityImportService