List template change to molecules not required (for now)

This commit is contained in:
Pfeil, Scott Robert 2020-01-23 11:01:36 -05:00
parent a2b62767bd
commit abc854e152
2 changed files with 16 additions and 7 deletions

View File

@ -17,7 +17,7 @@ import Foundation
public var isAtomicTabs: Bool?
public var header: MoleculeModelProtocol?
public var molecules: [ListItemModelProtocol]
public var molecules: [ListItemModelProtocol]?
public var footer: MoleculeModelProtocol?
public var line: LineModel?
@ -42,11 +42,7 @@ import Foundation
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
pageType = try typeContainer.decode(String.self, forKey: .pageType)
screenHeading = try typeContainer.decodeIfPresent(String.self, forKey: .screenHeading)
guard let molecules = try typeContainer.decodeMolecules(codingKey: .molecules) as? [ListItemModelProtocol] else {
throw JSONError.pathNotFound
}
self.molecules = molecules
molecules = try typeContainer.decodeMoleculesIfPresent(codingKey: .molecules) as? [ListItemModelProtocol]
isAtomicTabs = try typeContainer.decodeIfPresent(Bool.self, forKey: .isAtomicTabs)
header = try typeContainer.decodeMoleculeIfPresent(codingKey: .header)
footer = try typeContainer.decodeMoleculeIfPresent(codingKey: .footer)
@ -57,7 +53,7 @@ import Foundation
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(pageType, forKey: .pageType)
try container.encodeIfPresent(screenHeading, forKey: .screenHeading)
try container.encodeModels(molecules, forKey: .molecules)
try container.encodeModelsIfPresent(molecules, forKey: .molecules)
try container.encodeIfPresent(isAtomicTabs, forKey: .isAtomicTabs)
try container.encodeModelIfPresent(header, forKey: .header)
try container.encodeModelIfPresent(footer, forKey: .footer)

View File

@ -53,6 +53,19 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
return molecule
}
open override func shouldFinishProcessingLoad(_ loadObject: MVMCoreLoadObject, error: AutoreleasingUnsafeMutablePointer<MVMCoreErrorObject>) -> Bool {
let shouldFinish = super.shouldFinishProcessingLoad(loadObject, error: error)
// This template requires atleast one of the three layers.
if templateModel?.header == nil,
templateModel?.molecules?.count ?? 0 == 0,
templateModel?.footer == nil,
let errorObject = MVMCoreErrorObject(title: nil, message: MVMCoreGetterUtility.hardcodedString(withKey: HardcodedErrorUnableToProcess), messageToLog: "List template requires atleast one of the following: header, footer, molecules", code: CoreUIErrorCode.ErrorCodeListMolecule.rawValue, domain: ErrorDomainNative, location: String(describing: self)) {
error.pointee = errorObject
return false
}
return shouldFinish
}
open override func newDataBuildScreen() {
super.newDataBuildScreen()
setup()