git.iko.soy/dashared/hookah-tau
on develop help sign in
Подправила даты, вставила картинки на 2 экран
commit5807a8835a612938af962bc7830ad0be7708049d authorDarya Rednikina <rednikina.com@yandex.ru> dateTue 3 Dec 2019, 12:00 (7 years ago) parentf964fc9
10 files changed+172−47
Hookah Tau/Controllers/Client/Reservations/Cells/Reservation/ReservationView.swift+1−16 Hookah Tau/Controllers/Client/Reservations/Steps/2/SecondStepReservationViewController.swift+14−11 Hookah Tau/Controllers/Client/Reservations/Steps/2/SecondStepView.swift+84−20 Hookah Tau/Extensions+Date.swift+28 Hookah Tau/Supporting Files/Assets.xcassets/fff.imageset/Contents.json+15 Hookah Tau/Supporting Files/Assets.xcassets/fff.imageset/fff.pdf Hookah Tau/Supporting Files/Assets.xcassets/handle_left.imageset/Contents.json+15 Hookah Tau/Supporting Files/Assets.xcassets/handle_left.imageset/handle_left.pdf Hookah Tau/Supporting Files/Assets.xcassets/hhhh.pdf.imageset/Contents.json+15 Hookah Tau/Supporting Files/Assets.xcassets/hhhh.pdf.imageset/hhhh.pdf.pdf
Hookah Tau/Controllers/Client/Reservations/Cells/Reservation/ReservationView.swift+1−16
@@ -31,23 +31,8 @@ class ReservationView: UIView {
3131 adressLabel?.text = establishment.address
3232 maxPeopleLabel?.text = "\(model.numberOfGuests) " + (2...4 ~= model.numberOfGuests ? "человека" : "человек")
3333
34− let (date, time) = format(model.startTime, model.endTime)
34+ let (date, time) = Date.format(model.startTime, model.endTime)
3535 dateLabel?.text = date
3636 timeLabel?.text = time
3737 }
38−
39− private func format(_ startDate: Date, _ endDate: Date) -> (date: String, time: String) {
40− let dateFormatter = DateFormatter()
41− dateFormatter.calendar = Calendar.current
42− dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
43− dateFormatter.dateFormat = "d MMMM"
44− dateFormatter.locale = Locale(identifier: "ru_RU")
45−
46− let dateStr = "\(dateFormatter.string(from: startDate))"
47−
48− dateFormatter.dateFormat = "HH:mm"
49− let timeStr = "\(dateFormatter.string(from: startDate)) — \(dateFormatter.string(from: endDate))"
50−
51− return (dateStr, timeStr)
52− }
5338}
Hookah Tau/Controllers/Client/Reservations/Steps/2/SecondStepReservationViewController.swift+14−11
@@ -12,12 +12,16 @@ class SecondStepReservationViewController: BaseViewController {
1212
1313 // MARK: - Properties
1414
15− weak var coordinator: SecondStepReservationCoordinator?
16−
1715 @IBOutlet weak var childContentView: UIView!
1816
1917 var secondStepView: SecondStepView?
2018
19+ /// координатор
20+ weak var coordinator: SecondStepReservationCoordinator?
21+
22+ /// service для создания бронирования
23+ var reservationService: ReservationsService?
24+
2125 /// map view from the previous screen
2226 var mapView: MapImageScroll?
2327
@@ -26,12 +30,6 @@ class SecondStepReservationViewController: BaseViewController {
2630 /// address of the building to display in nav bar title
2731 var address: String = "Покровский бр., 11"
2832
29− var reservation: Reservation? {
30− didSet {
31− // todo: засетить все
32− }
33− }
34−
3533 /// booked periods for this table for this date
3634 var bookedPeriods: [ReservationPeriod] = [] {
3735 didSet {
@@ -63,6 +61,7 @@ class SecondStepReservationViewController: BaseViewController {
6361 setupChildContainer()
6462 setupButtons()
6563
64+ reservationService = ReservationsService(apiClient: APIClient.shared)
6665 }
6766
6867 override func viewWillAppear(_ animated: Bool) {
@@ -100,11 +99,12 @@ class SecondStepReservationViewController: BaseViewController {
10099
101100 let width = view.frame.width
102101
103− mapView?.scrollViewParent.contentInset = UIEdgeInsets(top: 100, left: width / 2, bottom: 0, right: width / 2)
104102 mapView?.scrollViewParent.setContentOffset(CGPoint(x: 0, y: 100), animated: false)
105−
103+ mapView?.scrollViewParent.contentInset = UIEdgeInsets(top: 100,
104+ left: width / 2,
105+ bottom: 0,
106+ right: width / 2)
106107 mapView?.isUserInteractionEnabled = false
107−
108108 view.sendSubviewToBack(map)
109109 }
110110
@@ -129,6 +129,9 @@ class SecondStepReservationViewController: BaseViewController {
129129 }
130130
131131 @objc func book() {
132+// guard let data = ReservationData(establishment: model?.establishment,
133+// startTime: , endTime: <#T##Date#>, numberOfGuests: <#T##Int#>, reservedTable: <#T##Int#>)
134+
132135 coordinator?.book(mapView)
133136 }
134137}
Hookah Tau/Controllers/Client/Reservations/Steps/2/SecondStepView.swift+84−20
@@ -8,6 +8,7 @@
88
99import UIKit
1010
11+/// стол, начало, интервалы (???), establishment
1112struct SecondStepModel {
1213 var establishment: Int
1314 var table: Int
@@ -31,10 +32,23 @@ class SecondStepView: UIView {
3132
3233 @IBOutlet weak var intervalsStackView: UIStackView!
3334
35+ var data: ReservationData? {
36+ didSet {
37+ guard let d = data else { return }
38+ let (date, time) = Date.format(d.startTime, d.endTime)
39+ totalBookingLabel.text = "Забронировать \(d.reservedTable) столик на \(d.numberOfGuests) человека \(date) \(time)?"
40+ }
41+ }
42+
3443 var model: SecondStepModel? {
3544 didSet {
3645 guard let model = model else { return }
37− totalBookingLabel.text = "Забронировать \(model.table) столик на \(Int(guestSlider.value)) человека \(model.startTime)?"
46+
47+ data = ReservationData(establishment: model.establishment,
48+ startTime: model.startTime,
49+ endTime: model.startTime.addHours(2),
50+ numberOfGuests: Int(guestSlider.value),
51+ reservedTable: model.table)
3852
3953 setUpIntervals(model.startTime)
4054 setUpReservedIntervals(model.reservedintervals)
@@ -45,23 +59,25 @@ class SecondStepView: UIView {
4559 var startLeadingConstraint: NSLayoutConstraint!
4660 var endLeadingConstraint: NSLayoutConstraint!
4761
48− var startPoint: UIView = {
49− var view = UIView()
50− view.backgroundColor = .blue
62+ var startPoint: UIImageView = {
63+ var view = UIImageView()
64+ view.isUserInteractionEnabled = true
65+ view.image = #imageLiteral(resourceName: "handle_left")
5166 view.translatesAutoresizingMaskIntoConstraints = false
5267 return view
5368 }()
5469
55− var endPoint: UIView = {
56− var view = UIView()
57− view.backgroundColor = .red
58− view.translatesAutoresizingMaskIntoConstraints = false
59− return view
70+ var endPoint: UIImageView = {
71+ var view = UIImageView()
72+ view.isUserInteractionEnabled = true
73+ view.image = #imageLiteral(resourceName: "fff")
74+ view.translatesAutoresizingMaskIntoConstraints = false
75+ return view
6076 }()
6177
6278 var fillInterval: UIView = {
6379 var view = UIView()
64− view.backgroundColor = #colorLiteral(red: 0.476841867, green: 0.5048075914, blue: 1, alpha: 0.604880137)
80+ view.backgroundColor = #colorLiteral(red: 0, green: 0.5921568627, blue: 1, alpha: 0.3426262843)
6581 view.translatesAutoresizingMaskIntoConstraints = false
6682 return view
6783 }()
@@ -82,7 +98,14 @@ class SecondStepView: UIView {
8298 let value = Int(sender.value)
8399 numberOfGuestsLabel.text = "Количество гостей: \(value)"
84100 infoLabel.text = getNumberOfCalians(value)
85− totalBookingLabel.text = "Забронировать \(model?.table ?? 0) столик на \(value) человека 29 марта с 3:00 до 5:30?"
101+
102+ guard let d = data else { return }
103+
104+ data = ReservationData(establishment: d.establishment,
105+ startTime: d.startTime,
106+ endTime: d.endTime,
107+ numberOfGuests: value,
108+ reservedTable: d.reservedTable)
86109 }
87110
88111 func getNumberOfCalians(_ sliderValue: Int) -> String {
@@ -108,31 +131,35 @@ class SecondStepView: UIView {
108131 }
109132 }
110133
134+
135+
111136 private func setUpBookingPeriod(_ startTime: Date) {
112137 self.scrollView.addSubview(startPoint)
113138 self.scrollView.addSubview(endPoint)
114139 self.scrollView.addSubview(fillInterval)
115140
116− let startDate = startTime.set(hours: 12, minutes: 0, seconds: 0)!
141+ let startDate = startTime.set(hours: 12, minutes: 0, seconds: 0)!// for client
117142
118− let startConstr = CGFloat(startDate.getMinutesPeriods(fromStart: startTime) * Constants.timepointWidth)
143+ let startConstr = CGFloat(startTime.getMinutesPeriods(fromStart: startDate) * Constants.timepointWidth)
119144
120− scrollView.setContentOffset(CGPoint(x: startConstr, y: 0), animated: true)
145+ scrollView.setContentOffset(CGPoint(x: startConstr - 50, y: 0), animated: true)
121146
122147 startLeadingConstraint = startPoint.leftAnchor.constraint(equalTo: scrollView.leftAnchor,
123148 constant: startConstr)
149+
124150 endLeadingConstraint = endPoint.leftAnchor.constraint(equalTo: scrollView.leftAnchor,
125151 constant:startConstr + CGFloat(10 * Constants.timepointWidth))
126152
127153 NSLayoutConstraint.activate([
128− startPoint.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 0),
129− endPoint.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 0),
130154
131155 startPoint.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: 0),
132156 endPoint.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: 0),
133157
134− startPoint.widthAnchor.constraint(equalToConstant: 7),
135− endPoint.widthAnchor.constraint(equalToConstant: 7),
158+ startPoint.widthAnchor.constraint(equalToConstant: Constants.pointWidth),
159+ endPoint.widthAnchor.constraint(equalToConstant: Constants.pointWidth),
160+
161+ startPoint.heightAnchor.constraint(equalToConstant: Constants.pointHeight),
162+ endPoint.heightAnchor.constraint(equalToConstant: Constants.pointHeight),
136163
137164 startLeadingConstraint,
138165 endLeadingConstraint,
@@ -140,7 +167,7 @@ class SecondStepView: UIView {
140167 fillInterval.leftAnchor.constraint(equalTo: startPoint.rightAnchor, constant: 0),
141168 fillInterval.rightAnchor.constraint(equalTo: endPoint.leftAnchor, constant: 0),
142169
143− fillInterval.topAnchor.constraint(equalTo: scrollView.topAnchor, constant: 0),
170+ fillInterval.heightAnchor.constraint(equalToConstant: Constants.pointHeight),
144171 fillInterval.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: 0)
145172 ])
146173
@@ -166,19 +193,53 @@ class SecondStepView: UIView {
166193 // MARK: - Pan
167194
168195 @objc func handlePanStart(recognizer:UIPanGestureRecognizer) {
196+ guard let d = data else { return }
197+
169198 let translation = recognizer.translation(in: self.intervalsStackView)
170199 if let view = recognizer.view {
171200 startLeadingConstraint.constant += translation.x
201+
202+ let offset = Int(startLeadingConstraint.constant) % Constants.timepointWidth
203+ if offset == 0 {
204+
205+ let startDate = d.startTime.set(hours: 12, minutes: 0, seconds: 0)!// for client
206+ let p = Int(startLeadingConstraint.constant) / Constants.timepointWidth
207+ let start = startDate.addPeriods(p)
208+
209+ data = ReservationData(establishment: d.establishment,
210+ startTime: start,
211+ endTime: d.endTime,
212+ numberOfGuests: d.numberOfGuests,
213+ reservedTable: d.reservedTable)
214+ }
215+
172216 view.setNeedsUpdateConstraints()
173217 }
174−
218+
219+
175220 recognizer.setTranslation(CGPoint.zero, in: self.intervalsStackView)
176221 }
177222
178223 @objc func handlePanEnd(recognizer:UIPanGestureRecognizer) {
224+ guard let d = data else { return }
225+
179226 let translation = recognizer.translation(in: self.intervalsStackView)
180227 if let view = recognizer.view {
181228 endLeadingConstraint.constant += translation.x
229+
230+ let offset = Int(endLeadingConstraint.constant) % Constants.timepointWidth
231+ if offset == 0 {
232+ let startDate = d.startTime.set(hours: 12, minutes: 0, seconds: 0)!// for client
233+ let p = Int(endLeadingConstraint.constant) / Constants.timepointWidth
234+ let end = startDate.addPeriods(p)
235+
236+ data = ReservationData(establishment: d.establishment,
237+ startTime: d.startTime,
238+ endTime: end,
239+ numberOfGuests: d.numberOfGuests,
240+ reservedTable: d.reservedTable)
241+ }
242+
182243 view.setNeedsUpdateConstraints()
183244 }
184245
@@ -200,5 +261,8 @@ extension SecondStepView {
200261 static let clientDuration = 90
201262 // 12:00 = 12 * 6
202263 static let clientStartingPoint = 72
264+
265+ static let pointWidth: CGFloat = 19
266+ static let pointHeight: CGFloat = 86
203267 }
204268}
Hookah Tau/Extensions+Date.swift+28
@@ -99,6 +99,17 @@ extension Date {
9999 return set(hours: 0, minutes: 0, seconds: 0)!
100100 }
101101
102+ func addHours(_ h: Int) -> Date {
103+ return self.addingTimeInterval(Double(h) * 60.0 * 60.0)
104+ }
105+
106+ func addPeriods(_ p: Int) -> Date {
107+ let h = (p * 10 / 60) % 24
108+ let m = (p * 10) % 60
109+
110+ return self.addingTimeInterval(Double(h) * 60.0 * 60.0 + Double(m) * 60.0)
111+ }
112+
102113 func set(hours: Int, minutes: Int, seconds: Int) -> Date? {
103114
104115 let dateFormatter = DateFormatter()
@@ -176,3 +187,20 @@ extension Date {
176187 }
177188 }
178189}
190+
191+extension Date {
192+ static func format(_ startDate: Date, _ endDate: Date) -> (date: String, time: String) {
193+ let dateFormatter = DateFormatter()
194+ dateFormatter.calendar = Calendar.current
195+ dateFormatter.timeZone = TimeZone(abbreviation: "UTC")
196+ dateFormatter.dateFormat = "d MMMM"
197+ dateFormatter.locale = Locale(identifier: "ru_RU")
198+
199+ let dateStr = "\(dateFormatter.string(from: startDate))"
200+
201+ dateFormatter.dateFormat = "HH:mm"
202+ let timeStr = "\(dateFormatter.string(from: startDate)) — \(dateFormatter.string(from: endDate))"
203+
204+ return (dateStr, timeStr)
205+ }
206+}
Hookah Tau/Supporting Files/Assets.xcassets/fff.imageset/Contents.jsonnew file+15
@@ -0,0 +1,15 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "fff.pdf"
6+ }
7+ ],
8+ "info" : {
9+ "version" : 1,
10+ "author" : "xcode"
11+ },
12+ "properties" : {
13+ "preserves-vector-representation" : true
14+ }
15+}
Hookah Tau/Supporting Files/Assets.xcassets/fff.imageset/fff.pdfnew file

Binary file not shown.

Hookah Tau/Supporting Files/Assets.xcassets/handle_left.imageset/Contents.jsonnew file+15
@@ -0,0 +1,15 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "handle_left.pdf"
6+ }
7+ ],
8+ "info" : {
9+ "version" : 1,
10+ "author" : "xcode"
11+ },
12+ "properties" : {
13+ "preserves-vector-representation" : true
14+ }
15+}
Hookah Tau/Supporting Files/Assets.xcassets/handle_left.imageset/handle_left.pdfnew file

Binary file not shown.

Hookah Tau/Supporting Files/Assets.xcassets/hhhh.pdf.imageset/Contents.jsonnew file+15
@@ -0,0 +1,15 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "hhhh.pdf.pdf"
6+ }
7+ ],
8+ "info" : {
9+ "version" : 1,
10+ "author" : "xcode"
11+ },
12+ "properties" : {
13+ "preserves-vector-representation" : true
14+ }
15+}
Hookah Tau/Supporting Files/Assets.xcassets/hhhh.pdf.imageset/hhhh.pdf.pdfnew file

Binary file not shown.