Skip to content

Commit 50ea648

Browse files
committed
this fix handles primary and secondary fields which are not strings
1 parent 911a405 commit 50ea648

File tree

7 files changed

+152
-73
lines changed

7 files changed

+152
-73
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ All notable changes to this project will be documented in this file.
33
Adheres to [Semantic Versioning](http://semver.org/).
44

55
---
6+
## 3.0.4
7+
8+
##### Bug Fixes
9+
* Primary and secondary fields which are not strings now work properly
10+
611
## 3.0.3
712

813
##### Bug Fixes

MAGE.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3578,7 +3578,7 @@
35783578
GCC_PREFIX_HEADER = "Mage/MAGE-Prefix.pch";
35793579
INFOPLIST_FILE = "Mage/MAGE-Info.plist";
35803580
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
3581-
MARKETING_VERSION = 3.0.3;
3581+
MARKETING_VERSION = 3.0.4;
35823582
OTHER_LDFLAGS = "$(inherited)";
35833583
PRODUCT_BUNDLE_IDENTIFIER = mil.nga.mage;
35843584
PRODUCT_NAME = MAGE;
@@ -3612,7 +3612,7 @@
36123612
GCC_PREFIX_HEADER = "Mage/MAGE-Prefix.pch";
36133613
INFOPLIST_FILE = "Mage/MAGE-Info.plist";
36143614
IPHONEOS_DEPLOYMENT_TARGET = 13.4;
3615-
MARKETING_VERSION = 3.0.3;
3615+
MARKETING_VERSION = 3.0.4;
36163616
OTHER_LDFLAGS = "$(inherited)";
36173617
PRODUCT_BUNDLE_IDENTIFIER = mil.nga.mage;
36183618
PRODUCT_NAME = MAGE;

Mage/ObservationEditCardCollectionViewController.swift

Lines changed: 77 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -347,21 +347,33 @@ import MaterialComponents.MDCCard
347347
return form[FormKey.id.key] as? Int == observationForm[EventKey.formId.key] as? Int
348348
}
349349

