modernization.
Adding json protocol to continue to support legacy (unfortunately)
This commit is contained in:
parent
6c08179b2a
commit
f2d5352cc3
@ -10,18 +10,22 @@ import Foundation
|
|||||||
import MVMCore
|
import MVMCore
|
||||||
|
|
||||||
/// Shows an alert using the model.
|
/// Shows an alert using the model.
|
||||||
open class ActionAlertHandler: MVMCoreActionHandlerProtocol {
|
open class ActionAlertHandler: MVMCoreJSONActionHandlerProtocol {
|
||||||
required public init() {}
|
required public init() {}
|
||||||
|
|
||||||
open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
open func performAction(with JSON: [AnyHashable : Any], model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
||||||
guard let model = model as? ActionAlertModel else { return }
|
var error: MVMCoreErrorObject? = nil
|
||||||
try await MVMCoreActionHandler.getOriginalJSON(with: model, additionalData: additionalData) { json, additionalData in
|
guard let alertObject = MVMCoreAlertObject.alertObjectWith(action: JSON, additionalData: additionalData, delegateObject: delegateObject, error: &error) else {
|
||||||
var error: MVMCoreErrorObject? = nil
|
throw MVMCoreError.errorObject(error!)
|
||||||
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 {
|
||||||
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowPopup(with: alertObject, alertJson: json)
|
|
||||||
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
//
|
//
|
||||||
import MVMCore
|
import MVMCore
|
||||||
|
|
||||||
@objcMembers public class ActionAlertModel: ActionModelProtocol {
|
public struct ActionAlertModel: ActionModelProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -7,8 +7,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
@objcMembers public class ActionCollapseNotificationModel: ActionModelProtocol {
|
public struct ActionCollapseNotificationModel: ActionModelProtocol {
|
||||||
|
|
||||||
public static var identifier: String = "collapseNotification"
|
public static var identifier: String = "collapseNotification"
|
||||||
public var actionType: String = ActionCollapseNotificationModel.identifier
|
public var actionType: String = ActionCollapseNotificationModel.identifier
|
||||||
|
|||||||
@ -10,20 +10,24 @@ import Foundation
|
|||||||
import MVMCore
|
import MVMCore
|
||||||
|
|
||||||
/// Shows the panel.
|
/// Shows the panel.
|
||||||
open class ActionOpenPanelHandler: MVMCoreActionHandlerProtocol {
|
open class ActionOpenPanelHandler: MVMCoreJSONActionHandlerProtocol {
|
||||||
required public init() {}
|
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 {
|
open func performAction(_ model: ActionModelProtocol, delegateObject: DelegateObject?, additionalData: [AnyHashable : Any]?) async throws {
|
||||||
guard let model = model as? ActionOpenPanelModel else { return }
|
guard let model = model as? ActionOpenPanelModel else { return }
|
||||||
try await MVMCoreActionHandler.getOriginalJSON(with: model, additionalData: additionalData) { json, additionalData in
|
let json = try MVMCoreActionHandler.convertActionToJSON(model)
|
||||||
switch model.panel {
|
try await performAction(with: json, model: model, delegateObject: delegateObject, additionalData: additionalData)
|
||||||
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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,8 +7,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
public class ActionOpenPanelModel: ActionModelProtocol {
|
public struct ActionOpenPanelModel: ActionModelProtocol {
|
||||||
|
|
||||||
public enum Panel: String, Codable {
|
public enum Panel: String, Codable {
|
||||||
case left
|
case left
|
||||||
|
|||||||
@ -23,8 +23,12 @@ open class ActionPopupHandler: MVMCoreActionHandlerProtocol {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowPopup(with: alertObject, alertJson: json!)
|
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowPopup(with: alertObject, alertJson: json!)
|
||||||
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
|
Task {
|
||||||
continuation.resume()
|
_ = await MainActor.run {
|
||||||
|
MVMCoreAlertHandler.shared()?.showAlert(with: alertObject)
|
||||||
|
}
|
||||||
|
continuation.resume()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,8 +6,9 @@
|
|||||||
// Copyright © 2019 myverizon. All rights reserved.
|
// Copyright © 2019 myverizon. All rights reserved.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
@objcMembers public class ActionPopupModel: ActionModelProtocol {
|
public struct ActionPopupModel: ActionModelProtocol {
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Properties
|
// MARK: - Properties
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
|
|||||||
@ -21,9 +21,13 @@ open class ActionTopAlertHandler: MVMCoreActionHandlerProtocol {
|
|||||||
continuation.resume(throwing: ModelRegistry.Error.decoderOther(message: "Alert Page \(model.pageType) missing ResponseInfo"))
|
continuation.resume(throwing: ModelRegistry.Error.decoderOther(message: "Alert Page \(model.pageType) missing ResponseInfo"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let alertObject = MVMCoreAlertObject(forPageType: model.pageType, responseInfo: responseInfo, additionalData: additionalData, delegateObject: delegateObject)!
|
|
||||||
(delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowTopAlert(with: alertObject, alertJson: json!)
|
var alertObject = MVMCoreAlertObject(forPageType: model.pageType, responseInfo: responseInfo, additionalData: additionalData, delegateObject: delegateObject)
|
||||||
alertObject.showAlert()
|
if let object = alertObject,
|
||||||
|
let closure = (delegateObject?.actionDelegate as? MVMCoreUIActionDelegateProtocol)?.willShowTopAlert {
|
||||||
|
alertObject = closure(object, json!)
|
||||||
|
}
|
||||||
|
alertObject?.showAlert()
|
||||||
continuation.resume()
|
continuation.resume()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
@objcMembers public class ActionTopAlertModel: ActionModelProtocol {
|
public struct ActionTopAlertModel: ActionModelProtocol {
|
||||||
|
|
||||||
public static var identifier: String = "topAlert"
|
public static var identifier: String = "topAlert"
|
||||||
public var actionType: String = ActionTopAlertModel.identifier
|
public var actionType: String = ActionTopAlertModel.identifier
|
||||||
|
|||||||
@ -7,8 +7,9 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import UIKit
|
import UIKit
|
||||||
|
import MVMCore
|
||||||
|
|
||||||
@objcMembers public class ActionTopNotificationModel: ActionModelProtocol {
|
public struct ActionTopNotificationModel: ActionModelProtocol {
|
||||||
|
|
||||||
public static var identifier: String = "topNotification"
|
public static var identifier: String = "topNotification"
|
||||||
public var actionType: String = ActionTopNotificationModel.identifier
|
public var actionType: String = ActionTopNotificationModel.identifier
|
||||||
|
|||||||
@ -10,10 +10,10 @@ import Foundation
|
|||||||
import MVMCore
|
import MVMCore
|
||||||
|
|
||||||
open class MVMCoreUIActionOpenPageHandler: ActionOpenPageHandler {
|
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).
|
// 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
|
var additionalData = additionalData
|
||||||
additionalData?.removeValue(forKey: KeySourceModel)
|
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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
import MVMCore
|
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
|
// MARK: - Properties
|
||||||
@ -27,7 +27,7 @@ import MVMCore
|
|||||||
public weak var manager: (UIViewController & MVMCoreViewManagerProtocol)?
|
public weak var manager: (UIViewController & MVMCoreViewManagerProtocol)?
|
||||||
|
|
||||||
/// A temporary iVar backer for delegateObject() until we change the protocol
|
/// 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)
|
MVMCoreUIDelegateObject.create(withDelegateForAll: self)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -450,7 +450,7 @@ import MVMCore
|
|||||||
let dataMap = behavior.compileLocalPageDataForTransfer(delegateObjectIVar)
|
let dataMap = behavior.compileLocalPageDataForTransfer(delegateObjectIVar)
|
||||||
pageForwardedData.merge(dataMap) { current, _ in current }
|
pageForwardedData.merge(dataMap) { current, _ in current }
|
||||||
}
|
}
|
||||||
return (requestParameters,pageForwardedData)
|
return (requestParameters, pageForwardedData)
|
||||||
}
|
}
|
||||||
|
|
||||||
open func logAction(withActionInformation actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) {
|
open func logAction(withActionInformation actionInformation: [AnyHashable: Any]?, additionalData: [AnyHashable: Any]?) {
|
||||||
|
|||||||
@ -178,7 +178,7 @@ open class SubNavManagerController: ViewController, MVMCoreViewManagerProtocol,
|
|||||||
guard let additionalData = additionalData,
|
guard let additionalData = additionalData,
|
||||||
additionalData.boolForKey("tabBarPressed") else {
|
additionalData.boolForKey("tabBarPressed") else {
|
||||||
// Pass to delegate
|
// 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.
|
// Allow opportunity to modify parameters.
|
||||||
requestParameters = getRequestParametersForNewTabLoad(requestParameters: requestParameters, model: model, additionalData: additionalData)
|
requestParameters = getRequestParametersForNewTabLoad(requestParameters: requestParameters, model: model, additionalData: additionalData)
|
||||||
|
|||||||
@ -16,8 +16,7 @@ import SafariServices
|
|||||||
open override func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable : Any]?) {
|
open override func defaultHandleActionError(_ error: MVMCoreErrorObject, additionalData: [AnyHashable : Any]?) {
|
||||||
super.defaultHandleActionError(error, additionalData: additionalData)
|
super.defaultHandleActionError(error, additionalData: additionalData)
|
||||||
guard !error.silentError else { return }
|
guard !error.silentError else { return }
|
||||||
Task {
|
Task(priority: .userInitiated) {
|
||||||
// TODO: Verify if necessary.
|
|
||||||
await MainActor.run {
|
await MainActor.run {
|
||||||
// Show alert
|
// Show alert
|
||||||
let alertObject = MVMCoreAlertObject.init(popupAlertWithError: error, isGreedy: false)!
|
let alertObject = MVMCoreAlertObject.init(popupAlertWithError: error, isGreedy: false)!
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user