From 223939da6fa93f74ed8150005a4163cc838933df Mon Sep 17 00:00:00 2001 From: Vladimir Rubin Date: Sun, 22 Dec 2024 22:52:30 +0200 Subject: [PATCH] feat: calendar view --- lib/exmr_web/live/exam_live/index.ex | 2 + lib/exmr_web/live/exam_live/index.html.heex | 80 +++++++++++++++------ 2 files changed, 59 insertions(+), 23 deletions(-) diff --git a/lib/exmr_web/live/exam_live/index.ex b/lib/exmr_web/live/exam_live/index.ex index d304dbc..501ec7a 100644 --- a/lib/exmr_web/live/exam_live/index.ex +++ b/lib/exmr_web/live/exam_live/index.ex @@ -12,6 +12,8 @@ defmodule ExmrWeb.ExamLive.Index do |> assign(:sort_by, "date") |> assign(:live_action, :index) |> assign(exam: %{}) + |> assign(events: Enum.group_by(Exams.list_exams(), & &1.date)) + |> assign(current_month: Date.utc_today()) {:ok, socket} end diff --git a/lib/exmr_web/live/exam_live/index.html.heex b/lib/exmr_web/live/exam_live/index.html.heex index 6b9b2c7..a80ae44 100644 --- a/lib/exmr_web/live/exam_live/index.html.heex +++ b/lib/exmr_web/live/exam_live/index.html.heex @@ -27,38 +27,72 @@ {exam.date} | {case Date.diff(exam.date, Date.utc_today()) do - 0 -> gettext("Today") - 1 -> gettext("Tommorow") - x when x > 1 -> ngettext("Tomorrow", "%{count} days left", x) - x when x < 0 -> ngettext("Yesterday", "%{count} days passed", x * -1) - end} + 0 -> gettext("Today") + 1 -> gettext("Tommorow") + x when x > 1 -> ngettext("Tomorrow", "%{count} days left", x) + x when x < 0 -> ngettext("Yesterday", "%{count} days passed", x * -1) + end} - - <.modal :if={@live_action in [:new, :edit]} id="exam-modal" show on_cancel={JS.patch(~p"/exams")}> - <.live_component - module={ExmrWeb.ExamLive.FormComponent} - id={@exam.id || :new} - title={@page_title} - action={@live_action} - exam={@exam} - patch={~p"/exams"} - /> + <.live_component module={ExmrWeb.ExamLive.FormComponent} id={@exam.id || :new} title={@page_title} + action={@live_action} exam={@exam} patch={~p"/exams"} /> + +
+ + + + + + + + +
+ + <%= for day <- ~w(Sun Mon Tue Wed Thu Fri Sat) do %> +
{day}
+ <% end %> + + + <%= for _ <- 1..(Date.day_of_week(@current_month) - 1) do %> +
+ <% end %> + + + <%= for day <- 1..Date.days_in_month(@current_month) do %> + <% {:ok, date}=Date.new(@current_month.year, @current_month.month, day) %> + +
+
{day}
+ + + + <% IO.puts("Date: #{date}") %> + <% IO.inspect(Map.get(@events, date)) %> + <%= case Map.get(@events, date) do %> + <% nil -> %> + + <% events -> %> +
    + <%= for event <- events do %> +
  • {event.subject}
  • + <% end %> +
+ <% end %> +
+ <% end %> +
+