From 447df655df903ca3adbe393820c4cd23cbd0bf71 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 09:12:09 -0500 Subject: [PATCH 1/5] make the error throwable --- .../BaseControllers/MFViewController+Model.swift | 2 +- MVMCoreUI/BaseControllers/MFViewController.m | 13 +++++++++++-- .../Models/ModelProtocols/TemplateProtocol.swift | 14 +++++--------- MVMCoreUI/Templates/MoleculeListTemplate.swift | 4 ++-- MVMCoreUI/Templates/MoleculeStackTemplate.swift | 4 ++-- MVMCoreUI/Templates/ThreeLayerTemplate.swift | 4 ++-- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/MVMCoreUI/BaseControllers/MFViewController+Model.swift b/MVMCoreUI/BaseControllers/MFViewController+Model.swift index 88f05360..3468748b 100644 --- a/MVMCoreUI/BaseControllers/MFViewController+Model.swift +++ b/MVMCoreUI/BaseControllers/MFViewController+Model.swift @@ -32,6 +32,6 @@ extension MFViewController: MoleculeDelegateProtocol { } public extension MFViewController { - @objc func parsePageJSON() { + @objc func parsePageJSON() throws { } } diff --git a/MVMCoreUI/BaseControllers/MFViewController.m b/MVMCoreUI/BaseControllers/MFViewController.m index 1d97efd9..d2ff7cda 100644 --- a/MVMCoreUI/BaseControllers/MFViewController.m +++ b/MVMCoreUI/BaseControllers/MFViewController.m @@ -96,7 +96,15 @@ - (BOOL)shouldFinishProcessingLoad:(nonnull MVMCoreLoadObject *)loadObject error:(MVMCoreErrorObject *_Nonnull *_Nonnull)error { self.pageType = loadObject.pageType; self.loadObject = loadObject; - [self parsePageJSON]; + + NSError *parseError = nil; + [self parsePageJSONAndReturnError:&parseError]; + if (parseError) { + if (error) { + *error = [MVMCoreErrorObject createErrorObjectForNSError:parseError location:[[MVMCoreLoadHandler sharedGlobal] errorLocationForRequest:loadObject]]; + } + return false; + } // Verifies all modules needed are loaded. return [MFViewController verifyRequiredModulesLoadedForLoadObject:loadObject error:error]; @@ -250,7 +258,8 @@ - (BOOL)newPageLoaded:(nonnull NSDictionary *)page { self.loadObject.pageJSON = page; - [self parsePageJSON]; + NSError *parseError = nil; + [self parsePageJSONAndReturnError:&parseError]; return YES; } diff --git a/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift index eb4463d5..0498ec5d 100644 --- a/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift +++ b/MVMCoreUI/Models/ModelProtocols/TemplateProtocol.swift @@ -14,15 +14,11 @@ public protocol TemplateProtocol: class { } public extension TemplateProtocol where Self: MFViewController { - func parseTemplateJSON() { + func parseTemplateJSON() throws { guard let pageJSON = self.loadObject?.pageJSON else { return } - do { - let data = try JSONSerialization.data(withJSONObject: pageJSON) - let decoder = JSONDecoder() - let templateModel = try decoder.decode(TemplateModel.self, from: data) - self.templateModel = templateModel - } catch { - MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") - } + let data = try JSONSerialization.data(withJSONObject: pageJSON) + let decoder = JSONDecoder() + let templateModel = try decoder.decode(TemplateModel.self, from: data) + self.templateModel = templateModel } } diff --git a/MVMCoreUI/Templates/MoleculeListTemplate.swift b/MVMCoreUI/Templates/MoleculeListTemplate.swift index 03f4e0fc..3a551a79 100644 --- a/MVMCoreUI/Templates/MoleculeListTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeListTemplate.swift @@ -14,8 +14,8 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol var observer: NSKeyValueObservation? public var templateModel: ListPageTemplateModel? - public override func parsePageJSON() { - parseTemplateJSON() + @objc public override func parsePageJSON() throws { + try parseTemplateJSON() } open override var loadObject: MVMCoreLoadObject? { diff --git a/MVMCoreUI/Templates/MoleculeStackTemplate.swift b/MVMCoreUI/Templates/MoleculeStackTemplate.swift index 39c814fa..74eae770 100644 --- a/MVMCoreUI/Templates/MoleculeStackTemplate.swift +++ b/MVMCoreUI/Templates/MoleculeStackTemplate.swift @@ -12,8 +12,8 @@ open class MoleculeStackTemplate: ThreeLayerViewController, TemplateProtocol { var observer: NSKeyValueObservation? public var templateModel: StackPageTemplateModel? - public override func parsePageJSON() { - parseTemplateJSON() + public override func parsePageJSON() throws { + try parseTemplateJSON() } open override var loadObject: MVMCoreLoadObject? { diff --git a/MVMCoreUI/Templates/ThreeLayerTemplate.swift b/MVMCoreUI/Templates/ThreeLayerTemplate.swift index 67326d09..472985e3 100644 --- a/MVMCoreUI/Templates/ThreeLayerTemplate.swift +++ b/MVMCoreUI/Templates/ThreeLayerTemplate.swift @@ -11,8 +11,8 @@ import UIKit @objcMembers open class ThreeLayerTemplate: ThreeLayerViewController, TemplateProtocol { public var templateModel: ThreeLayerPageTemplateModel? - public override func parsePageJSON() { - parseTemplateJSON() + @objc public override func parsePageJSON() throws { + try parseTemplateJSON() } override open func viewDidLoad() { From 77af932f5d52b5928973c93dd3efa7eba3a4c351 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 09:26:04 -0500 Subject: [PATCH 2/5] update old key --- MVMCoreUI/Models/Template/ListPageTemplateModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift index 61729c99..c3b2a120 100644 --- a/MVMCoreUI/Models/Template/ListPageTemplateModel.swift +++ b/MVMCoreUI/Models/Template/ListPageTemplateModel.swift @@ -10,7 +10,7 @@ import Foundation @objcMembers public class ListPageTemplateModel: TemplateModelProtocol { - public static var identifier: String = "listTemplate" + public static var identifier: String = "list" public var pageType: String public var screenHeading: String? From 9c0bea033c955a9807a0a8f6e9dfbea1b4cdb3ba Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 10:13:19 -0500 Subject: [PATCH 3/5] actionType fix --- MVMCoreUI/Atoms/Buttons/ButtonModel.swift | 4 ++-- MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift | 2 +- MVMCoreUI/Atoms/Buttons/LinkModel.swift | 2 +- MVMCoreUI/Molecules/Items/ListItemModel.swift | 2 +- MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift | 3 ++- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift index 9d9ad9c3..03eb7fc3 100644 --- a/MVMCoreUI/Atoms/Buttons/ButtonModel.swift +++ b/MVMCoreUI/Atoms/Buttons/ButtonModel.swift @@ -36,8 +36,8 @@ public class ButtonModel: MoleculeProtocol { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) title = try typeContainer.decode(String.self, forKey: .title) - action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.type) - style = try typeContainer.decode(ButtonStyle.self, forKey: .style) + action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) + style = try typeContainer.decodeIfPresent(ButtonStyle.self, forKey: .style) } public func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift index 3cc77a54..db2de2b0 100644 --- a/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/CaretLinkModel.swift @@ -45,7 +45,7 @@ public class CaretLinkModel: MoleculeProtocol { if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { self.enabled = enabled } - action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.type) + action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) } public func encode(to encoder: Encoder) throws { diff --git a/MVMCoreUI/Atoms/Buttons/LinkModel.swift b/MVMCoreUI/Atoms/Buttons/LinkModel.swift index 6b3ff39e..e2fca66c 100644 --- a/MVMCoreUI/Atoms/Buttons/LinkModel.swift +++ b/MVMCoreUI/Atoms/Buttons/LinkModel.swift @@ -33,7 +33,7 @@ public class LinkModel: MoleculeProtocol { let typeContainer = try decoder.container(keyedBy: CodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) title = try typeContainer.decode(String.self, forKey: .title) - action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.type) + action = try typeContainer.decodeModel(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) if let enabled = try typeContainer.decodeIfPresent(Bool.self, forKey: .enabled) { self.enabled = enabled } diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index bef2cb84..7208a2ce 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -28,7 +28,7 @@ import MVMCore required public init(from decoder: Decoder) throws { let typeContainer = try decoder.container(keyedBy: ListItemCodingKeys.self) backgroundColor = try typeContainer.decodeIfPresent(Color.self, forKey: .backgroundColor) - action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.type) + action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) style = try typeContainer.decodeIfPresent(String.self, forKey: .style) diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 53d14e44..5bc59593 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -24,10 +24,11 @@ import Foundation ModelRegistry.register(TabsModel.self) ModelRegistry.register(ScrollerModel.self) ModelRegistry.register(CornerLabelsModel.self) - // buttons ModelRegistry.register(LineModel.self) + // buttons ModelRegistry.register(ButtonModel.self) ModelRegistry.register(TwoButtonViewModel.self) + ModelRegistry.register(LinkModel.self) // list items ModelRegistry.register(ListItemModel.self) ModelRegistry.register(DropDownListItemModel.self) From 0090b686a576a96ed3bff93a74b46eabf23b629a Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Tue, 14 Jan 2020 11:11:28 -0500 Subject: [PATCH 4/5] default stryle and spacing --- MVMCoreUI/Molecules/Items/ListItemModel.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/MVMCoreUI/Molecules/Items/ListItemModel.swift b/MVMCoreUI/Molecules/Items/ListItemModel.swift index 7208a2ce..24cb05e0 100644 --- a/MVMCoreUI/Molecules/Items/ListItemModel.swift +++ b/MVMCoreUI/Molecules/Items/ListItemModel.swift @@ -15,7 +15,7 @@ import MVMCore public var action: ActionProtocol? public var hideArrow: Bool? public var line: LineModel? - public var style: String? + public var style: String? = "standard" enum ListItemCodingKeys: String, CodingKey { case backgroundColor @@ -31,10 +31,20 @@ import MVMCore action = try typeContainer.decodeModelIfPresent(codingKey: .action, typeCodingKey: ActionCodingKey.actionType) hideArrow = try typeContainer.decodeIfPresent(Bool.self, forKey: .hideArrow) line = try typeContainer.decodeIfPresent(LineModel.self, forKey: .line) - style = try typeContainer.decodeIfPresent(String.self, forKey: .style) + if let style = try typeContainer.decodeIfPresent(String.self, forKey: .style) { + self.style = style + } + try super.init(from: decoder) + + if useHorizontalMargins == nil { + useHorizontalMargins = true + } + if useVerticalMargins == nil { + useVerticalMargins = true + } } - + public override func encode(to encoder: Encoder) throws { try super.encode(to: encoder) var container = encoder.container(keyedBy: ListItemCodingKeys.self) @@ -43,5 +53,6 @@ import MVMCore try container.encodeIfPresent(hideArrow, forKey: .hideArrow) try container.encodeIfPresent(line, forKey: .line) try container.encodeIfPresent(style, forKey: .style) - } + } } + From 2f6859f5435275d406389afa86df42ce9905c207 Mon Sep 17 00:00:00 2001 From: "Pfeil, Scott Robert" Date: Tue, 14 Jan 2020 11:17:10 -0500 Subject: [PATCH 5/5] button model fix --- MVMCoreUI.xcodeproj/project.pbxproj | 9 ++++----- .../Atoms/Buttons/MFTextButton+ModelExtension.swift | 5 +---- .../PrimaryButton+MoleculeProtocolExtension.swift | 5 +---- .../{ModelHelper.swift => MoleculeModelHelper.swift} | 2 +- MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift | 2 +- 5 files changed, 8 insertions(+), 15 deletions(-) rename MVMCoreUI/Models/Extensions/{ModelHelper.swift => MoleculeModelHelper.swift} (98%) diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 1497d632..6580f328 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -93,7 +93,7 @@ 944589212385D6E900DE9FD4 /* DashLineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944589202385D6E900DE9FD4 /* DashLineModel.swift */; }; 944589232385DA9600DE9FD4 /* ImageViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 944589222385DA9500DE9FD4 /* ImageViewModel.swift */; }; 9455B19C234F8A0400A574DB /* MVMAnimationFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */; }; - 946EE1BA237B66D80036751F /* ModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B9237B66D80036751F /* ModelHelper.swift */; }; + 946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */; }; 948DB67E2326DCD90011F916 /* MultiProgress.swift in Sources */ = {isa = PBXBuildFile; fileRef = 948DB67D2326DCD90011F916 /* MultiProgress.swift */; }; 94C2D9842386F3F80006CF46 /* LabelAttributeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */; }; 94C2D9A123872BCC0006CF46 /* LabelAttributeUnderlineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */; }; @@ -364,7 +364,7 @@ 944589202385D6E900DE9FD4 /* DashLineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashLineModel.swift; sourceTree = ""; }; 944589222385DA9500DE9FD4 /* ImageViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewModel.swift; sourceTree = ""; }; 9455B19B234F8A0400A574DB /* MVMAnimationFramework.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MVMAnimationFramework.framework; path = ../SharedFrameworks/MVMAnimationFramework.framework; sourceTree = ""; }; - 946EE1B9237B66D80036751F /* ModelHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelHelper.swift; sourceTree = ""; }; + 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeModelHelper.swift; sourceTree = ""; }; 948DB67D2326DCD90011F916 /* MultiProgress.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MultiProgress.swift; sourceTree = ""; }; 94C2D9832386F3F80006CF46 /* LabelAttributeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeModel.swift; sourceTree = ""; }; 94C2D9A023872BCC0006CF46 /* LabelAttributeUnderlineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelAttributeUnderlineModel.swift; sourceTree = ""; }; @@ -684,7 +684,7 @@ 946EE1B5237B663A0036751F /* Extensions */ = { isa = PBXGroup; children = ( - 946EE1B9237B66D80036751F /* ModelHelper.swift */, + 946EE1B9237B66D80036751F /* MoleculeModelHelper.swift */, ); path = Extensions; sourceTree = ""; @@ -1561,7 +1561,6 @@ 012A889C23889E8400FE3DA1 /* TemplateModelProtocol.swift in Sources */, D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */, C003506123AA94CD00B6AC29 /* Button.swift in Sources */, - D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */, DBC4391B224421A0001AB423 /* CaretButton.swift in Sources */, 0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */, 0A6BF4722360C56C0028F841 /* BaseDropdownEntryField.swift in Sources */, @@ -1588,7 +1587,7 @@ 01509D912327ECE600EF99AA /* CornerLabels.swift in Sources */, D22D1F1B220341F60077CEC0 /* MVMCoreUICheckBox.m in Sources */, D29DF2CB21E7BFCC003B2FB9 /* MFSizeThreshold.m in Sources */, - 946EE1BA237B66D80036751F /* ModelHelper.swift in Sources */, + 946EE1BA237B66D80036751F /* MoleculeModelHelper.swift in Sources */, 01509D932327ECFB00EF99AA /* ProgressBar.swift in Sources */, D29770F521F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsViewController.m in Sources */, ); diff --git a/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift b/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift index a6df6745..a86c072e 100644 --- a/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift +++ b/MVMCoreUI/Atoms/Buttons/MFTextButton+ModelExtension.swift @@ -16,9 +16,6 @@ extension MFTextButton: ModelMoleculeViewProtocol { setTitleColor(model.textColor.uiColor, for: .normal) isEnabled = model.enabled backgroundColor = model.backgroundColor?.uiColor - //TODO: Use object when handleAction is rewrote to handle action model - if let actionMap = model.action.toJSON() { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - } + set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } } diff --git a/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift b/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift index f7192fc9..6f285e19 100644 --- a/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift +++ b/MVMCoreUI/Atoms/Buttons/PrimaryButton+MoleculeProtocolExtension.swift @@ -22,9 +22,6 @@ extension PrimaryButton: ModelMoleculeViewProtocol { setAsSecondaryCustom() } } - //TODO: Use object when handleAction is rewrote to handle action model - if let actionMap = model.action.toJSON() { - MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) - } + set(with: model.action, delegateObject: delegateObject, additionalData: additionalData) } } diff --git a/MVMCoreUI/Models/Extensions/ModelHelper.swift b/MVMCoreUI/Models/Extensions/MoleculeModelHelper.swift similarity index 98% rename from MVMCoreUI/Models/Extensions/ModelHelper.swift rename to MVMCoreUI/Models/Extensions/MoleculeModelHelper.swift index 72bb5f8f..e10fcc38 100644 --- a/MVMCoreUI/Models/Extensions/ModelHelper.swift +++ b/MVMCoreUI/Models/Extensions/MoleculeModelHelper.swift @@ -1,5 +1,5 @@ // -// ModelHelper.swift +// MoleculeModelHelper.swift // MVMCoreUI // // Created by Ryan on 11/12/19. diff --git a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift index 5bc59593..6a958061 100644 --- a/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift +++ b/MVMCoreUI/OtherHandlers/MoleculeObjectMapping.swift @@ -38,7 +38,7 @@ import Foundation //need to move labelattributemodel to different method ModelRegistry.register(LabelAttributeFontModel.self) ModelRegistry.register(LabelAttributeColorModel.self) - ModelRegistry.register(LabelAttributeImageModel.self) + //ModelRegistry.register(LabelAttributeImageModel.self) // We need to separate the registry by types due to collisions... ModelRegistry.register(LabelAttributeUnderlineModel.self) ModelRegistry.register(LabelAttributeStrikeThroughModel.self) ModelRegistry.register(LabelAttributeActionModel.self)