Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 46 additions & 8 deletions WooCommerce/Classes/ViewRelated/Orders/FulfillViewController.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import Foundation
import UIKit
import CocoaLumberjack

import Yosemite
import Gridicons

Expand Down Expand Up @@ -80,6 +82,7 @@ private extension FulfillViewController {
///
func setupTableView() {
tableView.tableFooterView = actionView
tableView.allowsSelection = false
}

///Setup: Action Button!
Expand Down Expand Up @@ -121,8 +124,42 @@ private extension FulfillViewController {
//
extension FulfillViewController {

/// Whenever the Fulfillment Action is pressed, we'll mark the order as Completed, and pull back to the previous screen.
///
@IBAction func fulfillWasPressed() {
// TODO: Fill Me!
let done = updateOrderAction(siteID: order.siteID, orderID: order.orderID, status: .completed)
let undo = updateOrderAction(siteID: order.siteID, orderID: order.orderID, status: order.status)

StoresManager.shared.dispatch(done)

displayOrderCompleteNotice {
StoresManager.shared.dispatch(undo)
}

navigationController?.popViewController(animated: true)
}

/// Returns an Order Update Action that will result in the specified Order Status updated accordingly.
///
private func updateOrderAction(siteID: Int, orderID: Int, status: OrderStatus) -> Action {
return OrderAction.updateOrder(siteID: siteID, orderID: orderID, status: status, onCompletion: { error in
guard let error = error else {
return
}

DDLogError("⛔️ Order Update Failure: [\(orderID).status = \(status.rawValue)]. Error: \(error)")
})
}

/// Displays the `Order Fulfilled` Notice. Whenever the `Undo` button gets pressed, we'll execute the `onUndoAction` closure.
///
private func displayOrderCompleteNotice(onUndoAction: @escaping () -> Void) {
let title = NSLocalizedString("Fulfillment", comment: "Fulfill Notice Title")
let message = NSLocalizedString("Order Marked as Complete!", comment: "Fulfill Notice Message")
let actionTitle = NSLocalizedString("Undo", comment: "Undo Action")
let notice = Notice(title: title, message: message, feedbackType: .success, actionTitle: actionTitle, actionHandler: onUndoAction)

AppDelegate.shared.noticePresenter.enqueue(notice: notice)
}
}

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

let tracking: Section = {
let title = NSLocalizedString("Optional Tracking Information", comment: "")
let row = Row.trackingAdd

return Section(title: title, secondaryTitle: nil, rows: [row])
}()
// TODO: Tracking support to be added via #185
// let tracking: Section = {
// let title = NSLocalizedString("Optional Tracking Information", comment: "")
// let row = Row.trackingAdd
//
// return Section(title: title, secondaryTitle: nil, rows: [row])
// }()

return [products, note, address, tracking].compactMap { $0 }
return [products, note, address].compactMap { $0 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<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">
<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">
<rect key="frame" x="0.0" y="0.0" width="320" height="44"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -11,7 +11,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CustomerInfoTableViewCell" rowHeight="130" id="KGk-i7-Jjw" userLabel="CustomerInfoTableViewCell" customClass="CustomerInfoTableViewCell" customModule="WooCommerce" customModuleProvider="target">
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="CustomerInfoTableViewCell" rowHeight="130" id="KGk-i7-Jjw" userLabel="CustomerInfoTableViewCell" customClass="CustomerInfoTableViewCell" customModule="WooCommerce" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="130"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -12,7 +12,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="CustomerNoteTableViewCell" rowHeight="52" id="KGk-i7-Jjw" userLabel="CustomerNoteTableViewCell" customClass="CustomerNoteTableViewCell" customModule="WooCommerce" customModuleProvider="target">
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" reuseIdentifier="CustomerNoteTableViewCell" rowHeight="52" id="KGk-i7-Jjw" userLabel="CustomerNoteTableViewCell" customClass="CustomerNoteTableViewCell" customModule="WooCommerce" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="52"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Gridicons
import Contacts
import MessageUI
import Yosemite
import Storage
import CocoaLumberjack


Expand Down Expand Up @@ -38,13 +39,24 @@ class OrderDetailsViewController: UIViewController {
}
private var sections = [Section]()

/// TODO: Replace with `ResultController` (OR) `ObjectController` ASAP
///
private lazy var resultsController: ResultsController<Storage.Order> = {
let viewContext = CoreDataManager.global.viewContext
let predicate = NSPredicate(format: "orderID = %ld", self.viewModel.order.orderID)
let descriptor = NSSortDescriptor(key: "orderID", ascending: true)

return ResultsController(viewContext: viewContext, matching: predicate, sortedBy: [descriptor])
}()


// MARK: - View Lifecycle

override func viewDidLoad() {
super.viewDidLoad()
configureNavigation()
configureTableView()
configureResultsController()
registerTableViewCells()
registerTableViewHeaderFooters()
}
Expand Down Expand Up @@ -84,6 +96,20 @@ private extension OrderDetailsViewController {
navigationItem.backBarButtonItem = UIBarButtonItem(title: String(), style: .plain, target: nil, action: nil)
}

/// TODO: Replace with `ResultController` (OR) `ObjectController` ASAP
///
func configureResultsController() {
try? resultsController.performFetch()
resultsController.onDidChangeContent = { [weak self] in
guard let `self` = self, let order = self.resultsController.fetchedObjects.first else {
return
}

self.viewModel = OrderDetailsViewModel(order: order)
self.tableView.reloadData()
}
}

/// Setup: Sections
///
func reloadSections() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
Expand All @@ -11,7 +11,7 @@
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner"/>
<placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/>
<tableViewCell contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" rowHeight="148" id="KGk-i7-Jjw" customClass="OrderNoteTableViewCell" customModule="WooCommerce" customModuleProvider="target">
<tableViewCell contentMode="scaleToFill" selectionStyle="none" indentationWidth="10" rowHeight="148" id="KGk-i7-Jjw" customClass="OrderNoteTableViewCell" customModule="WooCommerce" customModuleProvider="target">
<rect key="frame" x="0.0" y="0.0" width="320" height="148"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="KGk-i7-Jjw" id="H2p-sc-9uM">
Expand Down
Loading