Skip to content

Commit

Permalink
Merge pull request #151 from CristiHabliuc/validation-fixes
Browse files Browse the repository at this point in the history
Fixes some validation
  • Loading branch information
CristiHabliuc authored Nov 4, 2019
2 parents 05f21c1 + 88dfee7 commit 8eeea3b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 8 deletions.
4 changes: 2 additions & 2 deletions MonitorizareVot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MonitorizareVot/MonitorizareVot.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 4;
INFOPLIST_FILE = MonitorizareVot/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand All @@ -1261,7 +1261,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = MonitorizareVot/MonitorizareVot.entitlements;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 2;
CURRENT_PROJECT_VERSION = 4;
INFOPLIST_FILE = MonitorizareVot/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
Expand Down
1 change: 1 addition & 0 deletions MonitorizareVot/Base.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"Error.SaveNoteFailed" = "We couldn't save your note. Please try again later.";
"Error.UploadNoteFailed" = "We couldn't upload your note. We will retry later.";
"Error.SelectCountyFirst" = "Please select your county / district first.";
"Error.IncorrectStationNumber" = "Incorrect station number. Please double check the county and provided section number";

"Info.DataNotSyncronised" = "It appears that some of the questions have not been syncronised. Tap the button below to send the answers again";

Expand Down
16 changes: 11 additions & 5 deletions MonitorizareVot/PollingStation/SectionPickerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ class SectionPickerViewController: MVViewController {
}

func saveAndContinue() {
guard model.isSectionNumberCorrect else {
let alert = UIAlertController.error(withMessage: "Error.IncorrectStationNumber".localized)
present(alert, animated: true, completion: nil)
return
}

model.persist { [weak self] error in
if let error = error {
let alert = UIAlertController.error(withMessage: error.localizedDescription)
Expand All @@ -177,21 +183,21 @@ class SectionPickerViewController: MVViewController {
extension SectionPickerViewController: UITextFieldDelegate {
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
if let updated = (textField.text as NSString?)?.replacingCharacters(in: range, with: string) {
if let number = Int(updated),
let maxStationNumber = model.maximumStationNumber,
number <= maxStationNumber {
if let number = Int(updated) {
model.sectionId = number
return true
} else if updated == "" {
model.sectionId = nil
return true
} else {
return false
}
return true
}
return false
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()

if model.canContinue {
saveAndContinue()
}
Expand Down
4 changes: 4 additions & 0 deletions MonitorizareVot/PollingStation/SectionPickerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class SectionPickerViewModel: NSObject {
return countyCode != nil && sectionId != nil
}

var isSectionNumberCorrect: Bool {
return sectionId != nil && maximumStationNumber != nil && sectionId! <= maximumStationNumber!
}

var selectedCountyName: String? {
guard let code = countyCode else { return nil }
return getPollingStation(byCounty: code)?.name.capitalized
Expand Down
2 changes: 1 addition & 1 deletion MonitorizareVot/TableCells/FormSetTableCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class FormSetTableCell: UITableViewCell {
codeLabel.text = "(\(model.code.uppercased()))"
progressWidthConstraint.constant = -((1-model.progress) * cardContainer.frame.size.width)
answeredLabel.text = model.answeredOutOfTotalQuestions
progressContainer.isHidden = false
progressContainer.isHidden = model.progress == 0
outerCardContainer.layoutIfNeeded()
}

Expand Down
1 change: 1 addition & 0 deletions MonitorizareVot/ro.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"Error.SaveNoteFailed" = "Nu am reușit să salvăm nota. Te rugăm să încerci mai târziu.";
"Error.UploadNoteFailed" = "Nu am reușit să trimitem la server nota. Vom încerca mai târziu.";
"Error.SelectCountyFirst" = "Te rugăm să alegi județul/sectorul pentru a putea alege secția";
"Error.IncorrectStationNumber" = "Număr secție incorect. Te rugăm să verifici corectitudinea combinației județ - număr secție";

"Info.DataNotSyncronised" = "Se pare că unele răspunsuri nu au fost sincronizate cu serverul. Apasă butonul acesta pentru a le retrimite";

Expand Down

0 comments on commit 8eeea3b

Please sign in to comment.