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 style="height: 4px;" *ngIf="!(isLoading$ | async)"></div>
<div class="dashboard-state-dialog-content" mat-dialog-content fxFlex fxLayout="column" style="padding: 8px;"> <div class="dashboard-state-dialog-content" mat-dialog-content fxFlex fxLayout="column" style="padding: 8px;">
<tb-dashboard-page [embedded]="true" [syncStateWithQueryParam]="false" [hideToolbar]="hideToolbar" <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>
<div mat-dialog-actions fxLayoutAlign="end center"> <div mat-dialog-actions fxLayoutAlign="end center">
<button mat-button color="primary" <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 { Router } from '@angular/router';
import { DialogComponent } from '@shared/components/dialog.component'; import { DialogComponent } from '@shared/components/dialog.component';
import { Dashboard } from '@shared/models/dashboard.models'; import { Dashboard } from '@shared/models/dashboard.models';
import { IDashboardComponent } from '@home/models/dashboard-component.models';
export interface EmbedDashboardDialogData { export interface EmbedDashboardDialogData {
dashboard: Dashboard; dashboard: Dashboard;
@ -37,6 +38,7 @@ export interface EmbedDashboardDialogData {
hideToolbar: boolean; hideToolbar: boolean;
width?: number; width?: number;
height?: number; height?: number;
parentDashboard?: IDashboardComponent;
} }
@Component({ @Component({
@ -53,6 +55,7 @@ export class EmbedDashboardDialogComponent extends DialogComponent<EmbedDashboar
state = this.data.state; state = this.data.state;
title = this.data.title; title = this.data.title;
hideToolbar = this.data.hideToolbar; hideToolbar = this.data.hideToolbar;
parentDashboard = this.data.parentDashboard;
dialogStyle: any = {}; 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, title,
hideToolbar: hideDashboardToolbar, hideToolbar: hideDashboardToolbar,
width: dialogWidth, width: dialogWidth,
height: dialogHeight height: dialogHeight,
parentDashboard: this.widgetContext.parentDashboard ?
this.widgetContext.parentDashboard : this.widgetContext.dashboard
} }
}); });
this.cd.markForCheck(); 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) { if (this.defaultCountry) {
this.getFlagAndPhoneNumberData(this.defaultCountry); this.getFlagAndPhoneNumberData(this.defaultCountry);
} }
if (this.phoneFormGroup) { if (this.phoneFormGroup && this.phoneFormGroup.get('phoneNumber').value) {
this.defineCountryFromNumber(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 countryCallingCode = '+';
private modelValue: string; private modelValue: string;
private changeSubscriptions: Subscription[] = []; private changeSubscriptions: Subscription[] = [];
private validators: ValidatorFn[] = [(c: FormControl) => Validators.pattern(this.getPhoneNumberPattern())(c), this.validatePhoneNumber()]; private validators: ValidatorFn[] = [this.validatePhoneNumber()];
private propagateChange = (v: any) => { }; 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.changeSubscriptions.push(this.phoneFormGroup.get('phoneNumber').valueChanges.subscribe(value => {
this.updateModel(); let parsedPhoneNumber = null;
this.defineCountryFromNumber(value); if (value && this.parsePhoneNumberFromString) {
parsedPhoneNumber = this.parsePhoneNumberFromString(value);
this.defineCountryFromNumber(parsedPhoneNumber);
}
this.updateModel(parsedPhoneNumber);
})); }));
this.changeSubscriptions.push(this.phoneFormGroup.get('country').valueChanges.subscribe(value => { 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))); return String.fromCodePoint(...countryCode.split('').map(country => this.baseCode + country.charCodeAt(0)));
} }
private updateModelValueInFormat(parsedPhoneNumber: any) {
this.modelValue = parsedPhoneNumber.format('E.164');
}
validatePhoneNumber(): ValidatorFn { validatePhoneNumber(): ValidatorFn {
return (c: FormControl) => { return (c: FormControl) => {
const phoneNumber = c.value; const phoneNumber = c.value;
@ -201,20 +210,13 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
}; };
} }
private defineCountryFromNumber(phoneNumber) { private defineCountryFromNumber(parsedPhoneNumber) {
if (phoneNumber && this.parsePhoneNumberFromString) { const country = this.phoneFormGroup.get('country').value;
const parsedPhoneNumber = this.parsePhoneNumberFromString(phoneNumber); if (parsedPhoneNumber?.country && parsedPhoneNumber?.country !== country) {
const country = this.phoneFormGroup.get('country').value; this.phoneFormGroup.get('country').patchValue(parsedPhoneNumber.country, {emitEvent: true});
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 { validate(): ValidationErrors | null {
const phoneNumber = this.phoneFormGroup.get('phoneNumber'); const phoneNumber = this.phoneFormGroup.get('phoneNumber');
return phoneNumber.valid || this.countryCallingCode === phoneNumber.value ? null : { return phoneNumber.valid || this.countryCallingCode === phoneNumber.value ? null : {
@ -247,6 +249,8 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
if (phoneNumber) { if (phoneNumber) {
const parsedPhoneNumber = this.parsePhoneNumberFromString(phoneNumber); const parsedPhoneNumber = this.parsePhoneNumberFromString(phoneNumber);
if (parsedPhoneNumber?.isValid() && parsedPhoneNumber?.isPossible()) { if (parsedPhoneNumber?.isValid() && parsedPhoneNumber?.isPossible()) {
country = parsedPhoneNumber?.country || this.defaultCountry;
this.updateModelValueInFormat(parsedPhoneNumber);
this.isLegacy = false; this.isLegacy = false;
} else { } else {
const validators = [Validators.maxLength(255)]; const validators = [Validators.maxLength(255)];
@ -260,18 +264,19 @@ export class PhoneInputComponent implements OnInit, ControlValueAccessor, Valida
this.isLegacy = false; this.isLegacy = false;
} }
this.phoneFormGroup.updateValueAndValidity({emitEvent: false}); this.phoneFormGroup.updateValueAndValidity({emitEvent: false});
country = phoneNumber ? this.parsePhoneNumberFromString(phoneNumber)?.country || this.defaultCountry : this.defaultCountry;
this.getFlagAndPhoneNumberData(country); this.getFlagAndPhoneNumberData(country);
} }
this.phoneFormGroup.reset({phoneNumber, country}, {emitEvent: false}); this.phoneFormGroup.reset({phoneNumber, country}, {emitEvent: false});
} }
private updateModel() { private updateModel(parsedPhoneNumber?) {
const phoneNumber = this.phoneFormGroup.get('phoneNumber'); const phoneNumber = this.phoneFormGroup.get('phoneNumber');
if (phoneNumber.value === '+' || phoneNumber.value === this.countryCallingCode) { if (phoneNumber.value === '+' || phoneNumber.value === this.countryCallingCode) {
this.propagateChange(null); this.propagateChange(null);
} else if (phoneNumber.valid) { } else if (phoneNumber.valid) {
this.modelValue = phoneNumber.value; if (parsedPhoneNumber) {
this.updateModelValueInFormat(parsedPhoneNumber);
}
this.propagateChange(this.modelValue); this.propagateChange(this.modelValue);
} else { } else {
this.propagateChange(null); this.propagateChange(null);

Loading…
Cancel
Save