Unverified Commit 7ee75976 authored by Zach Knox's avatar Zach Knox
Browse files

Filter by campus (of which there is currently just fairfax)

parent c45e0aa0
......@@ -20,8 +20,9 @@ class Filters {
var showAlerts = ["Informational":true, "Minor Alerts":true, "Major Alerts":true]
var onlyFromLocations = [String: Bool]() // Locations to show, could simply use Location objects instead if you wanted
var onlyFromCategories = [String: Bool]() //same as above, but for Categories, not Locations
var onlyFromCategories = [String: Bool]() // same as above, but for Categories, not Locations
var onlyFromCampuses = [String: Bool]() // and for campuses
init() {
//nothing to do here
}
......@@ -32,7 +33,7 @@ class Filters {
let specifiedFacilities = List<Facility>()
// facility must be within both a specified location and category
for f in facilities {
if(onlyFromLocations[(f.facilityLocation?.building)!] == true && onlyFromCategories[(f.category?.categoryName)!] == true) {
if(onlyFromLocations[(f.facilityLocation?.building)!] == true && onlyFromCategories[(f.category?.categoryName)!] == true && onlyFromCampuses[(f.facilityLocation?.campus)!] == true) {
specifiedFacilities.append(f)
}
}
......
......@@ -149,6 +149,12 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
return
}
}
for f in filters.onlyFromCampuses {
if(f.value != true) {
LeftButton.title = "Filter (On)"
return
}
}
for f in filters.showAlerts {
if(f.value != true) {
LeftButton.title = "Filter (On)"
......@@ -395,6 +401,9 @@ class FacilitiesListViewController: UIViewController, UICollectionViewDelegate,
if(!filters.onlyFromLocations.keys.contains((f.facilityLocation?.building)!)) {
filters.onlyFromLocations.updateValue(true, forKey: (f.facilityLocation?.building)!)
}
if(!filters.onlyFromCampuses.keys.contains((f.facilityLocation?.campus)!)) {
filters.onlyFromCampuses.updateValue(true, forKey: (f.facilityLocation?.campus)!)
}
}
}
......
......@@ -56,7 +56,7 @@ class FilterSelectionTableViewController: UITableViewController {
var i = 1
for v in values {
if i == indexPath.row {
cell.textLabel?.text = v.key
cell.textLabel?.text = v.key.capitalized
if(v.value == true) {
cell.accessoryType = .checkmark
}
......@@ -93,7 +93,7 @@ class FilterSelectionTableViewController: UITableViewController {
else {
res = false
}
selectFunc((tableCell?.textLabel?.text)!, res)
selectFunc((tableCell?.textLabel?.text)!.lowercased(), res)
tableView.reloadRows(at: [IndexPath(row: 0, section: 0), indexPath], with: .automatic)
}
}
......
......@@ -90,7 +90,7 @@ class FiltersTableViewController: UITableViewController {
case 2:
return SortMethod.count
case 3:
return 3
return 4
default:
return 0
}
......@@ -206,6 +206,22 @@ class FiltersTableViewController: UITableViewController {
}
cell.detailTextLabel?.text = detail
case 2:
cell.textLabel?.text = "Campuses"
var i = 0
for c in filters.onlyFromCampuses {
if(c.value == true) {
i += 1
}
}
var detail: String
if(i == filters.onlyFromCampuses.count) {
detail = "All Selected"
}
else {
detail = "\(i) Selected"
}
cell.detailTextLabel?.text = detail
case 3:
cell.textLabel?.text = "Alerts"
var i = 0
for c in filters.showAlerts {
......@@ -316,6 +332,9 @@ class FiltersTableViewController: UITableViewController {
else if(sender as! UITableViewCell).textLabel?.text! == "Alerts" {
return filters.showAlerts
}
else if(sender as! UITableViewCell).textLabel?.text! == "Campuses" {
return filters.onlyFromCampuses
}
else {
return filters.onlyFromLocations
}
......@@ -327,6 +346,9 @@ class FiltersTableViewController: UITableViewController {
else if(sender as! UITableViewCell).textLabel?.text! == "Alerts" {
filters.showAlerts[key] = value
}
else if(sender as! UITableViewCell).textLabel?.text! == "Campuses" {
filters.onlyFromCampuses[key] = value
}
else {
filters.onlyFromLocations[key] = value
}
......@@ -371,6 +393,25 @@ class FiltersTableViewController: UITableViewController {
}
}
}
else if((sender as! UITableViewCell).textLabel?.text! == "Campuses") {
var foundFalse = false
for v in filters.onlyFromCampuses {
if !foundFalse {
if !v.value {
foundFalse = true
filters.onlyFromCampuses.updateValue(true, forKey: v.key)
}
}
else {
filters.onlyFromCampuses.updateValue(true, forKey: v.key)
}
}
if !foundFalse {
for v in filters.onlyFromCampuses {
filters.onlyFromCampuses.updateValue(false, forKey: v.key)
}
}
}
else {
var foundFalse = false
for v in filters.onlyFromLocations {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment