modernization.

Adding json protocol to continue to support legacy (unfortunately)
This commit is contained in:
Scott Pfeil 2022-07-28 18:25:56 -04:00
parent 6c08179b2a
commit f2d5352cc3
14 changed files with 58 additions and 39 deletions

View File

@ -10,18 +10,22 @@ import Foundation
import MVMCore
/// Shows an alert using the model.
open class ActionAlertHandler: MVMCoreActionHandlerProtocol {
open class ActionAlertHandler: MVMCoreJSONActionHandlerProtocol {
required public init() {}
open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
guard let model = model as? ActionAlertModel else { return }
try await MVMCoreActionHandler.getOriginalJSON(with: model, additionalData: additionalData) { json, additionalData in
var error: MVMCoreErrorObject? = nil
guard let alertObject = MVMCoreAlertObject.alertObjectWith(action: json, additionalData: additionalData, delegateObject: delegateObject, error: &error) else {
throw MVMCoreError.errorObject(error!)
}
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowPopup(with: alertObject, alertJson: json)
open func performAction(with JSON: [AnyHashable : Any], model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
var error: MVMCoreErrorObject? = nil
guard let alertObject = MVMCoreAlertObject.alertObjectWith(action: JSON, additionalData: additionalData, delegateObject: delegateObject, error: &error) else {
throw MVMCoreError.errorObject(error!)
}
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowPopup(with: alertObject, alertJson: JSON)
_ = await MainActor.run {
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
}
}
open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
let json = try MVMCoreActionHandler.convertActionToJSON(model)
try await performAction(with: json, model: model, delegateObject: delegateObject, additionalData: additionalData)
}
}

View File

@ -7,7 +7,7 @@
//
import MVMCore
@objcMembers public class ActionAlertModel: ActionModelProtocol {
public struct ActionAlertModel: ActionModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------

View File

@ -7,8 +7,9 @@
//
import UIKit
import MVMCore
@objcMembers public class ActionCollapseNotificationModel: ActionModelProtocol {
public struct ActionCollapseNotificationModel: ActionModelProtocol {
public static var identifier: String = "collapseNotification"
public var actionType: String = ActionCollapseNotificationModel.identifier

View File

@ -10,20 +10,24 @@ import Foundation
import MVMCore
/// Shows the panel.
open class ActionOpenPanelHandler: MVMCoreActionHandlerProtocol {
open class ActionOpenPanelHandler: MVMCoreJSONActionHandlerProtocol {
required public init() {}
open func performAction(with JSON: [AnyHashable : Any], model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
guard let model = model as? ActionOpenPanelModel else { return }
switch model.panel {
case .left, .menu:
await MVMCoreUISplitViewController.main()?.leftPanel?.willOpen?(withActionInformation: JSON, additionalData: additionalData)
await MVMCoreUISplitViewController.main()?.showLeftPanel(animated: true)
case .right, .support:
await MVMCoreUISplitViewController.main()?.rightPanel?.willOpen?(withActionInformation: JSON, additionalData: additionalData)
await MVMCoreUISplitViewController.main()?.showRightPanel(animated: true)
}
}
open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
guard let model = model as? ActionOpenPanelModel else { return }
try await MVMCoreActionHandler.getOriginalJSON(with: model, additionalData: additionalData) { json, additionalData in
switch model.panel {
case .left, .menu:
await MVMCoreUISplitViewController.main()?.leftPanel?.willOpen?(withActionInformation: json, additionalData: additionalData)
await MVMCoreUISplitViewController.main()?.showLeftPanel(animated: true)
case .right, .support:
await MVMCoreUISplitViewController.main()?.rightPanel?.willOpen?(withActionInformation: json, additionalData: additionalData)
await MVMCoreUISplitViewController.main()?.showRightPanel(animated: true)
}
}
let json = try MVMCoreActionHandler.convertActionToJSON(model)
try await performAction(with: json, model: model, delegateObject: delegateObject, additionalData: additionalData)
}
}

View File

@ -7,8 +7,9 @@
//
import Foundation
import MVMCore
public class ActionOpenPanelModel: ActionModelProtocol {
public struct ActionOpenPanelModel: ActionModelProtocol {
public enum Panel: String, Codable {
case left

View File

@ -23,8 +23,12 @@ open class ActionPopupHandler: MVMCoreActionHandlerProtocol {
return
}
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowPopup(with: alertObject, alertJson: json!)
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
continuation.resume()
Task {
_ = await MainActor.run {
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
}
continuation.resume()
}
})
}
}

View File

@ -6,8 +6,9 @@
// Copyright © 2019 myverizon. All rights reserved.
//
import MVMCore
@objcMembers public class ActionPopupModel: ActionModelProtocol {
public struct ActionPopupModel: ActionModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------

View File

@ -21,9 +21,13 @@ open class ActionTopAlertHandler: MVMCoreActionHandlerProtocol {
continuation.resume(throwing: ModelRegistry.Error.decoderOther(message: "Alert Page \(model.pageType) missing ResponseInfo"))
return
}
let alertObject = MVMCoreAlertObject(forPageType: model.pageType, responseInfo: responseInfo, additionalData: additionalData, delegateObject: delegateObject)!
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowTopAlert(with: alertObject, alertJson: json!)
alertObject.showAlert()
var alertObject = MVMCoreAlertObject(forPageType: model.pageType, responseInfo: responseInfo, additionalData: additionalData, delegateObject: delegateObject)
if let object = alertObject,
let closure = (delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowTopAlert {
alertObject = closure(object, json!)
}
alertObject?.showAlert()
continuation.resume()
})
}

View File

@ -8,7 +8,7 @@
import Foundation
@objcMembers public class ActionTopAlertModel: ActionModelProtocol {
public struct ActionTopAlertModel: ActionModelProtocol {
public static var identifier: String = "topAlert"
public var actionType: String = ActionTopAlertModel.identifier

View File

@ -7,8 +7,9 @@
//
import UIKit
import MVMCore
@objcMembers public class ActionTopNotificationModel: ActionModelProtocol {
public struct ActionTopNotificationModel: ActionModelProtocol {
public static var identifier: String = "topNotification"
public var actionType: String = ActionTopNotificationModel.identifier

View File

@ -10,10 +10,10 @@ import Foundation
import MVMCore
open class MVMCoreUIActionOpenPageHandler: ActionOpenPageHandler {
public override func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
open override func performAction(with JSON: [AnyHashable : Any], model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
// Cleanup the source model data to prevent it from being accidentally auto-forwarded in openPage network requests by blind additionalData insertions. (https://onejira.verizon.com/browse/CXTDT-135642, https://onejira.verizon.com/browse/CXTDT-136001).
var additionalData = additionalData
additionalData?.removeValue(forKey: KeySourceModel)
try await super.performAction(model, delegateObject: delegateObject, additionalData: additionalData)
try await super.performAction(with: JSON, model: model, delegateObject: delegateObject, additionalData: additionalData)
}
}

View File

@ -9,7 +9,7 @@
import UIKit
import MVMCore
@objc open class ViewController: UIViewController, MVMCoreViewControllerProtocol, MVMCoreViewManagerViewControllerProtocol, MoleculeDelegateProtocol, FormHolderProtocol, MVMCoreActionDelegateProtocol, ActionDelegateProtocol, MVMCoreLoadDelegateProtocol, UITextFieldDelegate, UITextViewDelegate, ObservingTextFieldDelegate, MVMCoreUIDetailViewProtocol, PageProtocol, PageBehaviorHandlerProtocol {
@objc open class ViewController: UIViewController, MVMCoreViewControllerProtocol, MVMCoreViewManagerViewControllerProtocol, MoleculeDelegateProtocol, FormHolderProtocol, MVMCoreActionDelegateProtocol, ActionOpenPageDelegateProtocol, MVMCoreLoadDelegateProtocol, UITextFieldDelegate, UITextViewDelegate, ObservingTextFieldDelegate, MVMCoreUIDetailViewProtocol, PageProtocol, PageBehaviorHandlerProtocol {
//--------------------------------------------------
// MARK: - Properties
@ -27,7 +27,7 @@ import MVMCore
public weak var manager: (UIViewController & MVMCoreViewManagerProtocol)?
/// A temporary iVar backer for delegateObject() until we change the protocol
public lazy var delegateObjectIVar: MVMCoreUIDelegateObject = {
open lazy var delegateObjectIVar: MVMCoreUIDelegateObject = {
MVMCoreUIDelegateObject.create(withDelegateForAll: self)
}()
@ -450,7 +450,7 @@ import MVMCore
let dataMap = behavior.compileLocalPageDataForTransfer(delegateObjectIVar)
pageForwardedData.merge(dataMap) { current, _ in current }
}
return (requestParameters,pageForwardedData)
return (requestParameters, pageForwardedData)
}
open func logAction(withActionInformation actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) {

View File

@ -178,7 +178,7 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
guard let additionalData = additionalData,
additionalData.boolForKey("tabBarPressed") else {
// Pass to delegate
return try (viewController as? ActionDelegateProtocol)?.getRequestParameters(for: model, delegateObject: delegateObject, additionalData: additionalData) ?? value
return try (viewController as? ActionOpenPageDelegateProtocol)?.getRequestParameters(for: model, delegateObject: delegateObject, additionalData: additionalData) ?? value
}
// Allow opportunity to modify parameters.
requestParameters = getRequestParametersForNewTabLoad(requestParameters: requestParameters, model: model, additionalData: additionalData)

View File

@ -16,8 +16,7 @@ import SafariServices
open override func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable : Any]?) {
super.defaultHandleActionError(error, additionalData: additionalData)
guard !error.silentError else { return }
Task {
// TODO: Verify if necessary.
Task(priority: .userInitiated) {
await MainActor.run {
// Show alert
let alertObject = MVMCoreAlertObject.init(popupAlertWithError: error, isGreedy: false)!