Jul 13 - Update codes to catch up with the web app updates: scheduled inspection and issue's handler

This commit is contained in:
Nguyen Ngo
2026-07-13 14:03:41 -04:00
parent c05f0029fb
commit 20f9a99646
22 changed files with 5800 additions and 18 deletions
+23
View File
@@ -153,6 +153,20 @@ final class LocalIssue {
/// Nil when unassigned. Updated on every pullAssignedIssues().
var assignedToName: String?
// Handler ("Handled By", phase35)
// Who resolves the issue: internal (our staff) | facility (facility's own
// staff) | vendor (external contractor). Synced from the server; the
// inspector may also set it from Issue Detail. nil-default optionals
// SwiftData lightweight migration safe.
var handlerType: String? // "internal" | "facility" | "vendor"
var handlerLabel: String? // human-readable label from server
var facilityHandlerName: String?
var facilityHandlerContact: String?
var facilityHandlerNotes: String?
var vendorName: String?
var vendorContact: String?
var vendorNotes: String?
// Explicit inverse declared so SwiftData has an unambiguous relationship
// graph at schema-build time. Without it the relationship is implicit,
// which can cause migration warnings or incorrect cascade behaviour on some
@@ -192,6 +206,15 @@ final class LocalIssue {
self.reportedByName = nil
self.areaNameCache = nil
self.assignedToName = nil
// Handler fields nil by default
self.handlerType = nil
self.handlerLabel = nil
self.facilityHandlerName = nil
self.facilityHandlerContact = nil
self.facilityHandlerNotes = nil
self.vendorName = nil
self.vendorContact = nil
self.vendorNotes = nil
}
var severityColor: String {
@@ -0,0 +1,47 @@
// Models/LocalScheduledInspection.swift
// --------------------------------------
// SwiftData model for planned/recurring inspection assignments (phase36).
//
// Read-only reference data pulled from the server (GET /api/v1/scheduled-inspections)
// and refreshed by SyncManager.pullScheduledInspections() never created or
// mutated on device. Surfaced in the "Scheduled" section on the Dashboard and
// My Inspections. Tapping "Start" opens the normal new-inspection flow with the
// facility + template preselected; the schedule lifecycle (fulfil / roll-forward)
// stays server-driven.
//
// All non-optional stored properties carry explicit inline defaults so SwiftData
// lightweight migration can add the new table without a migration plan.
import Foundation
import SwiftData
@Model
final class LocalScheduledInspection {
/// Server ID of the ScheduledInspection row stable unique identity.
@Attribute(.unique) var serverId: Int = 0
var facilityServerId: Int = 0
var facilityName: String = ""
var templateServerId: Int = 0
var templateName: String = ""
var inspectorId: Int? = nil
var frequency: String = "once" // once | daily | weekly | monthly
var frequencyLabel: String = "" // human-readable label from server
/// Raw ISO date string "YYYY-MM-DD" from the server (display fallback).
var dueDateString: String = ""
/// Parsed due date used for @Query sorting. Nil if the string was absent.
var nextDue: Date? = nil
var isOverdue: Bool = false
var notes: String? = nil
/// Last time this row was refreshed from the server pull.
var updatedAt: Date = Date()
init(serverId: Int) {
self.serverId = serverId
}
}