feat: calendar view
This commit is contained in:
parent
d5f7ddf250
commit
223939da6f
2 changed files with 59 additions and 23 deletions
|
@ -12,6 +12,8 @@ defmodule ExmrWeb.ExamLive.Index do
|
||||||
|> assign(:sort_by, "date")
|
|> assign(:sort_by, "date")
|
||||||
|> assign(:live_action, :index)
|
|> assign(:live_action, :index)
|
||||||
|> assign(exam: %{})
|
|> assign(exam: %{})
|
||||||
|
|> assign(events: Enum.group_by(Exams.list_exams(), & &1.date))
|
||||||
|
|> assign(current_month: Date.utc_today())
|
||||||
|
|
||||||
{:ok, socket}
|
{:ok, socket}
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,30 +35,64 @@
|
||||||
</b>
|
</b>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
<button phx-click="edit" phx-value-id={exam.id}
|
||||||
phx-click="edit"
|
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-3 rounded-md">
|
||||||
phx-value-id={exam.id}
|
|
||||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-3 rounded-md"
|
|
||||||
>
|
|
||||||
{gettext("Edit")}
|
{gettext("Edit")}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button phx-click="remove" phx-value-id={exam.id}
|
||||||
phx-click="remove"
|
class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 rounded-md">
|
||||||
phx-value-id={exam.id}
|
|
||||||
class="bg-red-500 hover:bg-red-700 text-white font-bold py-2 px-3 rounded-md"
|
|
||||||
>
|
|
||||||
{gettext("Remove")}
|
{gettext("Remove")}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<.modal :if={@live_action in [:new, :edit]} id="exam-modal" show on_cancel={JS.patch(~p"/exams")}>
|
<.modal :if={@live_action in [:new, :edit]} id="exam-modal" show on_cancel={JS.patch(~p"/exams")}>
|
||||||
<.live_component
|
<.live_component module={ExmrWeb.ExamLive.FormComponent} id={@exam.id || :new} title={@page_title}
|
||||||
module={ExmrWeb.ExamLive.FormComponent}
|
action={@live_action} exam={@exam} patch={~p"/exams"} />
|
||||||
id={@exam.id || :new}
|
|
||||||
title={@page_title}
|
|
||||||
action={@live_action}
|
|
||||||
exam={@exam}
|
|
||||||
patch={~p"/exams"}
|
|
||||||
/>
|
|
||||||
</.modal>
|
</.modal>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<!-- Navigation -->
|
||||||
|
<!-- <div class="flex justify-between mb-4"> -->
|
||||||
|
<!-- <button phx-click="previous_month" class="px-2 py-1 bg-blue-200">Previous</button> -->
|
||||||
|
<!-- <h2>{@current_month |> Date.to_string() |> String.replace("-", " ")}</h2> -->
|
||||||
|
<!-- <button phx-click="next_month" class="px-2 py-1 bg-blue-200">Next</button> -->
|
||||||
|
<!-- </div> -->
|
||||||
|
|
||||||
|
<!-- Calendar -->
|
||||||
|
<div class="grid grid-cols-7 gap-1">
|
||||||
|
<!-- Weekdays -->
|
||||||
|
<%= for day <- ~w(Sun Mon Tue Wed Thu Fri Sat) do %>
|
||||||
|
<div class="font-bold text-center">{day}</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<!-- Empty spaces for previous month -->
|
||||||
|
<%= for _ <- 1..(Date.day_of_week(@current_month) - 1) do %>
|
||||||
|
<div></div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<!-- Days of the month -->
|
||||||
|
<%= for day <- 1..Date.days_in_month(@current_month) do %>
|
||||||
|
<% {:ok, date}=Date.new(@current_month.year, @current_month.month, day) %>
|
||||||
|
|
||||||
|
<div class={["border rounded p-3", @current_month == date && "bg-zinc-800"]}>
|
||||||
|
<div class="text-sm font-bold">{day}</div>
|
||||||
|
|
||||||
|
<!-- Render events for the current day -->
|
||||||
|
|
||||||
|
<% IO.puts("Date: #{date}") %>
|
||||||
|
<% IO.inspect(Map.get(@events, date)) %>
|
||||||
|
<%= case Map.get(@events, date) do %>
|
||||||
|
<% nil -> %>
|
||||||
|
<!-- No events for this day -->
|
||||||
|
<% events -> %>
|
||||||
|
<ul class="mt-2 text-xs">
|
||||||
|
<%= for event <- events do %>
|
||||||
|
<li>{event.subject}</li>
|
||||||
|
<% end %>
|
||||||
|
</ul>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue