Skip to content

Commit aa05731

Browse files
Merge pull request #189 from woocommerce/issue/122-fulfillment-flow
Fulfillment: Mark as Complete Action
2 parents d13bfe0 + 1c1d60e commit aa05731

13 files changed

+155
-82
lines changed

WooCommerce/Classes/ViewRelated/Orders/FulfillViewController.swift

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Foundation
22
import UIKit
3+
import CocoaLumberjack
4+
35
import Yosemite
46
import Gridicons
57

@@ -80,6 +82,7 @@ private extension FulfillViewController {
8082
///
8183
func setupTableView() {
8284
tableView.tableFooterView = actionView
85+
tableView.allowsSelection = false
8386
}
8487

8588
///Setup: Action Button!
@@ -121,8 +124,42 @@ private extension FulfillViewController {
121124
//
122125
extension FulfillViewController {
123126

127+
/// Whenever the Fulfillment Action is pressed, we'll mark the order as Completed, and pull back to the previous screen.
128+
///
124129
@IBAction func fulfillWasPressed() {
125-
// TODO: Fill Me!
130+
let done = updateOrderAction(siteID: order.siteID, orderID: order.orderID, status: .completed)
131+
let undo = updateOrderAction(siteID: order.siteID, orderID: order.orderID, status: order.status)
132+
133+
StoresManager.shared.dispatch(done)
134+
135+
displayOrderCompleteNotice {
136+
StoresManager.shared.dispatch(undo)
137+
}
138+
139+
navigationController?.popViewController(animated: true)
140+
}
141+
142+
/// Returns an Order Update Action that will result in the specified Order Status updated accordingly.
143+
///
144+
private func updateOrderAction(siteID: Int, orderID: Int, status: OrderStatus) -> Action {
145+
return OrderAction.updateOrder(siteID: siteID, orderID: orderID, status: status, onCompletion: { error in
146+
guard let error = error else {
147+
return
148+
}
149+
150+
DDLogError("⛔️ Order Update Failure: [\(orderID).status = \(status.rawValue)]. Error: \(error)")
151+
})
152+
}
153+
154+
/// Displays the `Order Fulfilled` Notice. Whenever the `Undo` button gets pressed, we'll execute the `onUndoAction` closure.
155+
///
156+
private func displayOrderCompleteNotice(onUndoAction: @escaping () -> Void) {
157+
let title = NSLocalizedString("Fulfillment", comment: "Fulfill Notice Title")
158+
let message = NSLocalizedString("Order Marked as Complete!", comment: "Fulfill Notice Message")
159+
let actionTitle = NSLocalizedString("Undo", comment: "Undo Action")
160+
let notice = Notice(title: title, message: message, feedbackType: .success, actionTitle: actionTitle, actionHandler: onUndoAction)
161+
162+
AppDelegate.shared.noticePresenter.enqueue(notice: notice)
126163
}
127164
}
128165

@@ -345,13 +382,14 @@ private extension Section {
345382
return Section(title: title, secondaryTitle: nil, rows: [row])
346383
}()
347384

348-
let tracking: Section = {
349-
let title = NSLocalizedString("Optional Tracking Information", comment: "")
350-
let row = Row.trackingAdd
351-
352-
return Section(title: title, secondaryTitle: nil, rows: [row])
353-
}()
385+
// TODO: Tracking support to be added via #185
386+
// let tracking: Section = {
387+
// let title = NSLocalizedString("Optional Tracking Information", comment: "")
388+
// let row = Row.trackingAdd
389+
//
390+
// return Section(title: title, secondaryTitle: nil, rows: [row])
391+
// }()
354392

355-
return [products, note, address, tracking].compactMap { $0 }
393+
return [products, note, address].compactMap { $0 }
356394
}
357395
}

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/BillingDetailsTableViewCell.xib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<objects>
1212
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
1313
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14-
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="BillingDetailsTableViewCell" textLabel="drm-Ej-5OZ" style="IBUITableViewCellStyleDefault" id="KGk-i7-Jjw" userLabel="BillingDetailsTableViewCell" customClass="BillingDetailsTableViewCell" customModule="WooCommerce" customModuleProvider="target">
14+
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="BillingDetailsTableViewCell" textLabel="drm-Ej-5OZ" style="IBUITableViewCellStyleDefault" id="KGk-i7-Jjw" userLabel="BillingDetailsTableViewCell" customClass="BillingDetailsTableViewCell" customModule="WooCommerce" customModuleProvider="target">
1515
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
1616
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1717
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/CustomerInfoTableViewCell.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
@@ -11,7 +11,7 @@
1111
<objects>
1212
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
1313
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14-
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CustomerInfoTableViewCell" rowHeight="130" id="KGk-i7-Jjw" userLabel="CustomerInfoTableViewCell" customClass="CustomerInfoTableViewCell" customModule="WooCommerce" customModuleProvider="target">
14+
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="CustomerInfoTableViewCell" rowHeight="130" id="KGk-i7-Jjw" userLabel="CustomerInfoTableViewCell" customClass="CustomerInfoTableViewCell" customModule="WooCommerce" customModuleProvider="target">
1515
<rect key="frame" x="0.0" y="0.0" width="320" height="130"/>
1616
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1717
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/CustomerNoteTableViewCell.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
@@ -12,7 +12,7 @@
1212
<objects>
1313
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
1414
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
15-
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CustomerNoteTableViewCell" rowHeight="52" id="KGk-i7-Jjw" userLabel="CustomerNoteTableViewCell" customClass="CustomerNoteTableViewCell" customModule="WooCommerce" customModuleProvider="target">
15+
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="CustomerNoteTableViewCell" rowHeight="52" id="KGk-i7-Jjw" userLabel="CustomerNoteTableViewCell" customClass="CustomerNoteTableViewCell" customModule="WooCommerce" customModuleProvider="target">
1616
<rect key="frame" x="0.0" y="0.0" width="320" height="52"/>
1717
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1818
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/OrderDetailsViewController.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Gridicons
33
import Contacts
44
import MessageUI
55
import Yosemite
6+
import Storage
67
import CocoaLumberjack
78

