Skip to content

Commit

Permalink
added staff shifts to schedule page
Browse files Browse the repository at this point in the history
  • Loading branch information
s0phialiu committed Feb 17, 2024
1 parent 34d9b0e commit 5649362
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 12 deletions.
4 changes: 2 additions & 2 deletions HIAPI/Models/Staff.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions HackIllinois.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -358,11 +358,11 @@
D158EC302B5A2D440003D799 /* HIQRAttendeeScannerSelection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIQRAttendeeScannerSelection.swift; sourceTree = "<group>"; };
D158EC322B5A2DFE0003D799 /* HIScanPointsShopViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanPointsShopViewController.swift; sourceTree = "<group>"; };
D187BF572B781A1100AD7356 /* HIShiftCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIShiftCell.swift; sourceTree = "<group>"; };
D1BBA5672B70AB940017BD13 /* Staff.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Staff.swift; sourceTree = "<group>"; };
D1BBA5692B70ACCC0017BD13 /* StaffService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaffService.swift; sourceTree = "<group>"; };
D187BF592B78317600AD7356 /* Mentor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Mentor.swift; sourceTree = "<group>"; };
D187BF5B2B78318000AD7356 /* MentorService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MentorService.swift; sourceTree = "<group>"; };
D19D4C922B794F9100376E1B /* HIScanMentorViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HIScanMentorViewController.swift; sourceTree = "<group>"; };
D1BBA5672B70AB940017BD13 /* Staff.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Staff.swift; sourceTree = "<group>"; };
D1BBA5692B70ACCC0017BD13 /* StaffService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StaffService.swift; sourceTree = "<group>"; };
D1C5B6572B732E44000E766D /* refresh.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = refresh.json; sourceTree = "<group>"; };
D1F146392B605C57004E7FC9 /* Hack_Mushroom_Loading.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Hack_Mushroom_Loading.json; sourceTree = "<group>"; };
D3A309BA221116A600CBA351 /* HackIllinois.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HackIllinois.entitlements; sourceTree = "<group>"; };
Expand Down
23 changes: 23 additions & 0 deletions HackIllinois/Assets.xcassets/GrayPotion.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions HackIllinois/Assets.xcassets/GreenPotion.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
145 changes: 139 additions & 6 deletions HackIllinois/ViewControllers/HIScheduleViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Event> = {
let fetchRequest: NSFetchRequest<Event> = Event.fetchRequest()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -191,6 +200,7 @@ extension HIScheduleViewController {
}

// MARK: - Staff Shifts Control Setup

extension HIScheduleViewController {
@objc func setStaffShiftsControl() {
let customFontSize = UIDevice.current.userInterfaceIdiom == .pad ? 44 : 24
Expand All @@ -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]
Expand All @@ -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 }

Expand All @@ -248,16 +277,120 @@ 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)")
}
}
.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
}
}
}


Expand Down

0 comments on commit 5649362

Please sign in to comment.