|
|
|
@ -24,6 +24,9 @@ import { |
|
|
|
} from '@angular/forms'; |
|
|
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|
|
|
import { |
|
|
|
ActionConfig, |
|
|
|
ProvisionType, |
|
|
|
provisionTypeTranslationMap, |
|
|
|
WidgetActionType, |
|
|
|
WidgetMobileActionDescriptor, |
|
|
|
WidgetMobileActionType, |
|
|
|
@ -35,6 +38,7 @@ import { |
|
|
|
getDefaultGetPhoneNumberFunction, |
|
|
|
getDefaultHandleEmptyResultFunction, |
|
|
|
getDefaultHandleErrorFunction, |
|
|
|
getDefaultHandleNonMobileFallBackFunction, |
|
|
|
getDefaultProcessImageFunction, |
|
|
|
getDefaultProcessLaunchResultFunction, |
|
|
|
getDefaultProcessLocationFunction, |
|
|
|
@ -68,6 +72,12 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit |
|
|
|
|
|
|
|
functionScopeVariables: string[]; |
|
|
|
|
|
|
|
actionConfig: ActionConfig[]; |
|
|
|
commonActionConfig: ActionConfig[]; |
|
|
|
|
|
|
|
provisionTypes: string[] = Object.keys(ProvisionType); |
|
|
|
provisionTypeTranslationMap = provisionTypeTranslationMap; |
|
|
|
|
|
|
|
private requiredValue: boolean; |
|
|
|
get required(): boolean { |
|
|
|
return this.requiredValue; |
|
|
|
@ -99,8 +109,10 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit |
|
|
|
this.mobileActionFormGroup = this.fb.group({ |
|
|
|
type: [null, Validators.required], |
|
|
|
handleEmptyResultFunction: [null], |
|
|
|
handleErrorFunction: [null] |
|
|
|
handleErrorFunction: [null], |
|
|
|
handleNonMobileFallbackFunction: [null] |
|
|
|
}); |
|
|
|
this.getCommonActionConfigs(); |
|
|
|
this.mobileActionFormGroup.get('type').valueChanges.pipe( |
|
|
|
takeUntilDestroyed(this.destroyRef) |
|
|
|
).subscribe((type: WidgetMobileActionType) => { |
|
|
|
@ -109,6 +121,7 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit |
|
|
|
action = {...action, ...this.mobileActionTypeFormGroup.value}; |
|
|
|
} |
|
|
|
this.updateMobileActionType(type, action); |
|
|
|
this.getActionConfigs(); |
|
|
|
}); |
|
|
|
this.mobileActionFormGroup.valueChanges.pipe( |
|
|
|
takeUntilDestroyed(this.destroyRef) |
|
|
|
@ -133,10 +146,14 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit |
|
|
|
} |
|
|
|
|
|
|
|
writeValue(value: WidgetMobileActionDescriptor | null): void { |
|
|
|
this.mobileActionFormGroup.patchValue({type: value?.type, |
|
|
|
handleEmptyResultFunction: value?.handleEmptyResultFunction, |
|
|
|
handleErrorFunction: value?.handleErrorFunction}, {emitEvent: false}); |
|
|
|
this.mobileActionFormGroup.patchValue({ |
|
|
|
type: value?.type, |
|
|
|
handleEmptyResultFunction: value?.handleEmptyResultFunction, |
|
|
|
handleErrorFunction: value?.handleErrorFunction, |
|
|
|
handleNonMobileFallbackFunction: value?.handleNonMobileFallbackFunction |
|
|
|
}, {emitEvent: false}); |
|
|
|
this.updateMobileActionType(value?.type, value); |
|
|
|
this.getActionConfigs(); |
|
|
|
} |
|
|
|
|
|
|
|
private updateModel() { |
|
|
|
@ -164,6 +181,12 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit |
|
|
|
handleErrorFunction = getDefaultHandleErrorFunction(type); |
|
|
|
this.mobileActionFormGroup.patchValue({handleErrorFunction}, {emitEvent: false}); |
|
|
|
} |
|
|
|
let handleNonMobileFallbackFunction = action?.handleNonMobileFallbackFunction; |
|
|
|
const defaultHandleNonMobileFallbackFunction = getDefaultHandleNonMobileFallBackFunction(); |
|
|
|
if (defaultHandleNonMobileFallbackFunction !== handleNonMobileFallbackFunction) { |
|
|
|
handleNonMobileFallbackFunction = getDefaultHandleNonMobileFallBackFunction(); |
|
|
|
this.mobileActionFormGroup.patchValue({handleNonMobileFallbackFunction}, {emitEvent: false}); |
|
|
|
} |
|
|
|
} |
|
|
|
this.mobileActionTypeFormGroup = this.fb.group({}); |
|
|
|
if (type) { |
|
|
|
@ -183,6 +206,10 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit |
|
|
|
'processImageFunction', |
|
|
|
this.fb.control(processImageFunction, []) |
|
|
|
); |
|
|
|
this.mobileActionTypeFormGroup.addControl( |
|
|
|
'saveToGallery', |
|
|
|
this.fb.control(action?.saveToGallery || false, []) |
|
|
|
); |
|
|
|
break; |
|
|
|
case WidgetMobileActionType.mapDirection: |
|
|
|
case WidgetMobileActionType.mapLocation: |
|
|
|
@ -267,6 +294,10 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit |
|
|
|
'handleProvisionSuccessFunction', |
|
|
|
this.fb.control(handleProvisionSuccessFunction, [Validators.required]) |
|
|
|
); |
|
|
|
this.mobileActionTypeFormGroup.addControl( |
|
|
|
'provisionType', |
|
|
|
this.fb.control(action?.provisionType || ProvisionType.auto, []) |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
this.mobileActionTypeFormGroup.valueChanges.pipe( |
|
|
|
@ -276,5 +307,108 @@ export class MobileActionEditorComponent implements ControlValueAccessor, OnInit |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
getActionConfigs() { |
|
|
|
const type = this.mobileActionFormGroup.get('type').value; |
|
|
|
this.actionConfig = []; |
|
|
|
switch (type) { |
|
|
|
case this.mobileActionType.deviceProvision: |
|
|
|
this.actionConfig.push({ |
|
|
|
title: 'widget-action.mobile.handle-provision-success-function', |
|
|
|
formControlName: 'handleProvisionSuccessFunction', |
|
|
|
functionName: 'handleProvisionSuccess', |
|
|
|
functionArgs: ['deviceName', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'] |
|
|
|
}); |
|
|
|
break; |
|
|
|
case this.mobileActionType.mapDirection: |
|
|
|
case this.mobileActionType.mapLocation: |
|
|
|
this.actionConfig.push({ |
|
|
|
title: 'widget-action.mobile.get-location-function', |
|
|
|
formControlName: 'getLocationFunction', |
|
|
|
functionName: 'getLocation', |
|
|
|
functionArgs: ['$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_get_location_fn' |
|
|
|
}); |
|
|
|
this.actionConfig.push({ |
|
|
|
title: 'widget-action.mobile.process-launch-result-function', |
|
|
|
formControlName: 'processLaunchResultFunction', |
|
|
|
functionName: 'processLaunchResult', |
|
|
|
functionArgs: ['launched', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_process_launch_result_fn' |
|
|
|
}); |
|
|
|
break; |
|
|
|
case this.mobileActionType.makePhoneCall: |
|
|
|
this.actionConfig.push({ |
|
|
|
title: 'widget-action.mobile.get-phone-number-function', |
|
|
|
formControlName: 'getPhoneNumberFunction', |
|
|
|
functionName: 'getPhoneNumber', |
|
|
|
functionArgs: ['$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_get_phone_number_fn' |
|
|
|
}); |
|
|
|
this.actionConfig.push({ |
|
|
|
title: 'widget-action.mobile.process-launch-result-function', |
|
|
|
formControlName: 'processLaunchResultFunction', |
|
|
|
functionName: 'processLaunchResult', |
|
|
|
functionArgs: ['launched', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_process_launch_result_fn' |
|
|
|
}); |
|
|
|
break; |
|
|
|
case this.mobileActionType.takePhoto: |
|
|
|
case this.mobileActionType.takePictureFromGallery: |
|
|
|
case this.mobileActionType.takeScreenshot: |
|
|
|
this.actionConfig.push({ |
|
|
|
title: 'widget-action.mobile.process-image-function', |
|
|
|
formControlName: 'processImageFunction', |
|
|
|
functionName: 'processImage', |
|
|
|
functionArgs: ['imageUrl', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_process_image_fn' |
|
|
|
}); |
|
|
|
break; |
|
|
|
case this.mobileActionType.scanQrCode: |
|
|
|
this.actionConfig.push({ |
|
|
|
title: 'widget-action.mobile.process-qr-code-function', |
|
|
|
formControlName: 'processQrCodeFunction', |
|
|
|
functionName: 'processQrCode', |
|
|
|
functionArgs: ['code', 'format', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_process_qr_code_fn' |
|
|
|
}); |
|
|
|
break; |
|
|
|
case this.mobileActionType.getLocation: |
|
|
|
this.actionConfig.push({ |
|
|
|
title: 'widget-action.mobile.process-location-function', |
|
|
|
formControlName: 'processLocationFunction', |
|
|
|
functionName: 'processLocation', |
|
|
|
functionArgs: ['latitude', 'longitude', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_process_location_fn' |
|
|
|
}); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
getCommonActionConfigs() { |
|
|
|
this.commonActionConfig = [ |
|
|
|
{ |
|
|
|
title: 'widget-action.mobile.handle-empty-result-function', |
|
|
|
formControlName: 'handleEmptyResultFunction', |
|
|
|
functionName: 'handleEmptyResult', |
|
|
|
functionArgs: ['$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_handle_empty_result_fn' |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: 'widget-action.mobile.handle-error-function', |
|
|
|
formControlName: 'handleErrorFunction', |
|
|
|
functionName: 'handleError', |
|
|
|
functionArgs: ['error', '$event', 'widgetContext', 'entityId', 'entityName', 'additionalParams', 'entityLabel'], |
|
|
|
helpId: 'widget/action/mobile_handle_error_fn' |
|
|
|
}, |
|
|
|
{ |
|
|
|
title: 'widget-action.mobile.handle-non-mobile-fallback-function', |
|
|
|
formControlName: 'handleNonMobileFallbackFunction', |
|
|
|
functionName: 'handleNonMobileFallback', |
|
|
|
functionArgs: ['$event', 'widgetContext'], |
|
|
|
helpId: 'widget/action/mobile_handle_non_mobile_fallback_fn' |
|
|
|
} |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
protected readonly WidgetActionType = WidgetActionType; |
|
|
|
} |
|
|
|
|