Merge branch 'feature/action_top_notification' into 'develop'

molecular top notification action

See merge request BPHV_MIPS/mvm_core_ui!645
This commit is contained in:
Suresh, Kamlesh Jain 2020-12-28 17:21:13 -05:00
commit 1279a5304a
3 changed files with 53 additions and 20 deletions

View File

@ -12,7 +12,8 @@ import Foundation
public static var identifier: String = "topAlert" public static var identifier: String = "topAlert"
public var actionType: String = ActionTopAlertModel.identifier public var actionType: String = ActionTopAlertModel.identifier
public var pageType: String public var pageType: String?
public var topNotification: TopNotificationModel?
public var extraParameters: JSONValueDictionary? public var extraParameters: JSONValueDictionary?
public var analyticsData: JSONValueDictionary? public var analyticsData: JSONValueDictionary?
@ -21,4 +22,10 @@ import Foundation
self.extraParameters = extraParameters self.extraParameters = extraParameters
self.analyticsData = analyticsData self.analyticsData = analyticsData
} }
public init(topNotification: TopNotificationModel, _ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) {
self.topNotification = topNotification
self.extraParameters = extraParameters
self.analyticsData = analyticsData
}
} }

View File

@ -81,7 +81,8 @@
- (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
// Perform a top alert. // Perform a top alert.
NSString *pageTypeForTopAlert = [actionInformation stringForKey:KeyPageType]; NSString *pageTypeForTopAlert = [actionInformation string:KeyPageType];
if (pageTypeForTopAlert) {
[[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForTopAlert queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) { [[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForTopAlert queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
NSDictionary *responseInfo = [jsonDictionary dict:KeyResponseInfo]; NSDictionary *responseInfo = [jsonDictionary dict:KeyResponseInfo];
@ -93,6 +94,15 @@
[alertObject showAlert]; [alertObject showAlert];
} }
}]; }];
} else {
NSDictionary *topNotification = [actionInformation dict:@"topNotification"];
if (topNotification) {
[[MVMCoreUITopAlertView sharedGlobal] showTopAlertWith:topNotification];
} else {
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegateObject.actionDelegate class]),KeyActionTypeTopAlert]];
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegateObject:delegateObject];
}
}
} }
- (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject { - (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegateObject:(nullable DelegateObject *)delegateObject {
@ -152,6 +162,7 @@
- (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate { - (void)topAlertAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {
// Perform a top alert. // Perform a top alert.
NSString *pageTypeForTopAlert = [actionInformation stringForKey:KeyPageType]; NSString *pageTypeForTopAlert = [actionInformation stringForKey:KeyPageType];
if (pageTypeForTopAlert) {
[[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForTopAlert queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) { [[MVMCoreCache sharedCache] fetchJSONForPageType:pageTypeForTopAlert queue:nil waitUntilFinished:YES completionHandler:^(NSDictionary * _Nullable jsonDictionary) {
NSDictionary *responseInfo = [jsonDictionary dict:KeyResponseInfo]; NSDictionary *responseInfo = [jsonDictionary dict:KeyResponseInfo];
@ -163,6 +174,15 @@
[alertObject showAlert]; [alertObject showAlert];
} }
}]; }];
} else {
NSDictionary *topNotification = [actionInformation dict:@"topNotification"];
if (topNotification) {
[[MVMCoreUITopAlertView sharedGlobal] showTopAlertWith:topNotification];
} else {
MVMCoreErrorObject *error = [[MVMCoreErrorObject alloc] initWithTitle:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorTitle] message:[MVMCoreGetterUtility hardcodedStringWithKey:HardcodedErrorUnableToProcess] code:ErrorCodeParsingJSON domain:ErrorDomainNative location:[NSString stringWithFormat:@"%@_%@",NSStringFromClass([delegate class]),KeyActionTypeTopAlert]];
[self handleActionError:error actionInformation:actionInformation additionalData:additionalData delegate:delegate];
}
}
} }
- (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate { - (void)collapseNotificationAction:(nullable NSDictionary *)actionInformation additionalData:(nullable NSDictionary *)additionalData delegate:(nullable NSObject <MVMCoreLoadDelegateProtocol, MVMCorePresentationDelegateProtocol,MVMCoreActionDelegateProtocol>*)delegate {

View File

@ -61,6 +61,12 @@ public extension MVMCoreUITopAlertView {
MVMCoreAlertHandler.shared()?.add(operation) MVMCoreAlertHandler.shared()?.add(operation)
} }
/// Shows the top alert with the json.
@objc func showTopAlert(with json: [AnyHashable: Any]) {
guard let model = decodeTopNotification(with: json, delegateObject: getDelegateObject()) else { return }
showTopAlert(with: model)
}
/// Checks for existing top alert object of same type and updates it. Only happens for molecular top alerts. Returns true if we updated. /// Checks for existing top alert object of same type and updates it. Only happens for molecular top alerts. Returns true if we updated.
private func checkAndUpdateExisting(with topAlertObject: MVMCoreTopAlertObject) -> Bool { private func checkAndUpdateExisting(with topAlertObject: MVMCoreTopAlertObject) -> Bool {
guard let queue = MVMCoreAlertHandler.shared()?.topAlertQueue.operations else { return false } guard let queue = MVMCoreAlertHandler.shared()?.topAlertQueue.operations else { return false }