From 484b5785686430574aded0180d6e71eb1119cf7f Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 27 Aug 2024 14:30:39 -0500 Subject: [PATCH] added Pagination Signed-off-by: Matt Bruce --- MVMCoreUI.xcodeproj/project.pbxproj | 8 +++ MVMCoreUI/Atomic/Atoms/Views/Pagination.swift | 68 +++++++++++++++++++ .../Atomic/Atoms/Views/PaginationModel.swift | 67 ++++++++++++++++++ .../OtherHandlers/CoreUIModelMapping.swift | 1 + 4 files changed, 144 insertions(+) create mode 100644 MVMCoreUI/Atomic/Atoms/Views/Pagination.swift create mode 100644 MVMCoreUI/Atomic/Atoms/Views/PaginationModel.swift diff --git a/MVMCoreUI.xcodeproj/project.pbxproj b/MVMCoreUI.xcodeproj/project.pbxproj index 21144926..f3ba25ce 100644 --- a/MVMCoreUI.xcodeproj/project.pbxproj +++ b/MVMCoreUI.xcodeproj/project.pbxproj @@ -604,6 +604,8 @@ EA7AE5552C74F20600107C74 /* DatePickerEntryFieldModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7AE5542C74F20600107C74 /* DatePickerEntryFieldModel.swift */; }; EA7AE55C2C7D18A100107C74 /* BreadcrumbsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7AE55B2C7D18A100107C74 /* BreadcrumbsModel.swift */; }; EA7AE55E2C7D234500107C74 /* Breadcrumbs.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7AE55D2C7D234500107C74 /* Breadcrumbs.swift */; }; + EA7AE5602C7E554700107C74 /* PaginationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7AE55F2C7E554700107C74 /* PaginationModel.swift */; }; + EA7AE5622C7E555D00107C74 /* Pagination.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7AE5612C7E555D00107C74 /* Pagination.swift */; }; EA7D81602B2B6E6800D29F9E /* Icon.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7D815F2B2B6E6800D29F9E /* Icon.swift */; }; EA7D81622B2B6E7F00D29F9E /* IconModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7D81612B2B6E7F00D29F9E /* IconModel.swift */; }; EA7D81642B2BABCB00D29F9E /* TooltipModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA7D81632B2BABCB00D29F9E /* TooltipModel.swift */; }; @@ -1243,6 +1245,8 @@ EA7AE5542C74F20600107C74 /* DatePickerEntryFieldModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DatePickerEntryFieldModel.swift; sourceTree = ""; }; EA7AE55B2C7D18A100107C74 /* BreadcrumbsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BreadcrumbsModel.swift; sourceTree = ""; }; EA7AE55D2C7D234500107C74 /* Breadcrumbs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Breadcrumbs.swift; sourceTree = ""; }; + EA7AE55F2C7E554700107C74 /* PaginationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaginationModel.swift; sourceTree = ""; }; + EA7AE5612C7E555D00107C74 /* Pagination.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pagination.swift; sourceTree = ""; }; EA7D815F2B2B6E6800D29F9E /* Icon.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Icon.swift; sourceTree = ""; }; EA7D81612B2B6E7F00D29F9E /* IconModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IconModel.swift; sourceTree = ""; }; EA7D81632B2BABCB00D29F9E /* TooltipModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TooltipModel.swift; sourceTree = ""; }; @@ -2369,6 +2373,8 @@ D20492A524329CE200A5EED6 /* LoadImageView.swift */, 0A51F3E02475CB73002E08B6 /* LoadingSpinnerModel.swift */, 0A51F3E12475CB73002E08B6 /* LoadingSpinner.swift */, + EA7AE55F2C7E554700107C74 /* PaginationModel.swift */, + EA7AE5612C7E555D00107C74 /* Pagination.swift */, AA37CBD2251907200027344C /* StarsModel.swift */, AA37CBD42519072F0027344C /* Stars.swift */, AA07EA902510A442009A2AE3 /* StarModel.swift */, @@ -2957,6 +2963,7 @@ D29DF2CF21E7C104003B2FB9 /* MFLoadingViewController.m in Sources */, D28A837B23C928DA00DFE4FC /* MoleculeListCellProtocol.swift in Sources */, D28BA74D248589C800B75CB8 /* TabPageModelProtocol.swift in Sources */, + EA7AE5602C7E554700107C74 /* PaginationModel.swift in Sources */, 608211282AC6B57E00C3FC39 /* MVMCoreUILoggingHandler.swift in Sources */, 014AA72F23C5059B006F3E93 /* ThreeLayerPageTemplateModel.swift in Sources */, 0A21DB91235E0EDB00C160A2 /* DigitBox.swift in Sources */, @@ -2985,6 +2992,7 @@ EA7AE55C2C7D18A100107C74 /* BreadcrumbsModel.swift in Sources */, D20F3B44252E00E4004B3F56 /* PageProtocol.swift in Sources */, AA37CBD3251907200027344C /* StarsModel.swift in Sources */, + EA7AE5622C7E555D00107C74 /* Pagination.swift in Sources */, 8D084AD22410BF7600951227 /* ListOneColumnFullWidthTextBodyText.swift in Sources */, 94C0150C2421564A005811A9 /* ActionCollapseNotificationModel.swift in Sources */, D2CAC7CB251104E100C75681 /* NotificationXButtonModel.swift in Sources */, diff --git a/MVMCoreUI/Atomic/Atoms/Views/Pagination.swift b/MVMCoreUI/Atomic/Atoms/Views/Pagination.swift new file mode 100644 index 00000000..a34ff0d0 --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Views/Pagination.swift @@ -0,0 +1,68 @@ +// +// Pagination.swift +// MVMCoreUI +// +// Created by Matt Bruce on 8/27/24. +// Copyright © 2024 Verizon Wireless. All rights reserved. +// + +import Foundation +import VDS + +@objcMembers open class Pagination: VDS.Pagination, VDSMoleculeViewProtocol { + //------------------------------------------------------ + // MARK: - Properties + //------------------------------------------------------ + open var viewModel: PaginationModel! + open var delegateObject: MVMCoreUIDelegateObject? + open var additionalData: [AnyHashable : Any]? + + // Form Validation + open var fieldKey: String? + open var fieldValue: JSONValue? + open var groupName: String? + + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + + override public init(frame: CGRect) { + super.init(frame: frame) + } + + /// There is currently no intention on using xib files. + required public init?(coder aDecoder: NSCoder) { + super.init(coder: aDecoder) + fatalError("xib file is not implemented for Checkbox.") + } + + public convenience required init() { + self.init(frame:.zero) + } + + open override func setup() { + super.setup() + pageChangedPublisher + .sink { [weak self] control in + guard let self else { return } + viewModel?.selectedPage = control.selectedPage + }.store(in: &subscribers) + } + + open func viewModelDidUpdate() { + isEnabled = viewModel.enabled + surface = viewModel.surface + total = viewModel.totalPages + selectedPage = viewModel.selectedPage + } + + //-------------------------------------------------- + // MARK: - Actions + //-------------------------------------------------- + + //-------------------------------------------------- + // MARK: - MoleculeViewProtocol + //-------------------------------------------------- + public func updateView(_ size: CGFloat) {} + +} diff --git a/MVMCoreUI/Atomic/Atoms/Views/PaginationModel.swift b/MVMCoreUI/Atomic/Atoms/Views/PaginationModel.swift new file mode 100644 index 00000000..7027c7bb --- /dev/null +++ b/MVMCoreUI/Atomic/Atoms/Views/PaginationModel.swift @@ -0,0 +1,67 @@ +// +// PaginationModel.swift +// MVMCoreUI +// +// Created by Matt Bruce on 8/27/24. +// Copyright © 2024 Verizon Wireless. All rights reserved. +// + +import Foundation +import VDS +import MVMCore + +open class PaginationModel: MoleculeModelProtocol { + + //-------------------------------------------------- + // MARK: - Properties + //-------------------------------------------------- + open class var identifier: String { "pagination" } + open var moleculeName: String { Self.identifier } + open var backgroundColor: Color? + open var id: String = UUID().uuidString + + open var totalPages: Int = 0 + open var selectedPage: Int = 0 + open var enabled: Bool = true + open var inverted: Bool = false + open var surface: Surface { inverted ? .dark : .light } + + //-------------------------------------------------- + // MARK: - Keys + //-------------------------------------------------- + + private enum CodingKeys: String, CodingKey { + case totalPages + case selectedPage + case enabled + case inverted + } + + //-------------------------------------------------- + // MARK: - Initializers + //-------------------------------------------------- + + required public init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + totalPages = try container.decode(Int.self, forKey: .totalPages) + selectedPage = try container.decodeIfPresent(Int.self, forKey: .selectedPage) ?? 0 + enabled = try container.decodeIfPresent(Bool.self, forKey: .enabled) ?? false + inverted = try container.decodeIfPresent(Bool.self, forKey: .inverted) ?? false + } + + public func encode(to encoder: Encoder) throws { + var container = encoder.container(keyedBy: CodingKeys.self) + try container.encode(totalPages, forKey: .totalPages) + try container.encode(selectedPage, forKey: .selectedPage) + try container.encode(enabled, forKey: .enabled) + try container.encode(inverted, forKey: .inverted) + } + + public func isEqual(to model: any ModelComparisonProtocol) -> Bool { + guard let model = model as? Self else { return false } + return inverted == model.inverted + && enabled == model.enabled + && totalPages == model.totalPages + && selectedPage == model.selectedPage + } +} diff --git a/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift b/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift index da49a4a2..db0f9e6c 100644 --- a/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift +++ b/MVMCoreUI/OtherHandlers/CoreUIModelMapping.swift @@ -142,6 +142,7 @@ open class CoreUIModelMapping: ModelMapping { ModelRegistry.register(NavigationItemModel.self) ModelRegistry.register(NavigationImageButtonModel.self) ModelRegistry.register(NavigationLabelButtonModel.self) + ModelRegistry.register(handler: Pagination.self, for: PaginationModel.self) ModelRegistry.register(handler: Breadcrumbs.self, for: BreadcrumbsModel.self) ModelRegistry.register(BreadcrumbModel.self)