Merge branch 'feature/action_client_parameters_map' into 'feature/action_client_parameters'
map See merge request BPHV_MIPS/mvm_core!133
This commit is contained in:
commit
72bd5edc20
@ -10,7 +10,8 @@ import Foundation
|
||||
|
||||
public extension MVMCoreActionHandler {
|
||||
|
||||
@objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) throws {
|
||||
/// Iterates throw the clientParameters list. Gets values from the individul handlers and attaches the paramters to extraParameters.
|
||||
@objc func setClientParameter(with actionMap: [String: Any]?, completionHandler: @escaping ([String : Any]?) -> ()) {
|
||||
|
||||
guard let clientParameters = actionMap?.optionalDictionaryForKey("clientParameters") else {
|
||||
completionHandler(actionMap)
|
||||
@ -29,20 +30,27 @@ public extension MVMCoreActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
try ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in
|
||||
guard let clientParams = clientParams else {
|
||||
do {
|
||||
try ClientParameterRegistry.injectParameters(with: clientParameters) { (clientParams) in
|
||||
guard let clientParams = clientParams else {
|
||||
stopLoadingOverlay()
|
||||
completionHandler(actionMap)
|
||||
return
|
||||
}
|
||||
|
||||
var extraParams: [String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:]
|
||||
extraParams.merge(clientParams) { (_, new) in new }
|
||||
var actionMapM = actionMap
|
||||
actionMapM?[KeyExtraParameters] = extraParams
|
||||
|
||||
stopLoadingOverlay()
|
||||
completionHandler(actionMap)
|
||||
return
|
||||
completionHandler(actionMapM)
|
||||
}
|
||||
|
||||
var extraParams: [String : Any] = actionMap?.optionalDictionaryForKey(KeyExtraParameters) ?? [:]
|
||||
extraParams.merge(clientParams) { (_, new) in new }
|
||||
var actionMapM = actionMap
|
||||
actionMapM?[KeyExtraParameters] = extraParams
|
||||
|
||||
} catch {
|
||||
stopLoadingOverlay()
|
||||
completionHandler(actionMapM)
|
||||
completionHandler(actionMap)
|
||||
MVMCoreLoggingHandler.logDebugMessage(withDelegate: "Error clientParamters: \(error)")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,7 +128,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}];
|
||||
};
|
||||
|
||||
[self preprocessRequest:actionInformation actionBlock:performAction];
|
||||
[self setClientParameterWith:actionInformation completionHandler:performAction];
|
||||
}
|
||||
|
||||
- (void)shareAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
@ -293,7 +293,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
[weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegateObject:delegateObject];
|
||||
};
|
||||
|
||||
[self preprocessRequest:actionInformation actionBlock:performAction];
|
||||
[self setClientParameterWith:actionInformation completionHandler:performAction];
|
||||
}
|
||||
|
||||
- (void)prepareLinkAwayWithURL:(nullable NSURL *)url appURL:(nullable NSURL *)appURL actionInformation:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
|
||||
@ -443,27 +443,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
}];
|
||||
};
|
||||
|
||||
[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"]) {
|
||||
|
||||
NSError *error = nil;
|
||||
|
||||
[self setClientParameterWith:actionInformation error:&error completionHandler:^(NSDictionary<NSString *,id> * _Nullable actionDict) {
|
||||
actionBlock(actionDict);
|
||||
}];
|
||||
|
||||
if (error) {
|
||||
//MVMCoreLoggingHandler.logDebugMessage(withDelegate: "JS function reult: \(String(describing: result))")
|
||||
MVMCoreLog(@"Error clientParamters %@", error);
|
||||
actionBlock(actionInformation);
|
||||
}
|
||||
} else {
|
||||
actionBlock(actionInformation);
|
||||
}
|
||||
[self setClientParameterWith:actionInformation completionHandler:performAction];
|
||||
}
|
||||
|
||||
- (void)restartAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
|
||||
@ -582,7 +562,7 @@ NSString * const KeyActionTypeOpen = @"openPage";
|
||||
[weakSelf prepareLinkAwayWithURL:otherURL appURL:appURL actionInformation:actionMap additionalData:additionalData delegate:delegate];
|
||||
};
|
||||
|
||||
[self preprocessRequest:actionInformation actionBlock:performAction];
|
||||
[self setClientParameterWith:actionInformation completionHandler: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 {
|
||||
|
||||
@ -11,5 +11,5 @@ import Foundation
|
||||
public protocol ClientParameterProtocol {
|
||||
init()
|
||||
static var name: String { get }
|
||||
func fetchClientParameters(for paramModel: ClientParameterModelProtocol, timingOutIn timeout: Double, completionHandler:@escaping ([String: Any]?) -> ())
|
||||
func fetchClientParameters(for paramModel: ClientParameterModelProtocol, timingOutIn timeout: Double, completionHandler:@escaping (AnyHashable?) -> ())
|
||||
}
|
||||
|
||||
@ -73,11 +73,11 @@ import Foundation
|
||||
parametersList[parameterModel.type] = ["error": defaultErrorString]
|
||||
group.enter()
|
||||
// Dispatch asynchronous injection.
|
||||
clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (clientParam) in
|
||||
clientParameterRegistry.injectParameter(parameterModel, before: timeout) { (receivedParameter) in
|
||||
// Queue the results for merge.
|
||||
parametersWorkQueue.async {
|
||||
if let clientParam = clientParam {
|
||||
parametersList.merge(clientParam) { (_, new) in new }
|
||||
if let receivedParameter = receivedParameter {
|
||||
parametersList[parameterModel.type] = receivedParameter
|
||||
}
|
||||
group.leave() // Leaving is only done after setup (barriered).
|
||||
}
|
||||
@ -89,7 +89,7 @@ import Foundation
|
||||
}
|
||||
}
|
||||
|
||||
func injectParameter( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping ([String: Any]?) -> ()) {
|
||||
func injectParameter( _ parameterModel: ClientParameterModelProtocol, before timeout: Double, completionHandler:@escaping (AnyHashable?) -> ()) {
|
||||
guard let parammeterHandler = createParametersHandler(parameterModel.type) else {
|
||||
return completionHandler(nil)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user