diff --git a/HIAPI/Models/Staff.swift b/HIAPI/Models/Staff.swift index 20d1c983..3a088cc8 100644 --- a/HIAPI/Models/Staff.swift +++ b/HIAPI/Models/Staff.swift @@ -39,10 +39,10 @@ public struct Staff: Codable { case isPrivate case displayOnStaffCheckIn } - public let isPro: String + public let isPro: Bool public let eventId: String public let isStaff: Bool - public let name: Int + public let name: String public let description: String public let startTime: Date public let endTime: Date diff --git a/HackIllinois.xcodeproj/project.pbxproj b/HackIllinois.xcodeproj/project.pbxproj index 2779e95b..f63fe346 100644 --- a/HackIllinois.xcodeproj/project.pbxproj +++ b/HackIllinois.xcodeproj/project.pbxproj @@ -140,11 +140,11 @@ D158EC312B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift in Sources */ = {isa = PBXBuildFile; fileRef = D158EC302B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift */; }; D158EC332B5A2DFE0003D799 /* HIScanPointsShopViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D158EC322B5A2DFE0003D799 /* HIScanPointsShopViewController.swift */; }; D187BF582B781A1100AD7356 /* HIShiftCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF572B781A1100AD7356 /* HIShiftCell.swift */; }; - D1BBA5682B70AB940017BD13 /* Staff.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BBA5672B70AB940017BD13 /* Staff.swift */; }; - D1BBA56A2B70ACCC0017BD13 /* StaffService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BBA5692B70ACCC0017BD13 /* StaffService.swift */; }; D187BF5A2B78317600AD7356 /* Mentor.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF592B78317600AD7356 /* Mentor.swift */; }; D187BF5C2B78318000AD7356 /* MentorService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D187BF5B2B78318000AD7356 /* MentorService.swift */; }; D19D4C932B794F9100376E1B /* HIScanMentorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D19D4C922B794F9100376E1B /* HIScanMentorViewController.swift */; }; + D1BBA5682B70AB940017BD13 /* Staff.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BBA5672B70AB940017BD13 /* Staff.swift */; }; + D1BBA56A2B70ACCC0017BD13 /* StaffService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D1BBA5692B70ACCC0017BD13 /* StaffService.swift */; }; D1BE81172AC8FC680042C078 /* HIAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 95E3142A21FAD5B30092C22E /* HIAPI.framework */; }; D1BE81182AC8FC690042C078 /* HIAPI.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 95E3142A21FAD5B30092C22E /* HIAPI.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; D1C5B6582B732E44000E766D /* refresh.json in Resources */ = {isa = PBXBuildFile; fileRef = D1C5B6572B732E44000E766D /* refresh.json */; }; @@ -358,11 +358,11 @@ D158EC302B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIQRAttendeeScannerSelection.swift; sourceTree = ""; }; D158EC322B5A2DFE0003D799 /* HIScanPointsShopViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanPointsShopViewController.swift; sourceTree = ""; }; D187BF572B781A1100AD7356 /* HIShiftCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIShiftCell.swift; sourceTree = ""; }; - D1BBA5672B70AB940017BD13 /* Staff.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Staff.swift; sourceTree = ""; }; - D1BBA5692B70ACCC0017BD13 /* StaffService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaffService.swift; sourceTree = ""; }; D187BF592B78317600AD7356 /* Mentor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mentor.swift; sourceTree = ""; }; D187BF5B2B78318000AD7356 /* MentorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentorService.swift; sourceTree = ""; }; D19D4C922B794F9100376E1B /* HIScanMentorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanMentorViewController.swift; sourceTree = ""; }; + D1BBA5672B70AB940017BD13 /* Staff.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Staff.swift; sourceTree = ""; }; + D1BBA5692B70ACCC0017BD13 /* StaffService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaffService.swift; sourceTree = ""; }; D1C5B6572B732E44000E766D /* refresh.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = refresh.json; sourceTree = ""; }; D1F146392B605C57004E7FC9 /* Hack_Mushroom_Loading.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Hack_Mushroom_Loading.json; sourceTree = ""; }; D3A309BA221116A600CBA351 /* HackIllinois.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HackIllinois.entitlements; sourceTree = ""; }; diff --git a/HackIllinois/Assets.xcassets/GrayPotion.imageset/Contents.json b/HackIllinois/Assets.xcassets/GrayPotion.imageset/Contents.json new file mode 100644 index 00000000..75944daa --- /dev/null +++ b/HackIllinois/Assets.xcassets/GrayPotion.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "GrayPotion1x.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "GrayPotion2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "GrayPotion3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion1x.png b/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion1x.png new file mode 100644 index 00000000..0e244520 Binary files /dev/null and b/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion1x.png differ diff --git a/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion2x.png b/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion2x.png new file mode 100644 index 00000000..28724cb0 Binary files /dev/null and b/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion2x.png differ diff --git a/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion3x.png b/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion3x.png new file mode 100644 index 00000000..f0c3da79 Binary files /dev/null and b/HackIllinois/Assets.xcassets/GrayPotion.imageset/GrayPotion3x.png differ diff --git a/HackIllinois/Assets.xcassets/GreenPotion.imageset/Contents.json b/HackIllinois/Assets.xcassets/GreenPotion.imageset/Contents.json new file mode 100644 index 00000000..c7479437 --- /dev/null +++ b/HackIllinois/Assets.xcassets/GreenPotion.imageset/Contents.json @@ -0,0 +1,23 @@ +{ + "images" : [ + { + "filename" : "greenPotion.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "filename" : "greenPotion2x.png", + "idiom" : "universal", + "scale" : "2x" + }, + { + "filename" : "greenPotion3x.png", + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion.png b/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion.png new file mode 100644 index 00000000..7783e5e0 Binary files /dev/null and b/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion.png differ diff --git a/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion2x.png b/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion2x.png new file mode 100644 index 00000000..5e77a4c1 Binary files /dev/null and b/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion2x.png differ diff --git a/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion3x.png b/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion3x.png new file mode 100644 index 00000000..743a1bb0 Binary files /dev/null and b/HackIllinois/Assets.xcassets/GreenPotion.imageset/greenPotion3x.png differ diff --git a/HackIllinois/ViewControllers/HIScheduleViewController.swift b/HackIllinois/ViewControllers/HIScheduleViewController.swift index 85ea1672..31750b72 100644 --- a/HackIllinois/ViewControllers/HIScheduleViewController.swift +++ b/HackIllinois/ViewControllers/HIScheduleViewController.swift @@ -18,6 +18,9 @@ import HIAPI class HIScheduleViewController: HIEventListViewController { // MARK: - Properties var staffShifts: [Staff] = [] + private var labelColor: UIColor = .white // Default color + var hasSelectedShift = false + var segmentedControl: HIScheduleSegmentedControl! lazy var fetchedResultsController: NSFetchedResultsController = { let fetchRequest: NSFetchRequest = Event.fetchRequest() @@ -85,6 +88,10 @@ class HIScheduleViewController: HIEventListViewController { // MARK: - Actions extension HIScheduleViewController { @objc func didSelectTab(_ sender: HISegmentedControl) { + if hasSelectedShift { + removeStaffShiftContainerViews() + setUpShiftCells() + } currentTab = sender.selectedIndex updatePredicate() animateReload() @@ -137,7 +144,7 @@ extension HIScheduleViewController { super.loadView() let items = dataStore.map { $0.displayText } - let segmentedControl = HIScheduleSegmentedControl(titles: items, nums: [23, 24, 25]) + segmentedControl = HIScheduleSegmentedControl(titles: items, nums: [23, 24, 25]) segmentedControl.addTarget(self, action: #selector(didSelectTab(_:)), for: .valueChanged) segmentedControl.translatesAutoresizingMaskIntoConstraints = false view.addSubview(segmentedControl) @@ -155,9 +162,11 @@ extension HIScheduleViewController { let now = Date() if now > HITimeDataSource.shared.eventTimes.sundayStart { segmentedControl.selectedIndex = 2 + currentTab = 2 } else if now > HITimeDataSource.shared.eventTimes.saturdayStart { segmentedControl.selectedIndex = 1 + currentTab = 1 } let tableView = HITableView() @@ -191,6 +200,7 @@ extension HIScheduleViewController { } // MARK: - Staff Shifts Control Setup + extension HIScheduleViewController { @objc func setStaffShiftsControl() { let customFontSize = UIDevice.current.userInterfaceIdiom == .pad ? 44 : 24 @@ -202,7 +212,7 @@ extension HIScheduleViewController { let flexibleSpaceLeft3 = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) let scheduleButton = UIBarButtonItem(title: "SCHEDULE", style: .plain, target: self, action: #selector(scheduleButtonTapped(_:))) - scheduleButton.setTitleTextAttributes([NSAttributedString.Key.font: customFont], for: .normal) + scheduleButton.setTitleTextAttributes([NSAttributedString.Key.font: customFont, NSAttributedString.Key.foregroundColor: labelColor], for: .normal) // Add the flexible space items and custom button to the leftBarButtonItems array navigationItem.leftBarButtonItems = [flexibleSpaceLeft1, flexibleSpaceLeft2, flexibleSpaceLeft3, scheduleButton] @@ -213,30 +223,49 @@ extension HIScheduleViewController { // Create custom right bar button item let customButton = UIBarButtonItem(title: "SHIFTS", style: .plain, target: self, action: #selector(shiftsButtonTapped(_:))) - customButton.setTitleTextAttributes([NSAttributedString.Key.font: customFont], for: .normal) + customButton.setTitleTextAttributes([NSAttributedString.Key.font: customFont, NSAttributedString.Key.foregroundColor: labelColor], for: .normal) // Add the flexible space items and custom button to the rightBarButtonItems array navigationItem.rightBarButtonItems = [flexibleSpaceRight1, flexibleSpaceRight2, customButton] self.navigationItem.leftItemsSupplementBackButton = true } - + + func removeStaffShiftContainerViews() { + // Iterate through all subviews and remove container views for staff shifts + for subview in self.view.subviews { + if let containerView = subview as? UIView, containerView.backgroundColor == #colorLiteral(red: 1, green: 0.9803921569, blue: 0.8, alpha: 1) { + containerView.removeFromSuperview() + } + } + } + // Actions for left and right buttons @objc func scheduleButtonTapped(_ sender: UIButton) { if onlyShifts { onlyShifts = false backgroundView.image = #imageLiteral(resourceName: "PurpleBackground") + if UIDevice.current.userInterfaceIdiom != .pad { + labelColor = .white // Set label color to brown + setStaffShiftsControl() + } + // Call removeStaffShiftContainerViews to remove container views for staff shifts + hasSelectedShift = false + removeStaffShiftContainerViews() updatePredicate() animateReload() } } - @objc func shiftsButtonTapped(_ sender: UIButton) { if !onlyShifts { onlyShifts = !onlyShifts backgroundView.image = #imageLiteral(resourceName: "Pink Background") - //let label = HILabel(style: (UIDevice.current.userInterfaceIdiom == .pad) ? .viewTitle : .viewTitleBrown) + hasSelectedShift = true + if UIDevice.current.userInterfaceIdiom != .pad { + labelColor = #colorLiteral(red: 0.337254902, green: 0.1411764706, blue: 0.06666666667, alpha: 1) // Set label color to brown + setStaffShiftsControl() + } guard let user = HIApplicationStateController.shared.user else { return } @@ -248,9 +277,13 @@ extension HIScheduleViewController { print("Staff shifts: ", self.staffShifts) DispatchQueue.main.async { + // Set up shift cells + self.setUpShiftCells() + // Update predicate and animate reload self.updatePredicate() self.animateReload() } + } catch { print("An error has occurred in getting staff shifts \(error)") } @@ -258,6 +291,106 @@ extension HIScheduleViewController { .launch() } } + + func setUpShiftCells() { + // Get filtered events by date + let sundayStart = HITimeDataSource.shared.eventTimes.sundayStart + let saturdayStart = HITimeDataSource.shared.eventTimes.saturdayStart + + // Iterate through all subviews and remove container views for staff shifts + var padding = 0.0 + // Iterate through each staff shift and add a label to the container view + for (index, staffShift) in self.staffShifts.enumerated() { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss Z" + let dateString = staffShift.startTime + let calendar = Calendar.current + let dayComponent = calendar.component(.day, from: dateString) + var curr_idx = segmentedControl.selectedIndex + print("Day:", dayComponent) + print("Current tab:", curr_idx) + if curr_idx == 0 && dayComponent != 23 { + continue + } else if curr_idx == 1 && dayComponent != 24 { + continue + } else if curr_idx == 2 && dayComponent != 25 { + continue + } + // Set fixed width and height for the container view + let containerViewWidth: CGFloat = 340.0 + let containerViewHeight: CGFloat = 130.0 + + // Create a container view with a yellow background + let containerView = UIView() + containerView.translatesAutoresizingMaskIntoConstraints = false + containerView.backgroundColor = #colorLiteral(red: 1, green: 0.9803921569, blue: 0.8, alpha: 1) + containerView.layer.cornerRadius = 20.0 + containerView.layer.masksToBounds = true + + // Add the container view to the main view + self.view.addSubview(containerView) + + // Set up constraints for the fixed width and height + NSLayoutConstraint.activate([ + containerView.widthAnchor.constraint(equalToConstant: containerViewWidth), + containerView.heightAnchor.constraint(equalToConstant: containerViewHeight), + containerView.centerXAnchor.constraint(equalTo: self.view.centerXAnchor), + containerView.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 275 + padding) + ]) + let label = UILabel() + label.text = staffShift.name + label.font = HIAppearance.Font.eventTitle! + label.translatesAutoresizingMaskIntoConstraints = false + + // Add the label to the container view + containerView.addSubview(label) + + // Set up constraints for the labels within the container view + NSLayoutConstraint.activate([ + label.topAnchor.constraint(equalTo: containerView.topAnchor, constant: 15.0), + label.leadingAnchor.constraint(equalTo: containerView.leadingAnchor, constant: 20.0) + ]) + + // Add time, location, and description labels to shift cells + // Time label set up + var eventCellSpacing: CGFloat = 8.0 + var locationImageView = UIImageView(image: #imageLiteral(resourceName: "LocationSign")); var timeImageView = UIImageView(image: #imageLiteral(resourceName: "Clock")) + let timeLabel = HILabel(style: .time) + timeLabel.text = Formatter.simpleTime.string(from: staffShift.startTime) + " - " + Formatter.simpleTime.string(from: staffShift.endTime) + containerView.addSubview(timeImageView) + timeImageView.translatesAutoresizingMaskIntoConstraints = false + timeImageView.leadingAnchor.constraint(equalTo: label.leadingAnchor).isActive = true + timeImageView.bottomAnchor.constraint(equalTo: label.bottomAnchor, constant: 25.0).isActive = true + containerView.addSubview(timeLabel) + timeLabel.leadingAnchor.constraint(equalTo: timeImageView.trailingAnchor, constant: eventCellSpacing + 1).isActive = true + timeLabel.centerYAnchor.constraint(equalTo: timeImageView.centerYAnchor).isActive = true + + // Location label set up + let locationLabel = HILabel(style: .newLocation) + if staffShift.locations.count > 0 { + locationLabel.text = staffShift.locations.map { $0.name }.joined(separator: ", ") + } else { + locationLabel.text = "No Location" + } + containerView.addSubview(locationImageView) + locationImageView.translatesAutoresizingMaskIntoConstraints = false + containerView.addSubview(locationLabel) + locationImageView.leadingAnchor.constraint(equalTo: timeImageView.leadingAnchor, constant: 1.0).isActive = true + locationImageView.bottomAnchor.constraint(equalTo: timeImageView.bottomAnchor, constant: 25.0).isActive = true + locationLabel.leadingAnchor.constraint(equalTo: timeLabel.leadingAnchor).isActive = true + locationLabel.centerYAnchor.constraint(equalTo: locationImageView.centerYAnchor).isActive = true + + // Description label set up + let descriptionLabel = HILabel(style: .cellDescription) + descriptionLabel.numberOfLines = 1 + descriptionLabel.text = "\(staffShift.description)" + containerView.addSubview(descriptionLabel) + descriptionLabel.translatesAutoresizingMaskIntoConstraints = false + descriptionLabel.leadingAnchor.constraint(equalTo: locationImageView.leadingAnchor).isActive = true + descriptionLabel.bottomAnchor.constraint(equalTo: locationImageView.bottomAnchor, constant: 25.0).isActive = true + padding += 150.0 + } + } }