git.iko.soy/dashared/hookah-tau
on develop help sign in
Небольшой редизайн и теперь можно добавлять в чс из админки
commit722025457f2737c047b4d373487af9c5a8ef358e authorDarya Rednikina <rednikina.com@yandex.ru> dateThu 9 Jan 2020, 15:39 (7 years ago) parentbe45a28
11 files changed+173−17
Hookah Tau.xcodeproj/project.pbxproj+4 Hookah Tau/API/ClientsService/ClientsService.swift+17 Hookah Tau/API/ClientsService/Resolvers/BlocklistPutResolver.swift+33 Hookah Tau/Controllers/Admin/Clients/Cells/ClientTableViewCell.swift+8−2 Hookah Tau/Controllers/Admin/Clients/ClientList.storyboard+46−13 Hookah Tau/Controllers/Admin/Clients/ClientsViewController.swift+36 Hookah Tau/Models/User.swift+2−2 Hookah Tau/Supporting Files/Assets.xcassets/admin.imageset/Contents.json+12 Hookah Tau/Supporting Files/Assets.xcassets/admin.imageset/admin.pdf Hookah Tau/Supporting Files/Assets.xcassets/blacklist.imageset/Contents.json+15 Hookah Tau/Supporting Files/Assets.xcassets/blacklist.imageset/blacklist.pdf
Hookah Tau.xcodeproj/project.pbxproj+4
@@ -97,6 +97,7 @@
9797 12D8FA31237F08C700305F57 /* AllReservations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D8FA30237F08C700305F57 /* AllReservations.swift */; };
9898 12D928AF23C47DCF0051724D /* ADeleteReservationResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D928AE23C47DCF0051724D /* ADeleteReservationResolver.swift */; };
9999 12D928B123C486380051724D /* BaseTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D928B023C486380051724D /* BaseTableViewController.swift */; };
100+ 12D928B323C7464B0051724D /* BlocklistPutResolver.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12D928B223C7464B0051724D /* BlocklistPutResolver.swift */; };
100101 12DBEEB223539F2100AF1BB6 /* Client.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 12DBEEB123539F2100AF1BB6 /* Client.storyboard */; };
101102 12E35071239FA8CA004BB188 /* Extensions+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E35070239FA8CA004BB188 /* Extensions+String.swift */; };
102103 12E35074239FAF52004BB188 /* ClientsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 12E35073239FAF52004BB188 /* ClientsService.swift */; };
@@ -253,6 +254,7 @@
253254 12D8FA30237F08C700305F57 /* AllReservations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllReservations.swift; sourceTree = "<group>"; };
254255 12D928AE23C47DCF0051724D /* ADeleteReservationResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ADeleteReservationResolver.swift; sourceTree = "<group>"; };
255256 12D928B023C486380051724D /* BaseTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTableViewController.swift; sourceTree = "<group>"; };
257+ 12D928B223C7464B0051724D /* BlocklistPutResolver.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BlocklistPutResolver.swift; sourceTree = "<group>"; };
256258 12DBEEB123539F2100AF1BB6 /* Client.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Client.storyboard; sourceTree = "<group>"; };
257259 12E35070239FA8CA004BB188 /* Extensions+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Extensions+String.swift"; sourceTree = "<group>"; };
258260 12E35073239FAF52004BB188 /* ClientsService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientsService.swift; sourceTree = "<group>"; };
@@ -711,6 +713,7 @@
711713 children = (
712714 12E35077239FAFA4004BB188 /* ClientsListResolver.swift */,
713715 12E3507C239FD1F3004BB188 /* ClientReservationsResolver.swift */,
716+ 12D928B223C7464B0051724D /* BlocklistPutResolver.swift */,
714717 );
715718 path = Resolvers;
716719 sourceTree = "<group>";
@@ -1154,6 +1157,7 @@
11541157 F3895F4A233D323700FA6A37 /* CodeCoordinator.swift in Sources */,
11551158 12B3A7B923ACCD83009E2FA6 /* AddOtherAdminResolver.swift in Sources */,
11561159 12E3507F239FDFC2004BB188 /* ClientProfileCoordinator.swift in Sources */,
1160+ 12D928B323C7464B0051724D /* BlocklistPutResolver.swift in Sources */,
11571161 12838EB4236779C700CEF108 /* ApiResolver.swift in Sources */,
11581162 12838EA9236764A600CEF108 /* APIClient.swift in Sources */,
11591163 123615D12355141600D1122A /* ProfileView.swift in Sources */,
Hookah Tau/API/ClientsService/ClientsService.swift+17
@@ -63,4 +63,21 @@ class ClientsService {
6363 }
6464
6565 }
66+
67+ /// Метод для удаления или добавления пользователя в чс
68+ func changeBlockList(whatToDo: CrudMethod, phone: String, completion: @escaping ((Bool) -> Void)) {
69+ let resolver = BlocklistPutResolver(blockList: [phone])
70+ let request = ApiRequest(resolver: resolver, httpMethod: whatToDo)
71+
72+ apiClient.load(request: request.request) { (res) in
73+ switch res {
74+ case .failure:
75+ completion(false)
76+ return
77+ case .success:
78+ completion(true)
79+ return
80+ }
81+ }
82+ }
6683}
Hookah Tau/API/ClientsService/Resolvers/BlocklistPutResolver.swiftnew file+33
@@ -0,0 +1,33 @@
1+//
2+// BlocklistPutResolver.swift
3+// Hookah Tau
4+//
5+// Created by cstore on 09/01/2020.
6+// Copyright © 2020 Daria Rednikina. All rights reserved.
7+//
8+
9+import Foundation
10+
11+struct RequestBlocklist: MyCodable {
12+ var blockList: [String]
13+}
14+
15+class BlocklistPutResolver: ApiResolver {
16+ var name: String {
17+ return "/blocklist"
18+ }
19+
20+ var groupName: String? {
21+ return "/admin"
22+ }
23+
24+ var blockList: [String]
25+
26+ init(blockList: [String]) {
27+ self.blockList = blockList
28+ }
29+
30+ func parameters() -> MyCodable? {
31+ return RequestBlocklist(blockList: blockList)
32+ }
33+}
Hookah Tau/Controllers/Admin/Clients/Cells/ClientTableViewCell.swift+8−2
@@ -20,6 +20,11 @@ class ClientTableViewCell: UITableViewCell {
2020
2121 @IBOutlet weak var numberOfReservationsLabel: UILabel!
2222
23+ @IBOutlet weak var blockListImage: UIImageView!
24+
25+ @IBOutlet weak var isAdminImage: UIImageView!
26+
27+
2328 // MARK: - Lifecycle
2429
2530 override func awakeFromNib() {
@@ -36,8 +41,9 @@ class ClientTableViewCell: UITableViewCell {
3641 // MARK: - Bind
3742
3843 func bind(withModel model: Client) {
39− let name = model.name ?? "❔"
40− nameLabel.text = model.isAdmin ? "👑 " + name : name
44+ blockListImage.isHidden = !model.isBlocked
45+ isAdminImage.isHidden = !model.isAdmin
46+ nameLabel.text = model.name ?? "❔"
4147 phoneNumberLabel.text = model.phoneNumber.formattedNumber()
4248 numberOfReservationsLabel.text = "\(model.reservationCount)"
4349 }
Hookah Tau/Controllers/Admin/Clients/ClientList.storyboard+46−13
@@ -31,12 +31,17 @@
3131 <stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="equalSpacing" alignment="top" translatesAutoresizingMaskIntoConstraints="NO" id="vNV-bN-3No">
3232 <rect key="frame" x="0.0" y="0.0" width="179" height="53"/>
3333 <subviews>
34− <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Стасик" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4Cp-jh-0Gq">
34+ <stackView opaque="NO" contentMode="scaleToFill" distribution="equalSpacing" alignment="center" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="uoO-w2-5yG">
3535 <rect key="frame" x="0.0" y="0.0" width="78.5" height="26.5"/>
36− <fontDescription key="fontDescription" type="boldSystem" pointSize="22"/>
37− <color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
38− <nil key="highlightedColor"/>
39− </label>
36+ <subviews>
37+ <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Стасик" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="4Cp-jh-0Gq">
38+ <rect key="frame" x="0.0" y="0.0" width="78.5" height="26.5"/>
39+ <fontDescription key="fontDescription" type="boldSystem" pointSize="22"/>
40+ <color key="textColor" white="0.0" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
41+ <nil key="highlightedColor"/>
42+ </label>
43+ </subviews>
44+ </stackView>
4045 <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="+7 (901) 733-01-79" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="0gY-h5-AV2">
4146 <rect key="frame" x="0.0" y="29" width="179" height="24"/>
4247 <fontDescription key="fontDescription" type="system" pointSize="20"/>
@@ -46,16 +51,40 @@
4651 </subviews>
4752 </stackView>
4853 <stackView opaque="NO" contentMode="scaleToFill" alignment="center" spacingType="standard" translatesAutoresizingMaskIntoConstraints="NO" id="tJg-ju-bFY">
49− <rect key="frame" x="310.5" y="0.0" width="32.5" height="53"/>
54+ <rect key="frame" x="215.5" y="0.0" width="127.5" height="53"/>
5055 <subviews>
51− <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="3" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Gzo-kW-60Z">
52− <rect key="frame" x="0.0" y="14.5" width="12.5" height="24"/>
53− <fontDescription key="fontDescription" type="system" pointSize="20"/>
54− <nil key="textColor"/>
55− <nil key="highlightedColor"/>
56− </label>
56+ <stackView opaque="NO" contentMode="scaleToFill" spacing="40" translatesAutoresizingMaskIntoConstraints="NO" id="4et-BC-7iY">
57+ <rect key="frame" x="0.0" y="14" width="107.5" height="25"/>
58+ <subviews>
59+ <stackView opaque="NO" contentMode="scaleToFill" spacing="5" translatesAutoresizingMaskIntoConstraints="NO" id="BHD-cD-L1c">
60+ <rect key="frame" x="0.0" y="0.0" width="55" height="25"/>
61+ <subviews>
62+ <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="blacklist" translatesAutoresizingMaskIntoConstraints="NO" id="yw1-jl-Iil">
63+ <rect key="frame" x="0.0" y="0.0" width="25" height="25"/>
64+ <constraints>
65+ <constraint firstAttribute="width" constant="25" id="k7r-sC-Yro"/>
66+ <constraint firstAttribute="height" constant="25" id="kjF-aV-kTo"/>
67+ </constraints>
68+ </imageView>
69+ <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="admin" translatesAutoresizingMaskIntoConstraints="NO" id="Tlq-hK-YHS">
70+ <rect key="frame" x="30" y="0.0" width="25" height="25"/>
71+ <constraints>
72+ <constraint firstAttribute="width" constant="25" id="NSy-Ih-fCV"/>
73+ <constraint firstAttribute="height" constant="25" id="nOu-SF-8Yd"/>
74+ </constraints>
75+ </imageView>
76+ </subviews>
77+ </stackView>
78+ <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="3" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="Gzo-kW-60Z">
79+ <rect key="frame" x="95" y="0.0" width="12.5" height="25"/>
80+ <fontDescription key="fontDescription" type="system" pointSize="20"/>
81+ <nil key="textColor"/>
82+ <nil key="highlightedColor"/>
83+ </label>
84+ </subviews>
85+ </stackView>
5786 <imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="arrow" translatesAutoresizingMaskIntoConstraints="NO" id="DrQ-Ss-gIT">
58− <rect key="frame" x="20.5" y="16.5" width="12" height="20"/>
87+ <rect key="frame" x="115.5" y="16.5" width="12" height="20"/>
5988 </imageView>
6089 </subviews>
6190 </stackView>
@@ -70,6 +99,8 @@
7099 </constraints>
71100 </tableViewCellContentView>
72101 <connections>
102+ <outlet property="blockListImage" destination="yw1-jl-Iil" id="p09-KQ-ayQ"/>
103+ <outlet property="isAdminImage" destination="Tlq-hK-YHS" id="KZP-yS-8YQ"/>
73104 <outlet property="nameLabel" destination="4Cp-jh-0Gq" id="g6e-c0-x0u"/>
74105 <outlet property="numberOfReservationsLabel" destination="Gzo-kW-60Z" id="9J2-S4-fKq"/>
75106 <outlet property="phoneNumberLabel" destination="0gY-h5-AV2" id="rdb-GS-ceF"/>
@@ -159,6 +190,8 @@
159190 </scene>
160191 </scenes>
161192 <resources>
193+ <image name="admin" width="26" height="25"/>
162194 <image name="arrow" width="12" height="20"/>
195+ <image name="blacklist" width="25" height="25"/>
163196 </resources>
164197</document>
Hookah Tau/Controllers/Admin/Clients/ClientsViewController.swift+36
@@ -91,6 +91,23 @@ class ClientsViewController: BaseTableViewController {
9191 let documentsDirectory = paths[0]
9292 return documentsDirectory as NSString
9393 }
94+
95+ // MARK: - Change blocklist status
96+
97+ func updateUserBlockStatus(wasBlocked: Bool, phone: String, indexPath: IndexPath) {
98+ let crudMethod = wasBlocked ? CrudMethod.delete : CrudMethod.put
99+ clientsService?.changeBlockList(whatToDo: crudMethod, phone: phone, completion: { (res) in
100+ if res {
101+ self.tableView?.beginUpdates()
102+ self.tableView?.reloadRows(at: [indexPath], with: .automatic)
103+ self.dataSource[indexPath.row].isBlocked = !wasBlocked
104+ self.tableView?.endUpdates()
105+ } else {
106+ self.displayAlert(with: "Не удалось \(wasBlocked ? "удалить" : "добавить") пользователя \(wasBlocked ? "из" : "в") чс! Попробуйте еще раз!")
107+ return
108+ }
109+ })
110+ }
94111}
95112
96113// MARK: - Tableview
@@ -114,4 +131,23 @@ extension ClientsViewController {
114131 let user = dataSource[indexPath.row]
115132 coordinator?.openUserProfile(user)
116133 }
134+
135+ // Update
136+
137+ override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
138+ return true
139+ }
140+
141+ override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
142+
143+ let user = dataSource[indexPath.row]
144+ let blockButton = UITableViewRowAction(style: .normal, title: "\(!user.isBlocked ? "🙅🏻‍♀️" : "👍🏻")") { _,_ in
145+
146+ self.updateUserBlockStatus(wasBlocked: user.isBlocked, phone: user.phoneNumber, indexPath: indexPath)
147+ }
148+
149+ blockButton.backgroundColor = .black
150+
151+ return [blockButton]
152+ }
117153}
Hookah Tau/Models/User.swift+2−2
@@ -33,10 +33,10 @@ struct Client: MyCodable {
3333 var isBlocked: Bool
3434
3535 static var csvHeading: String {
36− return "uuid, name, phone, isAdmin, reservationCount, isBlocked\n"
36+ return "uuid, имя, телефон, админ, количество активных бронирований, в черном списке\n"
3737 }
3838
3939 var toString: String {
40− return "\(uuid), \(name ?? "❔"), \(phoneNumber), \(isAdmin), \(reservationCount), \(isBlocked)"
40+ return "\(uuid), \(name ?? "❔"), +79\(phoneNumber), \(isAdmin), \(reservationCount), \(isBlocked)"
4141 }
4242}
Hookah Tau/Supporting Files/Assets.xcassets/admin.imageset/Contents.jsonnew file+12
@@ -0,0 +1,12 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "admin.pdf"
6+ }
7+ ],
8+ "info" : {
9+ "version" : 1,
10+ "author" : "xcode"
11+ }
12+}
Hookah Tau/Supporting Files/Assets.xcassets/admin.imageset/admin.pdfnew file

Binary file not shown.

Hookah Tau/Supporting Files/Assets.xcassets/blacklist.imageset/Contents.jsonnew file+15
@@ -0,0 +1,15 @@
1+{
2+ "images" : [
3+ {
4+ "idiom" : "universal",
5+ "filename" : "blacklist.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/blacklist.imageset/blacklist.pdfnew file

Binary file not shown.