git.iko.soy/dashared/hookah-tau
on develop help sign in
начинаю собирать экран изменения брони
74b278eDarya Rednikina
Hookah Tau/Controllers/Client/Reservations/Active Reservations/ReservationsViewController.swift+1−1
@@ -55,7 +55,7 @@ class ReservationsViewController: BaseViewController {
55 setUpNavigationBar()
55 setUpNavigationBar()
56
56
57 reservationsService = ReservationsService(apiClient: APIClient.shared)
57 reservationsService = ReservationsService(apiClient: APIClient.shared)
58−
58+ navigationController?.navigationBar.prefersLargeTitles = true
59 setUpContentView()
59 setUpContentView()
60 }
60 }
61
61
Hookah Tau/Controllers/Client/Reservations/Adress of reservation/AddresViewController.swift+1
@@ -24,6 +24,7 @@ class AddresViewController: BaseViewController {
24 view.backgroundColor = .white
24 view.backgroundColor = .white
25 navigationItem.title = "Заведения"
25 navigationItem.title = "Заведения"
26
26
27+ navigationController?.navigationBar.prefersLargeTitles = true
27 setUpTableView()
28 setUpTableView()
28 }
29 }
29
30
Hookah Tau/Controllers/Client/Reservations/Reservation.storyboard+32
@@ -113,5 +113,37 @@
113 </objects>
113 </objects>
114 <point key="canvasLocation" x="1457.9710144927537" y="-38.169642857142854"/>
114 <point key="canvasLocation" x="1457.9710144927537" y="-38.169642857142854"/>
115 </scene>
115 </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>
116 </scenes>
148 </scenes>
117</document>
149</document>
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepReservationCoordinator.swift+20−6
@@ -19,22 +19,36 @@ class ThirdStepReservationCoordinator: BaseCoordinator {
19 /// Объект регистрации, созданной или существующей
19 /// Объект регистрации, созданной или существующей
20 var resrvation: Reservation?
20 var resrvation: Reservation?
21
21
22+ var reservationVC: ThirdStepReservationViewController?
23+
22 // MARK: - Lifecycle
24 // MARK: - Lifecycle
23
25
24 override func start() {
26 override func start() {
25 let storyboard = UIStoryboard(name: "Reservation", bundle: nil)
27 let storyboard = UIStoryboard(name: "Reservation", bundle: nil)
26− let reservationVC = storyboard.instantiateViewController(withIdentifier: "ThirdStepReservationViewController") as! ThirdStepReservationViewController
28+ reservationVC = storyboard.instantiateViewController(withIdentifier: "ThirdStepReservationViewController") as? ThirdStepReservationViewController
27
29
28− reservationVC.coordinator = self
30+ reservationVC?.coordinator = self
29− reservationVC.mapView = mapView
31+ reservationVC?.mapView = mapView
30− reservationVC.reservation = resrvation
32+ reservationVC?.reservation = resrvation
31
33
34+ guard let r = reservationVC else { return }
32− navigationController?.pushViewController(reservationVC, animated: false)
35+ navigationController?.pushViewController(r, animated: false)
33 }
36 }
34
37
35 /// You need to pass reservation object and map describing booked table
38 /// You need to pass reservation object and map describing booked table
36 func change(_ reservation: Reservation, _ map: MapImageScroll) {
39 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()
38 }
52 }
39
53
40 /// Goes back to `allReservations` screen
54 /// Goes back to `allReservations` screen
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepReservationViewController.swift+16−8
@@ -31,6 +31,9 @@ class ThirdStepReservationViewController: BaseViewController {
31 else { return }
31 else { return }
32
32
33 navigationItem.title = data.address
33 navigationItem.title = data.address
34+
35+ guard let res = reservation else { return }
36+ thirdStepView?.bind(withModel: res)
34 }
37 }
35 }
38 }
36
39
@@ -63,6 +66,7 @@ class ThirdStepReservationViewController: BaseViewController {
63 setupMap()
66 setupMap()
64
67
65 reservationService = ReservationsService(apiClient: APIClient.shared)
68 reservationService = ReservationsService(apiClient: APIClient.shared)
69+ navigationController?.navigationBar.prefersLargeTitles = false
66 }
70 }
67
71
68 override func viewWillAppear(_ animated: Bool) {
72 override func viewWillAppear(_ animated: Bool) {
@@ -78,22 +82,26 @@ class ThirdStepReservationViewController: BaseViewController {
78 return
82 return
79 }
83 }
80
84
85+ let width = view.frame.width
81 if reservation.establishment == 1 {
86 if reservation.establishment == 1 {
82 mapView = MapView1.loadFromNib()
87 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)
83 } else {
94 } else {
84 mapView = MapView2.loadFromNib()
95 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)
85 }
101 }
86
102
87 contentForMap.addSubviewThatFills(mapView)
103 contentForMap.addSubviewThatFills(mapView)
88
104
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−
97 mapView?.isUserInteractionEnabled = false
105 mapView?.isUserInteractionEnabled = false
98 mapView?.scrollToTable(table: reservation.reservedTable)
106 mapView?.scrollToTable(table: reservation.reservedTable)
99 }
107 }
Hookah Tau/Controllers/Client/Reservations/Steps/change /ChangeReservationCoordinator.swift+26−1
@@ -6,8 +6,33 @@
6// Copyright © 2019 Daria Rednikina. All rights reserved.
6// Copyright © 2019 Daria Rednikina. All rights reserved.
7//
7//
8
8
9−import Foundation
9+import UIKit
10
10
11class ChangeReservationCoordinator: BaseCoordinator {
11class ChangeReservationCoordinator: BaseCoordinator {
12
12
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+ }
13}
38}
Hookah Tau/Controllers/Client/Reservations/Steps/change /ChangeReservationViewController.swift+60−1
@@ -9,11 +9,70 @@
9import UIKit
9import UIKit
10
10
11class ChangeReservationViewController: BaseViewController {
11class 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+
13 override func viewDidLoad() {
38 override func viewDidLoad() {
14 super.viewDidLoad()
39 super.viewDidLoad()
15
40
41+ reservationService = ReservationsService(apiClient: APIClient.shared)
42+ setupButtons()
43+
44+ navigationItem.hidesBackButton = true
16 // Do any additional setup after loading the view.
45 // Do any additional setup after loading the view.
17 }
46 }
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+ }
18
77
19}
78}