Skip to content

Commit

Permalink
Convert empty string checks to native property "isEmpty". simplify st…
Browse files Browse the repository at this point in the history
…atus flow. convert status check for consistency
  • Loading branch information
LocalNewsTV committed Jun 13, 2024
1 parent ac927c8 commit 70ddc06
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class BlowbyTableCollectionViewCell: BaseShiftOverviewCollectionViewCell {
columns.append(TableViewColumnConfig(key: "", header: "Edit", type: .Button, buttonName: "Edit", showHeader: false))

// Disable adding blowbys if not completed and hide delete button
if model.getStatus() != .Draft && model.getStatus() != .Errors {
if [.Draft, .Errors].contains(model.getStatus()) {
columns.removeLast()
blowByButton.alpha = 0
blowByButton.isEnabled = false
Expand Down
16 changes: 6 additions & 10 deletions ipad/ViewControllers/Shift/ShiftViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,15 @@ class ShiftViewController: BaseViewController {
self.collectionView.reloadData()
addListeners()
}
/// Iterates through inspections checking formDidValidate. If any for
/// Iterates through inspections checking formDidValidate. If any form does validate, modifies all appropraite statuses to `.Errors`
private func updateStatuses() {
if(self.model!.status != "Completed"){
if (self.model!.inspections.allSatisfy(){$0.formDidValidate}){
self.model!.set(status: .Draft)
} else {
self.model!.set(status: .Draft)
self.model!.inspections.forEach{ inspection in
if(inspection.formDidValidate){
inspection.set(status: .Draft);
} else {
inspection.set(status: .Errors);
}
inspection.set(status: inspection.formDidValidate ? .Draft : .Errors)
}
}
}
Expand Down Expand Up @@ -277,19 +273,19 @@ class ShiftViewController: BaseViewController {

// MARK: Validation
func canSubmit() -> Bool {
return validationMessage() == ""
return validationMessage().isEmpty
}

func validationMessage() -> String {
var message: String = ""
guard let model = self.model else { return message }
var counter = 1
if model.startTime == "" {
if model.startTime.isEmpty {
message = "\(message)\n\(counter)- Missing Shift Start time."
counter += 1
}

if model.endTime == "" {
if model.endTime.isEmpty {
message = "\(message)\n\(counter)- Missing Shift End time."
counter += 1
}
Expand All @@ -310,7 +306,7 @@ class ShiftViewController: BaseViewController {
}

for inspection in model.inspections {
if inspection.inspectionTime == "" {
if inspection.inspectionTime.isEmpty {
message = "\(message)\n\(counter)- Missing Time of Inspection."
counter += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class WatercraftInspectionViewController: BaseViewController {
}

func canSubmit() -> Bool {
return validationMessage() == ""
return validationMessage().isEmpty
}

/// Enum error cases grouped by sections for clarity
Expand Down Expand Up @@ -698,8 +698,8 @@ class WatercraftInspectionViewController: BaseViewController {
message += "\n"
}
}
model.set(value: message == "", for: "formDidValidate")
if (message == "") {
model.set(value: message.isEmpty, for: "formDidValidate")
if (message.isEmpty) {
model.set(status: .Draft)
}

Expand Down
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 @@ -561,7 +561,7 @@ class TimeInput: InputItem {

func getValue() -> Time? {
let stringValue: String = self.value.get(type: self.type) as? String ?? ""
if stringValue == "" {return nil}
if stringValue.isEmpty {return nil}
return Time(string: stringValue)
}

Expand Down
2 changes: 1 addition & 1 deletion ipad/Views/Input Modal/InputModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class InputModal: ModalView, Theme {
}

func validateInput(text: String) -> Bool {
if text.removeWhitespaces() == "" {
if text.removeWhitespaces().isEmpty {
invalidInput(message: "Please enter a value")
return false
} else {
Expand Down
10 changes: 5 additions & 5 deletions ipad/Views/Major Cities Picker/MajorCityPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class MajorCityPicker: UIView, Theme {
self.searchBar.delegate = self
self.tableView.reloadData()
self.selectionsHeightConstraint.constant = 0
self.selectButton.isEnabled = !(self.selection.display == "")
self.selectButton.isEnabled = !(self.selection.display.isEmpty)
searchBar.isAccessibilityElement = true
searchBar.accessibilityLabel = "search-majorcities"
searchBar.accessibilityValue = "search-majorcities"
Expand Down Expand Up @@ -142,12 +142,12 @@ class MajorCityPicker: UIView, Theme {
}

private func showOrHideSelectionsIfNeeded() {
let selectTitle = !(self.selection.display == "") ? "Select (1)" : "Select"
let selectTitle = !(self.selection.display.isEmpty) ? "Select (1)" : "Select"
self.selectButton.setTitle(selectTitle, for: .normal)
self.selectButton.isEnabled = !(self.selection.display == "")
self.selectButton.isEnabled = !(self.selection.display.isEmpty)
UIView.animate(withDuration: 0.3) {
self.selectionsHeightConstraint.constant = !(self.selection.display == "") ? 60 : 0
self.collectionView.alpha = !(self.selection.display == "") ? 1 : 0
self.selectionsHeightConstraint.constant = !(self.selection.display.isEmpty) ? 60 : 0
self.collectionView.alpha = !(self.selection.display.isEmpty) ? 1 : 0
self.layoutIfNeeded()
}
}
Expand Down
4 changes: 2 additions & 2 deletions ipad/Views/New Blowby Modal/NewBlowbyModal.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class NewBlowbyModal: ModalView, Theme {

// If (Valid) Add Blowby, remove and return
var invalidFields: [String] = []
if newBlowBy!.timeStamp == "" {
if newBlowBy!.timeStamp.isEmpty {
invalidFields.append("Blowby Time")
}
if newBlowBy!.watercraftComplexity == "" {
if newBlowBy!.watercraftComplexity.isEmpty {
invalidFields.append("Watercraft Complexity")
}
if !invalidFields.isEmpty {
Expand Down
4 changes: 2 additions & 2 deletions ipadTests/testShift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class testShift: XCTestCase {
vc.setup(model: shiftModel)
shiftModel.inspections.append(createTestInspection())
shiftModel.boatsInspected = false
XCTAssert(vc.canSubmit() == false && (shiftModel.startTime == "" || shiftModel.endTime == ""))
XCTAssert(vc.canSubmit() == false && (shiftModel.startTime.isEmpty || shiftModel.endTime.isEmpty))
}

func testValidShiftForSubmission() {
Expand All @@ -70,7 +70,7 @@ class testShift: XCTestCase {
shiftModel.endTime = "18:00"
shiftModel.inspections.append(createTestInspection())
shiftModel.boatsInspected = true
XCTAssert(vc.canSubmit() == true && (shiftModel.startTime != "" || shiftModel.endTime != ""))
XCTAssert(vc.canSubmit() == true && (shiftModel.startTime.isEmpty || !shiftModel.endTime.isEmpty))
}

}

0 comments on commit 70ddc06

Please sign in to comment.