diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/mobile-action-editor.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/mobile-action-editor.component.ts index 8c36a64655..717e7b51b0 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/mobile-action-editor.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/mobile-action-editor.component.ts @@ -53,7 +53,12 @@ import { TbFunction } from '@shared/models/js-function.models'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { WidgetActionCallbacks } from '@home/components/widget/action/manage-widget-actions.component.models'; import { isDefinedAndNotNull } from '@core/utils'; -import { defaultMobilePageMap, getDefaultMobileMenuItem, WEB_URL_REGEX } from '@shared/models/mobile-app.models'; +import { + defaultMobilePageMap, + getDefaultMobileMenuItem, + WEB_URL_REGEX, + withDefaultWebScheme +} from '@shared/models/mobile-app.models'; @Component({ selector: 'tb-mobile-action-editor', @@ -194,7 +199,8 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit if (this.mobileActionFormGroup.valid && this.mobileActionTypeFormGroup.valid) { descriptor = { ...this.mobileActionFormGroup.getRawValue(), ...this.mobileActionTypeFormGroup.getRawValue() }; if (descriptor.type === WidgetMobileActionType.navigateTo) { - descriptor.navigationTarget = this.mobileActionTypeFormGroup.get('navigationTarget').value; + const target: MobileNavigationTarget = this.mobileActionTypeFormGroup.get('navigationTarget').value; + descriptor.navigationTarget = target.url ? {...target, url: withDefaultWebScheme(target.url)} : target; } } this.propagateChange(descriptor); diff --git a/ui-ngx/src/app/modules/home/pages/mobile/bundes/layout/custom-mobile-page.component.ts b/ui-ngx/src/app/modules/home/pages/mobile/bundes/layout/custom-mobile-page.component.ts index b6df3331bc..b3a4f60359 100644 --- a/ui-ngx/src/app/modules/home/pages/mobile/bundes/layout/custom-mobile-page.component.ts +++ b/ui-ngx/src/app/modules/home/pages/mobile/bundes/layout/custom-mobile-page.component.ts @@ -14,7 +14,8 @@ import { CustomMobilePage, MobilePageType, mobilePageTypeTranslations, - WEB_URL_REGEX + WEB_URL_REGEX, + withDefaultWebScheme } from '@shared/models/mobile-app.models'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { getCurrentAuthUser } from '@core/auth/auth.selectors'; @@ -89,7 +90,9 @@ export class CustomMobilePageComponent implements ControlValueAccessor, Validato this.customMobilePageForm.valueChanges.pipe( takeUntilDestroyed() - ).subscribe((value) => this.propagateChange(value)) + ).subscribe((value: CustomMobilePage) => + this.propagateChange(value?.url ? {...value, url: withDefaultWebScheme(value.url)} : value) + ); } registerOnChange(fn: any) { diff --git a/ui-ngx/src/app/shared/models/mobile-app.models.ts b/ui-ngx/src/app/shared/models/mobile-app.models.ts index 051bb79621..930558a4ff 100644 --- a/ui-ngx/src/app/shared/models/mobile-app.models.ts +++ b/ui-ngx/src/app/shared/models/mobile-app.models.ts @@ -11,6 +11,12 @@ import { MobileSelfRegistrationParams } from '@shared/models/self-register.model export const WEB_URL_REGEX = /^(https?:\/\/)?(localhost|([\p{L}\p{M}\w-]+\.)+[\p{L}\p{M}\w-]+)(:\d+)?(\/[\w\-._~:/?#[\]@!$&'()*+,;=%\p{L}\p{N}]*)?$/u; +// WEB_URL_REGEX accepts an address without a scheme, which the mobile app's web view can't open. +export const withDefaultWebScheme = (url: string): string => { + const value = url?.trim(); + return !value || /^https?:\/\//i.test(value) ? value : `https://${value}`; +}; + export interface QrCodeSettings extends HasTenantId { useSystemSettings: boolean; useDefaultApp: boolean;