diff --git a/dashboards/views/04c_madplan.yaml b/dashboards/views/04c_madplan.yaml index ed8133a..41a9f85 100644 --- a/dashboards/views/04c_madplan.yaml +++ b/dashboards/views/04c_madplan.yaml @@ -80,29 +80,23 @@ cards: - background: none - box-shadow: none custom_fields: - week: > + week: | [[[ - const items = entity.attributes.items || []; + if (!entity || !entity.attributes || !entity.attributes.items) + return 'Ingen madplan data'; + const items = entity.attributes.items; const dayNames = ['Søndag','Mandag','Tirsdag','Onsdag','Torsdag','Fredag','Lørdag']; const today = new Date().toISOString().slice(0,10); - - // Build date->meal map const meals = {}; - items.forEach(item => { + items.forEach(function(item) { if (item.recipe && item.recipe.name) { - meals[item.date] = { - name: item.recipe.name, - slug: item.recipe.slug || '' - }; + meals[item.date] = { name: item.recipe.name, slug: item.recipe.slug || '' }; } }); - - // Generate 7 days starting from Monday of current week const now = new Date(); const dayOfWeek = now.getDay(); const monday = new Date(now); monday.setDate(now.getDate() - (dayOfWeek === 0 ? 6 : dayOfWeek - 1)); - let html = '