Moved datevalidation rules to chatbot
This commit is contained in:
parent
5e36106d66
commit
44c44a83ae
@ -207,7 +207,6 @@
|
|||||||
94CA227D24058534002D6750 /* VerizonNHGeDS-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 94CA227924058533002D6750 /* VerizonNHGeDS-Regular.otf */; };
|
94CA227D24058534002D6750 /* VerizonNHGeDS-Regular.otf in Resources */ = {isa = PBXBuildFile; fileRef = 94CA227924058533002D6750 /* VerizonNHGeDS-Regular.otf */; };
|
||||||
94CA227E24058534002D6750 /* VerizonNHGeDS-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 94CA227A24058533002D6750 /* VerizonNHGeDS-Bold.otf */; };
|
94CA227E24058534002D6750 /* VerizonNHGeDS-Bold.otf in Resources */ = {isa = PBXBuildFile; fileRef = 94CA227A24058533002D6750 /* VerizonNHGeDS-Bold.otf */; };
|
||||||
94F6516D2437954100631BF9 /* Tabs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94F6516C2437954100631BF9 /* Tabs.swift */; };
|
94F6516D2437954100631BF9 /* Tabs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 94F6516C2437954100631BF9 /* Tabs.swift */; };
|
||||||
A5DB67FB26B2BE0D00DC6941 /* RuleDateValidationModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5DB67FA26B2BE0D00DC6941 /* RuleDateValidationModel.swift */; };
|
|
||||||
AA07EA912510A442009A2AE3 /* StarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA07EA902510A442009A2AE3 /* StarModel.swift */; };
|
AA07EA912510A442009A2AE3 /* StarModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA07EA902510A442009A2AE3 /* StarModel.swift */; };
|
||||||
AA07EA932510A451009A2AE3 /* Star.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA07EA922510A451009A2AE3 /* Star.swift */; };
|
AA07EA932510A451009A2AE3 /* Star.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA07EA922510A451009A2AE3 /* Star.swift */; };
|
||||||
AA0A257824766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0A257724766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift */; };
|
AA0A257824766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AA0A257724766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift */; };
|
||||||
@ -773,7 +772,6 @@
|
|||||||
94CA227A24058533002D6750 /* VerizonNHGeDS-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeDS-Bold.otf"; sourceTree = "<group>"; };
|
94CA227A24058533002D6750 /* VerizonNHGeDS-Bold.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeDS-Bold.otf"; sourceTree = "<group>"; };
|
||||||
94CA227B24058533002D6750 /* VerizonNHGeTX-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeTX-Regular.otf"; sourceTree = "<group>"; };
|
94CA227B24058533002D6750 /* VerizonNHGeTX-Regular.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = "VerizonNHGeTX-Regular.otf"; sourceTree = "<group>"; };
|
||||||
94F6516C2437954100631BF9 /* Tabs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tabs.swift; sourceTree = "<group>"; };
|
94F6516C2437954100631BF9 /* Tabs.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Tabs.swift; sourceTree = "<group>"; };
|
||||||
A5DB67FA26B2BE0D00DC6941 /* RuleDateValidationModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuleDateValidationModel.swift; sourceTree = "<group>"; };
|
|
||||||
AA07EA902510A442009A2AE3 /* StarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarModel.swift; sourceTree = "<group>"; };
|
AA07EA902510A442009A2AE3 /* StarModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StarModel.swift; sourceTree = "<group>"; };
|
||||||
AA07EA922510A451009A2AE3 /* Star.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Star.swift; sourceTree = "<group>"; };
|
AA07EA922510A451009A2AE3 /* Star.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Star.swift; sourceTree = "<group>"; };
|
||||||
AA0A257724766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableIconWithRightCaretBodyTextModel.swift; sourceTree = "<group>"; };
|
AA0A257724766C8A00862F64 /* ListLeftVariableIconWithRightCaretBodyTextModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListLeftVariableIconWithRightCaretBodyTextModel.swift; sourceTree = "<group>"; };
|
||||||
@ -1182,7 +1180,6 @@
|
|||||||
011D959E240453A1000E3791 /* RuleAllValueChangedModel.swift */,
|
011D959E240453A1000E3791 /* RuleAllValueChangedModel.swift */,
|
||||||
011D95A0240453D0000E3791 /* RuleEqualsModel.swift */,
|
011D95A0240453D0000E3791 /* RuleEqualsModel.swift */,
|
||||||
011D95A2240453F8000E3791 /* RuleRegexModel.swift */,
|
011D95A2240453F8000E3791 /* RuleRegexModel.swift */,
|
||||||
A5DB67FA26B2BE0D00DC6941 /* RuleDateValidationModel.swift */,
|
|
||||||
0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */,
|
0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */,
|
||||||
0A849EFD246F1775009F277F /* RuleEqualsIgnoreCaseModel.swift */,
|
0A849EFD246F1775009F277F /* RuleEqualsIgnoreCaseModel.swift */,
|
||||||
);
|
);
|
||||||
@ -2763,7 +2760,6 @@
|
|||||||
D29E28DA23D21AFA00ACEA85 /* StringAndMoleculeModel.swift in Sources */,
|
D29E28DA23D21AFA00ACEA85 /* StringAndMoleculeModel.swift in Sources */,
|
||||||
D260105D23D0BCD400764D80 /* Stack.swift in Sources */,
|
D260105D23D0BCD400764D80 /* Stack.swift in Sources */,
|
||||||
0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */,
|
0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */,
|
||||||
A5DB67FB26B2BE0D00DC6941 /* RuleDateValidationModel.swift in Sources */,
|
|
||||||
BB54C5212434D92F0038326C /* ListRightVariableButtonAllTextAndLinksModel.swift in Sources */,
|
BB54C5212434D92F0038326C /* ListRightVariableButtonAllTextAndLinksModel.swift in Sources */,
|
||||||
D2092349244A51D40044AD09 /* RadioSwatchModel.swift in Sources */,
|
D2092349244A51D40044AD09 /* RadioSwatchModel.swift in Sources */,
|
||||||
0A775F2824893937009EFB58 /* ThreeHeadlineBodyLinkModel.swift in Sources */,
|
0A775F2824893937009EFB58 /* ThreeHeadlineBodyLinkModel.swift in Sources */,
|
||||||
|
|||||||
@ -1,119 +0,0 @@
|
|||||||
//
|
|
||||||
// RuleDateValidationModel.swift
|
|
||||||
// MVMCoreUI
|
|
||||||
//
|
|
||||||
// Created by Tondapu, Alekhya on 29/07/21.
|
|
||||||
// Copyright © 2021 Verizon Wireless. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
public class RuleDateValidationModel: RulesProtocol {
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Properties
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
public static var identifier: String = "dateValidation"
|
|
||||||
public var type: String = RuleDateValidationModel.identifier
|
|
||||||
public var fields: [String]
|
|
||||||
public var date: String
|
|
||||||
public var dateFormat: String
|
|
||||||
public var errorMessage: [String: String]?
|
|
||||||
public var dateOperator: String
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Validation
|
|
||||||
//--------------------------------------------------
|
|
||||||
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
public func validate(_ fieldMolecules: [String: FormFieldProtocol],_ previousFieldValidity: [String: Bool]) -> (valid: Bool, fieldValidity: [String: Bool]) {
|
|
||||||
var valid = true
|
|
||||||
var compareValue: AnyHashable?
|
|
||||||
var previousValidity: [String: Bool] = [:]
|
|
||||||
var isValidDate: Bool = false
|
|
||||||
|
|
||||||
for formKey in fields {
|
|
||||||
guard let formField = fieldMolecules[formKey] else { continue }
|
|
||||||
|
|
||||||
if compareValue == nil {
|
|
||||||
compareValue = formField.formFieldValue()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Fetch date format and apply them to selected date from picker and validate date for comparision
|
|
||||||
let dateFormatter = DateFormatter()
|
|
||||||
dateFormatter.dateFormat = dateFormat
|
|
||||||
let validDate = dateFormatter.date(from: date) ?? Date()
|
|
||||||
let enteredDate = dateFormatter.date(from: compareValue as? String ?? "") ?? Date()
|
|
||||||
|
|
||||||
switch dateOperator {
|
|
||||||
case "greaterThanOrEqual":
|
|
||||||
isValidDate = enteredDate.isGreaterThanOrEqualToDate(validDate)
|
|
||||||
break
|
|
||||||
case "lessThanOrEqual":
|
|
||||||
isValidDate = enteredDate.isLessThanOrEqualToDate(validDate)
|
|
||||||
break
|
|
||||||
case "equal":
|
|
||||||
isValidDate = enteredDate.isEqualToDate(validDate)
|
|
||||||
break
|
|
||||||
case "greaterThan":
|
|
||||||
isValidDate = enteredDate.isGreaterThanDate(validDate)
|
|
||||||
break
|
|
||||||
case "lessThan":
|
|
||||||
isValidDate = enteredDate.isLessThanDate(validDate)
|
|
||||||
break
|
|
||||||
default: break
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isValidDate) {
|
|
||||||
valid = false
|
|
||||||
previousValidity[formKey] = valid
|
|
||||||
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(valid, rule: self)
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
var fieldValidity = valid
|
|
||||||
// If past rule is invalid for a field, the current rule should not flip the validity of a field
|
|
||||||
if let validity = previousFieldValidity[formKey], !validity, fieldValidity {
|
|
||||||
fieldValidity = false
|
|
||||||
}
|
|
||||||
(formField as? FormRuleWatcherFieldProtocol)?.setValidity(fieldValidity, rule: self)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
return (valid: valid, fieldValidity: previousValidity)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//--------------------------------------------------
|
|
||||||
// MARK: - Date Extension
|
|
||||||
//--------------------------------------------------
|
|
||||||
|
|
||||||
extension Date {
|
|
||||||
|
|
||||||
/// Note: This methods compare two dates without considering the time
|
|
||||||
func compareWithDate(_ date:Date) -> ComparisonResult {
|
|
||||||
let order = NSCalendar.current.compare(self, to: date, toGranularity: .day)
|
|
||||||
return order
|
|
||||||
}
|
|
||||||
|
|
||||||
func isLessThanDate(_ date: Date) -> Bool {
|
|
||||||
return compareWithDate(date) == .orderedAscending
|
|
||||||
}
|
|
||||||
|
|
||||||
func isGreaterThanDate(_ date: Date) -> Bool {
|
|
||||||
return compareWithDate(date) == .orderedDescending
|
|
||||||
}
|
|
||||||
|
|
||||||
func isEqualToDate(_ date: Date) -> Bool {
|
|
||||||
return compareWithDate(date) == .orderedSame
|
|
||||||
}
|
|
||||||
|
|
||||||
func isGreaterThanOrEqualToDate(_ date: Date) -> Bool {
|
|
||||||
return isEqualToDate(date) || isGreaterThanDate(date)
|
|
||||||
}
|
|
||||||
|
|
||||||
func isLessThanOrEqualToDate(_ date: Date) -> Bool {
|
|
||||||
return isEqualToDate(date) || isLessThanDate(date)
|
|
||||||
}
|
|
||||||
/// Note: This methods compare two dates without considering the time
|
|
||||||
}
|
|
||||||
@ -242,6 +242,5 @@ open class CoreUIModelMapping: ModelMapping {
|
|||||||
ModelRegistry.register(RuleEqualsModel.self)
|
ModelRegistry.register(RuleEqualsModel.self)
|
||||||
ModelRegistry.register(RuleEqualsIgnoreCaseModel.self)
|
ModelRegistry.register(RuleEqualsIgnoreCaseModel.self)
|
||||||
ModelRegistry.register(RuleRegexModel.self)
|
ModelRegistry.register(RuleRegexModel.self)
|
||||||
ModelRegistry.register(RuleDateValidationModel.self)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user