Skip to content

Commit fe3eddc

Browse files
committed
Merge branch 'develop' into issue/9-fullfill-order
2 parents 5e2277f + 6f20e78 commit fe3eddc

File tree

8 files changed

+237
-199
lines changed

8 files changed

+237
-199
lines changed

WooCommerce/Classes/Authentication/AuthenticationManager.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,7 @@ extension AuthenticationManager: WordPressAuthenticatorDelegate {
151151
fatalError("Self Hosted sites are not supported. Please review the Authenticator settings!")
152152
}
153153

154-
StoresManager.authenticate(username: username, authToken: authToken)
155-
156-
// TODO: Review
154+
StoresManager.shared.authenticate(username: username, authToken: authToken)
157155
onCompletion(nil)
158156
}
159157

WooCommerce/Classes/ViewRelated/Orders/OrdersViewController.swift

Lines changed: 14 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ class OrdersViewController: UIViewController {
55

66
@IBOutlet weak var tableView: UITableView!
77
var orders = [Order]()
8-
var searchResults = [Order]()
9-
let searchController = UISearchController(searchResultsController: nil)
8+
var filterResults = [Order]()
109
private var isUsingFilterAction = false
1110
var displaysNoResults: Bool {
12-
return searchResults.isEmpty && isUsingFilterAction
11+
return filterResults.isEmpty && isUsingFilterAction
1312
}
1413

1514
func loadSampleOrders() -> [Order] {
@@ -67,13 +66,12 @@ class OrdersViewController: UIViewController {
6766
super.viewDidLoad()
6867
configureNavigation()
6968
configureTableView()
70-
configureSearch()
7169
orders = loadSampleOrders()
7270
}
7371

7472
func configureNavigation() {
7573
title = NSLocalizedString("Orders", comment: "Orders title")
76-
let rightBarButton = UIBarButtonItem(image: Gridicon.iconOfType(.listUnordered),
74+
let rightBarButton = UIBarButtonItem(image: Gridicon.iconOfType(.menus),
7775
style: .plain,
7876
target: self,
7977
action: #selector(rightButtonTapped))
@@ -96,24 +94,6 @@ class OrdersViewController: UIViewController {
9694
tableView.register(nib, forCellReuseIdentifier: NoResultsTableViewCell.reuseIdentifier)
9795
}
9896

99-
func configureSearch() {
100-
searchController.searchResultsUpdater = self
101-
searchController.obscuresBackgroundDuringPresentation = false
102-
searchController.hidesNavigationBarDuringPresentation = false
103-
searchController.searchBar.delegate = self
104-
searchController.searchBar.placeholder = NSLocalizedString("Search all orders", comment: "Search placeholder text")
105-
searchController.searchBar.sizeToFit()
106-
107-
// This may need set app-wide in the future. Not yet.
108-
searchController.searchBar.barTintColor = tableView.backgroundColor
109-
searchController.searchBar.layer.borderWidth = 1
110-
searchController.searchBar.layer.borderColor = tableView.backgroundColor?.cgColor
111-
112-
// add it to the table header, which leaves us room for pull-to-refresh control
113-
tableView.tableHeaderView = searchController.searchBar
114-
tableView.contentOffset = CGPoint(x: 0.0, y: searchController.searchBar.frame.size.height)
115-
}
116-
11797
@objc func rightButtonTapped() {
11898
let actionSheet = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
11999
actionSheet.view.tintColor = StyleManager.wooCommerceBrandColor
@@ -141,11 +121,11 @@ class OrdersViewController: UIViewController {
141121
return
142122
}
143123

144-
searchResults = orders.filter { order in
124+
filterResults = orders.filter { order in
145125
return order.status.description.contains(status.description)
146126
}
147127

148-
isUsingFilterAction = searchResults.count != orders.count
128+
isUsingFilterAction = filterResults.count != orders.count
149129
tableView.reloadData()
150130
}
151131

@@ -156,21 +136,10 @@ class OrdersViewController: UIViewController {
156136
customOrders.append(order)
157137
}
158138
}
159-
searchResults = customOrders
160-
isUsingFilterAction = searchResults.count != orders.count
139+
filterResults = customOrders
140+
isUsingFilterAction = filterResults.count != orders.count
161141
tableView.reloadData()
162142
}
163-
164-
// MARK: Search bar
165-
func isFiltering() -> Bool {
166-
let usingSearch = searchController.isActive && !searchBarIsEmpty()
167-
let usingFilter = isUsingFilterAction
168-
return usingSearch || usingFilter
169-
}
170-
171-
func searchBarIsEmpty() -> Bool {
172-
return searchController.searchBar.text?.isEmpty ?? true
173-
}
174143
}
175144

176145
// MARK: UITableViewDataSource
@@ -181,19 +150,19 @@ extension OrdersViewController: UITableViewDataSource {
181150
}
182151

183152
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
184-
if isFiltering() {
185-
if searchResults.isEmpty {
186-
return Constants.searchResultsNotFoundRowCount
153+
if isUsingFilterAction == true {
154+
if filterResults.isEmpty {
155+
return Constants.filterResultsNotFoundRowCount
187156
}
188-
return searchResults.count
157+
return filterResults.count
189158
}
190159
return orders.count
191160
}
192161

193162
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
194163
guard !displaysNoResults else {
195164
let cell = tableView.dequeueReusableCell(withIdentifier: NoResultsTableViewCell.reuseIdentifier, for: indexPath) as! NoResultsTableViewCell
196-
cell.configure(text: NSLocalizedString("No results found. Clear the filter or search bar to try again.", comment: "Displays message to user when no filter or search results were found."))
165+
cell.configure(text: NSLocalizedString("No results found. Clear the filter to try again.", comment: "Displays message to user when no filter results were found."))
197166
return cell
198167
}
199168
let order = orderAtIndexPath(indexPath)
@@ -208,7 +177,7 @@ extension OrdersViewController: UITableViewDataSource {
208177
}
209178

210179
func orderAtIndexPath(_ indexPath: IndexPath) -> Order {
211-
return isFiltering() ? searchResults[indexPath.row] : orders[indexPath.row]
180+
return isUsingFilterAction ? filterResults[indexPath.row] : orders[indexPath.row]
212181
}
213182
}
214183

@@ -229,10 +198,6 @@ extension OrdersViewController: UITableViewDelegate {
229198
return
230199
}
231200

232-
if searchController.isActive {
233-
searchController.dismiss(animated: true, completion: nil)
234-
}
235-
236201
if segue.identifier == Constants.orderDetailsSegue {
237202
if let singleOrderViewController = segue.destination as? OrderDetailsViewController {
238203
let indexPath = sender as! IndexPath
@@ -245,40 +210,12 @@ extension OrdersViewController: UITableViewDelegate {
245210
}
246211
}
247212

248-
// MARK: UISearchResultsUpdating
249-
//
250-
extension OrdersViewController: UISearchResultsUpdating {
251-
func updateSearchResults(for searchController: UISearchController) {
252-
guard let searchString = searchController.searchBar.text else {
253-
return
254-
}
255-
// TODO: filter search results properly
256-
searchResults = orders.filter { order in
257-
return order.shippingAddress.firstName.lowercased().contains(searchString.lowercased())
258-
}
259-
tableView.reloadData()
260-
}
261-
}
262-
263-
// MARK: UISearchBarDelegate
264-
//
265-
extension OrdersViewController: UISearchBarDelegate {
266-
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
267-
tableView.reloadData()
268-
}
269-
270-
func searchBarCancelButtonClicked(_ searchBar: UISearchBar) {
271-
searchController.searchBar.resignFirstResponder()
272-
tableView.reloadData()
273-
}
274-
}
275-
276213
// MARK: Constants
277214
//
278215
extension OrdersViewController {
279216
struct Constants {
280217
static let rowHeight = CGFloat(86)
281218
static let orderDetailsSegue = "ShowOrderDetailsViewController"
282-
static let searchResultsNotFoundRowCount = 1
219+
static let filterResultsNotFoundRowCount = 1
283220
}
284221
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import Foundation
2+
import Yosemite
3+
import Storage
4+
import Networking
5+
6+
7+
8+
// MARK: - AuthenticatedState
9+
//
10+
class AuthenticatedState: StoresManagerState {
11+
12+
/// Active Credentials
13+
///
14+
private let credentials: Credentials
15+
16+
/// Dispatcher: Glues all of the Stores!
17+
///
18+
private let dispatcher = Dispatcher()
19+
20+
/// Retains all of the active Services
21+
///
22+
private let services: [ActionsProcessor]
23+
24+
/// CredentialsManager: By Reference, for unit testing purposes.
25+
///
26+
private let keychain: CredentialsManager
27+
28+
29+
30+
/// Designated Initializer
31+
///
32+
init(keychain: CredentialsManager, credentials: Credentials) {
33+
let storageManager = CoreDataManager.global
34+
let network = AlamofireNetwork(credentials: credentials)
35+
36+
services = [
37+
AccountStore(dispatcher: dispatcher, storageManager: storageManager, network: network)
38+
]
39+
40+
self.credentials = credentials
41+
self.keychain = keychain
42+
}
43+
44+
45+
/// Executed whenever the state is activated.
46+
///
47+
func didEnter() {
48+
keychain.saveDefaultCredentials(credentials)
49+
}
50+
51+
52+
/// Forwards the received action to the Actions Dispatcher.
53+
///
54+
func onAction(_ action: Action) {
55+
dispatcher.dispatch(action)
56+
}
57+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Foundation
2+
import Yosemite
3+
4+
5+
6+
// MARK: - DeauthenticatedState
7+
//
8+
class DeauthenticatedState: StoresManagerState {
9+
10+
/// CredentialsManager: By Reference, for unit testing purposes.
11+
///
12+
private let keychain: CredentialsManager
13+
14+
15+
/// Designated Initializer
16+
///
17+
init(keychain: CredentialsManager) {
18+
self.keychain = keychain
19+
}
20+
21+
/// This method should run only when the app got deauthenticated.
22+
///
23+
func didEnter() {
24+
keychain.removeDefaultCredentials()
25+
AppDelegate.shared.displayAuthenticator()
26+
}
27+
28+
29+
/// NO-OP: During deauth method, we're not running any actions.
30+
///
31+
func onAction(_ action: Action) { }
32+
}

0 commit comments

Comments
 (0)