-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added support to view activities assessment point entries filte…
…red by class - added `:classes_ids` opt to `Assessments.list_activity_students_entries/2` - added `:classes_ids` and `:preload` opts to `Schools.list_user_classes/2` - created `LantternWeb.Helpers.NotifyHelpers` to centralize `notify_parent` and `notify_component` calls (we need to replace local implementations with the helper yet) - created `SchoolLive.ClassFilterFormComponent`
- Loading branch information
Showing
10 changed files
with
293 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule LantternWeb.Helpers.NotifyHelpers do | ||
def notify_parent(module, msg, %{notify_parent: true}), | ||
do: send(self(), {module, msg}) | ||
|
||
def notify_parent(_module, _msg, _assigns), do: nil | ||
|
||
def notify_component(module, msg, %{notify_component: %Phoenix.LiveComponent.CID{} = cid}), | ||
do: Phoenix.LiveView.send_update(cid, action: {module, msg}) | ||
|
||
def notify_component(_module, _msg, _assigns), do: nil | ||
end |
55 changes: 55 additions & 0 deletions
55
lib/lanttern_web/live/school_live/class_filter_form_component.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
defmodule LantternWeb.SchoolLive.ClassFilterFormComponent do | ||
@moduledoc """ | ||
Class filter form component. | ||
This form is used inside a `<.slide_over>` component, | ||
where the "submit" button is rendered. | ||
""" | ||
|
||
use LantternWeb, :live_component | ||
alias Lanttern.Schools | ||
import LantternWeb.Helpers.NotifyHelpers | ||
|
||
def render(assigns) do | ||
~H""" | ||
<div> | ||
<.form id="class-filter-form" for={@form} phx-submit="save" phx-target={@myself}> | ||
<div class="flex gap-6"> | ||
<fieldset class="flex-1"> | ||
<legend class="text-base font-semibold leading-6 text-ltrn-subtle">Classes</legend> | ||
<div class="mt-4 divide-y divide-ltrn-lighter border-b border-t border-ltrn-lighter"> | ||
<.check_field | ||
:for={opt <- @classes} | ||
id={"class-#{opt.id}"} | ||
field={@form[:classes_ids]} | ||
opt={opt} | ||
/> | ||
</div> | ||
</fieldset> | ||
</div> | ||
</.form> | ||
</div> | ||
""" | ||
end | ||
|
||
# lifecycle | ||
|
||
def update(%{current_user: current_user} = assigns, socket) do | ||
classes_ids = Map.get(assigns, :classes_ids, []) | ||
|
||
{:ok, | ||
socket | ||
|> assign(assigns) | ||
|> assign(:classes, Schools.list_user_classes(current_user)) | ||
|> assign(:form, to_form(%{"classes_ids" => classes_ids}, as: :classes))} | ||
end | ||
|
||
# event handlers | ||
|
||
def handle_event("save", params, socket) do | ||
params = Map.get(params, "classes", %{"classes_ids" => []}) | ||
notify_parent(__MODULE__, {:save, params}, socket.assigns) | ||
notify_component(__MODULE__, {:save, params}, socket.assigns) | ||
{:noreply, socket} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.