e15ff93465
- MealType gains breakfast/snack (chronological order drives slot/row order). - AppSettings.activeMealTypes: single source of truth for enabled meals, backed by new optional enabledMealTypesRaw with legacy mealWindows fallback — additive migration, keeps pre-2.0 installs and iCloud snapshots working. Legacy field kept coherent by the setter. time(for:) resolves per-meal event times (breakfast 8:00 / snack 17:00 defaults on old stores). - Replaced the 5 duplicated mealWindows→[MealType] derivations (slot sync, default plan creation, week calendar, export view) with activeMealTypes. - CalendarService: per-type event names and times. - Export styles: per-type accent colors and gradients. - Widget: generic meals list (N rows) instead of hardcoded lunch/dinner; compact families fall back to main meals when >2 are active. - Settings: 4 meal toggles (min 1) replace the 3-option picker. - Onboarding: meal step is now multi-select over the 4 types. - iCloud sync: enabledMealTypesRaw synced (optional, pre-2.0 compatible). - Localized breakfast/snack in all 6 languages. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BkanrydYtrme8wipTzWssG
66 lines
2.4 KiB
Swift
66 lines
2.4 KiB
Swift
import Foundation
|
|
import SwiftData
|
|
|
|
struct DefaultDataService {
|
|
|
|
static func createDefaultTags(context: ModelContext, saveImmediately: Bool = true) {
|
|
let defaults: [(name: String, nameEN: String, color: String, maxPerWeek: Int?, noConsecutive: Bool, noDuplicateInDay: Bool, mealTypeRestriction: String?, sortOrder: Int)] = [
|
|
("Carne", "Meat", "#E74C3C", 3, true, true, nil, 0),
|
|
("Pescado", "Fish", "#3498DB", 2, true, true, nil, 1),
|
|
("Legumbres", "Legumes", "#95A5A6", 2, false, true, nil, 2),
|
|
("Verduras", "Vegetables", "#2ECC71", nil, false, false, nil, 3),
|
|
("Huevos", "Eggs", "#F1C40F", 2, false, true, nil, 4),
|
|
("Pasta/Arroz", "Pasta/Rice", "#D4AC6E", 3, true, false, nil, 5),
|
|
("Solo Cena", "Dinner Only", "#9B59B6", nil, false, false, "dinner", 6),
|
|
("Solo Comida", "Lunch Only", "#E67E22", nil, false, false, "lunch", 7),
|
|
("Con Gluten", "Contains Gluten", "#8B4513", nil, false, false, nil, 8),
|
|
("Sin Gluten", "Gluten Free", "#1ABC9C", nil, false, false, nil, 9)
|
|
]
|
|
|
|
for d in defaults {
|
|
let tag = Tag(
|
|
name: d.name,
|
|
nameEN: d.nameEN,
|
|
color: d.color,
|
|
maxPerWeek: d.maxPerWeek,
|
|
noConsecutive: d.noConsecutive,
|
|
noDuplicateInDay: d.noDuplicateInDay,
|
|
mealTypeRestriction: d.mealTypeRestriction,
|
|
isDefault: true,
|
|
sortOrder: d.sortOrder
|
|
)
|
|
context.insert(tag)
|
|
}
|
|
|
|
if saveImmediately {
|
|
try? context.save()
|
|
}
|
|
}
|
|
|
|
static func createDefaultSettings(context: ModelContext) {
|
|
let settings = AppSettings()
|
|
context.insert(settings)
|
|
try? context.save()
|
|
}
|
|
|
|
static func createWeekPlan(for weekStart: Date, settings: AppSettings, context: ModelContext) -> WeekPlan {
|
|
let plan = WeekPlan(weekStartDate: weekStart)
|
|
context.insert(plan)
|
|
|
|
let maxDay = settings.includeWeekends ? 6 : 4
|
|
let mealTypes: [String] = settings.activeMealTypes.map(\.rawValue)
|
|
|
|
for day in 0...maxDay {
|
|
for mealType in mealTypes {
|
|
let slot = MealSlot(dayOfWeek: day, mealType: mealType)
|
|
slot.weekPlan = plan
|
|
plan.slots.append(slot)
|
|
context.insert(slot)
|
|
}
|
|
}
|
|
|
|
try? context.save()
|
|
return plan
|
|
}
|
|
}
|