Merge branch 'feature/entry_fields_models' of https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui into feature/entry_fields_models
This commit is contained in:
commit
86e6a0aba7
@ -40,7 +40,9 @@ import UIKit
|
|||||||
for moleculeList in molecules {
|
for moleculeList in molecules {
|
||||||
var json1d = [[AnyHashable: Any]]()
|
var json1d = [[AnyHashable: Any]]()
|
||||||
for molecule in moleculeList {
|
for molecule in moleculeList {
|
||||||
json1d.append((molecule as? ListItemModel)!.toJSON()!)
|
if let moleculeDictionary = (molecule as? ListItemModel)?.toJSON() {
|
||||||
|
json1d.append(moleculeDictionary)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
json2d.append(json1d)
|
json2d.append(json1d)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,10 +9,10 @@
|
|||||||
import UIKit
|
import UIKit
|
||||||
|
|
||||||
open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol {
|
open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol {
|
||||||
|
|
||||||
public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]?
|
public var moleculesInfo: [(identifier: String, class: AnyClass, molecule: ListItemModelProtocol)]?
|
||||||
var observer: NSKeyValueObservation?
|
var observer: NSKeyValueObservation?
|
||||||
|
|
||||||
public var templateModel: ListPageTemplateModel?
|
public var templateModel: ListPageTemplateModel?
|
||||||
@objc public override func parsePageJSON() throws {
|
@objc public override func parsePageJSON() throws {
|
||||||
try parseTemplateJSON()
|
try parseTemplateJSON()
|
||||||
@ -31,11 +31,11 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
open override func viewForTop() -> UIView {
|
open override func viewForTop() -> UIView {
|
||||||
guard let headerModel = templateModel?.header,
|
guard let headerModel = templateModel?.header,
|
||||||
let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(headerModel, delegateObject() as? MVMCoreUIDelegateObject, false) else {
|
let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(headerModel, delegateObject() as? MVMCoreUIDelegateObject, false) else {
|
||||||
return super.viewForTop()
|
return super.viewForTop()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Temporary, Default the horizontal padding
|
// Temporary, Default the horizontal padding
|
||||||
@ -48,7 +48,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
override open func viewForBottom() -> UIView {
|
override open func viewForBottom() -> UIView {
|
||||||
guard let footerModel = templateModel?.footer,
|
guard let footerModel = templateModel?.footer,
|
||||||
let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(footerModel, delegateObject() as? MVMCoreUIDelegateObject, false) else {
|
let molecule = MVMCoreUIMoleculeMappingObject.shared()?.createMolecule(footerModel, delegateObject() as? MVMCoreUIDelegateObject, false) else {
|
||||||
return super.viewForBottom()
|
return super.viewForBottom()
|
||||||
}
|
}
|
||||||
return molecule
|
return molecule
|
||||||
}
|
}
|
||||||
@ -97,7 +97,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
open override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
||||||
guard let moleculeInfo = moleculesInfo?[indexPath.row],
|
guard let moleculeInfo = moleculesInfo?[indexPath.row],
|
||||||
let cell = tableView.dequeueReusableCell(withIdentifier: moleculeInfo.identifier) else {
|
let cell = tableView.dequeueReusableCell(withIdentifier: moleculeInfo.identifier) else {
|
||||||
return UITableViewCell()
|
return UITableViewCell()
|
||||||
}
|
}
|
||||||
let delegate = delegateObject() as? MVMCoreUIDelegateObject
|
let delegate = delegateObject() as? MVMCoreUIDelegateObject
|
||||||
let moleculeCell = cell as? MVMCoreUIMoleculeViewProtocol
|
let moleculeCell = cell as? MVMCoreUIMoleculeViewProtocol
|
||||||
@ -145,17 +145,15 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
public override func addMolecules(_ molecules: [[AnyHashable: Any]], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||||
|
|
||||||
var tmpMolecules = [ListItemModelProtocol]()
|
var tmpMolecules = [ListItemModelProtocol]()
|
||||||
|
|
||||||
molecules.forEach { molecule in
|
molecules.forEach { molecule in
|
||||||
let data = try? JSONSerialization.data(withJSONObject: molecule)
|
if let data = try? JSONSerialization.data(withJSONObject: molecule), let listItemModel = try? JSONDecoder().decode(ListItemModel.self, from: data) {
|
||||||
let listItemModel = try? JSONDecoder().decode(ListItemModel.self, from: data!)
|
tmpMolecules.append(listItemModel)
|
||||||
let jsonData = try? JSONSerialization.jsonObject(with: data!, options: .allowFragments)
|
}
|
||||||
let json = String(data: data!, encoding: String.Encoding.utf8)
|
|
||||||
tmpMolecules.append(listItemModel!)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
@ -180,9 +178,9 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
var tmpMolecules = [ListItemModelProtocol]()
|
var tmpMolecules = [ListItemModelProtocol]()
|
||||||
|
|
||||||
molecules.forEach { molecule in
|
molecules.forEach { molecule in
|
||||||
let data = try? JSONSerialization.data(withJSONObject: molecule)
|
if let data = try? JSONSerialization.data(withJSONObject: molecule), let listItemModel = try? JSONDecoder().decode(ListItemModel.self, from: data) {
|
||||||
let listItemModel = try? JSONDecoder().decode(ListItemModel.self, from: data!)
|
tmpMolecules.append(listItemModel)
|
||||||
tmpMolecules.append(listItemModel!)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var indexPaths: [IndexPath] = []
|
var indexPaths: [IndexPath] = []
|
||||||
@ -202,21 +200,21 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
|
|
||||||
public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
public func addMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||||
// This dispatch is needed to fix a race condition that can occur if this function is called during the table setup.
|
// This dispatch is needed to fix a race condition that can occur if this function is called during the table setup.
|
||||||
DispatchQueue.main.async {
|
DispatchQueue.main.async {
|
||||||
guard let indexPath = self.tableView?.indexPath(for: sender) else { return }
|
guard let indexPath = self.tableView?.indexPath(for: sender) else { return }
|
||||||
var indexPaths: [IndexPath] = []
|
var indexPaths: [IndexPath] = []
|
||||||
for molecule in molecules {
|
for molecule in molecules {
|
||||||
if let info = self.getMoleculeInfo(with: molecule) {
|
if let info = self.getMoleculeInfo(with: molecule) {
|
||||||
self.tableView?.register(info.class, forCellReuseIdentifier: info.identifier)
|
self.tableView?.register(info.class, forCellReuseIdentifier: info.identifier)
|
||||||
let index = indexPath.row + 1 + indexPaths.count
|
let index = indexPath.row + 1 + indexPaths.count
|
||||||
self.moleculesInfo?.insert(info, at: index)
|
self.moleculesInfo?.insert(info, at: index)
|
||||||
indexPaths.append(IndexPath(row: index, section: 0))
|
indexPaths.append(IndexPath(row: index, section: 0))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.tableView?.insertRows(at: indexPaths, with: animation)
|
self.tableView?.insertRows(at: indexPaths, with: animation)
|
||||||
self.updateViewConstraints()
|
self.updateViewConstraints()
|
||||||
self.view.layoutIfNeeded()
|
self.view.layoutIfNeeded()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
public func removeMolecules(_ molecules: [ListItemModelProtocol], sender: UITableViewCell, animation: UITableView.RowAnimation) {
|
||||||
@ -241,7 +239,7 @@ open class MoleculeListTemplate: ThreeLayerTableViewController, TemplateProtocol
|
|||||||
guard let listItem = listItem,
|
guard let listItem = listItem,
|
||||||
let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(listItem),
|
let moleculeClass = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeClass(listItem),
|
||||||
let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.nameForReuse(listItem, delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.moleculeName else {
|
let moleculeName = (moleculeClass as? ModelMoleculeViewProtocol.Type)?.nameForReuse(listItem, delegateObject() as? MVMCoreUIDelegateObject) ?? listItem.moleculeName else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return (moleculeName, moleculeClass, listItem)
|
return (moleculeName, moleculeClass, listItem)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user