Showing
1 changed file
with
37 additions
and
1 deletions
... | @@ -28,6 +28,7 @@ public struct GlobalVariables { | ... | @@ -28,6 +28,7 @@ public struct GlobalVariables { |
28 | static var metersWebview: Double = 0.0 | 28 | static var metersWebview: Double = 0.0 |
29 | static var merchantList: Array<swiftApi.MerchantModel> = [] | 29 | static var merchantList: Array<swiftApi.MerchantModel> = [] |
30 | static var trackingStepsEnabled: Bool = false | 30 | static var trackingStepsEnabled: Bool = false |
31 | + static var carouselList: Array<swiftApi.CampaignItemModel> = [] | ||
31 | } | 32 | } |
32 | 33 | ||
33 | var timer: DispatchSourceTimer? | 34 | var timer: DispatchSourceTimer? |
... | @@ -102,6 +103,19 @@ public class swiftApi { | ... | @@ -102,6 +103,19 @@ public class swiftApi { |
102 | GlobalVariables.trackingStepsEnabled = newValue | 103 | GlobalVariables.trackingStepsEnabled = newValue |
103 | } | 104 | } |
104 | 105 | ||
106 | + public func setCarouselList(_ campaigns: Array<CampaignItemModel>) -> Void { | ||
107 | + // let sortedCampaigns = campaigns.sorted { | ||
108 | + // ($0._sorting ?? 0) < ($1._sorting ?? 0) | ||
109 | + // } | ||
110 | + | ||
111 | + GlobalVariables.carouselList = campaigns | ||
112 | + } | ||
113 | + | ||
114 | + public func getCarouselList() -> Array<CampaignItemModel> { | ||
115 | + | ||
116 | + return GlobalVariables.carouselList | ||
117 | + } | ||
118 | + | ||
105 | 119 | ||
106 | public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { | 120 | public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void { |
107 | 121 | ||
... | @@ -764,6 +778,7 @@ public class swiftApi { | ... | @@ -764,6 +778,7 @@ public class swiftApi { |
764 | public var type: String? | 778 | public var type: String? |
765 | public var sorting: Int? | 779 | public var sorting: Int? |
766 | private var ccms: LoyaltyContextualOfferModel? | 780 | private var ccms: LoyaltyContextualOfferModel? |
781 | + private var carousel: String? | ||
767 | 782 | ||
768 | public init() { | 783 | public init() { |
769 | self.index_url = "" | 784 | self.index_url = "" |
... | @@ -786,6 +801,7 @@ public class swiftApi { | ... | @@ -786,6 +801,7 @@ public class swiftApi { |
786 | self.type = "" | 801 | self.type = "" |
787 | self.sorting = 0 | 802 | self.sorting = 0 |
788 | self.ccms = nil | 803 | self.ccms = nil |
804 | + self.carousel = "false" | ||
789 | } | 805 | } |
790 | 806 | ||
791 | public init(dictionary: [String: Any]) { | 807 | public init(dictionary: [String: Any]) { |
... | @@ -810,6 +826,7 @@ public class swiftApi { | ... | @@ -810,6 +826,7 @@ public class swiftApi { |
810 | self.ccms_offer = extra_fields["ccms_offer"] as? String? ?? "false" | 826 | self.ccms_offer = extra_fields["ccms_offer"] as? String? ?? "false" |
811 | self.badge = extra_fields["badge"] as? String? ?? "" | 827 | self.badge = extra_fields["badge"] as? String? ?? "" |
812 | self.type = extra_fields["type"] as? String? ?? "" | 828 | self.type = extra_fields["type"] as? String? ?? "" |
829 | + self.carousel = extra_fields["carousel"] as? String? ?? "false" | ||
813 | } else { | 830 | } else { |
814 | self.subcategory = "" | 831 | self.subcategory = "" |
815 | self.loyaltyCampaignId = "" | 832 | self.loyaltyCampaignId = "" |
... | @@ -817,6 +834,7 @@ public class swiftApi { | ... | @@ -817,6 +834,7 @@ public class swiftApi { |
817 | self.ccms_offer = "false" | 834 | self.ccms_offer = "false" |
818 | self.badge = "" | 835 | self.badge = "" |
819 | self.type = "" | 836 | self.type = "" |
837 | + self.carousel = "false" | ||
820 | } | 838 | } |
821 | 839 | ||
822 | // let extra_fields = dictionary["extra_fields"] as AnyObject | 840 | // let extra_fields = dictionary["extra_fields"] as AnyObject |
... | @@ -999,6 +1017,15 @@ public class swiftApi { | ... | @@ -999,6 +1017,15 @@ public class swiftApi { |
999 | self.ccms = newValue | 1017 | self.ccms = newValue |
1000 | } | 1018 | } |
1001 | } | 1019 | } |
1020 | + | ||
1021 | + public var _carousel: String? { | ||
1022 | + get { // getter | ||
1023 | + return self.carousel | ||
1024 | + } | ||
1025 | + set(newValue) { //setter | ||
1026 | + self.carousel = newValue | ||
1027 | + } | ||
1028 | + } | ||
1002 | } | 1029 | } |
1003 | 1030 | ||
1004 | public class CampaignDataModel { | 1031 | public class CampaignDataModel { |
... | @@ -1067,6 +1094,7 @@ public class swiftApi { | ... | @@ -1067,6 +1094,7 @@ public class swiftApi { |
1067 | 1094 | ||
1068 | func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void { | 1095 | func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void { |
1069 | var campaignsArray:Array<CampaignItemModel> = [] | 1096 | var campaignsArray:Array<CampaignItemModel> = [] |
1097 | + var carouselArray:Array<CampaignItemModel> = [] | ||
1070 | 1098 | ||
1071 | if let responseDataDictionary = campaignsData as? [String: AnyObject] { | 1099 | if let responseDataDictionary = campaignsData as? [String: AnyObject] { |
1072 | 1100 | ||
... | @@ -1091,7 +1119,13 @@ public class swiftApi { | ... | @@ -1091,7 +1119,13 @@ public class swiftApi { |
1091 | 1119 | ||
1092 | swiftApi().setUniqueCampaignList(campaignsArray) | 1120 | swiftApi().setUniqueCampaignList(campaignsArray) |
1093 | 1121 | ||
1094 | - SwiftEventBus.post("campaigns_retrieved") | 1122 | + carouselArray = campaignsArray.filter { |
1123 | + let tempCampaign = $0 | ||
1124 | + let isCarouselItem = (tempCampaign._carousel != nil) && (tempCampaign._carousel == "true") | ||
1125 | + | ||
1126 | + return (isCarouselItem) | ||
1127 | + } | ||
1128 | + swiftApi().setCarouselList(carouselArray) | ||
1095 | 1129 | ||
1096 | var filteredCampaigns = campaignsArray.filter { | 1130 | var filteredCampaigns = campaignsArray.filter { |
1097 | let tempCampaign = $0 | 1131 | let tempCampaign = $0 |
... | @@ -1110,6 +1144,8 @@ public class swiftApi { | ... | @@ -1110,6 +1144,8 @@ public class swiftApi { |
1110 | } | 1144 | } |
1111 | 1145 | ||
1112 | getCampaignsCallback(sortedCampaigns); | 1146 | getCampaignsCallback(sortedCampaigns); |
1147 | + | ||
1148 | + SwiftEventBus.post("campaigns_retrieved") | ||
1113 | }) | 1149 | }) |
1114 | 1150 | ||
1115 | } else { | 1151 | } else { | ... | ... |
-
Please register or login to post a comment