Browse Source

Merge branch 'master' of github.com:thingsboard/thingsboard into feature/check_tenant_entity_for_nodes

pull/7569/head
Andrii Shvaika 4 years ago
parent
commit
778d637f47
  1. 2
      rule-engine/rule-engine-components/src/main/resources/public/static/rulenode/rulenode-core-config.js
  2. 2
      ui-ngx/src/app/modules/home/components/widget/dialog/embed-dashboard-dialog.component.html
  3. 3
      ui-ngx/src/app/modules/home/components/widget/dialog/embed-dashboard-dialog.component.ts
  4. 4
      ui-ngx/src/app/modules/home/components/widget/widget.component.ts
  5. 43
      ui-ngx/src/app/shared/components/phone-input.component.ts

2
rule-engine/rule-engine-components/src/main/resources/public/static/rulenode/rulenode-core-config.js

File diff suppressed because one or more lines are too long

2
ui-ngx/src/app/modules/home/components/widget/dialog/embed-dashboard-dialog.component.html

@ -28,7 +28,7 @@
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div>
<div class="dashboard-state-dialog-content" mat-dialog-content fxFlex fxLayout="column" style="padding: 8px;">
<tb-dashboard-page [embedded]="true" [syncStateWithQueryParam]="false" [hideToolbar]="hideToolbar"
[currentState]="state" [dashboard]="dashboard" style="width: 100%; height: 100%;"></tb-dashboard-page>
[currentState]="state" [dashboard]="dashboard" [parentDashboard]="parentDashboard" style="width: 100%; height: 100%;"></tb-dashboard-page>
</div>
<div mat-dialog-actions fxLayoutAlign="end center">
<button mat-button color="primary"

3
ui-ngx/src/app/modules/home/components/widget/dialog/embed-dashboard-dialog.component.ts

@ -29,6 +29,7 @@ import { AppState } from '@core/core.state';
import { Router } from '@angular/router';
import { DialogComponent } from '@shared/components/dialog.component';
import { Dashboard } from '@shared/models/dashboard.models';
import { IDashboardComponent } from '@home/models/dashboard-component.models';
export interface EmbedDashboardDialogData {
dashboard: Dashboard;
@ -37,6 +38,7 @@ export interface EmbedDashboardDialogData {
hideToolbar: boolean;
width?: number;
height?: number;
parentDashboard?: IDashboardComponent;
}
@Component({
@ -53,6 +55,7 @@ export class EmbedDashboardDialogComponent extends DialogComponent<EmbedDashboar
state = this.data.state;
title = this.data.title;
hideToolbar = this.data.hideToolbar;
parentDashboard = this.data.parentDashboard;
dialogStyle: any = {};

4
ui-ngx/src/app/modules/home/components/widget/widget.component.ts

@ -1446,7 +1446,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI
title,
hideToolbar: hideDashboardToolbar,
width: dialogWidth,
height: dialogHeight
height: dialogHeight,
parentDashboard: this.widgetContext.parentDashboard ?
this.widgetContext.parentDashboard : this.widgetContext.dashboard
}
});
this.cd.markForCheck();

43
ui-ngx/src/app/shared/components/phone-input.component.ts

@ -97,8 +97,9 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
if (this.defaultCountry) {
this.getFlagAndPhoneNumberData(this.defaultCountry);
}
if (this.phoneFormGroup) {
this.defineCountryFromNumber(this.phoneFormGroup.get('phoneNumber').value);
if (this.phoneFormGroup && this.phoneFormGroup.get('phoneNumber').value) {
const parsedPhoneNumber = this.parsePhoneNumberFromString(this.phoneFormGroup.get('phoneNumber').value);
this.defineCountryFromNumber(parsedPhoneNumber);
}
}
}
@ -110,7 +111,7 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
private countryCallingCode = '+';
private modelValue: string;
private changeSubscriptions: Subscription[] = [];
private validators: ValidatorFn[] = [(c: FormControl) => Validators.pattern(this.getPhoneNumberPattern())(c), this.validatePhoneNumber()];
private validators: ValidatorFn[] = [this.validatePhoneNumber()];
private propagateChange = (v: any) => { };
@ -133,8 +134,12 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
});
this.changeSubscriptions.push(this.phoneFormGroup.get('phoneNumber').valueChanges.subscribe(value => {
this.updateModel();
this.defineCountryFromNumber(value);
let parsedPhoneNumber = null;
if (value && this.parsePhoneNumberFromString) {
parsedPhoneNumber = this.parsePhoneNumberFromString(value);
this.defineCountryFromNumber(parsedPhoneNumber);
}
this.updateModel(parsedPhoneNumber);
}));
this.changeSubscriptions.push(this.phoneFormGroup.get('country').valueChanges.subscribe(value => {
@ -184,6 +189,10 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
return String.fromCodePoint(...countryCode.split('').map(country => this.baseCode + country.charCodeAt(0)));
}
private updateModelValueInFormat(parsedPhoneNumber: any) {
this.modelValue = parsedPhoneNumber.format('E.164');
}
validatePhoneNumber(): ValidatorFn {
return (c: FormControl) => {
const phoneNumber = c.value;
@ -201,20 +210,13 @@ 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});
}
private defineCountryFromNumber(parsedPhoneNumber) {
const country = this.phoneFormGroup.get('country').value;
if (parsedPhoneNumber?.country && parsedPhoneNumber?.country !== country) {
this.phoneFormGroup.get('country').patchValue(parsedPhoneNumber.country, {emitEvent: true});
}
}
private getPhoneNumberPattern(): RegExp {
return new RegExp(`^${this.countryCallingCode.replace('+', '\\+')}$|^\\+[1-9]\\d{1,14}$`);
}
validate(): ValidationErrors | null {
const phoneNumber = this.phoneFormGroup.get('phoneNumber');
return phoneNumber.valid || this.countryCallingCode === phoneNumber.value ? null : {
@ -247,6 +249,8 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
if (phoneNumber) {
const parsedPhoneNumber = this.parsePhoneNumberFromString(phoneNumber);
if (parsedPhoneNumber?.isValid() && parsedPhoneNumber?.isPossible()) {
country = parsedPhoneNumber?.country || this.defaultCountry;
this.updateModelValueInFormat(parsedPhoneNumber);
this.isLegacy = false;
} else {
const validators = [Validators.maxLength(255)];
@ -260,18 +264,19 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
this.isLegacy = false;
}
this.phoneFormGroup.updateValueAndValidity({emitEvent: false});
country = phoneNumber ? this.parsePhoneNumberFromString(phoneNumber)?.country || this.defaultCountry : this.defaultCountry;
this.getFlagAndPhoneNumberData(country);
}
this.phoneFormGroup.reset({phoneNumber, country}, {emitEvent: false});
}
private updateModel() {
private updateModel(parsedPhoneNumber?) {
const phoneNumber = this.phoneFormGroup.get('phoneNumber');
if (phoneNumber.value === '+' || phoneNumber.value === this.countryCallingCode) {
this.propagateChange(null);
} else if (phoneNumber.valid) {
this.modelValue = phoneNumber.value;
if (parsedPhoneNumber) {
this.updateModelValueInFormat(parsedPhoneNumber);
}
this.propagateChange(this.modelValue);
} else {
this.propagateChange(null);

Loading…
Cancel
Save