89

@@ -38,13 +39,24 @@ class OrderDetailsViewController: UIViewController {
3839
}
3940
private var sections = [Section]()
4041

42+
/// TODO: Replace with `ResultController` (OR) `ObjectController` ASAP
43+
///
44+
private lazy var resultsController: ResultsController<Storage.Order> = {
45+
let viewContext = CoreDataManager.global.viewContext
46+
let predicate = NSPredicate(format: "orderID = %ld", self.viewModel.order.orderID)
47+
let descriptor = NSSortDescriptor(key: "orderID", ascending: true)
48+
49+
return ResultsController(viewContext: viewContext, matching: predicate, sortedBy: [descriptor])
50+
}()
51+
4152

4253
// MARK: - View Lifecycle
4354

4455
override func viewDidLoad() {
4556
super.viewDidLoad()
4657
configureNavigation()
4758
configureTableView()
59+
configureResultsController()
4860
registerTableViewCells()
4961
registerTableViewHeaderFooters()
5062
}
@@ -84,6 +96,20 @@ private extension OrderDetailsViewController {
8496
navigationItem.backBarButtonItem = UIBarButtonItem(title: String(), style: .plain, target: nil, action: nil)
8597
}
8698

99+
/// TODO: Replace with `ResultController` (OR) `ObjectController` ASAP
100+
///
101+
func configureResultsController() {
102+
try? resultsController.performFetch()
103+
resultsController.onDidChangeContent = { [weak self] in
104+
guard let `self` = self, let order = self.resultsController.fetchedObjects.first else {
105+
return
106+
}
107+
108+
self.viewModel = OrderDetailsViewModel(order: order)
109+
self.tableView.reloadData()
110+
}
111+
}
112+
87113
/// Setup: Sections
88114
///
89115
func reloadSections() {

WooCommerce/Classes/ViewRelated/Orders/OrderDetails/OrderNoteTableViewCell.xib

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14109" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14113" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina4_7" orientation="portrait">
44
<adaptation id="fullscreen"/>
55
</device>
@@ -11,7 +11,7 @@
1111
<objects>
1212
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
1313
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
14-
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="148" id="KGk-i7-Jjw" customClass="OrderNoteTableViewCell" customModule="WooCommerce" customModuleProvider="target">
14+
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="148" id="KGk-i7-Jjw" customClass="OrderNoteTableViewCell" customModule="WooCommerce" customModuleProvider="target">
1515
<rect key="frame" x="0.0" y="0.0" width="320" height="148"/>
1616
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
1717
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">

0 commit comments

Comments
 (0)