Skip to content

Commit

Permalink
feat: Added updated station names and station comments text
Browse files Browse the repository at this point in the history
- Added dynamic station comments required for specific stations
- Adjusted form sizing and layout
- Added validation for required station comments
- renamed typo variables
- removed debug code
  • Loading branch information
PaulGarewal committed Dec 4, 2024
1 parent 9572472 commit b17fa77
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 30 deletions.
2 changes: 1 addition & 1 deletion ipad/Constants/AppRemoteAPIConst.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class RemoteURLManager {
static var `default` = {
// Here We Can use Target Flag to customize
// Switch Env
return RemoteURLManager(.prod)
return RemoteURLManager(.dev)
}()

init(_ env: RemoteEnv) {
Expand Down
4 changes: 3 additions & 1 deletion ipad/Constants/StringConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ struct ShiftFormHeaders {
struct ShiftStart {
static let startTime = "Shift Start Time *"
static let k9OnShift = "k9 On Shift"
static let station = "Station"
static let station = "Station *"
static let comments = "Shift Start Comments"
static let shiftStartDate = "Shift Start Date *"
static let stationComments = "Station Information"
static let stationCommentsRequired = "Station Information *"
}

struct ShiftEnd {
Expand Down
2 changes: 1 addition & 1 deletion ipad/Database/Storage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class Storage {
let shifts = Storage.shared.getSyncableItems()
var invalidShifts: [ShiftModel] = []
for shift in shifts {
if shift.shitEndComments.count > 300 || shift.shitStartComments.count > 300 {
if shift.shiftEndComments.count > 300 || shift.shiftStartComments.count > 300 {
invalidShifts.append(shift)
continue
}
Expand Down
37 changes: 27 additions & 10 deletions ipad/Models/Shift/Form Fields/ShiftFormHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,28 @@ class ShiftFormHelper {
dropdownItems: DropdownHelper.shared.getDropdown(for: .stations)
)
sectionItems.append(station)
let shitStartComments = TextAreaInput(
key: "shitStartComments",

let shiftStartComments = TextAreaInput(
key: "shiftStartComments",
header: ShiftFormHeaders.ShiftStart.comments,
editable: editable ?? true,
value: object?.shitStartComments ?? "",
value: object?.shiftStartComments ?? "",
width: .Full
)
sectionItems.append(shitStartComments)

sectionItems.append(shiftStartComments)

let stationComments = TextAreaInput(
key: "stationComments",
header: stationRequired(object?.station ?? "")
? ShiftFormHeaders.ShiftStart.stationCommentsRequired
: ShiftFormHeaders.ShiftStart.stationComments,
editable: editable ?? true,
value: object?.stationComments ?? "",
width: .Full
)

sectionItems.append(stationComments)

return sectionItems
}
/// Gets the required Input objects needed for the ShiftEndFields section of shift
Expand Down Expand Up @@ -94,14 +106,14 @@ class ShiftFormHelper {
width: .Third
)
sectionItems.append(boatsInspected)
let shitEndComments = TextAreaInput(
key: "shitEndComments",
let shiftEndComments = TextAreaInput(
key: "shiftEndComments",
header: ShiftFormHeaders.ShiftEnd.comments,
editable: editable ?? true,
value: object?.shitEndComments ?? "",
value: object?.shiftEndComments ?? "",
width: .Full
)
sectionItems.append(shitEndComments)
sectionItems.append(shiftEndComments)

return sectionItems
}
Expand All @@ -120,4 +132,9 @@ class ShiftFormHelper {
return columns
}

private static func stationRequired(_ station: String?) -> Bool {
guard let station = station else { return false }
let requiredStations = ["Other", "Project", "Emergency Response"]
return requiredStations.contains(station)
}
}
11 changes: 7 additions & 4 deletions ipad/Models/Shift/ShiftModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ class ShiftModel: Object, BaseRealmObject {
@objc dynamic var motorizedBlowBys: Int = 0
@objc dynamic var nonMotorizedBlowBys: Int = 0
@objc dynamic var station: String = ""
@objc dynamic var shitStartComments: String = ""
@objc dynamic var shitEndComments: String = ""
@objc dynamic var stationComments: String = ""
@objc dynamic var shiftStartComments: String = ""
@objc dynamic var shiftEndComments: String = ""
let BlowbyFields = ["reportedToRapp", "timeStamp", "watercraftComplexity"];
var inspections: List<WatercraftInspectionModel> = List<WatercraftInspectionModel>()
var blowbys: List<BlowbyModel> = List<BlowbyModel>()
Expand Down Expand Up @@ -267,8 +268,10 @@ class ShiftModel: Object, BaseRealmObject {
"location": "NA",
"motorizedBlowBys": motorizedBlowBys,
"nonMotorizedBlowBys": nonMotorizedBlowBys,
"shiftStartComment": shitStartComments.count > 1 ? shitStartComments : "None",
"shiftEndComment": shitEndComments.count > 1 ? shitEndComments : "None",
"stationComments": stationComments.count > 1 ? stationComments : "",
"stationCommentsRequired": stationCommentsRequired.count > 1 ? stationCommentsRequired : "",
"shiftStartComment": shiftStartComments.count > 1 ? shiftStartComments : "",
"shiftEndComment": shiftEndComments.count > 1 ? shiftEndComments : "",
"boatsInspected": boatsInspected,
"k9OnShift": k9OnShif
]
Expand Down
36 changes: 25 additions & 11 deletions ipad/ViewControllers/Shift/ShiftViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,17 @@ class ShiftViewController: BaseViewController {

// MARK: Input Item Changed
@objc func inputItemValueChanged(notification: Notification) {
guard let item: InputItem = notification.object as? InputItem else {return}
// Set value in Realm object
if let m = model {
m.set(value: item.value.get(type: item.type) as Any, for: item.key)
guard let item: InputItem = notification.object as? InputItem else { return }

// Handle station selection changes
if item.key.lowercased() == "station" {
// Trigger form reload to update dependencies
self.collectionView.reloadData()
}

// Update model
if let model = self.model {
model.set(value: item.value.get(type: item.type) as Any, for: item.key)
}
}

Expand Down Expand Up @@ -257,7 +264,12 @@ class ShiftViewController: BaseViewController {
let spacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
navigationItem.setRightBarButtonItems([saveButton, spacer, deleteButton], animated: true)
}


private func stationRequired(_ station: String) -> Bool {
let requiresComments = ["Other", "Project", "Emergency Response"]
return requiresComments.contains(station)
}

// MARK: Validation
func canSubmit() -> Bool {
return validationMessage() == ""
Expand Down Expand Up @@ -291,6 +303,11 @@ class ShiftViewController: BaseViewController {
message = "\(message)\n\(counter)- Please choose a station."
counter += 1
}

if model.stationComments.isEmpty && stationRequired(model.station) {
message = "\(message)\n\(counter)- Please add station information."
counter += 1
}

for inspection in model.inspections {
if inspection.inspectionTime == "" {
Expand Down Expand Up @@ -481,9 +498,6 @@ extension ShiftViewController: UICollectionViewDataSource, UICollectionViewDeleg
let cell = getShiftBlowbysHeaderCollectionViewCell(indexPath: indexPath)
cell.setup(object: model, callback: {[weak self] in
guard let strongSelf = self else {return}
if strongSelf.isEditable {
print("Yolo")
}
})
return cell
case .Blowbys:
Expand Down Expand Up @@ -528,11 +542,11 @@ extension ShiftViewController: UICollectionViewDataSource, UICollectionViewDeleg
case .Header:
return CGSize(width: fullWdtih, height: 35)
case .StartShift:
let estimatedContentHeight = InputGroupView.estimateContentHeight(for: ShiftFormHelper.getShiftEndFields(for: model, editable: true))
return CGSize(width: fullWdtih, height: estimatedContentHeight)
let estimatedContentHeight = InputGroupView.estimateContentHeight(for: ShiftFormHelper.getShiftStartFields(for: model, editable: true))
return CGSize(width: fullWdtih, height: estimatedContentHeight + 110)
case .EndShift:
let estimatedContentHeight = InputGroupView.estimateContentHeight(for: ShiftFormHelper.getShiftEndFields(for: model, editable: true))
return CGSize(width: fullWdtih, height: estimatedContentHeight)
return CGSize(width: fullWdtih, height: estimatedContentHeight + 110)
}
}
}
2 changes: 1 addition & 1 deletion ipad/Views/Form/Input Cells/InputItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ class TextAreaInput: InputItem {
var dependency: [InputDependency] = []
var type: InputItemType = .TextArea
var width: InputItemWidthSize
var height: CGFloat = 200
var height: CGFloat = 100
var key: String
var value: InputValue
var header: String
Expand Down
2 changes: 1 addition & 1 deletion ipad/Views/New Shift Modal/NewShiftModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class NewShiftModal: ModalView, Theme {
public func initialize(delegate: InputDelegate, onStart: @escaping (_ model: ShiftModel) -> Void, onCancel: @escaping () -> Void) {
self.onStart = onStart
self.onCancel = onCancel
setFixed(width: 550, height: 400)
setFixed(width: 800, height: 500)
present()
style()
self.model = ShiftModel()
Expand Down

0 comments on commit b17fa77

Please sign in to comment.