Browse Source

fix(ui): add https:// to mobile web view URLs saved without a scheme

The mobile bundle layout editor accepts a web view URL without a scheme
and saved it as typed, and the mobile app can't load such an address.
The layout page and the Navigate to page action now save it with
https:// in front, as the Home quick links already do.
pull/16890/head
Artem Babak 13 hours ago
parent
commit
13c911272b
  1. 10
      ui-ngx/src/app/modules/home/components/widget/lib/settings/common/action/mobile-action-editor.component.ts
  2. 7
      ui-ngx/src/app/modules/home/pages/mobile/bundes/layout/custom-mobile-page.component.ts
  3. 6
      ui-ngx/src/app/shared/models/mobile-app.models.ts

10
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);

7
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) {

6
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;

Loading…
Cancel
Save