WIP: basic implmentation
This commit is contained in:
parent
5440e8e5b6
commit
a5960728c4
@ -21,6 +21,12 @@
|
||||
/* End PBXAggregateTarget section */
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
016FF6EE259A4E6300F5E4AA /* ClientParameterModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */; };
|
||||
016FF6F2259A4FCC00F5E4AA /* ClientParameterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */; };
|
||||
016FF6F6259B9AED00F5E4AA /* ClientParameterRegistry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */; };
|
||||
016FF6FC259BA27E00F5E4AA /* ClientParameterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */; };
|
||||
016FF706259D180000F5E4AA /* ActionHandler+ClientParameters.swift in Sources */ = {isa = PBXBuildFile; fileRef = 016FF705259D180000F5E4AA /* ActionHandler+ClientParameters.swift */; };
|
||||
01934FE725A4FFC2003DCD67 /* ClientParameterActionProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */; };
|
||||
01C851CF23CF7B260021F976 /* JSONMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851CE23CF7B260021F976 /* JSONMap.swift */; };
|
||||
01C851D123CF97FE0021F976 /* ActionBackModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D023CF97FE0021F976 /* ActionBackModel.swift */; };
|
||||
01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */; };
|
||||
@ -144,6 +150,12 @@
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterModelProtocol.swift; sourceTree = "<group>"; };
|
||||
016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterModel.swift; sourceTree = "<group>"; };
|
||||
016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterRegistry.swift; sourceTree = "<group>"; };
|
||||
016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterProtocol.swift; sourceTree = "<group>"; };
|
||||
016FF705259D180000F5E4AA /* ActionHandler+ClientParameters.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "ActionHandler+ClientParameters.swift"; sourceTree = "<group>"; };
|
||||
01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientParameterActionProtocol.swift; sourceTree = "<group>"; };
|
||||
01C851CE23CF7B260021F976 /* JSONMap.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JSONMap.swift; sourceTree = "<group>"; };
|
||||
01C851D023CF97FE0021F976 /* ActionBackModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionBackModel.swift; sourceTree = "<group>"; };
|
||||
01DF561321F90ADC00CC099B /* Dictionary+MFConvenience.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Dictionary+MFConvenience.swift"; sourceTree = "<group>"; };
|
||||
@ -286,6 +298,18 @@
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
016FF6EC259A4E3E00F5E4AA /* Client Parameters */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
016FF6FB259BA27E00F5E4AA /* ClientParameterProtocol.swift */,
|
||||
016FF6ED259A4E6300F5E4AA /* ClientParameterModelProtocol.swift */,
|
||||
016FF6F1259A4FCC00F5E4AA /* ClientParameterModel.swift */,
|
||||
016FF6F5259B9AED00F5E4AA /* ClientParameterRegistry.swift */,
|
||||
01934FE625A4FFC2003DCD67 /* ClientParameterActionProtocol.swift */,
|
||||
);
|
||||
path = "Client Parameters";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
8876D5BF1FB50A9E00EB2E3D = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -405,6 +429,7 @@
|
||||
946EE1B6237B66630036751F /* ActionType */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
016FF6EC259A4E3E00F5E4AA /* Client Parameters */,
|
||||
01F2A03523A80A7300D954D8 /* ActionModelProtocol.swift */,
|
||||
946EE1BB237B691A0036751F /* ActionOpenPageModel.swift */,
|
||||
01F2A03823A812DD00D954D8 /* ActionOpenUrlModel.swift */,
|
||||
@ -560,6 +585,7 @@
|
||||
AFBB96B51FBA3CEC0008D868 /* MVMCoreActionDelegateProtocol.h */,
|
||||
AFBB96B61FBA3CEC0008D868 /* MVMCoreActionHandler.h */,
|
||||
AFBB96B71FBA3CEC0008D868 /* MVMCoreActionHandler.m */,
|
||||
016FF705259D180000F5E4AA /* ActionHandler+ClientParameters.swift */,
|
||||
);
|
||||
path = ActionHandling;
|
||||
sourceTree = "<group>";
|
||||
@ -784,6 +810,7 @@
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
AFED77A71FCCA29400BAE689 /* MVMCoreViewControllerProgrammaticMappingObject.m in Sources */,
|
||||
016FF706259D180000F5E4AA /* ActionHandler+ClientParameters.swift in Sources */,
|
||||
946EE1A7237B5B1C0036751F /* ModelRegistry.swift in Sources */,
|
||||
AFBB96641FBA3A570008D868 /* MVMCoreLoadHandler.m in Sources */,
|
||||
AFFCFA671FCCC0D700FD0730 /* MVMCoreLoadingOverlayHandler.m in Sources */,
|
||||
@ -820,6 +847,7 @@
|
||||
AFED77A31FCCA29400BAE689 /* MVMCoreViewControllerNibMappingObject.m in Sources */,
|
||||
8876D5EB1FB50AB000EB2E3D /* NSDecimalNumber+MFConvenience.m in Sources */,
|
||||
01F2A03923A812DD00D954D8 /* ActionOpenUrlModel.swift in Sources */,
|
||||
01934FE725A4FFC2003DCD67 /* ClientParameterActionProtocol.swift in Sources */,
|
||||
AFBB96351FBA34310008D868 /* MVMCoreErrorConstants.m in Sources */,
|
||||
AF43A5881FBB67D6008E9347 /* MVMCoreActionUtility.m in Sources */,
|
||||
AFED77A61FCCA29400BAE689 /* MVMCoreViewControllerStoryBoardMappingObject.m in Sources */,
|
||||
@ -830,6 +858,7 @@
|
||||
8876D5F51FB50AB000EB2E3D /* UILabel+MFCustom.m in Sources */,
|
||||
AFBB96B31FBA3B590008D868 /* MVMCoreGetterUtility.m in Sources */,
|
||||
AF43A7071FC4D7A2008E9347 /* MVMCoreObject.m in Sources */,
|
||||
016FF6F6259B9AED00F5E4AA /* ClientParameterRegistry.swift in Sources */,
|
||||
94C014D924212360005811A9 /* ActionSettingModel.swift in Sources */,
|
||||
D2DEDCB723C63F3B00C44CC4 /* Clamping.swift in Sources */,
|
||||
01DF561421F90ADC00CC099B /* Dictionary+MFConvenience.swift in Sources */,
|
||||
@ -845,10 +874,13 @@
|
||||
AFBB96941FBA3A9A0008D868 /* MVMCorePresentAnimationOperation.m in Sources */,
|
||||
94C014D524211AF0005811A9 /* ActionCancelModel.swift in Sources */,
|
||||
AF43A5841FBB66DE008E9347 /* MVMCoreConstants.m in Sources */,
|
||||
016FF6F2259A4FCC00F5E4AA /* ClientParameterModel.swift in Sources */,
|
||||
D2DEDCBB23C65BC300C44CC4 /* Percent.swift in Sources */,
|
||||
AFBB966A1FBA3A570008D868 /* MVMCoreLoadRequestOperation.m in Sources */,
|
||||
016FF6FC259BA27E00F5E4AA /* ClientParameterProtocol.swift in Sources */,
|
||||
8876D5F31FB50AB000EB2E3D /* UIFont+MFSpacing.m in Sources */,
|
||||
D282AAB82240342D00C46919 /* NSNumber+Extension.swift in Sources */,
|
||||
016FF6EE259A4E6300F5E4AA /* ClientParameterModelProtocol.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@ -0,0 +1,41 @@
|
||||
//
|
||||
// ActionHandler+ClientParameters.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/30/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
//- (void)handleActionWithDictionary:(nullable NSDictionary *)dictionary additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
//
|
||||
// NSString *action = [dictionary stringForKey:KeyActionType];
|
||||
// [self handleAction:action actionInformation:dictionary additionalData:additionalData delegate:delegate];
|
||||
//}
|
||||
|
||||
public extension MVMCoreActionHandler {
|
||||
|
||||
@objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) {
|
||||
|
||||
guard let paramsList = actionMap?.optionalArrayForChainOfKeysOrIndexes(["clientParameters", "list"]) as? [[String : Any]] else {
|
||||
completionHandler(actionMap)
|
||||
return
|
||||
}
|
||||
|
||||
MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.startLoading()
|
||||
ClientParameterRegistry.injectParams(with: paramsList) { (clientParams) in
|
||||
guard let clientParams = clientParams else {
|
||||
completionHandler(actionMap)
|
||||
return
|
||||
}
|
||||
var extraParams:[String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:]
|
||||
extraParams.merge(clientParams) { (_, new) in new }
|
||||
var actionMapM = actionMap
|
||||
actionMapM?[KeyExtraParameters] = extraParams
|
||||
|
||||
MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.stopLoading(true)
|
||||
completionHandler(actionMapM)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,22 +107,28 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
|
||||
// Loads the given page type.
|
||||
NSString *pageType = [actionInformation stringForKey:KeyPageType];
|
||||
if (pageType.length > 0) {
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation];
|
||||
|
||||
[self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
|
||||
if (pageType.length == 0) {
|
||||
// No page type to load, show error.
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeOpen]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
return;
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) {
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionMap];
|
||||
|
||||
[weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
if ([delegateObject.actionDelegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) {
|
||||
[delegateObject.actionDelegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData];
|
||||
} else {
|
||||
[MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
}];
|
||||
} else {
|
||||
|
||||
// No page type to load, show error.
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeOpen]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
}
|
||||
};
|
||||
|
||||
[self preprocessRequest:actionInformation actionBlock:performAction];
|
||||
}
|
||||
|
||||
- (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
@ -266,23 +272,28 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
#pragma mark - open url functions
|
||||
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
|
||||
// Gets the app url
|
||||
NSURL *appURL = nil;
|
||||
NSString *appURLString = [actionInformation string:KeyLinkAwayAppURL];
|
||||
if (appURLString.length > 0) {
|
||||
appURL = [NSURL URLWithString:appURLString];
|
||||
}
|
||||
|
||||
// Gets the browser url
|
||||
NSURL *otherURL = nil;
|
||||
NSString *otherURLString = [actionInformation string:KeyLinkAwayURL];
|
||||
if (otherURLString.length > 0) {
|
||||
otherURL = [NSURL URLWithString:otherURLString];
|
||||
}
|
||||
|
||||
// Provide the URL and App URL to be modified if needed by a subclass or delegate.
|
||||
[self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) {
|
||||
// Gets the app url
|
||||
NSURL *appURL = nil;
|
||||
NSString *appURLString = [actionMap string:KeyLinkAwayAppURL];
|
||||
if (appURLString.length > 0) {
|
||||
appURL = [NSURL URLWithString:appURLString];
|
||||
}
|
||||
|
||||
// Gets the browser url
|
||||
NSURL *otherURL = nil;
|
||||
NSString *otherURLString = [actionMap string:KeyLinkAwayURL];
|
||||
if (otherURLString.length > 0) {
|
||||
otherURL = [NSURL URLWithString:otherURLString];
|
||||
}
|
||||
|
||||
// Provide the URL and App URL to be modified if needed by a subclass or delegate.
|
||||
[self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject];
|
||||
};
|
||||
|
||||
[self preprocessRequest:actionInformation actionBlock:performAction];
|
||||
}
|
||||
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
@ -411,21 +422,39 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
|
||||
// Loads the given page type.
|
||||
NSString *pageType = [actionInformation stringForKey:KeyPageType];
|
||||
if (pageType.length > 0) {
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionInformation];
|
||||
|
||||
[self updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
|
||||
if (pageType.length == 0) {
|
||||
// No page type to load, show error.
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeOpen]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate];
|
||||
return;
|
||||
}
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) {
|
||||
MVMCoreRequestParameters *requestParameters = [[MVMCoreRequestParameters alloc] initWithActionMap:actionMap];
|
||||
|
||||
[weakSelf updateRequestParametersBeforeHandleOpenPageAction:requestParameters callBack:^(MVMCoreRequestParameters * _Nonnull requestParameters) {
|
||||
if ([delegate respondsToSelector:@selector(handleOpenPageForRequestParameters:actionInformation:additionalData:)]) {
|
||||
[delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionInformation additionalData:additionalData];
|
||||
[delegate handleOpenPageForRequestParameters:requestParameters actionInformation:actionMap additionalData:additionalData];
|
||||
} else {
|
||||
[MVMCoreActionHandler defaultHandleOpenPageForRequestParameters:requestParameters additionalData:additionalData delegate:delegate];
|
||||
}
|
||||
}];
|
||||
};
|
||||
|
||||
[self preprocessRequest:actionInformation actionBlock:performAction];
|
||||
}
|
||||
|
||||
- (void)preprocessRequest:(nullable NSDictionary *)actionInformation actionBlock:(nullable void (^)(NSDictionary*))actionBlock {
|
||||
// Check for client params and fetch the parameters
|
||||
if ([actionInformation dict:@"clientParameters"]) {
|
||||
[self setClientParameterWith:actionInformation
|
||||
completionHandler:^(NSDictionary<NSString *,id> * _Nullable actionDict) {
|
||||
actionBlock(actionDict);
|
||||
}];
|
||||
} else {
|
||||
|
||||
// No page type to load, show error.
|
||||
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeNoPageType domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeOpen]];
|
||||
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate];
|
||||
actionBlock(actionInformation);
|
||||
}
|
||||
}
|
||||
|
||||
@ -524,23 +553,28 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}
|
||||
|
||||
- (void)linkAwayAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
// Gets the app url
|
||||
NSURL *appURL = nil;
|
||||
NSString *appURLString = [actionInformation string:KeyLinkAwayAppURL];
|
||||
if (appURLString.length > 0) {
|
||||
appURL = [NSURL URLWithString:appURLString];
|
||||
}
|
||||
|
||||
// Gets the browser url
|
||||
NSURL *otherURL = nil;
|
||||
NSString *otherURLString = [actionInformation string:KeyLinkAwayURL];
|
||||
if (otherURLString.length > 0) {
|
||||
otherURL = [NSURL URLWithString:otherURLString];
|
||||
}
|
||||
|
||||
// Provide the URL and App URL to be modified if needed by a subclass or delegate.
|
||||
[self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionInformation additionalData:additionalData delegate:delegate];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
void (^performAction)(NSDictionary*) = ^(NSDictionary* actionMap) {
|
||||
// Gets the app url
|
||||
NSURL *appURL = nil;
|
||||
NSString *appURLString = [actionMap string:KeyLinkAwayAppURL];
|
||||
if (appURLString.length > 0) {
|
||||
appURL = [NSURL URLWithString:appURLString];
|
||||
}
|
||||
|
||||
// Gets the browser url
|
||||
NSURL *otherURL = nil;
|
||||
NSString *otherURLString = [actionMap string:KeyLinkAwayURL];
|
||||
if (otherURLString.length > 0) {
|
||||
otherURL = [NSURL URLWithString:otherURLString];
|
||||
}
|
||||
|
||||
// Provide the URL and App URL to be modified if needed by a subclass or delegate.
|
||||
[self prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate];
|
||||
};
|
||||
|
||||
[self preprocessRequest:actionInformation actionBlock:performAction];
|
||||
}
|
||||
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
|
||||
@objcMembers open class ActionOpenPageModel: ActionModelProtocol {
|
||||
@objcMembers open class ActionOpenPageModel: ActionModelProtocol, ClientParameterActionProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
@ -20,7 +20,8 @@
|
||||
public var presentationStyle: String?
|
||||
public var tabBarIndex: Int?
|
||||
public var background: Bool?
|
||||
|
||||
public var clientParameterModel: ClientParameterModel?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initialzier
|
||||
//--------------------------------------------------
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
|
||||
@objcMembers public class ActionOpenUrlModel: ActionModelProtocol {
|
||||
@objcMembers public class ActionOpenUrlModel: ActionModelProtocol, ClientParameterActionProtocol {
|
||||
//--------------------------------------------------
|
||||
// MARK: - Properties
|
||||
//--------------------------------------------------
|
||||
@ -30,6 +30,7 @@
|
||||
public var dontShowProgress: Bool?
|
||||
public var headerParameters: JSONValueDictionary?
|
||||
public var enableNativeScroll: Bool?
|
||||
public var clientParameterModel: ClientParameterModel?
|
||||
|
||||
//--------------------------------------------------
|
||||
// MARK: - Initialzier
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
//
|
||||
// ClientParameterActionProtocol.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 1/5/21.
|
||||
// Copyright © 2021 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol ClientParameterActionProtocol {
|
||||
var clientParameterModel: ClientParameterModel? { get set }
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
//
|
||||
// ClientParameterModel.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/28/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public class ClientParameterModel: Codable {
|
||||
var timeout: Double?
|
||||
var list: [ClientParameterModelProtocol]
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
case timeout
|
||||
case list
|
||||
}
|
||||
|
||||
required public init(from decoder: Decoder) throws {
|
||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||
timeout = try typeContainer.decodeIfPresent(Double.self, forKey: .timeout)
|
||||
list = try typeContainer.decodeModels(codingKey: .list)
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||
try container.encode(timeout, forKey: .timeout)
|
||||
try container.encodeModels(list, forKey: .list)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
//
|
||||
// ClientParameterProtocol.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/28/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol ClientParameterModelProtocol: ModelProtocol {
|
||||
var type: String { get }
|
||||
var inputParameters: JSONValueDictionary? { get set }
|
||||
}
|
||||
|
||||
public extension ClientParameterModelProtocol {
|
||||
|
||||
var type: String {
|
||||
get { Self.identifier }
|
||||
}
|
||||
|
||||
static var categoryCodingKey: String {
|
||||
return "type"
|
||||
}
|
||||
|
||||
static var categoryName: String {
|
||||
return "\(ClientParameterModelProtocol.self)"
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,35 @@
|
||||
//
|
||||
// ClientParameterProtocol.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/29/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
public protocol ClientParameterProtocol {
|
||||
init()
|
||||
static var name: String { get }
|
||||
func clientParameter(with paramModel: ClientParameterModelProtocol?) -> [String: Any]?
|
||||
}
|
||||
|
||||
extension ClientParameterProtocol {
|
||||
/// Handle encoding and errors
|
||||
public func getJSON(with paramModel: ClientParameterModelProtocol?) -> JSONDictionary? {
|
||||
guard let dataModel = paramModel,
|
||||
let json = dataModel.toJSON() else {
|
||||
// JSON parsing failed
|
||||
if let errorObject = MVMCoreErrorObject(title: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorTitle),
|
||||
message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess),
|
||||
messageToLog: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess),
|
||||
code: ErrorCode.parsingJSON.rawValue,
|
||||
domain: ErrorDomainNative,
|
||||
location: String(describing: Self.name)) {
|
||||
//MFLoggingHandler.addError(toLog: errorObject)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return json
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,79 @@
|
||||
//
|
||||
// ClientParameterRegistry.swift
|
||||
// MVMCore
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 12/29/20.
|
||||
// Copyright © 2020 myverizon. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
|
||||
@objcMembers open class ClientParameterRegistry: NSObject {
|
||||
|
||||
public static let shared = ClientParameterRegistry()
|
||||
private var mapping: [String: ClientParameterProtocol.Type] = [:]
|
||||
|
||||
public func register<T:ClientParameterProtocol>(param: T.Type) {
|
||||
mapping[T.name] = param
|
||||
}
|
||||
|
||||
public func createParam(_ actionType: String) -> ClientParameterProtocol? {
|
||||
guard let patamType = mapping[actionType] else { return nil }
|
||||
return patamType.init()
|
||||
}
|
||||
|
||||
static func injectParams(with paramsModelList: [[String: Any]]?,
|
||||
completionHandler:@escaping ([String: Any]?) -> ()) {
|
||||
|
||||
let clientParameterRegistry = ClientParameterRegistry.shared
|
||||
guard let paramsModelList = paramsModelList else {
|
||||
completionHandler(nil)
|
||||
return
|
||||
}
|
||||
|
||||
var paramsList: [String: Any] = [:]
|
||||
MVMCoreDispatchUtility.performSyncBlock( inBackground: { () -> Void in
|
||||
for param in paramsModelList {
|
||||
if let clientParam = clientParameterRegistry.injectParam(param) {
|
||||
paramsList.merge(clientParam) { (_, new) in new }
|
||||
}
|
||||
}
|
||||
})
|
||||
completionHandler(paramsList)
|
||||
print("")
|
||||
}
|
||||
|
||||
func injectParam( _ param: [String: Any]) -> [String: Any]? {
|
||||
if let paramModel = try? ClientParameterRegistry.getModel(param),
|
||||
let param = ClientParameterRegistry.shared.createParam(paramModel.type) {
|
||||
return param.clientParameter(with: paramModel)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
/// Add all registry here.
|
||||
public static func registerParameters() {
|
||||
|
||||
}
|
||||
|
||||
/// Register Default Core Bridge Objects
|
||||
public static func register<T:ClientParameterProtocol, M: ModelProtocol>(parameter: T.Type, type: M.Type) {
|
||||
try? ModelRegistry.register(type)
|
||||
ClientParameterRegistry.shared.register(param: parameter)
|
||||
}
|
||||
|
||||
public static func getModel(_ json: [String: Any]) throws -> ClientParameterModelProtocol {
|
||||
guard let paramType = json.optionalStringForKey("type") else {
|
||||
throw ModelRegistry.Error.other(message: "parameterType missing")
|
||||
}
|
||||
guard let type = ModelRegistry.getType(for: paramType, with: ClientParameterModelProtocol.self) else {
|
||||
throw ModelRegistry.Error.decoderErrorModelNotMapped()
|
||||
}
|
||||
guard let model = try type.decode(jsonDict: json) as? ClientParameterModelProtocol else {
|
||||
throw ModelRegistry.Error.decoderError
|
||||
}
|
||||
return model
|
||||
}
|
||||
}
|
||||
@ -17,6 +17,7 @@
|
||||
if (self = [super init]) {
|
||||
self.session = [self createNSURLSession];
|
||||
[ModelMapping registerObjects];
|
||||
[ClientParameterRegistry registerParameters];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "MVMCoreRequestParameters.h"
|
||||
|
||||
#define ENABLE_HARD_CODED_RESPONSE 0 && DEBUG
|
||||
#define ENABLE_HARD_CODED_RESPONSE 1 && DEBUG
|
||||
|
||||
#if ENABLE_HARD_CODED_RESPONSE
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user