@@ -8,7 +8,7 @@
9import UIKit
9import UIKit
11−class ProfileTableViewController: BaseTableViewController {
11+class ProfileTableViewController: BaseViewController {
13 // MARK: - IBAOutlets
13 // MARK: - IBAOutlets
@@ -30,24 +30,41 @@ class ProfileTableViewController: BaseTableViewController {
34+ @IBOutlet weak var contentView: UIView!
33 // MARK: - properties
36 // MARK: - properties
38+ var tableView: UITableView?
35 var clientsService: ClientsService?
40 var clientsService: ClientsService?
37 var reservationsService: ReservationsService?
42 var reservationsService: ReservationsService?
39− var user: FullUser? {
44+ var user: FullUser?
41− guard let u = user else { return }
42− navigationItem.title = u.name
46 weak var coodinator: ClientProfileCoordinator?
46 weak var coodinator: ClientProfileCoordinator?
48+ var noReserationsYetView: AdminNoReservationsView?
50+ var activityIndicator: UIActivityIndicatorView?
52+ var refreshControl: UIRefreshControl?
48 var dataSource: [Reservation] = [] {
54 var dataSource: [Reservation] = [] {
56+ guard let empty = noReserationsYetView else { return }
57+ if dataSource.isEmpty {
50− tableView.reloadData()
59+ tableView?.alpha = 0
65+ refreshControl?.endRefreshing()
66+ activityIndicator?.stopAnimating()
67+ tableView?.reloadData()
@@ -56,10 +73,12 @@ class ProfileTableViewController: BaseTableViewController {
56 override func viewDidLoad() {
73 override func viewDidLoad() {
57 super.viewDidLoad()
74 super.viewDidLoad()
59− tableView?.register(ReservationCell.self, forCellReuseIdentifier: reservationCell)
61 clientsService = ClientsService(apiClient: APIClient.shared)
76 clientsService = ClientsService(apiClient: APIClient.shared)
62 reservationsService = ReservationsService(apiClient: APIClient.shared)
77 reservationsService = ReservationsService(apiClient: APIClient.shared)
81+ setupActivityIndicator()
63 loadReservations()
82 loadReservations()
@@ -68,13 +87,55 @@ class ProfileTableViewController: BaseTableViewController {
68 tabBarController?.tabBar.isHidden = true
87 tabBarController?.tabBar.isHidden = true
93+ guard let u = user else { return }
94+ navigationItem.title = u.name
95+ navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(book))
99+ tableView = UITableView()
102+ refreshControl = UIRefreshControl()
103+ refreshControl?.addTarget(self, action: #selector(refresh), for: .valueChanged)
104+ tableView?.refreshControl = refreshControl
106+ tableView?.dataSource = self
107+ tableView?.delegate = self
109+ noReserationsYetView = AdminNoReservationsView.loadFromNib()
110+ noReserationsYetView?.setup(withTitle: "У этого пользователя пока нет ни одной брони :(")
111+ noReserationsYetView?.bookButton?.addTarget(self, action: #selector(book), for: .touchUpInside)
112+ contentView.addSubviewThatFills(noReserationsYetView)
113+ noReserationsYetView?.alpha = 0
115+ tableView?.register(ReservationCell.self, forCellReuseIdentifier: reservationCell)
117+ contentView.addSubviewThatFills(tableView)
119+ tableView?.alpha = 0
122+ func setupActivityIndicator() {
124+ activityIndicator = UIActivityIndicatorView()
125+ view.addSubviewThatFills(activityIndicator)
126+ activityIndicator?.startAnimating()
130+ // MARK: - Api calls
71 func loadReservations() {
132 func loadReservations() {
72 guard let uuid = user?.uuid else { return }
133 guard let uuid = user?.uuid else { return }
73 clientsService?.loadReservationsForUser(withUUID: uuid,
134 clientsService?.loadReservationsForUser(withUUID: uuid,
74 completion: { [weak self] (res) in
135 completion: { [weak self] (res) in
75 switch res {
136 switch res {
76 case .failure(let err):
137 case .failure(let err):
77− print(err)
138+ self?.displayAlert(forError: err)
78 case .success(let data):
139 case .success(let data):
79 self?.dataSource = data
140 self?.dataSource = data
@@ -115,18 +176,25 @@ class ProfileTableViewController: BaseTableViewController {
116 self.displayAlert(with: "Номер скопирован!")
177 self.displayAlert(with: "Номер скопирован!")
180+ @objc func refresh() {
121// MARK: - Table view data source
189// MARK: - Table view data source
123−extension ProfileTableViewController {
191+extension ProfileTableViewController: UITableViewDelegate, UITableViewDataSource {
125− override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
193+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
126 return dataSource.count
194 return dataSource.count
129− override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
197+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
130 let cell = tableView.dequeueReusableCell(withIdentifier: reservationCell, for: indexPath) as! ReservationCell
198 let cell = tableView.dequeueReusableCell(withIdentifier: reservationCell, for: indexPath) as! ReservationCell
132 cell.bind(withModel: dataSource[indexPath.row])
200 cell.bind(withModel: dataSource[indexPath.row])
@@ -136,7 +204,7 @@ extension ProfileTableViewController {
139− override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
207+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
140 guard let u = user else { return }
208 guard let u = user else { return }
141 let r = dataSource[indexPath.row]
209 let r = dataSource[indexPath.row]
142 let reservation = ReservationWithUser(reservation: r, user: u)
210 let reservation = ReservationWithUser(reservation: r, user: u)
@@ -145,11 +213,11 @@ extension ProfileTableViewController {
146 // Update
214 // Update
148− override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
216+ func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
149 return true
217 return true
152− override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
220+ func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
154 let uuid = dataSource[indexPath.row].uuid
222 let uuid = dataSource[indexPath.row].uuid
155 let cancelButton = UITableViewRowAction(style: .normal, title: "❌") { _,_ in
223 let cancelButton = UITableViewRowAction(style: .normal, title: "❌") { _,_ in