Add Actions

This commit is contained in:
Pfeil, Scott Robert 2021-05-28 10:23:17 -04:00
parent af0ebf8678
commit 42b8b37c58
3 changed files with 38 additions and 6 deletions

View File

@ -46,9 +46,9 @@
model.selected = accordionButton.isSelected
if accordionButton.isSelected {
MVMCoreActionHandler.shared()?.handleAction("addMoleculesAction", actionInformation: nil, additionalData: [KeySourceModel: model], delegateObject: delegateObject)
MVMCoreActionHandler.shared()?.handleAction(AddMoleculesActionModel.identifier, actionInformation: nil, additionalData: [KeySourceModel: model], delegateObject: delegateObject)
} else {
MVMCoreActionHandler.shared()?.handleAction("removeMoleculesAction", actionInformation: nil, additionalData: [KeySourceModel: model], delegateObject: delegateObject)
MVMCoreActionHandler.shared()?.handleAction(RemoveMoleculesActionModel.identifier, actionInformation: nil, additionalData: [KeySourceModel: model], delegateObject: delegateObject)
}
if (accordionListItemModel?.hideLineWhenExpanded ?? false) && (self.bottomSeparatorView?.shouldBeVisible() ?? false) {

View File

@ -32,10 +32,10 @@ import UIKit
MVMCoreDispatchUtility.performBlock(inBackground: {
if let oldValue = oldValue,
oldValue.count > 0 {
MVMCoreUIActionHandler.shared()?.synchronouslyHandleAction("removeMoleculesAction", actionInformation: nil, additionalData: [KeySourceModel: model], delegateObject: self.delegateObject)
MVMCoreUIActionHandler.shared()?.synchronouslyHandleAction(RemoveMoleculesActionModel.identifier, actionInformation: nil, additionalData: [KeySourceModel: model], delegateObject: self.delegateObject)
}
MVMCoreActionHandler.shared()?.handleAction("addMoleculesAction", actionInformation: nil, additionalData: [KeySourceModel: model], delegateObject: self.delegateObject)
MVMCoreActionHandler.shared()?.handleAction(AddMoleculesActionModel.identifier, actionInformation: nil, additionalData: [KeySourceModel: model], delegateObject: self.delegateObject)
})
}
}

View File

@ -73,7 +73,7 @@ public class AddRemoveMoleculeBehavior: PageCustomActionHandlerBehavior {
}
public func handleAction(type actionType: String?, information: [AnyHashable : Any]?, additionalData: [AnyHashable : Any]?) -> Bool {
if actionType == "addMoleculesAction" {
if actionType == AddMoleculesActionModel.identifier {
guard let list = delegate?.moleculeListDelegate,
let model = additionalData?[KeySourceModel] as? (ListItemModelProtocol & MoleculeModelProtocol & AddMolecules),
let moleculesToAdd = model.getRecursiveMoleculesToAdd(),
@ -82,7 +82,7 @@ public class AddRemoveMoleculeBehavior: PageCustomActionHandlerBehavior {
list.addMolecules(moleculesToAdd.0, indexPath: indexPath, animation: moleculesToAdd.2)
}
return true
} else if actionType == "removeMoleculesAction" {
} else if actionType == RemoveMoleculesActionModel.identifier {
guard let list = delegate?.moleculeListDelegate,
let model = additionalData?[KeySourceModel] as? (ListItemModelProtocol & MoleculeModelProtocol & RemoveMolecules),
let moleculesToRemove = model.getRecursiveMoleculesToRemove() else { return true }
@ -105,3 +105,35 @@ private extension MoleculeListProtocol {
return indexPath
}
}
public class AddMoleculesActionModel: ActionModelProtocol {
public static var identifier: String = "addMoleculesAction"
public var actionType: String = AddMoleculesActionModel.identifier
public var extraParameters: JSONValueDictionary?
public var analyticsData: JSONValueDictionary?
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) {
self.extraParameters = extraParameters
self.analyticsData = analyticsData
}
}
public class RemoveMoleculesActionModel: ActionModelProtocol {
public static var identifier: String = "removeMoleculesAction"
public var actionType: String = RemoveMoleculesActionModel.identifier
public var extraParameters: JSONValueDictionary?
public var analyticsData: JSONValueDictionary?
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(_ extraParameters: JSONValueDictionary? = nil, _ analyticsData: JSONValueDictionary? = nil) {
self.extraParameters = extraParameters
self.analyticsData = analyticsData
}
}