git.iko.soy/dashared/hookah-tau
on develop help sign in
Баг с датами + кнопки на 1 экране брони
commit8dfcf6cb6ecc9bb7a3485abf953d05a01185aa36 authorDarya Rednikina <rednikina.com@yandex.ru> dateFri 29 Nov 2019, 13:06 (7 years ago) parent65f3f63
5 files changed+36−19
Hookah Tau/Components/Button.swift+8−7 Hookah Tau/Components/TableButtonStyle.swift+1−1 Hookah Tau/Controllers/Client/Reservations/Steps/1/FirstStepReservationViewController.swift+16−1 Hookah Tau/Controllers/Client/Reservations/Steps/1/FirstStepView.swift+10−9 Hookah Tau/Extensions+Date.swift+1−1
Hookah Tau/Components/Button.swift+8−7
@@ -22,10 +22,11 @@ class Button: UIButton {
2222
2323 override var isEnabled: Bool {
2424 didSet {
25− //alpha = isEnabled ? 1 : 0.8
25+ alpha = isEnabled ? 1 : 0.8
2626 }
2727 }
2828
29+ /// State when chosen table is Booked
2930 public var availiable = true {
3031 willSet {
3132 willUpdateBookingState(newValue: availiable)
@@ -51,12 +52,12 @@ class Button: UIButton {
5152 }
5253
5354 private func willUpdateBookingState(newValue avaliable: Bool) {
54− isEnabled = !avaliable
55+ isEnabled = avaliable
5556
56− if availiable {
57− style?.changeToAvailiableState(button: self)
58− } else {
59− style?.changeToBookedState(button: self)
60− }
57+// if availiable {
58+// style?.changeToAvailiableState(button: self)
59+// } else {
60+// style?.changeToBookedState(button: self)
61+// }
6162 }
6263}
Hookah Tau/Components/TableButtonStyle.swift+1−1
@@ -25,7 +25,7 @@ class TableStyle {
2525 let stripe = CALayer()
2626
2727 stripe.frame = CGRect(x: 0, y: -10, width: 2, height: 500)
28− stripe.backgroundColor = UIColor.black.cgColor
28+ stripe.backgroundColor = UIColor.white.cgColor
2929 stripe.transform = CATransform3DMakeRotation(0.52, 0, 0, 1.0)
3030
3131 replicatorLayer.instanceCount = 60
Hookah Tau/Controllers/Client/Reservations/Steps/1/FirstStepReservationViewController.swift+16−1
@@ -59,7 +59,6 @@ class FirstStepReservationViewController: BaseViewController {
5959 let button = Button()
6060 let style = BlackButtonStyle()
6161 style.apply(to: button, withTitle: "ПОЗВОНИТЬ")
62− //button.addTarget(self, action: #selector(cancelChange), for: .touchUpInside)
6362 return button
6463 }()
6564
@@ -88,6 +87,7 @@ class FirstStepReservationViewController: BaseViewController {
8887 constant: -childContentView.frame.height - 20)
8988
9089 continueButton.addTarget(self, action: #selector(continueBooking), for: .touchUpInside)
90+ callButton.addTarget(self, action: #selector(call(phone:)), for: .touchUpInside)
9191 }
9292
9393 func performUpdate() {
@@ -150,6 +150,14 @@ class FirstStepReservationViewController: BaseViewController {
150150 coordinator?.makeReservation(model: model,
151151 mapView: map)
152152 }
153+
154+ @objc func call(phone: String) {
155+ guard
156+ let phone = TotalStorage.standard.getEstablishment(establishmentId)?.admin,
157+ let urlPhone = URL(string: "tel://79\(phone)") else { return }
158+
159+ UIApplication.shared.open(urlPhone)
160+ }
153161}
154162
155163extension FirstStepReservationViewController: MapHandler {
@@ -162,6 +170,13 @@ extension FirstStepReservationViewController: MapHandler {
162170extension FirstStepReservationViewController: MapUpdater {
163171 func update(_ date: Date) {
164172 let areBooked = allReservations?.intervals[date.getDMY()]?[date] ?? []
173+
174+ if Set(areBooked).contains(tableId) {
175+ continueButton.availiable = false
176+ } else {
177+ continueButton.availiable = true
178+ }
179+
165180 mapView?.performUpdate(inactive: areBooked)
166181 }
167182}
Hookah Tau/Controllers/Client/Reservations/Steps/1/FirstStepView.swift+10−9
@@ -16,7 +16,7 @@ class FirstStepView: UIView {
1616
1717 weak var mapUpdater: MapUpdater?
1818
19− var chosenPoint: Int? = 0 {
19+ var chosenPoint: Int? {
2020 didSet {
2121 guard
2222 let periods = chosenPoint,
@@ -27,7 +27,7 @@ class FirstStepView: UIView {
2727 }
2828 }
2929
30− var fullDate: Date? = Date.getDateFromCurrent() {
30+ var fullDate: Date? {
3131 didSet {
3232 guard let date = fullDate, let _ = chosenPoint else { return }
3333
@@ -57,11 +57,10 @@ class FirstStepView: UIView {
5757 var bookingsForDates: [Date: [ReservationPeriod]] = [:] {
5858 didSet {
5959 guard
60− let date = fullDate?.getDMY(),
61− let reservPeriods = bookingsForDates[date]
60+ let date = fullDate?.getDMY()
6261 else { return }
6362
64− setUpBookingsForIntervals(reservations: reservPeriods)
63+ setUpBookingsForIntervals(reservations: bookingsForDates[date] ?? [])
6564 }
6665 }
6766
@@ -125,8 +124,9 @@ class FirstStepView: UIView {
125124 bookingsViewsForDate = []
126125
127126 for reservation in reservations {
128− let uiview = UIView(frame: CGRect(x: 0, y: 0, width: Constants.widthTimePoint * reservation.duration, height: 71))
129− uiview.backgroundColor = #colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)
127+ let uiview = UIView(frame: CGRect(x: 0, y: 0, width: Constants.widthTimePoint * reservation.duration, height: Constants.heightIntervals))
128+ uiview.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 0.5)
129+
130130
131131 uiview.translatesAutoresizingMaskIntoConstraints = false
132132 scrollViewIntervals.addSubview(uiview)
@@ -135,11 +135,11 @@ class FirstStepView: UIView {
135135 let startDate = Date.getDateFromCurrent(days: date)!.set(hours: 12, minutes: 0, seconds: 0)!
136136
137137 NSLayoutConstraint.activate([
138− uiview.topAnchor.constraint(equalToSystemSpacingBelow: scrollViewIntervals.topAnchor, multiplier: 0),
139138 uiview.bottomAnchor.constraint(equalToSystemSpacingBelow: scrollViewIntervals.bottomAnchor, multiplier: 0),
140139 uiview.leftAnchor.constraint(equalTo: scrollViewIntervals.leftAnchor,
141140 constant: CGFloat(Constants.widthTimePoint / 2 + Constants.widthTimePoint * reservation.startTime.getMinutesPeriods(fromStart: startDate))),
142− uiview.widthAnchor.constraint(equalToConstant: CGFloat(Constants.widthTimePoint * reservation.duration))
141+ uiview.widthAnchor.constraint(equalToConstant: CGFloat(Constants.widthTimePoint * reservation.duration)),
142+ uiview.heightAnchor.constraint(equalToConstant: CGFloat(Constants.heightIntervals))
143143 ])
144144
145145 bookingsViewsForDate.append(uiview)
@@ -247,5 +247,6 @@ extension FirstStepView {
247247 static let daysCount = 14
248248 static let widthTimePoint = 11
249249 static let widthDate = 31
250+ static let heightIntervals = 70
250251 }
251252}
Hookah Tau/Extensions+Date.swift+1−1
@@ -124,7 +124,7 @@ extension Date {
124124 }
125125
126126 func getMinutesPeriods(fromStart startDate: Date) -> Int {
127− let diffInMins = Calendar.current.dateComponents([.minute], from: self, to: startDate).minute!
127+ let diffInMins = Calendar.current.dateComponents([.minute], from: startDate, to: self).minute!
128128 let periods = diffInMins / 10
129129 return periods
130130 }