Skip to content

Commit

Permalink
Info section fix (#81)
Browse files Browse the repository at this point in the history
* added section items

* added country name

* added rule result

* added new type of HCertValidity

* added Limited Validity

* changed func to show sections for rules

* added public initializer for InfoSection

* fixed initializer

* removed all before added new

Co-authored-by: Alexandr Chernyy <[email protected]>
  • Loading branch information
alexchornyi and pingus-nikalex authored Jul 7, 2021
1 parent f102355 commit bc84072
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Localization/SwiftDGC/en.xcloc/Localized Contents/en.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -1283,6 +1283,11 @@
<target>Vaccination</target>
<note/>
</trans-unit>
<trans-unit id="enum.HCertValidity.ruleInvalid" xml:space="preserve">
<source>Limited validity</source>
<target>Limited validity</target>
<note/>
</trans-unit>
<trans-unit id="enum.HCertValidity.invalid" xml:space="preserve">
<source>Invalid</source>
<target>Invalid</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"enum.HCertType.recovery" = "Recovery";
"enum.HCertValidity.valid" = "Valid";
"enum.HCertValidity.invalid" = "Invalid";
"enum.HCertValidity.invalid" = "Limited validity";
"header.cert-type" = "Certificate Type";
"header.dob" = "Date of Birth";
"header.std-fn" = "Standardised Family Name";
Expand Down
77 changes: 75 additions & 2 deletions Sources/Models/HCert.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public enum HCertType: String {
public enum HCertValidity: String {
case valid
case invalid
case ruleInvalid
}

let attributeKeys: [AttributeKey: [String]] = [
Expand All @@ -72,13 +73,30 @@ public enum InfoSectionStyle {
case fixedWidthFont
}

public enum RuleValidationResult: Int {
case error = 0
case passed
case open
}

public struct InfoSection {
public var header: String
public var content: String
public var style = InfoSectionStyle.normal
public var isPrivate = false
public var sectionItems: [InfoSection] = []
public var isExpanded: Bool = false
public var countryName: String?
public var ruleValidationResult: RuleValidationResult = .open

public init(header: String, content: String, style: InfoSectionStyle = .normal, isPrivate: Bool = false, countryName: String? = nil, ruleValidationResult: RuleValidationResult = .open) {
self.header = header
self.content = content
self.countryName = countryName
self.style = style
self.isPrivate = isPrivate
self.ruleValidationResult = ruleValidationResult
}
}

public struct HCertConfig {
Expand Down Expand Up @@ -190,10 +208,65 @@ public struct HCert {
validityFailures.append(contentsOf: statement.validityFailures)
}

public mutating func makeSectionForRuleError(errorString: String) {
info = [InfoSection(header: l10n("header.validity-errors"), content: errorString)]
//
public mutating func makeSectionForRuleError(infoSections: InfoSection) {
info.removeAll()
info = isValid ? [] : [
InfoSection(header: l10n("header.validity-errors"), content: validityFailures.joined(separator: " "))
]
info += [
InfoSection(
header: l10n("header.cert-type"),
content: certTypeString
)
] + personIdentifiers
info += [infoSections]
if let date = get(.dateOfBirth).string {
info += [
InfoSection(
header: l10n("header.dob"),
content: date
)
]
}
if let last = get(.lastNameStandardized).string {
info += [
InfoSection(
header: l10n("header.std-fn"),
content: last.replacingOccurrences(
of: "<",
with: String.zeroWidthSpace + "<" + String.zeroWidthSpace),
style: .fixedWidthFont
)
]
}
if let first = get(.firstNameStandardized).string {
info += [
InfoSection(
header: l10n("header.std-gn"),
content: first.replacingOccurrences(
of: "<",
with: String.zeroWidthSpace + "<" + String.zeroWidthSpace),
style: .fixedWidthFont
)
]
}
info += statement == nil ? [] : statement.info
info += [
InfoSection(
header: l10n("header.expires-at"),
content: exp.dateTimeStringUtc
),
InfoSection(
header: l10n("header.uvci"),
content: uvci,
style: .fixedWidthFont,
isPrivate: true
)
]
}

//

mutating func makeSections() {
info = isValid ? [] : [
Expand Down
1 change: 1 addition & 0 deletions Sources/SupportingFiles/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"enum.HCertType.recovery" = "Recovery";
"enum.HCertValidity.valid" = "Valid";
"enum.HCertValidity.invalid" = "Invalid";
"enum.HCertValidity.ruleInvalid" = "Limited validity";
"header.cert-type" = "Certificate Type";
"header.dob" = "Date of Birth";
"header.std-fn" = "Standardised Family Name";
Expand Down

0 comments on commit bc84072

Please sign in to comment.