git.iko.soy/dashared/hookah-tau
on develop help sign in
последняя вертелка готова 🥳
commitb1378c4a8fa20f47fa1251f00aa6038d0c62c0aa authorDarya Rednikina <rednikina.com@yandex.ru> dateTue 3 Dec 2019, 23:43 (7 years ago) parent74b278e
4 files changed+193−6
Hookah Tau/Controllers/Client/Reservations/Steps/2/SecondStepView.swift+9−4 Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepView.swift+121 Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepView.xib+59−1 Hookah Tau/Extensions+Date.swift+4−1
Hookah Tau/Controllers/Client/Reservations/Steps/2/SecondStepView.swift+9−4
@@ -173,8 +173,7 @@ class SecondStepView: UIView {
173173 }
174174
175175
176−
177− private func setUpBookingPeriod(_ startTime: Date) {
176+ private func setUpBookingPeriod(_ startTime: Date, _ endTime: Date? = nil) {
178177 self.scrollView.addSubview(startPoint)
179178 self.scrollView.addSubview(endPoint)
180179 self.scrollView.addSubview(fillInterval)
@@ -188,8 +187,14 @@ class SecondStepView: UIView {
188187 startLeadingConstraint = startPoint.leftAnchor.constraint(equalTo: scrollView.leftAnchor,
189188 constant: startConstr)
190189
191− endLeadingConstraint = endPoint.leftAnchor.constraint(equalTo: scrollView.leftAnchor,
192− constant:startConstr + Constants.minBookingLength)
190+ if let end = endTime {
191+ let endConstr = CGFloat(end.getMinutesPeriods(fromStart: startDate) * Constants.widthTimePoint)
192+ endLeadingConstraint = endPoint.leftAnchor.constraint(equalTo: scrollView.leftAnchor,
193+ constant: endConstr)
194+ } else {
195+ endLeadingConstraint = endPoint.leftAnchor.constraint(equalTo: scrollView.leftAnchor,
196+ constant:startConstr + Constants.minBookingLength)
197+ }
193198
194199 NSLayoutConstraint.activate([
195200
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepView.swift+121
@@ -14,6 +14,8 @@ struct ThirdStepViewModel {
1414
1515class ThirdStepView: UIView {
1616
17+ // MARK: - IBAOutlets
18+
1719 @IBOutlet weak var totalLabel: UILabel!
1820
1921 @IBOutlet weak var infoLabel: UILabel!
@@ -27,7 +29,34 @@ class ThirdStepView: UIView {
2729
2830 @IBOutlet weak var timeInterval: UIView!
2931
32+ @IBOutlet weak var stackView: UIStackView!
33+
34+ @IBOutlet weak var scrollView: UIScrollView!
35+
36+ // MARK: - Properties
37+
38+ /// Время начала вертелки.
39+ var startDate: Date?
40+
41+ // констрейнты начала и конца интервала
42+ var startLeadingConstraint: NSLayoutConstraint!
43+ var endLeadingConstraint: NSLayoutConstraint!
44+
45+ var reservation: Reservation? {
46+ didSet {
47+ // isAdmin
48+ let isAdmin = DataStorage.standard.getUserModel()?.isAdmin ?? false
49+ startDate = reservation?.startTime.addHours(-1)
50+
51+ setupStackView(isAdmin)
52+ setUpBookingPeriod()
53+ }
54+ }
55+
56+ // MARK: - bind
57+
3058 func bind(withModel model: Reservation) {
59+ reservation = model
3160 let date = format(model.startTime, model.endTime)
3261
3362 totalLabel.text = "Забронирован \(model.reservedTable) столик на \(model.numberOfGuests)-х\n \(date)"
@@ -53,4 +82,96 @@ class ThirdStepView: UIView {
5382 let num = people > 6 ? 2 : 1
5483 return num
5584 }
85+
86+ var startPoint: UIView = {
87+ var view = UIView()
88+ view.backgroundColor = #colorLiteral(red: 0.2901960784, green: 0.5647058824, blue: 0.8862745098, alpha: 1)
89+ view.translatesAutoresizingMaskIntoConstraints = false
90+ return view
91+ }()
92+
93+ var endPoint: UIView = {
94+ var view = UIView()
95+ view.backgroundColor = #colorLiteral(red: 0.2901960784, green: 0.5647058824, blue: 0.8862745098, alpha: 1)
96+ view.translatesAutoresizingMaskIntoConstraints = false
97+ return view
98+ }()
99+
100+ /// Интервал
101+ var fillInterval: UIView = {
102+ var view = UIView()
103+ view.backgroundColor = #colorLiteral(red: 0, green: 0.5921568627, blue: 1, alpha: 0.3426262843)
104+ view.translatesAutoresizingMaskIntoConstraints = false
105+ return view
106+ }()
107+
108+ func setupStackView(_ isAdmin: Bool) {
109+ guard let startPoint = startDate else { return }
110+
111+ let startingPoint = startPoint.getAdminsStartingPoint()
112+ let endingPoint = startingPoint + (isAdmin ? Constants.adminDuration : Constants.clientDuration)
113+
114+ for period in startingPoint...endingPoint {
115+ let timePointView = TimePointView.loadFromNib()
116+ timePointView?.setUp(withTimePoint: period)
117+ let view = UIView(frame: CGRect(x: 0, y: 0, width: 35, height: 106))
118+ view.addSubviewThatFills(timePointView)
119+ stackView.addArrangedSubview(view)
120+ }
121+ }
122+
123+ func setUpBookingPeriod() {
124+ self.scrollView.addSubview(startPoint)
125+ self.scrollView.addSubview(endPoint)
126+ self.scrollView.addSubview(fillInterval)
127+
128+ guard
129+ let startDate = startDate,
130+ let startTime = reservation?.startTime,
131+ let endTime = reservation?.endTime else { return }
132+
133+ let startConstr = CGFloat(startTime.getMinutesPeriods(fromStart: startDate) * Constants.widthTimePoint) + 3
134+ startLeadingConstraint = startPoint.leftAnchor.constraint(equalTo: scrollView.leftAnchor,
135+ constant: startConstr)
136+
137+ let endConstr = CGFloat(endTime.getMinutesPeriods(fromStart: startDate) * Constants.widthTimePoint) + 3
138+ endLeadingConstraint = endPoint.leftAnchor.constraint(equalTo: scrollView.leftAnchor,
139+ constant: endConstr)
140+
141+ scrollView.setContentOffset(CGPoint(x: startConstr - 50, y: 0), animated: true)
142+
143+ NSLayoutConstraint.activate([
144+
145+ startPoint.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: 0),
146+ endPoint.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: 0),
147+
148+ startPoint.widthAnchor.constraint(equalToConstant: Constants.pointWidth),
149+ endPoint.widthAnchor.constraint(equalToConstant: Constants.pointWidth),
150+
151+ startPoint.heightAnchor.constraint(equalToConstant: Constants.pointHeight),
152+ endPoint.heightAnchor.constraint(equalToConstant: Constants.pointHeight),
153+
154+ startLeadingConstraint,
155+ endLeadingConstraint,
156+
157+ fillInterval.leftAnchor.constraint(equalTo: startPoint.rightAnchor, constant: 0),
158+ fillInterval.rightAnchor.constraint(equalTo: endPoint.leftAnchor, constant: 0),
159+
160+ fillInterval.heightAnchor.constraint(equalToConstant: Constants.pointHeight),
161+ fillInterval.bottomAnchor.constraint(equalTo: scrollView.bottomAnchor, constant: 0)
162+ ])
163+ }
164+}
165+
166+extension ThirdStepView {
167+ enum Constants {
168+ static let widthTimePoint = 11
169+ static let pointWidth: CGFloat = 5
170+ static let pointHeight: CGFloat = 85
171+
172+ static let adminDuration = 288
173+ static let clientDuration = 90
174+ // 12:00 = 12 * 6
175+ static let clientStartingPoint = 72
176+ }
56177}
Hookah Tau/Controllers/Client/Reservations/Steps/3/ThirdStepView.xib+59−1
@@ -51,9 +51,65 @@
5151 </stackView>
5252 <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="ByV-f1-mVO">
5353 <rect key="frame" x="0.0" y="207.5" width="414" height="106"/>
54− <color key="backgroundColor" systemColor="systemBlueColor" red="0.0" green="0.47843137254901963" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
54+ <subviews>
55+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="JpA-EH-PLI">
56+ <rect key="frame" x="0.0" y="21" width="414" height="85"/>
57+ <subviews>
58+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="TgV-cB-bMd">
59+ <rect key="frame" x="0.0" y="0.0" width="414" height="1"/>
60+ <color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
61+ <constraints>
62+ <constraint firstAttribute="height" constant="1" id="kOS-eB-bWd"/>
63+ </constraints>
64+ </view>
65+ <view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="nzW-L7-eY8">
66+ <rect key="frame" x="0.0" y="84" width="414" height="1"/>
67+ <color key="backgroundColor" white="0.66666666666666663" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
68+ <constraints>
69+ <constraint firstAttribute="height" constant="1" id="BNR-Cz-HJe"/>
70+ </constraints>
71+ </view>
72+ </subviews>
73+ <color key="backgroundColor" red="0.8901960784313725" green="0.8901960784313725" blue="0.8901960784313725" alpha="1" colorSpace="calibratedRGB"/>
74+ <constraints>
75+ <constraint firstItem="TgV-cB-bMd" firstAttribute="leading" secondItem="JpA-EH-PLI" secondAttribute="leading" id="3ZT-oY-Rzz"/>
76+ <constraint firstAttribute="height" constant="85" id="7jH-zS-CoD"/>
77+ <constraint firstAttribute="trailing" secondItem="nzW-L7-eY8" secondAttribute="trailing" id="HSn-Vn-8Kb"/>
78+ <constraint firstItem="TgV-cB-bMd" firstAttribute="top" secondItem="JpA-EH-PLI" secondAttribute="top" id="K34-18-ZM8"/>
79+ <constraint firstAttribute="bottom" secondItem="nzW-L7-eY8" secondAttribute="bottom" id="hKT-AB-KQS"/>
80+ <constraint firstItem="nzW-L7-eY8" firstAttribute="leading" secondItem="JpA-EH-PLI" secondAttribute="leading" id="lqp-3j-OoO"/>
81+ <constraint firstAttribute="trailing" secondItem="TgV-cB-bMd" secondAttribute="trailing" id="r1u-XE-GXS"/>
82+ </constraints>
83+ </view>
84+ <scrollView clipsSubviews="YES" multipleTouchEnabled="YES" userInteractionEnabled="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="gQW-4g-8T5">
85+ <rect key="frame" x="0.0" y="0.0" width="414" height="106"/>
86+ <subviews>
87+ <stackView opaque="NO" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="Gfj-mL-wQq">
88+ <rect key="frame" x="0.0" y="0.0" width="414" height="106"/>
89+ </stackView>
90+ </subviews>
91+ <constraints>
92+ <constraint firstItem="Gfj-mL-wQq" firstAttribute="width" secondItem="gQW-4g-8T5" secondAttribute="width" priority="250" id="DhE-CT-MGo"/>
93+ <constraint firstItem="Gfj-mL-wQq" firstAttribute="height" secondItem="gQW-4g-8T5" secondAttribute="height" id="JdJ-xb-2kM"/>
94+ <constraint firstAttribute="bottom" secondItem="Gfj-mL-wQq" secondAttribute="bottom" id="Pji-4z-R86"/>
95+ <constraint firstItem="Gfj-mL-wQq" firstAttribute="top" secondItem="gQW-4g-8T5" secondAttribute="top" id="UBW-vr-VEu"/>
96+ <constraint firstAttribute="trailing" secondItem="Gfj-mL-wQq" secondAttribute="trailing" id="gkv-lF-jaW"/>
97+ <constraint firstItem="Gfj-mL-wQq" firstAttribute="leading" secondItem="gQW-4g-8T5" secondAttribute="leading" id="yZy-o3-tDY"/>
98+ </constraints>
99+ <viewLayoutGuide key="contentLayoutGuide" id="jEg-I8-hwu"/>
100+ <viewLayoutGuide key="frameLayoutGuide" id="EFO-bp-t4s"/>
101+ </scrollView>
102+ </subviews>
103+ <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
55104 <constraints>
105+ <constraint firstItem="JpA-EH-PLI" firstAttribute="leading" secondItem="ByV-f1-mVO" secondAttribute="leading" id="0Yf-vL-RSK"/>
106+ <constraint firstAttribute="trailing" secondItem="JpA-EH-PLI" secondAttribute="trailing" id="N9T-dc-Auk"/>
107+ <constraint firstAttribute="bottom" secondItem="JpA-EH-PLI" secondAttribute="bottom" id="QPT-JY-erJ"/>
108+ <constraint firstItem="gQW-4g-8T5" firstAttribute="top" secondItem="ByV-f1-mVO" secondAttribute="top" id="Qz6-Bm-fcB"/>
56109 <constraint firstAttribute="height" constant="106" id="UWZ-LN-h4r"/>
110+ <constraint firstItem="gQW-4g-8T5" firstAttribute="leading" secondItem="ByV-f1-mVO" secondAttribute="leading" id="gZ2-dm-HGX"/>
111+ <constraint firstAttribute="bottom" secondItem="gQW-4g-8T5" secondAttribute="bottom" id="idD-XC-tGe"/>
112+ <constraint firstAttribute="trailing" secondItem="gQW-4g-8T5" secondAttribute="trailing" id="mWv-Uy-FiK"/>
57113 </constraints>
58114 </view>
59115 </subviews>
@@ -74,6 +130,8 @@
74130 <connections>
75131 <outlet property="closeButton" destination="QjM-My-aZ0" id="Z3P-aG-bf1"/>
76132 <outlet property="infoLabel" destination="7xJ-nJ-IFN" id="jlH-CO-a0K"/>
133+ <outlet property="scrollView" destination="gQW-4g-8T5" id="lLC-JE-ZUm"/>
134+ <outlet property="stackView" destination="Gfj-mL-wQq" id="k5A-hd-BiB"/>
77135 <outlet property="timeInterval" destination="ByV-f1-mVO" id="oB4-jH-8Ot"/>
78136 <outlet property="totalLabel" destination="xHF-9h-q9F" id="W94-2J-w0A"/>
79137 </connections>
Hookah Tau/Extensions+Date.swift+4−1
@@ -162,7 +162,10 @@ extension Date {
162162 }
163163
164164 func getAdminsStartingPoint() -> Int {
165− let comp = Calendar.current.dateComponents([.hour, .minute], from: self)
165+ var calendar = Calendar.current
166+ calendar.timeZone = TimeZone(abbreviation: "UTC")!
167+
168+ let comp = calendar.dateComponents([.hour, .minute], from: self)
166169 return (comp.hour! * 6 + comp.minute! / 10)
167170 }
168171