Merge branch 'bugfix/label_model_fix' into 'develop'

Codable Change

See merge request BPHV_MIPS/mvm_core_ui!254
This commit is contained in:
Pfeil, Scott Robert 2020-02-12 22:06:34 -05:00
commit f94056bc9a
20 changed files with 149 additions and 58 deletions

View File

@ -17,6 +17,7 @@ public enum GraphStyle: String, Codable {
} }
public class CircleProgressModel: MoleculeModelProtocol { public class CircleProgressModel: MoleculeModelProtocol {
public static var identifier: String = "circleProgress" public static var identifier: String = "circleProgress"
public var style: GraphStyle = .unlimited { public var style: GraphStyle = .unlimited {
didSet { didSet {

View File

@ -9,6 +9,9 @@
import UIKit import UIKit
@objcMembers public class LabelAttributeColorModel: LabelAttributeModel { @objcMembers public class LabelAttributeColorModel: LabelAttributeModel {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
override public class var identifier: String { override public class var identifier: String {
return "color" return "color"
@ -16,14 +19,21 @@ import UIKit
var textColor: String? var textColor: String?
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case textColor case textColor
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.textColor = try typeContainer.decodeIfPresent(String.self, forKey: .textColor) textColor = try typeContainer.decodeIfPresent(String.self, forKey: .textColor)
try super.init(from: decoder) try super.init(from: decoder)
} }

View File

@ -8,7 +8,12 @@
import UIKit import UIKit
@objcMembers public class LabelAttributeFontModel: LabelAttributeModel { @objcMembers public class LabelAttributeFontModel: LabelAttributeModel {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
override public class var identifier: String { override public class var identifier: String {
return "font" return "font"
} }
@ -17,17 +22,25 @@ import UIKit
var name: String? var name: String?
var size: CGFloat? var size: CGFloat?
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case style case style
case name case name
case size case size
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.style = try typeContainer.decodeIfPresent(String.self, forKey: .style) style = try typeContainer.decodeIfPresent(String.self, forKey: .style)
self.name = try typeContainer.decodeIfPresent(String.self, forKey: .name) name = try typeContainer.decodeIfPresent(String.self, forKey: .name)
self.size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size) size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size)
try super.init(from: decoder) try super.init(from: decoder)
} }

View File

@ -9,7 +9,10 @@
import UIKit import UIKit
class LabelAttributeImageModel: LabelAttributeModel { class LabelAttributeImageModel: LabelAttributeModel {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
override public class var identifier: String { override public class var identifier: String {
return "image" return "image"
} }
@ -18,17 +21,25 @@ class LabelAttributeImageModel: LabelAttributeModel {
var name: String? var name: String?
var URL: String? var URL: String?
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case size case size
case name case name
case URL case URL
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size) size = try typeContainer.decodeIfPresent(CGFloat.self, forKey: .size)
self.name = try typeContainer.decodeIfPresent(String.self, forKey: .name) name = try typeContainer.decodeIfPresent(String.self, forKey: .name)
self.URL = try typeContainer.decodeIfPresent(String.self, forKey: .URL) URL = try typeContainer.decodeIfPresent(String.self, forKey: .URL)
try super.init(from: decoder) try super.init(from: decoder)
} }

View File

@ -9,6 +9,17 @@
import Foundation import Foundation
@objcMembers open class LabelAttributeModel: Model { @objcMembers open class LabelAttributeModel: Model {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var categoryName: String {
return "\(LabelAttributeModel.self)"
}
public static var categoryCodingKey: String {
return "type"
}
public class var identifier: String { public class var identifier: String {
return "" return ""
@ -18,17 +29,25 @@ import Foundation
var location: Int var location: Int
var length: Int var length: Int
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case type case type
case location case location
case length case length
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
self.type = try typeContainer.decode(String.self, forKey: .type) type = try typeContainer.decode(String.self, forKey: .type)
self.location = try typeContainer.decode(Int.self, forKey: .location) location = try typeContainer.decode(Int.self, forKey: .location)
self.length = try typeContainer.decode(Int.self, forKey: .length) length = try typeContainer.decode(Int.self, forKey: .length)
} }
public func encode(to encoder: Encoder) throws { public func encode(to encoder: Encoder) throws {
@ -37,5 +56,4 @@ import Foundation
try container.encode(location, forKey: .location) try container.encode(location, forKey: .location)
try container.encode(length, forKey: .length) try container.encode(length, forKey: .length)
} }
} }

View File

@ -9,41 +9,35 @@
import Foundation import Foundation
extension MFViewController: MoleculeDelegateProtocol { extension MFViewController: MoleculeDelegateProtocol {
public func getModuleWithName(_ name: String?) -> [AnyHashable : Any]? {
guard let name = name else { public func getModuleWithName(_ name: String?) -> [AnyHashable: Any]? {
return nil guard let name = name else { return nil }
}
return loadObject?.modulesJSON?.optionalDictionaryForKey(name) return loadObject?.modulesJSON?.optionalDictionaryForKey(name)
} }
public func getModuleWithName(_ moduleName: String) -> MoleculeModelProtocol? { public func getModuleWithName(_ moleculeName: String) -> MoleculeModelProtocol? {
guard let moduleJSON = loadObject?.modulesJSON?.optionalDictionaryForKey(moduleName), guard let moduleJSON = loadObject?.modulesJSON?.optionalDictionaryForKey(moleculeName),
let moleculeName = moduleJSON.optionalStringForKey("moleculeName"), let moleculeName = moduleJSON.optionalStringForKey("moleculeName"),
let modelType = ModelRegistry.getType(for: moleculeName) as? MoleculeModelProtocol.Type else { let modelType = ModelRegistry.getType(for: moleculeName, with: MoleculeModelProtocol.self)
return nil else { return nil }
}
do { do {
return try modelType.decode(jsonDict: moduleJSON) return try modelType.decode(jsonDict: moduleJSON) as? MoleculeModelProtocol
} catch { } catch {
MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)") MVMCoreUILoggingHandler.logDebugMessage(withDelegate: "error: \(error)")
} }
return nil return nil
} }
@objc public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { @objc public func moleculeLayoutUpdated(_ molecule: UIView & MVMCoreUIMoleculeViewProtocol) { }
}
@objc public func addMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { @objc public func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { }
// Do nothing
}
@objc public func removeMolecules(_ molecules: [[AnyHashable : Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { @objc public func removeMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) { }
// Do nothing
}
} }
public extension MFViewController { public extension MFViewController {
@objc func parsePageJSON() throws { @objc func parsePageJSON() throws { }
}
} }

View File

@ -8,7 +8,9 @@
import Foundation import Foundation
extension KeyedDecodingContainer where Key : CodingKey {
extension KeyedDecodingContainer where Key: CodingKey {
private enum TypeCodingKey: String, CodingKey { private enum TypeCodingKey: String, CodingKey {
case moleculeName case moleculeName
} }

View File

@ -8,7 +8,8 @@
import Foundation import Foundation
public protocol CarouselItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol { public protocol CarouselItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol {
var peakingUI: Bool? {get} var peakingUI: Bool? { get }
var peakingArrowColor: Color? {get} var peakingArrowColor: Color? { get }
} }

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
public protocol CarouselPagingModelProtocol: MoleculeModelProtocol { public protocol CarouselPagingModelProtocol: MoleculeModelProtocol {
var position: Float? {get} var position: Float? { get }
} }

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
public protocol ContainerModelProtocol { public protocol ContainerModelProtocol {
var horizontalAlignment: UIStackView.Alignment? { get set } var horizontalAlignment: UIStackView.Alignment? { get set }
var verticalAlignment: UIStackView.Alignment? { get set } var verticalAlignment: UIStackView.Alignment? { get set }

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
public protocol EnableableModelProtocol { public protocol EnableableModelProtocol {
var enabled: Bool { get set } var enabled: Bool { get set }
} }

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
public protocol FormModelProtocol: Model { public protocol FormModelProtocol: Model {
var required: Bool? { get } var required: Bool? { get }
var fieldKey: String? { get } var fieldKey: String? { get }

View File

@ -8,6 +8,7 @@
import Foundation import Foundation
public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol { public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeModelProtocol {
var line: LineModel? { get set } var line: LineModel? { get set }
var action: ActionModelProtocol? { get set } var action: ActionModelProtocol? { get set }
@ -16,14 +17,14 @@ public protocol ListItemModelProtocol: ContainerModelProtocol, MoleculeModelProt
} }
// Not a strict requirement. // Not a strict requirement.
extension ListItemModelProtocol { public extension ListItemModelProtocol {
public var action: ActionModelProtocol? { var action: ActionModelProtocol? {
get { return nil } get { return nil }
set { } set { }
} }
public var style: String? { var style: String? {
get { return nil } get { return nil }
set { } set { }
} }

View File

@ -1,12 +1,22 @@
import Foundation import Foundation
public protocol MoleculeModelProtocol: Model { public protocol MoleculeModelProtocol: Model {
var moleculeName: String? { get } var moleculeName: String? { get }
var backgroundColor: Color? { get set} var backgroundColor: Color? { get set}
} }
extension MoleculeModelProtocol { public extension MoleculeModelProtocol {
public var moleculeName: String? {
var moleculeName: String? {
get { return Self.identifier } get { return Self.identifier }
} }
static var categoryName: String {
return "\(MoleculeModelProtocol.self)"
}
static var categoryCodingKey: String {
return "moleculeName"
}
} }

View File

@ -8,7 +8,8 @@
import Foundation import Foundation
public protocol PageModelProtocol: Model {
public protocol PageModelProtocol {
var pageType: String { get set } var pageType: String { get set }
var screenHeading: String? { get set } var screenHeading: String? { get set }
var isAtomicTabs: Bool? { get set } var isAtomicTabs: Bool? { get set }

View File

@ -8,12 +8,22 @@
import Foundation import Foundation
public protocol TemplateModelProtocol: PageModelProtocol {
public protocol TemplateModelProtocol: PageModelProtocol, Model {
var template: String { get } var template: String { get }
} }
extension TemplateModelProtocol { public extension TemplateModelProtocol {
public var template: String {
var template: String {
get { return Self.identifier } get { return Self.identifier }
} }
static var categoryCodingKey: String {
return "template"
}
static var categoryName: String {
return "\(TemplateModelProtocol.self)"
}
} }

View File

@ -11,7 +11,7 @@ import Foundation
public extension MVMCoreUIMoleculeMappingObject { public extension MVMCoreUIMoleculeMappingObject {
func register<M: Model, V: MVMCoreUIMoleculeViewProtocol>(viewClass: V.Type, viewModelClass: M.Type) { func register<M: Model, V: MVMCoreUIMoleculeViewProtocol>(viewClass: V.Type, viewModelClass: M.Type) {
ModelRegistry.register(viewModelClass) try? ModelRegistry.register(viewModelClass)
MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(viewClass, forKey: viewModelClass.identifier as NSString) MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(viewClass, forKey: viewModelClass.identifier as NSString)
} }

View File

@ -18,13 +18,13 @@ import Foundation
// Label // Label
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Label.self, viewModelClass: LabelModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Label.self, viewModelClass: LabelModel.self)
//need to move labelattributemodel to different method // need to move labelattributemodel to different method
ModelRegistry.register(LabelAttributeFontModel.self) try? ModelRegistry.register(LabelAttributeFontModel.self)
ModelRegistry.register(LabelAttributeColorModel.self) try? ModelRegistry.register(LabelAttributeColorModel.self)
//ModelRegistry.register(LabelAttributeImageModel.self) // We need to separate the registry by types due to collisions... try? ModelRegistry.register(LabelAttributeImageModel.self) // We need to separate the registry by types due to collisions...
ModelRegistry.register(LabelAttributeUnderlineModel.self) try? ModelRegistry.register(LabelAttributeUnderlineModel.self)
ModelRegistry.register(LabelAttributeStrikeThroughModel.self) try? ModelRegistry.register(LabelAttributeStrikeThroughModel.self)
ModelRegistry.register(LabelAttributeActionModel.self) try? ModelRegistry.register(LabelAttributeActionModel.self)
// Buttons // Buttons
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: PillButton.self, viewModelClass: ButtonModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: PillButton.self, viewModelClass: ButtonModel.self)
@ -40,7 +40,6 @@ import Foundation
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: DateDropdownEntryField.self, viewModelClass: DateDropdownEntryFieldModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: DateDropdownEntryField.self, viewModelClass: DateDropdownEntryFieldModel.self)
// Other Atoms // Other Atoms
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: Label.self, viewModelClass: LabelModel.self)
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: ProgressBar.self, viewModelClass: ProgressBarModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: ProgressBar.self, viewModelClass: ProgressBarModel.self)
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MultiProgress.self, viewModelClass: MultiProgressBarModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: MultiProgress.self, viewModelClass: MultiProgressBarModel.self)
MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CaretView.self, viewModelClass: CaretViewModel.self) MVMCoreUIMoleculeMappingObject.shared()?.register(viewClass: CaretView.self, viewModelClass: CaretViewModel.self)
@ -107,6 +106,6 @@ import Foundation
MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(MVMCoreUIPageControl.self, forKey: "barsPager" as NSString) MVMCoreUIMoleculeMappingObject.shared()?.moleculeMapping.setObject(MVMCoreUIPageControl.self, forKey: "barsPager" as NSString)
// TODO: Need View // TODO: Need View
ModelRegistry.register(TabsModel.self) try? ModelRegistry.register(TabsModel.self)
} }
} }

View File

@ -9,7 +9,10 @@
import Foundation import Foundation
@objcMembers public class ListPageTemplateModel: TemplateModelProtocol { @objcMembers public class ListPageTemplateModel: TemplateModelProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
public static var identifier: String = "list" public static var identifier: String = "list"
public var pageType: String public var pageType: String
@ -21,12 +24,20 @@ import Foundation
public var footer: MoleculeModelProtocol? public var footer: MoleculeModelProtocol?
public var line: LineModel? public var line: LineModel?
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
public init(pageType: String, screenHeading: String?, molecules: [ListItemModelProtocol]) { public init(pageType: String, screenHeading: String?, molecules: [ListItemModelProtocol]) {
self.pageType = pageType self.pageType = pageType
self.screenHeading = screenHeading self.screenHeading = screenHeading
self.molecules = molecules self.molecules = molecules
} }
//--------------------------------------------------
// MARK: - Keys
//--------------------------------------------------
private enum CodingKeys: String, CodingKey { private enum CodingKeys: String, CodingKey {
case moleculeName case moleculeName
case pageType case pageType
@ -38,6 +49,10 @@ import Foundation
case isAtomicTabs case isAtomicTabs
} }
//--------------------------------------------------
// MARK: - Codec
//--------------------------------------------------
required public init(from decoder: Decoder) throws { required public init(from decoder: Decoder) throws {
let typeContainer = try decoder.container(keyedBy: CodingKeys.self) let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
pageType = try typeContainer.decode(String.self, forKey: .pageType) pageType = try typeContainer.decode(String.self, forKey: .pageType)

View File

@ -14,6 +14,7 @@ public protocol TemplateProtocol: class {
} }
public extension TemplateProtocol where Self: MFViewController { public extension TemplateProtocol where Self: MFViewController {
func parseTemplateJSON() throws { func parseTemplateJSON() throws {
guard let pageJSON = self.loadObject?.pageJSON else { return } guard let pageJSON = self.loadObject?.pageJSON else { return }
let data = try JSONSerialization.data(withJSONObject: pageJSON) let data = try JSONSerialization.data(withJSONObject: pageJSON)