Skip to content

Commit

Permalink
Added SearchBar, moving to last clean and test
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-headspace committed Nov 26, 2018
1 parent d5cac3d commit df6b53e
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 29 deletions.
16 changes: 8 additions & 8 deletions Musgravite.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = R3KUK9JKD6;
DEVELOPMENT_TEAM = R935X42Z66;
INFOPLIST_FILE = Musgravite/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -968,7 +968,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_IDENTITY = "iPhone Developer";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = R3KUK9JKD6;
DEVELOPMENT_TEAM = R935X42Z66;
INFOPLIST_FILE = Musgravite/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down Expand Up @@ -1029,7 +1029,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = R3KUK9JKD6;
DEVELOPMENT_TEAM = R935X42Z66;
INFOPLIST_FILE = MusgraviteUITests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1049,7 +1049,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = R3KUK9JKD6;
DEVELOPMENT_TEAM = R935X42Z66;
INFOPLIST_FILE = MusgraviteUITests/Info.plist;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1070,7 +1070,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = R3KUK9JKD6;
DEVELOPMENT_TEAM = R935X42Z66;
IBSC_MODULE = WMusgravite_Extension;
INFOPLIST_FILE = WMusgravite/Info.plist;
PRODUCT_BUNDLE_IDENTIFIER = com.aabotech.Musgravite.watchkitapp;
Expand All @@ -1089,7 +1089,7 @@
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = R3KUK9JKD6;
DEVELOPMENT_TEAM = R935X42Z66;
IBSC_MODULE = WMusgravite_Extension;
INFOPLIST_FILE = WMusgravite/Info.plist;
PRODUCT_BUNDLE_IDENTIFIER = com.aabotech.Musgravite.watchkitapp;
Expand All @@ -1108,7 +1108,7 @@
ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication;
CODE_SIGN_ENTITLEMENTS = "WMusgravite Extension/WMusgravite Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = R3KUK9JKD6;
DEVELOPMENT_TEAM = R935X42Z66;
INFOPLIST_FILE = "WMusgravite Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -1131,7 +1131,7 @@
ASSETCATALOG_COMPILER_COMPLICATION_NAME = Complication;
CODE_SIGN_ENTITLEMENTS = "WMusgravite Extension/WMusgravite Extension.entitlements";
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = R3KUK9JKD6;
DEVELOPMENT_TEAM = R935X42Z66;
INFOPLIST_FILE = "WMusgravite Extension/Info.plist";
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
Binary file not shown.
74 changes: 58 additions & 16 deletions Musgravite/Controller/LaboratorySearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,32 @@ extension UITableView {
})

})

self.backgroundView = emptyView
self.separatorStyle = .none
}

func restore() {

self.backgroundView = nil
self.separatorStyle = .singleLine

}

}

class LaboratorySearchViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UITableViewDataSource, UITableViewDelegate {

class LaboratorySearchViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate {
/* Elements on the interface */
@IBOutlet weak var bigImageOutlet: UIImageView!
@IBOutlet weak var bigTitleOutlet: UILabel!
@IBOutlet weak var descriptionOutlet: UITextView!
@IBOutlet weak var floorsCollectionView: UICollectionView!
@IBOutlet weak var labsTableView: UITableView!
@IBOutlet weak var searchBar: UISearchBar!

/* Information for the interface */
var floorData:JSON?
var labByFloorData:[JSON]?
var labData:JSON?
var superFiltered:[JSON]?
var searchFiltered:[JSON]?
var isSearching = false

/* Selected floor variable - To show information in the table view */
var selectedFloor = -1
Expand All @@ -103,6 +102,8 @@ class LaboratorySearchViewController: UIViewController, UICollectionViewDelegate

override func viewDidLoad() {
super.viewDidLoad()
searchBar.delegate = self
searchBar.returnKeyType = UIReturnKeyType.done
retrieveData()
}

Expand All @@ -113,6 +114,11 @@ class LaboratorySearchViewController: UIViewController, UICollectionViewDelegate
labByFloorData = filterLabArray()
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
view.endEditing(true)
super.touchesBegan(touches, with: event)
}

/* Dont allow the ViewController to appear */
override func viewWillDisappear(_ animated: Bool) {
if isMovingFromParent {
Expand Down Expand Up @@ -150,25 +156,61 @@ class LaboratorySearchViewController: UIViewController, UICollectionViewDelegate
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (labByFloorData?.count)! == 0 {
tableView.setEmptyView(title: "Sin laboratorios", message: "Aún no has seleccionado un piso", messageImage: UIImage(named: "Nautilus")!)
}else{
tableView.restore()

if isSearching {
if (searchFiltered?.count)! == 0 {
tableView.setEmptyView(title: "Sin laboratorios", message: "No hay laboratorios con ese nombre", messageImage: UIImage(named: "Nautilus")!)
}else{
tableView.restore()
}
return (searchFiltered?.count)!
} else {
if (labByFloorData?.count)! == 0 {
tableView.setEmptyView(title: "Sin laboratorios", message: "Aún no has seleccionado un piso", messageImage: UIImage(named: "Nautilus")!)
}else{
tableView.restore()
}
return (labByFloorData?.count)!
}
return (labByFloorData?.count)!
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "labCells", for: indexPath) as! LabTableViewCell
cell.title.text = labByFloorData![indexPath.item]["nombre"].stringValue
cell.location.text = labByFloorData![indexPath.item]["ubicacion"].stringValue

return cell
if isSearching {
let cell = tableView.dequeueReusableCell(withIdentifier: "labCells", for: indexPath) as! LabTableViewCell
cell.title.text = searchFiltered![indexPath.item]["nombre"].stringValue
cell.location.text = searchFiltered![indexPath.item]["ubicacion"].stringValue

return cell
} else {
let cell = tableView.dequeueReusableCell(withIdentifier: "labCells", for: indexPath) as! LabTableViewCell
cell.title.text = labByFloorData![indexPath.item]["nombre"].stringValue
cell.location.text = labByFloorData![indexPath.item]["ubicacion"].stringValue

return cell
}
}

func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {
if searchBar.text == nil || searchBar.text == "" {
isSearching = false
view.endEditing(true)
labsTableView.reloadData()
} else {
isSearching = true
searchFiltered = labData?.arrayValue.filter({$0["nombre"].stringValue.contains(searchText)})
labsTableView.reloadData()
}
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let vc = segue.destination as! DetailViewController
let selectedLab = labByFloorData![(labsTableView.indexPathForSelectedRow?.row)!]
var selectedLab:JSON?
if isSearching {
selectedLab = searchFiltered![(labsTableView.indexPathForSelectedRow?.row)!]
} else {
selectedLab = labByFloorData![(labsTableView.indexPathForSelectedRow?.row)!]
}
vc.labInformation = selectedLab
}
}
18 changes: 13 additions & 5 deletions Musgravite/View/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
</connections>
</collectionView>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="PJx-0w-UaT">
<rect key="frame" x="0.0" y="423" width="375" height="389"/>
<rect key="frame" x="0.0" y="471" width="375" height="341"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
<prototypes>
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="labCells" rowHeight="70" id="qlL-1m-L7j" customClass="LabTableViewCell" customModule="Musgravite" customModuleProvider="target">
Expand Down Expand Up @@ -469,6 +469,10 @@
<outlet property="delegate" destination="Azx-5G-eG2" id="Cmc-eY-Is1"/>
</connections>
</tableView>
<searchBar contentMode="redraw" translatesAutoresizingMaskIntoConstraints="NO" id="KSk-cI-61L">
<rect key="frame" x="0.0" y="415" width="375" height="56"/>
<textInputTraits key="textInputTraits"/>
</searchBar>
</subviews>
<color key="backgroundColor" red="0.91395015734706431" green="0.91395015734706431" blue="0.91395015734706431" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
<constraints>
Expand All @@ -478,7 +482,9 @@
<constraint firstItem="CNG-Zo-ve4" firstAttribute="trailing" secondItem="g5b-1u-ThL" secondAttribute="trailing" id="42A-j7-pQf"/>
<constraint firstItem="PJx-0w-UaT" firstAttribute="leading" secondItem="g5b-1u-ThL" secondAttribute="leading" id="C28-Jo-Pcb"/>
<constraint firstItem="Ca7-ND-XYu" firstAttribute="leading" secondItem="g5b-1u-ThL" secondAttribute="leading" constant="16" id="CF1-hb-PHW"/>
<constraint firstItem="KSk-cI-61L" firstAttribute="trailing" secondItem="p7k-Q2-By0" secondAttribute="trailing" id="EYU-Mr-RjH"/>
<constraint firstItem="CNG-Zo-ve4" firstAttribute="trailing" secondItem="g5b-1u-ThL" secondAttribute="trailing" id="FPQ-RZ-5cl"/>
<constraint firstItem="KSk-cI-61L" firstAttribute="leading" secondItem="p7k-Q2-By0" secondAttribute="leading" id="JqG-N9-YJt"/>
<constraint firstItem="Ca7-ND-XYu" firstAttribute="centerX" secondItem="CNG-Zo-ve4" secondAttribute="centerX" id="KIt-ig-ZyB"/>
<constraint firstItem="YgL-bH-T47" firstAttribute="top" secondItem="Ca7-ND-XYu" secondAttribute="bottom" constant="8" id="KUv-JC-8S9"/>
<constraint firstItem="CNG-Zo-ve4" firstAttribute="top" secondItem="tLZ-jw-RNc" secondAttribute="top" id="Kb3-Ee-YUd"/>
Expand All @@ -498,7 +504,8 @@
<constraint firstItem="CNG-Zo-ve4" firstAttribute="leading" secondItem="g5b-1u-ThL" secondAttribute="leading" id="jWL-4b-BDK"/>
<constraint firstItem="g5b-1u-ThL" firstAttribute="trailing" secondItem="Ca7-ND-XYu" secondAttribute="trailing" constant="16" id="jxb-Ir-fCP"/>
<constraint firstItem="Ca7-ND-XYu" firstAttribute="trailing" secondItem="YgL-bH-T47" secondAttribute="trailing" id="mLr-S3-va1"/>
<constraint firstItem="PJx-0w-UaT" firstAttribute="top" secondItem="p7k-Q2-By0" secondAttribute="bottom" constant="8" id="oLb-5f-2RH"/>
<constraint firstItem="PJx-0w-UaT" firstAttribute="top" secondItem="p7k-Q2-By0" secondAttribute="bottom" constant="56" id="oLb-5f-2RH"/>
<constraint firstItem="KSk-cI-61L" firstAttribute="top" secondItem="p7k-Q2-By0" secondAttribute="bottom" id="oci-lh-4q1"/>
<constraint firstItem="p7k-Q2-By0" firstAttribute="trailing" secondItem="g5b-1u-ThL" secondAttribute="trailing" id="ppV-y0-QdA"/>
<constraint firstItem="YgL-bH-T47" firstAttribute="top" secondItem="Ca7-ND-XYu" secondAttribute="bottom" constant="8" symbolic="YES" id="uei-DQ-rxZ"/>
<constraint firstItem="PJx-0w-UaT" firstAttribute="trailing" secondItem="g5b-1u-ThL" secondAttribute="trailing" id="vNo-2q-qC0"/>
Expand All @@ -514,11 +521,12 @@
<outlet property="descriptionOutlet" destination="YgL-bH-T47" id="RXt-Zy-Rr6"/>
<outlet property="floorsCollectionView" destination="p7k-Q2-By0" id="DW8-wM-70c"/>
<outlet property="labsTableView" destination="PJx-0w-UaT" id="v1T-Kj-CS9"/>
<outlet property="searchBar" destination="KSk-cI-61L" id="Lxd-zp-QtN"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="X4z-1K-QQM" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2759" y="355"/>
<point key="canvasLocation" x="2757.5999999999999" y="354.67980295566502"/>
</scene>
<!--Detail View Controller-->
<scene sceneID="LqA-tC-acw">
Expand Down Expand Up @@ -1118,7 +1126,7 @@
<scene sceneID="PsT-nS-S81">
<objects>
<viewController storyboardIdentifier="CharacterCreatorViewController" id="S8d-Th-MfX" customClass="CharacterCreatorViewController" customModule="Musgravite" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleAspectFit" id="NQ2-oG-PU9">
<view key="view" contentMode="scaleAspectFit" ambiguous="YES" id="NQ2-oG-PU9">
<rect key="frame" x="0.0" y="0.0" width="1850" height="812"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
Expand Down Expand Up @@ -1165,7 +1173,7 @@
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</view>
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="5xA-Ou-6R2">
<scrollView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5xA-Ou-6R2">
<rect key="frame" x="0.0" y="524" width="1850" height="288"/>
<subviews>
<view contentMode="scaleToFill" translatesAutoresizingMaskIntoConstraints="NO" id="PTZ-PQ-1q9">
Expand Down

0 comments on commit df6b53e

Please sign in to comment.