From 7983a6cf5967610699e44afd4590ceaf7fcc04ec Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 12 Dec 2018 15:31:42 -0500 Subject: [PATCH 1/4] Got the search working --- Restaurant Royale.xcodeproj/project.pbxproj | 8 ++ RestaurantRoyale/Base.lproj/Main.storyboard | 105 +++++++++++++++---- RestaurantRoyale/RewardsViewController.swift | 80 ++++++++++++-- RestaurantRoyale/TableViewCell.swift | 24 +++++ RestaurantRoyale/infoViewController.swift | 40 +++++++ 5 files changed, 228 insertions(+), 29 deletions(-) create mode 100644 RestaurantRoyale/TableViewCell.swift create mode 100644 RestaurantRoyale/infoViewController.swift diff --git a/Restaurant Royale.xcodeproj/project.pbxproj b/Restaurant Royale.xcodeproj/project.pbxproj index 599961c..2e74726 100644 --- a/Restaurant Royale.xcodeproj/project.pbxproj +++ b/Restaurant Royale.xcodeproj/project.pbxproj @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ 0131FCF721B08F3A0087BAA6 /* TabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0131FCF621B08F3A0087BAA6 /* TabViewController.swift */; }; 0131FCF921B0933F0087BAA6 /* RewardsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0131FCF821B0933F0087BAA6 /* RewardsViewController.swift */; }; + 01A7E02121C1836700C5D5DC /* TableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A7E02021C1836700C5D5DC /* TableViewCell.swift */; }; + 01A7E02321C184D900C5D5DC /* infoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A7E02221C184D900C5D5DC /* infoViewController.swift */; }; 30362D0621B319FC00AB07E8 /* gif.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30362D0521B319FC00AB07E8 /* gif.swift */; }; CB00DE048DF123642887EB65 /* Pods_Restaurant_Royale.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E00D4DEFE6DFD07D30EAC895 /* Pods_Restaurant_Royale.framework */; }; D90CB6531A739B7A00228A1F /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = D90CB6521A739B7A00228A1F /* AppDelegate.swift */; }; @@ -37,6 +39,8 @@ /* Begin PBXFileReference section */ 0131FCF621B08F3A0087BAA6 /* TabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewController.swift; sourceTree = ""; }; 0131FCF821B0933F0087BAA6 /* RewardsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RewardsViewController.swift; sourceTree = ""; }; + 01A7E02021C1836700C5D5DC /* TableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewCell.swift; sourceTree = ""; }; + 01A7E02221C184D900C5D5DC /* infoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = infoViewController.swift; sourceTree = ""; }; 2C7E16726DE474D67283AED2 /* Pods-Restaurant Royale.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Restaurant Royale.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Restaurant Royale/Pods-Restaurant Royale.debug.xcconfig"; sourceTree = ""; }; 30362D0521B319FC00AB07E8 /* gif.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = gif.swift; sourceTree = ""; }; 308B7289218FDB950027F45B /* TollyToLocal.gpx */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = TollyToLocal.gpx; sourceTree = ""; }; @@ -129,7 +133,9 @@ E978543521C053D5003313D1 /* slots.gif */, E978543321C053CA003313D1 /* rouletteWheel.gif */, D90CB6561A739B7A00228A1F /* Main.storyboard */, + 01A7E02021C1836700C5D5DC /* TableViewCell.swift */, 0131FCF821B0933F0087BAA6 /* RewardsViewController.swift */, + 01A7E02221C184D900C5D5DC /* infoViewController.swift */, E9FD90A221C07E0900864EA7 /* RestaurantManager.swift */, 0131FCF621B08F3A0087BAA6 /* TabViewController.swift */, D90CB6591A739B7A00228A1F /* Images.xcassets */, @@ -313,12 +319,14 @@ E9CC65E1219CDE5D00B3EDE1 /* SignUpViewController.swift in Sources */, 30362D0621B319FC00AB07E8 /* gif.swift in Sources */, D90CB6531A739B7A00228A1F /* AppDelegate.swift in Sources */, + 01A7E02121C1836700C5D5DC /* TableViewCell.swift in Sources */, E9CC65E3219CDE6700B3EDE1 /* LoginViewController.swift in Sources */, E9CC65DF219CD82500B3EDE1 /* InitialViewController.swift in Sources */, E9FD90A321C07E0900864EA7 /* RestaurantManager.swift in Sources */, D9835AF31AA6076800D265BC /* Utilities.swift in Sources */, 0131FCF721B08F3A0087BAA6 /* TabViewController.swift in Sources */, 0131FCF921B0933F0087BAA6 /* RewardsViewController.swift in Sources */, + 01A7E02321C184D900C5D5DC /* infoViewController.swift in Sources */, E9CC65E5219CE1E500B3EDE1 /* ProfileViewController.swift in Sources */, E9F340C221BF86B900779987 /* Constants.swift in Sources */, ); diff --git a/RestaurantRoyale/Base.lproj/Main.storyboard b/RestaurantRoyale/Base.lproj/Main.storyboard index 8b5460d..44bb0fd 100644 --- a/RestaurantRoyale/Base.lproj/Main.storyboard +++ b/RestaurantRoyale/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ - + - + @@ -472,15 +472,15 @@ - + - + @@ -492,29 +492,53 @@ - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + - + - + - + @@ -522,17 +546,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + - + diff --git a/RestaurantRoyale/RewardsViewController.swift b/RestaurantRoyale/RewardsViewController.swift index fe11f4a..d22f15d 100644 --- a/RestaurantRoyale/RewardsViewController.swift +++ b/RestaurantRoyale/RewardsViewController.swift @@ -8,22 +8,80 @@ import UIKit -class RewardsViewController: UIViewController { - +class RewardsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate { + @IBOutlet weak var tableView: UITableView! + @IBOutlet weak var searchBar: UISearchBar! + var manager = RestaurantManager() var restaurantArray = [Restaurant]() override func viewDidLoad() { super.viewDidLoad() - - manager.GetEveryRestaurant(completion: { loaded in - self.restaurantArray = loaded - for restaurant in self.restaurantArray { - print(restaurant.name) - } - // Do Array things here, like updating the tableview - }) + setupSearch() + loadData() + + } + + fileprivate func setupSearch() + { + searchBar.delegate = self + tableView.dataSource = self + tableView.delegate = self + } + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return matches.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell") as! TableViewCell + + let text = matches[indexPath.row].name + + cell.textLabel?.text = text + + return cell + } + + func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let vc = storyboard?.instantiateViewController(withIdentifier: "infoViewController") as! infoViewController + + vc.restaurantName = matches[indexPath.row].name + vc.location = matches[indexPath.row].location + vc.category = matches[indexPath.row].categories[0] + self.navigationController?.pushViewController(vc, animated: true) + } + + func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { + if (searchText == ""){ + matches = restaurantArray } - + else{ + matches = restaurantArray.filter{$0.name.contains(searchText)} + matches = matches.sorted { $0.name < $1.name } + } + tableView.reloadData() + } + + func numberOfSections(in tableView: UITableView) -> Int { + return 1 + } + + fileprivate var matches: [Restaurant] = [] + + func loadData(){ + manager.GetEveryRestaurant(completion: { loaded in + self.restaurantArray = loaded + for restaurant in self.restaurantArray { + print(restaurant.name) + self.matches.append(restaurant) + } + self.tableView.reloadData() + // Do Array things here, like updating the tableview + }) + matches = restaurantArray + matches = matches.sorted { $0.name < $1.name} + } + } diff --git a/RestaurantRoyale/TableViewCell.swift b/RestaurantRoyale/TableViewCell.swift new file mode 100644 index 0000000..051a380 --- /dev/null +++ b/RestaurantRoyale/TableViewCell.swift @@ -0,0 +1,24 @@ +// +// TableViewCell.swift +// Restaurant Royale +// +// Created by Joseph Crocker on 12/12/18. +// Copyright © 2018 Ken Toh. All rights reserved. +// + +import UIKit + +class TableViewCell: UITableViewCell { + + override func awakeFromNib() { + super.awakeFromNib() + // Initialization code + } + + override func setSelected(_ selected: Bool, animated: Bool) { + super.setSelected(selected, animated: animated) + + // Configure the view for the selected state + } + +} diff --git a/RestaurantRoyale/infoViewController.swift b/RestaurantRoyale/infoViewController.swift new file mode 100644 index 0000000..bb09289 --- /dev/null +++ b/RestaurantRoyale/infoViewController.swift @@ -0,0 +1,40 @@ +// +// infoViewController.swift +// Restaurant Royale +// +// Created by Joseph Crocker on 12/12/18. +// Copyright © 2018 Ken Toh. All rights reserved. +// + +import UIKit +import MapKit + +class infoViewController: UIViewController { + @IBOutlet weak var restaurantNameLabel: UITextField! + @IBOutlet weak var categoryLabel: UITextField! + + var restaurantName = "" + var location = CLLocationCoordinate2D() + var category = "" + + + override func viewDidLoad() { + super.viewDidLoad() + + // Do any additional setup after loading the view. + restaurantNameLabel.text = restaurantName + categoryLabel.text = category + } + + + /* + // MARK: - Navigation + + // In a storyboard-based application, you will often want to do a little preparation before navigation + override func prepare(for segue: UIStoryboardSegue, sender: Any?) { + // Get the new view controller using segue.destination. + // Pass the selected object to the new view controller. + } + */ + +} From 85e5182eca43cbc54fbe3d6834881d406a52a967 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 12 Dec 2018 15:46:27 -0500 Subject: [PATCH 2/4] Search function --- RestaurantRoyale/RewardsViewController.swift | 4 ++-- RestaurantRoyale/infoViewController.swift | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/RestaurantRoyale/RewardsViewController.swift b/RestaurantRoyale/RewardsViewController.swift index d22f15d..bd3112e 100644 --- a/RestaurantRoyale/RewardsViewController.swift +++ b/RestaurantRoyale/RewardsViewController.swift @@ -47,8 +47,7 @@ class RewardsViewController: UIViewController, UITableViewDataSource, UITableVie func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let vc = storyboard?.instantiateViewController(withIdentifier: "infoViewController") as! infoViewController - vc.restaurantName = matches[indexPath.row].name - vc.location = matches[indexPath.row].location + vc.restaurant = matches[indexPath.row] vc.category = matches[indexPath.row].categories[0] self.navigationController?.pushViewController(vc, animated: true) } @@ -82,6 +81,7 @@ class RewardsViewController: UIViewController, UITableViewDataSource, UITableVie }) matches = restaurantArray matches = matches.sorted { $0.name < $1.name} + tableView.reloadData() } } diff --git a/RestaurantRoyale/infoViewController.swift b/RestaurantRoyale/infoViewController.swift index bb09289..0eea343 100644 --- a/RestaurantRoyale/infoViewController.swift +++ b/RestaurantRoyale/infoViewController.swift @@ -13,8 +13,7 @@ class infoViewController: UIViewController { @IBOutlet weak var restaurantNameLabel: UITextField! @IBOutlet weak var categoryLabel: UITextField! - var restaurantName = "" - var location = CLLocationCoordinate2D() + var restaurant = Restaurant() var category = "" @@ -22,7 +21,7 @@ class infoViewController: UIViewController { super.viewDidLoad() // Do any additional setup after loading the view. - restaurantNameLabel.text = restaurantName + restaurantNameLabel.text = restaurant.name categoryLabel.text = category } From f3759464d28c7b2a405876e8200700d46ca00677 Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 12 Dec 2018 16:00:12 -0500 Subject: [PATCH 3/4] h --- RestaurantRoyale/Base.lproj/Main.storyboard | 34 ++++++++++++++------ RestaurantRoyale/RestaurantManager.swift | 2 +- RestaurantRoyale/RewardsViewController.swift | 2 ++ RestaurantRoyale/infoViewController.swift | 5 ++- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/RestaurantRoyale/Base.lproj/Main.storyboard b/RestaurantRoyale/Base.lproj/Main.storyboard index 44bb0fd..15202e5 100644 --- a/RestaurantRoyale/Base.lproj/Main.storyboard +++ b/RestaurantRoyale/Base.lproj/Main.storyboard @@ -496,16 +496,13 @@ - + - + - - - @@ -547,29 +544,46 @@ - - + + - + - - + + + + + + + diff --git a/RestaurantRoyale/RestaurantManager.swift b/RestaurantRoyale/RestaurantManager.swift index 71a086b..fc74d2d 100644 --- a/RestaurantRoyale/RestaurantManager.swift +++ b/RestaurantRoyale/RestaurantManager.swift @@ -16,7 +16,7 @@ class RestaurantManager { var restaurantsArray = [Restaurant]() - db.collection("restaurants").getDocuments() { (querySnapshot, err) in + db.collection("restaurants").order(by: "name").getDocuments() { (querySnapshot, err) in if let err = err { print("Error getting documents: \(err)") completion(restaurantsArray) diff --git a/RestaurantRoyale/RewardsViewController.swift b/RestaurantRoyale/RewardsViewController.swift index bd3112e..e656019 100644 --- a/RestaurantRoyale/RewardsViewController.swift +++ b/RestaurantRoyale/RewardsViewController.swift @@ -37,6 +37,8 @@ class RewardsViewController: UIViewController, UITableViewDataSource, UITableVie func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell") as! TableViewCell + matches = matches.sorted {$0.name < $1.name} + let text = matches[indexPath.row].name cell.textLabel?.text = text diff --git a/RestaurantRoyale/infoViewController.swift b/RestaurantRoyale/infoViewController.swift index 0eea343..38b23c7 100644 --- a/RestaurantRoyale/infoViewController.swift +++ b/RestaurantRoyale/infoViewController.swift @@ -25,7 +25,10 @@ class infoViewController: UIViewController { categoryLabel.text = category } - + @IBAction func mapButton(_ sender: Any) { + restaurant.openMapToRestaurant() + } + /* // MARK: - Navigation From d6e729f4d7b124dd478bf6e520c186736cd9ad5d Mon Sep 17 00:00:00 2001 From: Joseph Date: Wed, 12 Dec 2018 16:05:31 -0500 Subject: [PATCH 4/4] G --- Restaurant Royale.xcodeproj/project.pbxproj | 8 ++++---- RestaurantRoyale/Base.lproj/Main.storyboard | 4 ++-- ...rdsViewController.swift => SearchViewController.swift} | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) rename RestaurantRoyale/{RewardsViewController.swift => SearchViewController.swift} (94%) diff --git a/Restaurant Royale.xcodeproj/project.pbxproj b/Restaurant Royale.xcodeproj/project.pbxproj index 2e74726..43ee4dc 100644 --- a/Restaurant Royale.xcodeproj/project.pbxproj +++ b/Restaurant Royale.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 0131FCF721B08F3A0087BAA6 /* TabViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0131FCF621B08F3A0087BAA6 /* TabViewController.swift */; }; - 0131FCF921B0933F0087BAA6 /* RewardsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0131FCF821B0933F0087BAA6 /* RewardsViewController.swift */; }; + 0131FCF921B0933F0087BAA6 /* SearchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0131FCF821B0933F0087BAA6 /* SearchViewController.swift */; }; 01A7E02121C1836700C5D5DC /* TableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A7E02021C1836700C5D5DC /* TableViewCell.swift */; }; 01A7E02321C184D900C5D5DC /* infoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01A7E02221C184D900C5D5DC /* infoViewController.swift */; }; 30362D0621B319FC00AB07E8 /* gif.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30362D0521B319FC00AB07E8 /* gif.swift */; }; @@ -38,7 +38,7 @@ /* Begin PBXFileReference section */ 0131FCF621B08F3A0087BAA6 /* TabViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabViewController.swift; sourceTree = ""; }; - 0131FCF821B0933F0087BAA6 /* RewardsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RewardsViewController.swift; sourceTree = ""; }; + 0131FCF821B0933F0087BAA6 /* SearchViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewController.swift; sourceTree = ""; }; 01A7E02021C1836700C5D5DC /* TableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TableViewCell.swift; sourceTree = ""; }; 01A7E02221C184D900C5D5DC /* infoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = infoViewController.swift; sourceTree = ""; }; 2C7E16726DE474D67283AED2 /* Pods-Restaurant Royale.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Restaurant Royale.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Restaurant Royale/Pods-Restaurant Royale.debug.xcconfig"; sourceTree = ""; }; @@ -134,7 +134,7 @@ E978543321C053CA003313D1 /* rouletteWheel.gif */, D90CB6561A739B7A00228A1F /* Main.storyboard */, 01A7E02021C1836700C5D5DC /* TableViewCell.swift */, - 0131FCF821B0933F0087BAA6 /* RewardsViewController.swift */, + 0131FCF821B0933F0087BAA6 /* SearchViewController.swift */, 01A7E02221C184D900C5D5DC /* infoViewController.swift */, E9FD90A221C07E0900864EA7 /* RestaurantManager.swift */, 0131FCF621B08F3A0087BAA6 /* TabViewController.swift */, @@ -325,7 +325,7 @@ E9FD90A321C07E0900864EA7 /* RestaurantManager.swift in Sources */, D9835AF31AA6076800D265BC /* Utilities.swift in Sources */, 0131FCF721B08F3A0087BAA6 /* TabViewController.swift in Sources */, - 0131FCF921B0933F0087BAA6 /* RewardsViewController.swift in Sources */, + 0131FCF921B0933F0087BAA6 /* SearchViewController.swift in Sources */, 01A7E02321C184D900C5D5DC /* infoViewController.swift in Sources */, E9CC65E5219CE1E500B3EDE1 /* ProfileViewController.swift in Sources */, E9F340C221BF86B900779987 /* Constants.swift in Sources */, diff --git a/RestaurantRoyale/Base.lproj/Main.storyboard b/RestaurantRoyale/Base.lproj/Main.storyboard index 15202e5..3335194 100644 --- a/RestaurantRoyale/Base.lproj/Main.storyboard +++ b/RestaurantRoyale/Base.lproj/Main.storyboard @@ -480,10 +480,10 @@ - + - + diff --git a/RestaurantRoyale/RewardsViewController.swift b/RestaurantRoyale/SearchViewController.swift similarity index 94% rename from RestaurantRoyale/RewardsViewController.swift rename to RestaurantRoyale/SearchViewController.swift index e656019..6ec87cf 100644 --- a/RestaurantRoyale/RewardsViewController.swift +++ b/RestaurantRoyale/SearchViewController.swift @@ -1,5 +1,5 @@ // -// RewardsViewController.swift +// SearchViewController.swift // Restaurant Royale // // Created by Joseph Crocker on 11/29/18. @@ -8,7 +8,7 @@ import UIKit -class RewardsViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate { +class SearchViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate { @IBOutlet weak var tableView: UITableView! @IBOutlet weak var searchBar: UISearchBar!