350+
let fields: [[String: Any]] = eventForm?[FormKey.fields.key] as? [[String: Any]] ?? [];
351+
350352
var formPrimaryValue: String? = nil;
351353
var formSecondaryValue: String? = nil;
352-
if let primaryField = eventForm?[FormKey.primaryFeedField.key] as! String? {
353-
if let obsfield = observationForm[primaryField] as! String? {
354-
formPrimaryValue = obsfield;
354+
if let primaryFieldName = eventForm?[FormKey.primaryFeedField.key] as? String {
355+
if let primaryField = fields.first(where: { field in
356+
return (field[FieldKey.name.key] as? String) == primaryFieldName
357+
}) {
358+
if let obsfield = observationForm[primaryFieldName] {
359+
formPrimaryValue = Observation.fieldValueText(obsfield, field: primaryField)
360+
}
355361
}
356362
}
357-
if let secondaryField = eventForm?[FormKey.secondaryFeedField.key] as! String? {
358-
if let obsfield = observationForm[secondaryField] as! String? {
359-
formSecondaryValue = obsfield;
363+
364+
if let secondaryFieldName = eventForm?[FormKey.secondaryFeedField.key] as? String {
365+
if let secondaryField = fields.first(where: { field in
366+
return (field[FieldKey.name.key] as? String) == secondaryFieldName
367+
}) {
368+
if let obsfield = observationForm[secondaryFieldName] {
369+
formSecondaryValue = Observation.fieldValueText(obsfield, field: secondaryField)
370+
}
360371
}
361372
}
373+
362374
let formView = ObservationFormView(observation: self.observation!, form: observationForm, eventForm: eventForm, formIndex: index, viewController: self, observationFormListener: self, delegate: delegate, attachmentSelectionDelegate: self);
363-
if let safeScheme = scheme {
364-
formView.applyTheme(withScheme: safeScheme);
375+
if let scheme = scheme {
376+
formView.applyTheme(withScheme: scheme);
365377
}
366378
let formSpacerView = UIView(forAutoLayout: ());
367379
formSpacerView.addSubview(formView);
@@ -387,8 +399,8 @@ import MaterialComponents.MDCCard
387399
button.applyTextTheme(withScheme: globalErrorContainerScheme())
388400

389401
var tintColor: UIColor? = nil;
390-
if let safeColor = eventForm?[FormKey.color.key] as? String {
391-
tintColor = UIColor(hex: safeColor);
402+
if let color = eventForm?[FormKey.color.key] as? String {
403+
tintColor = UIColor(hex: color);
392404
} else {
393405
tintColor = scheme?.colorScheme.primaryColor
394406
}
@@ -405,8 +417,8 @@ import MaterialComponents.MDCCard
405417
// or reorder remove the form so the user is not distracted with a refresh
406418
observation?.addForm(toBeDeleted: sender.tag);
407419
cards[sender.tag].isHidden = true;
408-
if let safeObservation = self.observation {
409-
self.commonFieldView?.setObservation(observation: safeObservation);
420+
if let observation = self.observation {
421+
self.commonFieldView?.setObservation(observation: observation);
410422
}
411423

412424
setupFormDependentButtons();
@@ -418,8 +430,8 @@ import MaterialComponents.MDCCard
418430
self.cards[sender.tag].isHidden = false;
419431
self.observation?.removeForm(toBeDeleted: sender.tag);
420432
self.setupFormDependentButtons();
421-
if let safeObservation = self.observation {
422-
self.commonFieldView?.setObservation(observation: safeObservation);
433+
if let observation = self.observation {
434+
self.commonFieldView?.setObservation(observation: observation);
423435
}
424436
}
425437
messageAction.handler = actionHandler;
@@ -431,19 +443,32 @@ import MaterialComponents.MDCCard
431443
let eventForm: [String: Any]? = self.eventForms.first { (eventForm) -> Bool in
432444
return eventForm[FormKey.id.key] as? Int == form[EventKey.formId.key] as? Int
433445
}
446+
447+
let fields: [[String: Any]] = eventForm?[FormKey.fields.key] as? [[String: Any]] ?? [];
448+
434449
var formPrimaryValue: String? = nil;
435450
var formSecondaryValue: String? = nil;
436-
if let primaryField = eventForm?[FormKey.primaryField.key] as! String? {
437-
if let obsfield = form[primaryField] as? String {
438-
formPrimaryValue = obsfield;
451+
452+
if let primaryFieldName = eventForm?[FormKey.primaryFeedField.key] as? String {
453+
if let primaryField = fields.first(where: { field in
454+
return (field[FieldKey.name.key] as? String) == primaryFieldName
455+
}) {
456+
if let obsfield = form[primaryFieldName] {
457+
formPrimaryValue = Observation.fieldValueText(obsfield, field: primaryField)
458+
}
439459
}
440460
}
441-
if let secondaryField = eventForm?[FormKey.secondaryField.key] as! String? {
442-
// TODO: handle non strings
443-
if let obsfield = form[secondaryField] as! String? {
444-
formSecondaryValue = obsfield;
461+
462+
if let secondaryFieldName = eventForm?[FormKey.secondaryFeedField.key] as? String {
463+
if let secondaryField = fields.first(where: { field in
464+
return (field[FieldKey.name.key] as? String) == secondaryFieldName
465+
}) {
466+
if let obsfield = form[secondaryFieldName] {
467+
formSecondaryValue = Observation.fieldValueText(obsfield, field: secondaryField)
468+
}
445469
}
446470
}
471+
447472
cards[index].header = formPrimaryValue;
448473
cards[index].subheader = formSecondaryValue;
449474
}
@@ -452,10 +477,10 @@ import MaterialComponents.MDCCard
452477
// allow MDCButton ink ripple
453478
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { [self] in
454479
removeDeletedForms();
455-
guard let safeObservation = self.observation else {
480+
guard let observation = self.observation else {
456481
return
457482
}
458-
self.delegate?.reorderForms(observation: safeObservation);
483+
self.delegate?.reorderForms(observation: observation);
459484
}
460485
}
461486

@@ -480,16 +505,16 @@ import MaterialComponents.MDCCard
480505

481506
@objc func saveObservation(sender: UIBarButtonItem) {
482507
removeDeletedForms();
483-
guard let safeObservation = self.observation else { return }
508+
guard let observation = self.observation else { return }
484509
if (checkObservationValidity()) {
485-
self.delegate?.saveObservation(observation: safeObservation);
510+
self.delegate?.saveObservation(observation: observation);
486511
}
487512
}
488513

489514
func checkObservationValidity() -> Bool {
490515
var valid: Bool = false;
491-
if let safeCommonFieldView = commonFieldView {
492-
valid = safeCommonFieldView.checkValidity(enforceRequired: true)
516+
if let commonFieldView = commonFieldView {
517+
valid = commonFieldView.checkValidity(enforceRequired: true)
493518
} else {
494519
valid = true;
495520
}
@@ -543,14 +568,15 @@ import MaterialComponents.MDCCard
543568

544569
// check each form for min max
545570
var formIdCount: [Int : Int] = [ : ];
546-
if let safeObservation = self.observation, let safeProperties = safeObservation.properties {
547-
if (safeProperties.keys.contains(ObservationKey.forms.key)) {
548-
let observationForms: [[String: Any]] = safeProperties[ObservationKey.forms.key] as! [[String: Any]];
549-
let formsToBeDeleted = observation?.getFormsToBeDeleted() ?? IndexSet();
550-
for (index, form) in observationForms.enumerated() {
551-
if (!formsToBeDeleted.contains(index)) {
552-
let formId = form[EventKey.formId.key] as! Int;
553-
formIdCount[formId] = (formIdCount[formId] ?? 0) + 1;
571+
if let observation = self.observation, let properties = observation.properties {
572+
if (properties.keys.contains(ObservationKey.forms.key)) {
573+
if let observationForms: [[String: Any]] = properties[ObservationKey.forms.key] as? [[String: Any]] {
574+
let formsToBeDeleted = observation.getFormsToBeDeleted();
575+
for (index, form) in observationForms.enumerated() {
576+
if (!formsToBeDeleted.contains(index)) {
577+
let formId = form[EventKey.formId.key] as! Int;
578+
formIdCount[formId] = (formIdCount[formId] ?? 0) + 1;
579+
}
554580
}
555581
}
556582
}
@@ -638,8 +664,8 @@ import MaterialComponents.MDCCard
638664
self.observation?.properties = observationProperties;
639665
let previousStackViewHeight = stackView.bounds.size.height;
640666
let card:ExpandableCard = addObservationFormView(observationForm: newForm, index: observationForms.count - 1);
641-
if let safeScheme = scheme {
642-
card.applyTheme(withScheme: safeScheme);
667+
if let scheme = scheme {
668+
card.applyTheme(withScheme: scheme);
643669
}
644670
card.expanded = true;
645671
// scroll the view down to the form they just added but not quite all the way down because then it looks like you
@@ -680,8 +706,8 @@ extension ObservationEditCardCollectionViewController: ObservationCommonProperti
680706
observationProperties[ObservationKey.provider.key] = provider;
681707
observation?.properties = observationProperties;
682708
observation?.setGeometry(geometry);
683-
if let safeObservation = self.observation {
684-
commonFieldView?.setObservation(observation: safeObservation);
709+
if let observation = self.observation {
710+
commonFieldView?.setObservation(observation: observation);
685711
}
686712
}
687713
}
@@ -723,20 +749,29 @@ extension ObservationEditCardCollectionViewController: AttachmentSelectionDelega
723749
if (attachment.url == nil) {
724750
return;
725751
}
726-
attachmentViewCoordinator = AttachmentViewCoordinator(rootViewController: self.navigationController!, attachment: attachment, delegate: self, scheme: scheme);
752+
guard let nav = self.navigationController else {
753+
return;
754+
}
755+
attachmentViewCoordinator = AttachmentViewCoordinator(rootViewController: nav, attachment: attachment, delegate: self, scheme: scheme);
727756
attachmentViewCoordinator?.start();
728757
}
729758

730759
func selectedUnsentAttachment(_ unsentAttachment: [AnyHashable : Any]!) {
731-
attachmentViewCoordinator = AttachmentViewCoordinator(rootViewController: self.navigationController!, url: URL(fileURLWithPath: unsentAttachment["localPath"] as! String), contentType: (unsentAttachment["contentType"] as! String), delegate: self, scheme: scheme);
760+
guard let nav = self.navigationController else {
761+
return;
762+
}
763+
attachmentViewCoordinator = AttachmentViewCoordinator(rootViewController: nav, url: URL(fileURLWithPath: unsentAttachment["localPath"] as! String), contentType: (unsentAttachment["contentType"] as! String), delegate: self, scheme: scheme);
732764
attachmentViewCoordinator?.start();
733765
}
734766

735767
func selectedNotCachedAttachment(_ attachment: Attachment!, completionHandler handler: ((Bool) -> Void)!) {
736768
if (attachment.url == nil) {
737769
return;
738770
}
739-
attachmentViewCoordinator = AttachmentViewCoordinator(rootViewController: self.navigationController!, attachment: attachment, delegate: self, scheme: scheme);
771+
guard let nav = self.navigationController else {
772+
return;
773+
}
774+
attachmentViewCoordinator = AttachmentViewCoordinator(rootViewController: nav, attachment: attachment, delegate: self, scheme: scheme);
740775
attachmentViewCoordinator?.start();
741776
}
742777
}

Mage/ObservationFormTableViewCell.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,17 +108,27 @@ class ObservationFormTableViewCell: UITableViewCell {
108108
}
109109

110110
func configure(observationForm: [String : Any], eventForm: [String: Any], scheme: MDCContainerScheming?) {
111+
let fields: [[String: Any]] = eventForm[FormKey.fields.key] as? [[String: Any]] ?? [];
112+
111113
var formPrimaryValue: String? = nil;
112-
if let primaryField = eventForm[FormKey.primaryFeedField.key] as! String? {
113-
if let obsfield = observationForm[primaryField] as? String? {
114-
formPrimaryValue = obsfield;
114+
var formSecondaryValue: String? = nil;
115+
if let primaryFieldName = eventForm[FormKey.primaryFeedField.key] as? String {
116+
if let primaryField = fields.first(where: { field in
117+
return (field[FieldKey.name.key] as? String) == primaryFieldName
118+
}) {
119+
if let obsfield = observationForm[primaryFieldName] {
120+
formPrimaryValue = Observation.fieldValueText(obsfield, field: primaryField)
121+
}
115122
}
116123
}
117124

118-
var formSecondaryValue: String? = nil;
119-
if let secondaryField = eventForm[FormKey.secondaryFeedField.key] as! String? {
120-
if let obsfield = observationForm[secondaryField] as? String? {
121-
formSecondaryValue = obsfield;
125+
if let secondaryFieldName = eventForm[FormKey.secondaryFeedField.key] as? String {
126+
if let secondaryField = fields.first(where: { field in
127+
return (field[FieldKey.name.key] as? String) == secondaryFieldName
128+
}) {
129+
if let obsfield = observationForm[secondaryFieldName] {
130+
formSecondaryValue = Observation.fieldValueText(obsfield, field: secondaryField)
131+
}
122132
}
123133
}
124134

0 commit comments

Comments
 (0)