06/23 Fix inspection layout display and exported PDF file (sent via email)
This commit is contained in:
@@ -459,7 +459,7 @@ struct ExecuteInspectionView: View {
|
||||
let existingFormData = inspection.formData
|
||||
var data: [String: Any] = [:]
|
||||
for (k, v) in formValues {
|
||||
if let s = v as? String, s.hasPrefix("local://"),
|
||||
if v.hasPrefix("local://"),
|
||||
let saved = existingFormData[k] as? String, saved.hasPrefix("uploads/") {
|
||||
data[k] = saved
|
||||
} else {
|
||||
@@ -532,7 +532,7 @@ struct ExecuteInspectionView: View {
|
||||
let existingFormData = inspection.formData
|
||||
var data: [String: Any] = [:]
|
||||
for (k, v) in formValues {
|
||||
if let s = v as? String, s.hasPrefix("local://"),
|
||||
if v.hasPrefix("local://"),
|
||||
let saved = existingFormData[k] as? String, saved.hasPrefix("uploads/") {
|
||||
// processPhotoQueue already uploaded this photo — keep the server path
|
||||
data[k] = saved
|
||||
|
||||
@@ -678,9 +678,17 @@ struct ReadOnlyGridFormView: View {
|
||||
let skipTypes: Set<String> = ["label", "section",
|
||||
"button_submit", "button_print", "button_email"]
|
||||
|
||||
// Sort schema by (row, col) once — same as web PDF and InspectionPDFGenerator.
|
||||
let sortedSchema = schema.sorted {
|
||||
let r0 = $0["row"] as? Int ?? 0, r1 = $1["row"] as? Int ?? 0
|
||||
if r0 != r1 { return r0 < r1 }
|
||||
let c0 = $0["col"] as? Int ?? 0, c1 = $1["col"] as? Int ?? 0
|
||||
return c0 < c1
|
||||
}
|
||||
|
||||
// Pass 1 — answered data field IDs
|
||||
var answeredIds = Set<String>()
|
||||
for f in schema {
|
||||
for f in sortedSchema {
|
||||
guard let ftype = f["type"] as? String, !skipTypes.contains(ftype) else { continue }
|
||||
let fid = f["id"] as? String ?? (f["id"] as? Int).map(String.init) ?? ""
|
||||
let val = formValues[fid] ?? ""
|
||||
@@ -691,7 +699,7 @@ struct ReadOnlyGridFormView: View {
|
||||
// Pass 2 — label IDs that immediately precede an answered field
|
||||
var visibleLabelIds = Set<String>()
|
||||
var lbuf: [String] = []
|
||||
for f in schema {
|
||||
for f in sortedSchema {
|
||||
let ftype = f["type"] as? String ?? ""
|
||||
let fid = f["id"] as? String ?? (f["id"] as? Int).map(String.init) ?? ""
|
||||
if ftype == "label" {
|
||||
@@ -705,7 +713,7 @@ struct ReadOnlyGridFormView: View {
|
||||
// Pass 3 — section IDs that precede at least one answered field
|
||||
var visibleSectionIds = Set<String>()
|
||||
var pendingSecId: String? = nil
|
||||
for f in schema {
|
||||
for f in sortedSchema {
|
||||
let ftype = f["type"] as? String ?? ""
|
||||
let fid = f["id"] as? String ?? (f["id"] as? Int).map(String.init) ?? ""
|
||||
if ftype == "section" {
|
||||
@@ -715,18 +723,20 @@ struct ReadOnlyGridFormView: View {
|
||||
}
|
||||
}
|
||||
|
||||
// Pass 4 — group fields by original row, keep schema order
|
||||
// Pass 4 — group fields by original row, keep schema order.
|
||||
// sortedSchema already computed above — reuse it.
|
||||
var rowGroups: [Int: [[String: Any]]] = [:]
|
||||
var rowOrder: [Int] = []
|
||||
for f in schema {
|
||||
for f in sortedSchema {
|
||||
let row = f["row"] as? Int ?? 1
|
||||
if rowGroups[row] == nil { rowOrder.append(row); rowGroups[row] = [] }
|
||||
rowGroups[row]!.append(f)
|
||||
}
|
||||
|
||||
// Pass 5 — for each row, collect visible fields; skip rows with none
|
||||
// Pass 5 — for each row, collect visible fields; skip rows with none.
|
||||
// Iterate in rowOrder (insertion order of sorted schema = row order).
|
||||
var result: [RowGroup] = []
|
||||
for origRow in rowOrder.sorted() {
|
||||
for origRow in rowOrder {
|
||||
guard let group = rowGroups[origRow] else { continue }
|
||||
var visibleInRow: [[String: Any]] = []
|
||||
for f in group {
|
||||
|
||||
Reference in New Issue
Block a user