git.iko.soy/dashared/hookah-tau
on develop help sign in
Полностью переделала экран просмотра профиля пользователя

Добавлен pull to reload, добавлен экран " у этого пользователя еще нет броней", добавлена вертелка загрузки

commitb32f9ed1d7b9fd39399796091fb1b159d070c8b4 authorDarya Rednikina <rednikina.com@yandex.ru> dateThu 9 Jan 2020, 12:59 (7 years ago) parent51fb80f
4 files changed+157−68
Hookah Tau/Controllers/Admin/Clients/ClientList.storyboard+65−50 Hookah Tau/Controllers/Admin/Clients/Profile/ProfileTableViewController.swift+86−18 Hookah Tau/Controllers/Admin/Reservations/Views/No reserv/AdminNoReservationsView.swift+5 Hookah Tau/Controllers/Admin/Reservations/Views/No reserv/AdminNoReservationsView.xib+1
Hookah Tau/Controllers/Admin/Clients/ClientList.storyboard+65−50
@@ -1,9 +1,10 @@
11<?xml version="1.0" encoding="UTF-8"?>
2−<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14868" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="15702" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33 <device id="retina4_7" orientation="portrait" appearance="light"/>
44 <dependencies>
55 <deployment identifier="iOS"/>
6− <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14824"/>
6+ <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="15704"/>
7+ <capability name="Safe area layout guides" minToolsVersion="9.0"/>
78 <capability name="Stack View standard spacing" minToolsVersion="9.0"/>
89 <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
910 </dependencies>
@@ -86,61 +87,75 @@
8687 <point key="canvasLocation" x="0.80000000000000004" y="-112.89355322338831"/>
8788 </scene>
8889 <!--Profile Table View Controller-->
89− <scene sceneID="8Qr-sA-YQr">
90+ <scene sceneID="APa-VZ-6hd">
9091 <objects>
91− <tableViewController storyboardIdentifier="ProfileTableViewController" id="mqB-EY-UGh" customClass="ProfileTableViewController" customModule="Hookah_Tau" customModuleProvider="target" sceneMemberID="viewController">
92− <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="N1B-QX-4Kn">
92+ <viewController storyboardIdentifier="ProfileTableViewController" id="ZVH-jf-rtc" customClass="ProfileTableViewController" customModule="Hookah_Tau" customModuleProvider="target" sceneMemberID="viewController">
93+ <view key="view" contentMode="scaleToFill" id="rcq-M9-CvR">
9394 <rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
9495 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
96+ <subviews>
97+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ciO-ia-Oob">
98+ <rect key="frame" x="0.0" y="0.0" width="375" height="65"/>
99+ <subviews>
100+ <stackView opaque="NO" contentMode="scaleToFill" distribution="equalSpacing" alignment="center" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="IBA-bj-CWK">
101+ <rect key="frame" x="8" y="16" width="359" height="37"/>
102+ <subviews>
103+ <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4WC-gi-jbD" customClass="Button" customModule="Hookah_Tau" customModuleProvider="target">
104+ <rect key="frame" x="0.0" y="0.0" width="180" height="37"/>
105+ <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
106+ <constraints>
107+ <constraint firstAttribute="width" constant="180" id="bJA-V9-gw9"/>
108+ <constraint firstAttribute="height" constant="37" id="pdo-AO-o8a"/>
109+ </constraints>
110+ <state key="normal" title="Button"/>
111+ </button>
112+ <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="gfq-ql-lka" customClass="Button" customModule="Hookah_Tau" customModuleProvider="target">
113+ <rect key="frame" x="224" y="0.0" width="135" height="37"/>
114+ <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
115+ <constraints>
116+ <constraint firstAttribute="width" constant="135" id="Xn3-v6-SLp"/>
117+ <constraint firstAttribute="height" constant="37" id="z68-vW-NjK"/>
118+ </constraints>
119+ <state key="normal" title="Button"/>
120+ </button>
121+ </subviews>
122+ </stackView>
123+ </subviews>
124+ <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
125+ <constraints>
126+ <constraint firstItem="IBA-bj-CWK" firstAttribute="leading" secondItem="ciO-ia-Oob" secondAttribute="leading" constant="8" id="WZS-Vq-tuP"/>
127+ <constraint firstAttribute="trailing" secondItem="IBA-bj-CWK" secondAttribute="trailing" constant="8" id="Yk3-D1-1kg"/>
128+ <constraint firstItem="IBA-bj-CWK" firstAttribute="top" secondItem="ciO-ia-Oob" secondAttribute="top" constant="16" id="fWO-oj-NuN"/>
129+ <constraint firstItem="IBA-bj-CWK" firstAttribute="leading" secondItem="ciO-ia-Oob" secondAttribute="leading" constant="8" id="gP2-jh-5El"/>
130+ <constraint firstAttribute="height" constant="65" id="pzZ-zw-kbc"/>
131+ </constraints>
132+ </view>
133+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="T0s-lX-Z5m">
134+ <rect key="frame" x="0.0" y="65" width="375" height="602"/>
135+ <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
136+ </view>
137+ </subviews>
95138 <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
96− <view key="tableHeaderView" contentMode="scaleToFill" id="oN2-r5-lTy">
97− <rect key="frame" x="0.0" y="0.0" width="375" height="65"/>
98− <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
99− <subviews>
100− <stackView opaque="NO" contentMode="scaleToFill" spacing="47" translatesAutoresizingMaskIntoConstraints="NO" id="UpQ-Uf-0Kc">
101− <rect key="frame" x="8" y="16" width="359" height="37"/>
102− <subviews>
103− <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="nFA-T3-Dxe" customClass="Button" customModule="Hookah_Tau" customModuleProvider="target">
104− <rect key="frame" x="0.0" y="0.0" width="177" height="37"/>
105− <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
106− <constraints>
107− <constraint firstAttribute="height" constant="37" id="41i-38-mHD"/>
108− <constraint firstAttribute="width" constant="174" id="po9-OR-zq1"/>
109− </constraints>
110− <state key="normal" title="Button"/>
111− </button>
112− <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="HkY-u9-thv" customClass="Button" customModule="Hookah_Tau" customModuleProvider="target">
113− <rect key="frame" x="224" y="0.0" width="135" height="37"/>
114− <color key="backgroundColor" white="0.66666666669999997" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
115− <constraints>
116− <constraint firstAttribute="height" constant="37" id="LDw-fn-Xem"/>
117− <constraint firstAttribute="width" constant="135" id="swI-oV-Khe"/>
118− </constraints>
119− <state key="normal" title="Button"/>
120− </button>
121− </subviews>
122− </stackView>
123− </subviews>
124− <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
125− <constraints>
126− <constraint firstItem="UpQ-Uf-0Kc" firstAttribute="top" secondItem="oN2-r5-lTy" secondAttribute="top" constant="16" id="58o-fg-n3i"/>
127− <constraint firstItem="UpQ-Uf-0Kc" firstAttribute="leading" secondItem="oN2-r5-lTy" secondAttribute="leading" constant="8" id="5ik-TQ-N4U"/>
128− <constraint firstAttribute="trailing" secondItem="UpQ-Uf-0Kc" secondAttribute="trailing" constant="8" id="8Ca-3C-Xld"/>
129− </constraints>
130− </view>
131− <connections>
132− <outlet property="dataSource" destination="mqB-EY-UGh" id="YZe-zB-7f3"/>
133− <outlet property="delegate" destination="mqB-EY-UGh" id="JPi-98-LhH"/>
134− </connections>
135− </tableView>
139+ <constraints>
140+ <constraint firstItem="ciO-ia-Oob" firstAttribute="trailing" secondItem="tIS-3m-xwG" secondAttribute="trailing" id="3An-sM-OCN"/>
141+ <constraint firstItem="ciO-ia-Oob" firstAttribute="top" secondItem="tIS-3m-xwG" secondAttribute="top" id="5zl-uZ-sTi"/>
142+ <constraint firstItem="T0s-lX-Z5m" firstAttribute="leading" secondItem="tIS-3m-xwG" secondAttribute="leading" id="7qA-Hh-3Us"/>
143+ <constraint firstItem="T0s-lX-Z5m" firstAttribute="trailing" secondItem="tIS-3m-xwG" secondAttribute="trailing" id="9VD-9Q-wGX"/>
144+ <constraint firstItem="T0s-lX-Z5m" firstAttribute="top" secondItem="ciO-ia-Oob" secondAttribute="bottom" id="RSL-fo-wIb"/>
145+ <constraint firstItem="ciO-ia-Oob" firstAttribute="leading" secondItem="tIS-3m-xwG" secondAttribute="leading" id="Tuq-su-gbn"/>
146+ <constraint firstItem="T0s-lX-Z5m" firstAttribute="bottom" secondItem="tIS-3m-xwG" secondAttribute="bottom" id="iQj-LM-Im9"/>
147+ </constraints>
148+ <viewLayoutGuide key="safeArea" id="tIS-3m-xwG"/>
149+ </view>
136150 <connections>
137− <outlet property="copyButton" destination="HkY-u9-thv" id="RLs-cg-y3g"/>
138− <outlet property="phoneButton" destination="nFA-T3-Dxe" id="d7H-jf-NB5"/>
151+ <outlet property="contentView" destination="T0s-lX-Z5m" id="9Z0-5T-f7Z"/>
152+ <outlet property="copyButton" destination="gfq-ql-lka" id="BNi-Ip-AyF"/>
153+ <outlet property="phoneButton" destination="4WC-gi-jbD" id="xlf-g7-CzU"/>
139154 </connections>
140− </tableViewController>
141− <placeholder placeholderIdentifier="IBFirstResponder" id="1YW-I1-Y6m" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
155+ </viewController>
156+ <placeholder placeholderIdentifier="IBFirstResponder" id="g4Y-1k-Lxr" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
142157 </objects>
143− <point key="canvasLocation" x="880.79999999999995" y="-111.0944527736132"/>
158+ <point key="canvasLocation" x="1188" y="-113"/>
144159 </scene>
145160 </scenes>
146161 <resources>
Hookah Tau/Controllers/Admin/Clients/Profile/ProfileTableViewController.swift+86−18
@@ -8,7 +8,7 @@
88
99import UIKit
1010
11−class ProfileTableViewController: BaseTableViewController {
11+class ProfileTableViewController: BaseViewController {
1212
1313 // MARK: - IBAOutlets
1414
@@ -30,24 +30,41 @@ class ProfileTableViewController: BaseTableViewController {
3030 }
3131 }
3232
33+
34+ @IBOutlet weak var contentView: UIView!
35+
3336 // MARK: - properties
3437
38+ var tableView: UITableView?
39+
3540 var clientsService: ClientsService?
3641
3742 var reservationsService: ReservationsService?
3843
39− var user: FullUser? {
40− didSet {
41− guard let u = user else { return }
42− navigationItem.title = u.name
43− }
44− }
44+ var user: FullUser?
4545
4646 weak var coodinator: ClientProfileCoordinator?
4747
48+ var noReserationsYetView: AdminNoReservationsView?
49+
50+ var activityIndicator: UIActivityIndicatorView?
51+
52+ var refreshControl: UIRefreshControl?
53+
4854 var dataSource: [Reservation] = [] {
4955 didSet {
50− tableView.reloadData()
56+ guard let empty = noReserationsYetView else { return }
57+ if dataSource.isEmpty {
58+ empty.alpha = 1
59+ tableView?.alpha = 0
60+ } else {
61+ empty.alpha = 0
62+ tableView?.alpha = 1
63+ }
64+
65+ refreshControl?.endRefreshing()
66+ activityIndicator?.stopAnimating()
67+ tableView?.reloadData()
5168 }
5269 }
5370
@@ -56,10 +73,12 @@ class ProfileTableViewController: BaseTableViewController {
5673 override func viewDidLoad() {
5774 super.viewDidLoad()
5875
59− tableView?.register(ReservationCell.self, forCellReuseIdentifier: reservationCell)
60−
6176 clientsService = ClientsService(apiClient: APIClient.shared)
6277 reservationsService = ReservationsService(apiClient: APIClient.shared)
78+
79+ setupNavBar()
80+ setupTable()
81+ setupActivityIndicator()
6382 loadReservations()
6483 }
6584
@@ -68,13 +87,55 @@ class ProfileTableViewController: BaseTableViewController {
6887 tabBarController?.tabBar.isHidden = true
6988 }
7089
90+ // MARK: - Setup
91+
92+ func setupNavBar() {
93+ guard let u = user else { return }
94+ navigationItem.title = u.name
95+ navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(book))
96+ }
97+
98+ func setupTable() {
99+ tableView = UITableView()
100+
101+ // refresh control
102+ refreshControl = UIRefreshControl()
103+ refreshControl?.addTarget(self, action: #selector(refresh), for: .valueChanged)
104+ tableView?.refreshControl = refreshControl
105+
106+ tableView?.dataSource = self
107+ tableView?.delegate = self
108+
109+ noReserationsYetView = AdminNoReservationsView.loadFromNib()
110+ noReserationsYetView?.setup(withTitle: "У этого пользователя пока нет ни одной брони :(")
111+ noReserationsYetView?.bookButton?.addTarget(self, action: #selector(book), for: .touchUpInside)
112+ contentView.addSubviewThatFills(noReserationsYetView)
113+ noReserationsYetView?.alpha = 0
114+
115+ tableView?.register(ReservationCell.self, forCellReuseIdentifier: reservationCell)
116+
117+ contentView.addSubviewThatFills(tableView)
118+
119+ tableView?.alpha = 0
120+ }
121+
122+ func setupActivityIndicator() {
123+
124+ activityIndicator = UIActivityIndicatorView()
125+ view.addSubviewThatFills(activityIndicator)
126+ activityIndicator?.startAnimating()
127+
128+ }
129+
130+ // MARK: - Api calls
131+
71132 func loadReservations() {
72133 guard let uuid = user?.uuid else { return }
73134 clientsService?.loadReservationsForUser(withUUID: uuid,
74135 completion: { [weak self] (res) in
75136 switch res {
76137 case .failure(let err):
77− print(err)
138+ self?.displayAlert(forError: err)
78139 case .success(let data):
79140 self?.dataSource = data
80141 }
@@ -115,18 +176,25 @@ class ProfileTableViewController: BaseTableViewController {
115176 //Alert
116177 self.displayAlert(with: "Номер скопирован!")
117178 }
118−
179+
180+ @objc func refresh() {
181+ loadReservations()
182+ }
183+
184+ @objc func book() {
185+
186+ }
119187}
120188
121189// MARK: - Table view data source
122190
123−extension ProfileTableViewController {
191+extension ProfileTableViewController: UITableViewDelegate, UITableViewDataSource {
124192
125− override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
193+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
126194 return dataSource.count
127195 }
128196
129− override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
197+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
130198 let cell = tableView.dequeueReusableCell(withIdentifier: reservationCell, for: indexPath) as! ReservationCell
131199
132200 cell.bind(withModel: dataSource[indexPath.row])
@@ -136,7 +204,7 @@ extension ProfileTableViewController {
136204
137205 // tap
138206
139− override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
207+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
140208 guard let u = user else { return }
141209 let r = dataSource[indexPath.row]
142210 let reservation = ReservationWithUser(reservation: r, user: u)
@@ -145,11 +213,11 @@ extension ProfileTableViewController {
145213
146214 // Update
147215
148− override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
216+ func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
149217 return true
150218 }
151219
152− override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
220+ func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
153221
154222 let uuid = dataSource[indexPath.row].uuid
155223 let cancelButton = UITableViewRowAction(style: .normal, title: "❌") { _,_ in
Hookah Tau/Controllers/Admin/Reservations/Views/No reserv/AdminNoReservationsView.swift+5
@@ -12,6 +12,8 @@ class AdminNoReservationsView: UIView {
1212
1313 // MARK: - IBAOutlets
1414
15+ @IBOutlet weak var titleLabel: UILabel?
16+
1517 @IBOutlet weak var bookButton: Button? {
1618 didSet {
1719 let style = BlackButtonStyle()
@@ -19,4 +21,7 @@ class AdminNoReservationsView: UIView {
1921 }
2022 }
2123
24+ func setup(withTitle title: String) {
25+ titleLabel?.text = title
26+ }
2227}
Hookah Tau/Controllers/Admin/Reservations/Views/No reserv/AdminNoReservationsView.xib+1
@@ -46,6 +46,7 @@
4646 <viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
4747 <connections>
4848 <outlet property="bookButton" destination="y3F-ua-mLb" id="aC4-gz-Gqd"/>
49+ <outlet property="titleLabel" destination="Svd-DB-3Zu" id="n8Z-Wq-vzC"/>
4950 </connections>
5051 <point key="canvasLocation" x="137.68115942028987" y="91.741071428571431"/>
5152 </view>