git.iko.soy/dashared/hookah-tau
on develop help sign in
начинаю собирать экран изменения брони
commit74b278ef8c5752f87e27b4f88442a5ba4ab218ce authorDarya Rednikina <rednikina.com@yandex.ru> dateTue 3 Dec 2019, 22:08 (7 years ago) parentdafc126
7 files changed+156−17
Hookah Tau/Controllers/Client/Reservations/Active Reservations/ReservationsViewController.swift+1−1 Hookah Tau/Controllers/Client/Reservations/Adress of reservation/AddresViewController.swift+1 Hookah Tau/Controllers/Client/Reservations/Reservation.storyboard+32 Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepReservationCoordinator.swift+20−6 Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepReservationViewController.swift+16−8 Hookah Tau/Controllers/Client/Reservations/Steps/change /ChangeReservationCoordinator.swift+26−1 Hookah Tau/Controllers/Client/Reservations/Steps/change /ChangeReservationViewController.swift+60−1
Hookah Tau/Controllers/Client/Reservations/Active Reservations/ReservationsViewController.swift+1−1
@@ -55,7 +55,7 @@ class ReservationsViewController: BaseViewController {
5555 setUpNavigationBar()
5656
5757 reservationsService = ReservationsService(apiClient: APIClient.shared)
58−
58+ navigationController?.navigationBar.prefersLargeTitles = true
5959 setUpContentView()
6060 }
6161
Hookah Tau/Controllers/Client/Reservations/Adress of reservation/AddresViewController.swift+1
@@ -24,6 +24,7 @@ class AddresViewController: BaseViewController {
2424 view.backgroundColor = .white
2525 navigationItem.title = "Заведения"
2626
27+ navigationController?.navigationBar.prefersLargeTitles = true
2728 setUpTableView()
2829 }
2930
Hookah Tau/Controllers/Client/Reservations/Reservation.storyboard+32
@@ -113,5 +113,37 @@
113113 </objects>
114114 <point key="canvasLocation" x="1457.9710144927537" y="-38.169642857142854"/>
115115 </scene>
116+ <!--Change Reservation View Controller-->
117+ <scene sceneID="zZt-Ob-8J3">
118+ <objects>
119+ <viewController storyboardIdentifier="ChangeReservationViewController" id="qmR-St-vh2" customClass="ChangeReservationViewController" customModule="Hookah_Tau" customModuleProvider="target" sceneMemberID="viewController">
120+ <view key="view" contentMode="scaleToFill" id="mnl-c9-WGz">
121+ <rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
122+ <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
123+ <subviews>
124+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="kon-kQ-rMb">
125+ <rect key="frame" x="0.0" y="502" width="414" height="394"/>
126+ <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
127+ <constraints>
128+ <constraint firstAttribute="height" constant="394" id="Ppm-PI-ASV"/>
129+ </constraints>
130+ </view>
131+ </subviews>
132+ <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/>
133+ <constraints>
134+ <constraint firstItem="kon-kQ-rMb" firstAttribute="leading" secondItem="Oj9-9F-isg" secondAttribute="leading" id="5wF-Rc-6Na"/>
135+ <constraint firstAttribute="bottom" secondItem="kon-kQ-rMb" secondAttribute="bottom" id="IAO-aj-hyT"/>
136+ <constraint firstItem="kon-kQ-rMb" firstAttribute="trailing" secondItem="Oj9-9F-isg" secondAttribute="trailing" id="cZG-IB-ohm"/>
137+ </constraints>
138+ <viewLayoutGuide key="safeArea" id="Oj9-9F-isg"/>
139+ </view>
140+ <connections>
141+ <outlet property="childContentView" destination="kon-kQ-rMb" id="5DH-RF-lEQ"/>
142+ </connections>
143+ </viewController>
144+ <placeholder placeholderIdentifier="IBFirstResponder" id="H8g-xl-PmS" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
145+ </objects>
146+ <point key="canvasLocation" x="2350.7246376811595" y="-38.169642857142854"/>
147+ </scene>
116148 </scenes>
117149</document>
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepReservationCoordinator.swift+20−6
@@ -19,22 +19,36 @@ class ThirdStepReservationCoordinator: BaseCoordinator {
1919 /// Объект регистрации, созданной или существующей
2020 var resrvation: Reservation?
2121
22+ var reservationVC: ThirdStepReservationViewController?
23+
2224 // MARK: - Lifecycle
2325
2426 override func start() {
2527 let storyboard = UIStoryboard(name: "Reservation", bundle: nil)
26− let reservationVC = storyboard.instantiateViewController(withIdentifier: "ThirdStepReservationViewController") as! ThirdStepReservationViewController
28+ reservationVC = storyboard.instantiateViewController(withIdentifier: "ThirdStepReservationViewController") as? ThirdStepReservationViewController
2729
28− reservationVC.coordinator = self
29− reservationVC.mapView = mapView
30− reservationVC.reservation = resrvation
30+ reservationVC?.coordinator = self
31+ reservationVC?.mapView = mapView
32+ reservationVC?.reservation = resrvation
3133
32− navigationController?.pushViewController(reservationVC, animated: false)
34+ guard let r = reservationVC else { return }
35+ navigationController?.pushViewController(r, animated: false)
3336 }
3437
3538 /// You need to pass reservation object and map describing booked table
3639 func change(_ reservation: Reservation, _ map: MapImageScroll) {
37− //
40+ let changeCoordinator = ChangeReservationCoordinator(navigationController: navigationController)
41+
42+ changeCoordinator.reservation = reservation
43+ changeCoordinator.map = map
44+
45+ changeCoordinator.didFinish = { [weak self] res in
46+ self?.removeDependency(changeCoordinator)
47+ self?.navigationController?.popViewController(animated: false)
48+ self?.reservationVC?.reservation = res
49+ }
50+
51+ changeCoordinator.start()
3852 }
3953
4054 /// Goes back to `allReservations` screen
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepReservationViewController.swift+16−8
@@ -31,6 +31,9 @@ class ThirdStepReservationViewController: BaseViewController {
3131 else { return }
3232
3333 navigationItem.title = data.address
34+
35+ guard let res = reservation else { return }
36+ thirdStepView?.bind(withModel: res)
3437 }
3538 }
3639
@@ -63,6 +66,7 @@ class ThirdStepReservationViewController: BaseViewController {
6366 setupMap()
6467
6568 reservationService = ReservationsService(apiClient: APIClient.shared)
69+ navigationController?.navigationBar.prefersLargeTitles = false
6670 }
6771
6872 override func viewWillAppear(_ animated: Bool) {
@@ -78,22 +82,26 @@ class ThirdStepReservationViewController: BaseViewController {
7882 return
7983 }
8084
85+ let width = view.frame.width
8186 if reservation.establishment == 1 {
8287 mapView = MapView1.loadFromNib()
88+ mapView?.scrollViewParent.contentInset = UIEdgeInsets(top: 0,
89+ left: width / 2,
90+ bottom: 200,
91+ right: width / 2)
92+
93+ mapView?.scrollViewParent.setContentOffset(CGPoint(x: 0, y: 50), animated: false)
8394 } else {
8495 mapView = MapView2.loadFromNib()
96+ mapView?.scrollViewParent.setContentOffset(CGPoint(x: 0, y: -100), animated: false)
97+ mapView?.scrollViewParent.contentInset = UIEdgeInsets(top: 100,
98+ left: width / 2,
99+ bottom: 100,
100+ right: width / 2)
85101 }
86102
87103 contentForMap.addSubviewThatFills(mapView)
88104
89− let width = view.frame.width
90− mapView?.scrollViewParent.contentInset = UIEdgeInsets(top: 0,
91− left: width / 2,
92− bottom: 300,
93− right: width / 2)
94−
95− mapView?.scrollViewParent.setContentOffset(CGPoint(x: 0, y: -100), animated: false)
96−
97105 mapView?.isUserInteractionEnabled = false
98106 mapView?.scrollToTable(table: reservation.reservedTable)
99107 }
Hookah Tau/Controllers/Client/Reservations/Steps/change /ChangeReservationCoordinator.swift+26−1
@@ -6,8 +6,33 @@
66// Copyright © 2019 Daria Rednikina. All rights reserved.
77//
88
9−import Foundation
9+import UIKit
1010
1111class ChangeReservationCoordinator: BaseCoordinator {
1212
13+ // MARK: - Peoperties
14+
15+ var reservation: Reservation?
16+
17+ var map: MapImageScroll?
18+
19+ var didFinish: ((Reservation) -> Void)?
20+
21+ // MARK: - Lifecycle
22+
23+ override func start() {
24+ let storyboard = UIStoryboard(name: "Reservation", bundle: nil)
25+ let vc = storyboard.instantiateViewController(withIdentifier: "ChangeReservationViewController") as? ChangeReservationViewController
26+
27+ guard let viewController = vc else { return }
28+
29+ viewController.reservation = reservation
30+ viewController.coordinator = self
31+ navigationController?.pushViewController(viewController, animated: false)
32+ }
33+
34+ /// Закончили редактирование, все хорошо
35+ func finish(_ r: Reservation) {
36+ didFinish?(r)
37+ }
1338}
Hookah Tau/Controllers/Client/Reservations/Steps/change /ChangeReservationViewController.swift+60−1
@@ -9,11 +9,70 @@
99import UIKit
1010
1111class ChangeReservationViewController: BaseViewController {
12−
12+
13+ // MARK: - IBAOutlets
14+
15+ @IBOutlet weak var childContentView: UIView!
16+
17+ // MARK: - Peoperties
18+
19+ var reservation: Reservation?
20+
21+ var secondStepView: SecondStepView?
22+
23+ var reservationService: ReservationsService?
24+
25+ weak var coordinator: ChangeReservationCoordinator?
26+
27+ // MARK: - Buttons
28+
29+ var confirmButton: Button = {
30+ var button = Button()
31+ var style = BlackButtonStyle()
32+ style.apply(to: button, withTitle: "ПОДТВЕРДИТЬ")
33+ return button
34+ }()
35+
36+ // MARK: - Lifecycle
37+
1338 override func viewDidLoad() {
1439 super.viewDidLoad()
1540
41+ reservationService = ReservationsService(apiClient: APIClient.shared)
42+ setupButtons()
43+
44+ navigationItem.hidesBackButton = true
1645 // Do any additional setup after loading the view.
1746 }
47+
48+ // MARK: - setup
49+
50+ func setupButtons() {
51+ addStackViewWithButtons( rightBtn: confirmButton,
52+ constant: -childContentView.frame.height - 20)
53+
54+ confirmButton.addTarget(self, action: #selector(changeReservation), for: .touchUpInside)
55+ }
56+
57+ // MARK: - Handlers
58+
59+ @objc func changeReservation() {
60+ guard let r = reservation else { return }
61+ confirmButton.loading = true
62+
63+ reservationService?.updateReservation(startTime: r.startTime,
64+ numberOfGuests: r.numberOfGuests,
65+ endTime: r.endTime,
66+ uuid: r.uuid,
67+ completion: { [weak self] (res) in
68+ if res {
69+ self?.coordinator?.finish(r)
70+ } else {
71+ self?.displayAlert(with: "Что-то пошло не так! Попробуешь еще раз?")
72+ }
73+
74+ self?.confirmButton.loading = false
75+ })
76+ }
1877
1978}