Skip to content

Commit

Permalink
ios: add the button to access the "other sales"
Browse files Browse the repository at this point in the history
  • Loading branch information
foxfriends committed Feb 2, 2019
1 parent 479412d commit ac86753
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,18 @@ extension ConventionListViewController: UITableViewDelegate {
})
.disposed(by: headerView.disposeBag)
return headerView
case .present,
.presentEmpty:
let headerView = TableHeaderView(title: title, showBar: false, showMore: true)
headerView.seeAllButton.setTitle("Other Sales"¡, for: .normal)
headerView.rx.seeAll
.subscribe(onNext: { _ in RecordsOverviewViewController.show() })
.disposed(by: headerView.disposeBag)
return headerView
default:
let headerView = TableHeaderView(title: title, showBar: section != 0, showMore: showMore)
headerView.rx.seeAll
.subscribe(onNext: { _ in
AllConventionsListViewController.show(conventions: conventions)
})
.subscribe(onNext: { _ in AllConventionsListViewController.show(conventions: conventions) })
.disposed(by: headerView.disposeBag)
return headerView
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ extension RecordListViewController {
if let convention = convention {
return convention.fill(true).discard()
} else {
// NOTE: this will cause issues on deep pages!
return ConArtist.model.loadRecords(fresh: true).discard()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,18 @@ class RecordsOverviewViewController : ConArtistViewController {
@IBOutlet weak var recordsTableView: UITableView!
@IBOutlet weak var netProfitLabel: UILabel!
@IBOutlet weak var netProfitAmountLabel: UILabel!
@IBOutlet weak var netProfitContainer: UIView!

fileprivate var convention: Convention?
fileprivate let sections = BehaviorRelay<[Section]>(value: [])
var loading = false

fileprivate let disposeBag = DisposeBag()
fileprivate let refreshControl = UIRefreshControl()

var moreToLoad: Bool {
return convention == nil && (!ConArtist.model.records.value.isEmpty && !ConArtist.model.records.value.isFull)
}
}

// MARK: - Lifecycle
Expand All @@ -60,14 +66,21 @@ extension RecordsOverviewViewController {
setupLocalization()
setupSubscriptions()
setupRefreshControl()
_ = ConArtist.model.loadRecords(fresh: true).subscribe()
navBar.title = convention?.name ?? "Sales"¡
netProfitAmountLabel.font = netProfitAmountLabel.font.usingFeatures([.tabularFigures])
}

private func setupRefreshControl() {
recordsTableView.refreshControl = refreshControl
refreshControl.rx.controlEvent([.valueChanged])
.flatMapLatest { [convention] _ in convention!.fill(true) }
.flatMapLatest { [convention] _ -> Observable<Void> in
if let convention = convention {
return convention.fill(true).discard()
} else {
return ConArtist.model.loadRecords(fresh: true).discard()
}
}
.subscribe(onNext: { [refreshControl] in refreshControl.endRefreshing() })
.disposed(by: disposeBag)
}
Expand Down Expand Up @@ -168,6 +181,11 @@ extension RecordsOverviewViewController {
.drive(onNext: { [recordsTableView] sections in recordsTableView?.reloadData() })
.disposed(by: disposeBag)

sections.asDriver()
.map { $0.isEmpty }
.drive(netProfitContainer.rx.isHidden)
.disposed(by: disposeBag)

navBar.leftButton.rx.tap
.subscribe(onNext: { ConArtist.model.navigate(back: 1) })
.disposed(by: disposeBag)
Expand All @@ -185,16 +203,28 @@ extension RecordsOverviewViewController: UITableViewDataSource {
}

func numberOfSections(in tableView: UITableView) -> Int {
return sections.value.count
return max(sections.value.count, 1) + (moreToLoad ? 1 : 0)
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
guard let section = self.section(at: section) else { return 0 }
guard let section = self.section(at: section) else { return 1 }
return section.expanded ? section.items.count : 0
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let item = item(for: indexPath) else { fatalError("Item for records table is missing!") }
guard let item = item(for: indexPath) else {
if sections.value.isEmpty {
let cell = tableView.dequeueReusableCell(withIdentifier: EmptyStateTableViewCell.ID, for: indexPath) as! EmptyStateTableViewCell
if convention == nil {
cell.setup(text: "<Empty no-con records list message>"¡)
} else {
cell.setup(text: "<Empty records list message>"¡)
}
return cell
} else {
return tableView.dequeueReusableCell(withIdentifier: LoadingTableViewCell.ID, for: indexPath)
}
}
switch item {
case .expense(let expense):
let cell = tableView.dequeueReusableCell(withIdentifier: ExpenseTableViewCell.ID, for: indexPath) as! ExpenseTableViewCell
Expand All @@ -206,6 +236,15 @@ extension RecordsOverviewViewController: UITableViewDataSource {
return cell
}
}

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if cell is LoadingTableViewCell && !loading {
loading = true
ConArtist.model.loadRecords()
.subscribe(onNext: { [unowned self] _ in self.loading = false })
.disposed(by: disposeBag)
}
}
}

// MARK: - UITableViewDelegate
Expand Down Expand Up @@ -254,6 +293,14 @@ extension RecordsOverviewViewController: UITableViewDelegate {
return view
}

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
guard !sections.value.isEmpty else { // empty state cell is auto
return UITableView.automaticDimension
}
// the rest all 50
return 50
}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
guard case .expense(let expense)? = item(for: indexPath) else { return UISwipeActionsConfiguration(actions: []) }
var actions: [UIContextualAction] = []
Expand Down
52 changes: 50 additions & 2 deletions ios/ConArtist/Storyboard/Records.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<rect key="frame" x="0.0" y="64" width="375" height="603"/>
<color key="backgroundColor" name="Background"/>
<view key="tableFooterView" contentMode="scaleToFill" id="x8C-UE-zo2">
<rect key="frame" x="0.0" y="173.5" width="375" height="50"/>
<rect key="frame" x="0.0" y="283.5" width="375" height="50"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="nD7-kH-8l4">
Expand Down Expand Up @@ -170,6 +170,53 @@
<outlet property="modifiedMarkView" destination="FzY-3g-wY1" id="VJw-Jg-n4q"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="EmptyStateCell" rowHeight="60" id="3rH-Cz-0eo" customClass="EmptyStateTableViewCell" customModule="ConArtist" customModuleProvider="target">
<rect key="frame" x="0.0" y="155.5" width="375" height="60"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="3rH-Cz-0eo" id="eVS-5f-sBx">
<rect key="frame" x="0.0" y="0.0" width="375" height="60"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="You haven't sold anything yet" textAlignment="center" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="MVP-Fs-EZ9">
<rect key="frame" x="20" y="20" width="335" height="20"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<color key="textColor" name="TextPlaceholder"/>
<nil key="highlightedColor"/>
</label>
</subviews>
<constraints>
<constraint firstItem="MVP-Fs-EZ9" firstAttribute="top" secondItem="eVS-5f-sBx" secondAttribute="top" constant="20" id="7LQ-gW-qDW"/>
<constraint firstItem="MVP-Fs-EZ9" firstAttribute="leading" secondItem="eVS-5f-sBx" secondAttribute="leading" constant="20" id="PMa-H0-Xrf"/>
<constraint firstAttribute="bottom" secondItem="MVP-Fs-EZ9" secondAttribute="bottom" constant="20" id="Qh7-A5-qQm"/>
<constraint firstAttribute="trailing" secondItem="MVP-Fs-EZ9" secondAttribute="trailing" constant="20" id="gfJ-1S-XB9"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" name="Background"/>
<connections>
<outlet property="label" destination="MVP-Fs-EZ9" id="CxI-t9-u9G"/>
</connections>
</tableViewCell>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="none" indentationWidth="10" reuseIdentifier="LoadingCell" rowHeight="50" id="hL6-7F-YqU" customClass="LoadingTableViewCell" customModule="ConArtist" customModuleProvider="target">
<rect key="frame" x="0.0" y="215.5" width="375" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="hL6-7F-YqU" id="rNF-2V-ZlV">
<rect key="frame" x="0.0" y="0.0" width="375" height="50"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<activityIndicatorView opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" animating="YES" style="white" translatesAutoresizingMaskIntoConstraints="NO" id="0x9-3q-cDh">
<rect key="frame" x="177.5" y="15" width="20" height="20"/>
</activityIndicatorView>
</subviews>
<constraints>
<constraint firstItem="0x9-3q-cDh" firstAttribute="centerX" secondItem="rNF-2V-ZlV" secondAttribute="centerX" id="5dy-Eu-gEH"/>
<constraint firstItem="0x9-3q-cDh" firstAttribute="centerY" secondItem="rNF-2V-ZlV" secondAttribute="centerY" id="zHa-an-m0a"/>
</constraints>
</tableViewCellContentView>
<color key="backgroundColor" name="Background"/>
<connections>
<outlet property="loadingSpinner" destination="0x9-3q-cDh" id="N8y-d1-Rfe"/>
</connections>
</tableViewCell>
</prototypes>
<connections>
<outlet property="dataSource" destination="sB1-LD-czp" id="mCT-hH-Y7B"/>
Expand Down Expand Up @@ -201,6 +248,7 @@
<connections>
<outlet property="navBar" destination="fKa-3X-ujY" id="tv3-B5-5oz"/>
<outlet property="netProfitAmountLabel" destination="xa9-pk-OH6" id="t2x-Nn-9bc"/>
<outlet property="netProfitContainer" destination="x8C-UE-zo2" id="ca7-md-3mo"/>
<outlet property="netProfitLabel" destination="6T2-dg-xtG" id="QpL-Qa-k8p"/>
<outlet property="recordsTableView" destination="HrW-vR-wi4" id="5IL-Fd-Web"/>
</connections>
Expand Down Expand Up @@ -755,7 +803,7 @@
<color red="0.2669999897480011" green="0.2669999897480011" blue="0.2669999897480011" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="Brand">
<color red="0.85500001907348633" green="0.28200000524520874" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<color red="0.81176470588235294" green="0.27058823529411763" blue="0.086274509803921567" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
</namedColor>
<namedColor name="Divider">
<color red="1" green="1" blue="1" alpha="0.11999999731779099" colorSpace="custom" customColorSpace="sRGB"/>
Expand Down
1 change: 1 addition & 0 deletions shared/localization/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ Info = "Info"
"No activity for this day" = "No activity for this day"
Revenue = "Revenue"
Sales = "Sales"
"Other Sales" = "Other Sales"
Sale = "Sale"
"Today's hours" = "Today's hours"
"View on map" = "View on map"
Expand Down
1 change: 1 addition & 0 deletions shared/localization/zh.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ Reorder = "改组"
"Reset Password" = "重设密码"
Revenue = "收入"
Sales = "销售"
"Other Sales" = "别的销售"
Sale = "销售"
"Sales By Type" = "TODO: translate"
"Sales Over Time" = "TODO: translate"
Expand Down

0 comments on commit ac86753

Please sign in to comment.