Created
March 21, 2016 11:15
-
-
Save frosty/a5cefb3adcee3b70de41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/WordPress/Classes/Models/Plan.swift b/WordPress/Classes/Models/Plan.swift | |
index 5a4826d..ba8053c 100644 | |
--- a/WordPress/Classes/Models/Plan.swift | |
+++ b/WordPress/Classes/Models/Plan.swift | |
@@ -14,6 +14,16 @@ struct Plan { | |
let fullTitle: String | |
let description: String | |
let productIdentifier: String? | |
+ var featureGroups = [PlanFeatureGroup]() | |
+ | |
+ init(id: PlanID, slug: String, title: String, fullTitle: String, description: String, productIdentifier: String? = nil) { | |
+ self.id = id | |
+ self.slug = slug | |
+ self.title = title | |
+ self.fullTitle = fullTitle | |
+ self.description = description | |
+ self.productIdentifier = productIdentifier | |
+ } | |
} | |
extension Plan { | |
@@ -124,14 +134,4 @@ struct PlanFeature { | |
struct PlanFeatureGroup { | |
let title: String? | |
let slugs: [String] | |
- | |
- static private var groups = [Plan: [PlanFeatureGroup]]() | |
- | |
- static func groupsForPlan(plan: Plan) -> [PlanFeatureGroup]? { | |
- return groups[plan] | |
- } | |
- | |
- static func setGroups(groups: [PlanFeatureGroup], forPlan plan: Plan) { | |
- self.groups[plan] = groups | |
- } | |
} | |
diff --git a/WordPress/Classes/Networking/PlansRemote.swift b/WordPress/Classes/Networking/PlansRemote.swift | |
index 105e28a..a9f4bf8 100644 | |
--- a/WordPress/Classes/Networking/PlansRemote.swift | |
+++ b/WordPress/Classes/Networking/PlansRemote.swift | |
@@ -40,12 +40,13 @@ private func mapPlansResponse(response: AnyObject) throws -> (activePlan: Plan, | |
guard let planId = planDetails["product_id"] as? Int else { | |
throw PlansRemote.Error.DecodeError | |
} | |
- guard let plan = defaultPlans.withID(planId) else { | |
+ guard var plan = defaultPlans.withID(planId) else { | |
throw PlansRemote.Error.UnsupportedPlan | |
} | |
if let featureGroupsJson = planDetails["features_highlight"] as? [[String: AnyObject]] { | |
- parseFeatureGroups(featureGroupsJson, forPlan: plan) | |
+ let featureGroups = parseFeatureGroups(featureGroupsJson) | |
+ plan.featureGroups = featureGroups | |
} | |
let plans = result.1 + [plan] | |
@@ -64,13 +65,13 @@ private func mapPlansResponse(response: AnyObject) throws -> (activePlan: Plan, | |
return (activePlan, availablePlans) | |
} | |
-private func parseFeatureGroups(json: [[String: AnyObject]], forPlan plan: Plan) { | |
+private func parseFeatureGroups(json: [[String: AnyObject]]) -> [PlanFeatureGroup] { | |
let groups: [PlanFeatureGroup] = json.flatMap { groupJson in | |
guard let slugs = groupJson["items"] as? [String] else { return nil } | |
return PlanFeatureGroup(title: groupJson["title"] as? String, slugs: slugs) | |
} | |
- | |
- PlanFeatureGroup.setGroups(groups, forPlan: plan) | |
+ | |
+ return groups | |
} | |
class PlanFeaturesRemote: ServiceRemoteREST { | |
diff --git a/WordPress/Classes/ViewRelated/Plans/PlanComparisonViewController.swift b/WordPress/Classes/ViewRelated/Plans/PlanComparisonViewController.swift | |
index aa554d6..c5acd95 100644 | |
--- a/WordPress/Classes/ViewRelated/Plans/PlanComparisonViewController.swift | |
+++ b/WordPress/Classes/ViewRelated/Plans/PlanComparisonViewController.swift | |
@@ -35,7 +35,7 @@ class PlanComparisonViewController: UIViewController { | |
} | |
}() | |
- private let allPlans = defaultPlans | |
+ var allPlans = [Plan]() | |
lazy private var cancelXButton: UIBarButtonItem = { | |
let button = UIBarButtonItem(image: UIImage(named: "gridicons-cross"), style: .Plain, target: self, action: "closeTapped") | |
@@ -44,10 +44,11 @@ class PlanComparisonViewController: UIViewController { | |
return button | |
}() | |
- class func controllerWithInitialPlan(plan: Plan, activePlan: Plan? = nil) -> PlanComparisonViewController { | |
+ class func controllerWithInitialPlan(plan: Plan, activePlan: Plan? = nil, allPlans: [Plan] = [Plan]()) -> PlanComparisonViewController { | |
let storyboard = UIStoryboard(name: "Plans", bundle: NSBundle.mainBundle()) | |
let controller = storyboard.instantiateViewControllerWithIdentifier(NSStringFromClass(self)) as! PlanComparisonViewController | |
+ controller.allPlans = allPlans | |
controller.activePlan = activePlan | |
controller.currentPlan = plan | |
diff --git a/WordPress/Classes/ViewRelated/Plans/PlanDetailViewController.swift b/WordPress/Classes/ViewRelated/Plans/PlanDetailViewController.swift | |
index b3cc2b0..bfb308c 100644 | |
--- a/WordPress/Classes/ViewRelated/Plans/PlanDetailViewController.swift | |
+++ b/WordPress/Classes/ViewRelated/Plans/PlanDetailViewController.swift | |
@@ -209,11 +209,11 @@ class PlanDetailViewController: UIViewController { | |
case .Loading, .Error(_): | |
return ImmuTable.Empty | |
case .Ready(let plan): | |
- guard let groups = PlanFeatureGroup.groupsForPlan(plan) else { | |
+ if plan.featureGroups.count == 0 { | |
return ImmuTable.Empty | |
} | |
- return ImmuTable(sections: groups.map { group in | |
+ return ImmuTable(sections: plan.featureGroups.map { group in | |
let features = group.slugs.map { PlanFeaturesService.featureForPlan(plan, withSlug: $0) } | |
return ImmuTableSection(headerText: group.title, rows: features.map({ TextRow(title: $0!.title, value: $0!.description) }), footerText: nil) | |
diff --git a/WordPress/Classes/ViewRelated/Plans/PlanListViewController.swift b/WordPress/Classes/ViewRelated/Plans/PlanListViewController.swift | |
index 2203838..0c744f7 100644 | |
--- a/WordPress/Classes/ViewRelated/Plans/PlanListViewController.swift | |
+++ b/WordPress/Classes/ViewRelated/Plans/PlanListViewController.swift | |
@@ -105,7 +105,7 @@ enum PlanListViewModel { | |
price: price, | |
description: plan.description, | |
icon: icon, | |
- action: presenter.present(self.controllerForPlanDetails(plan, activePlan: activePlan)) | |
+ action: presenter.present(self.controllerForPlanDetails(plan, activePlan: activePlan, allPlans: plans.map { $0.plan })) | |
) | |
}) | |
return ImmuTable(sections: [ | |
@@ -116,9 +116,9 @@ enum PlanListViewModel { | |
} | |
} | |
- func controllerForPlanDetails(plan: Plan, activePlan: Plan) -> ImmuTableRowControllerGenerator { | |
+ func controllerForPlanDetails(plan: Plan, activePlan: Plan, allPlans: [Plan]) -> ImmuTableRowControllerGenerator { | |
return { row in | |
- let planVC = PlanComparisonViewController.controllerWithInitialPlan(plan, activePlan: activePlan) | |
+ let planVC = PlanComparisonViewController.controllerWithInitialPlan(plan, activePlan: activePlan, allPlans: allPlans) | |
let navigationVC = RotationAwareNavigationViewController(rootViewController: planVC) | |
navigationVC.modalPresentationStyle = .FormSheet | |
return navigationVC |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment