Files
Claper/lib/claper_web/views/layout_view.ex
Raúl R Pearson 2a3a497130 Expand events tests (#175)
* Add with_env.sh as dev.sh replacement

This new script can load env vars from any path, supplied with the
optional --env option (still defaults to .env) and accepts any arbitrary
command after that: `mix phx.new`, `iex -S mix phx.server`, `mix test`.
This provides support for having multiple `.env*` files. One for dev,
one for test, for example. The previous setup wasn't picking up the
right Postgres connection string for tests and was creating problems.

* Fix assorted compilation warnings

* Make :name and :started_at required in event changesets

* Refactor get_event!/2 to take ID and UUID

* Make event ordering more consistent

* Fix spelling of leaded_by with led_by

* Refactor get_managed_event!/3

While testing I found that this did not return `Ecto.NoResultsError`
when no events were found. This new version does and it also uses a
single database query.

* Make get_different_event_with_code/2 private

* Enable youtube.com pattern for YouTube embeds

* Refactor duplicate_event/2

When duplicating an event without a presentation, an error was raised. I
attempted to fix that and ended up cleaning up the implementation a bit.
I also discovered issue #178 was raised, so I fixed the implementation
to skip copying `vote_count` for poll options.

* Add activity leader test fixture

* Make DataCase db connection check out conditional

* Expand event tests
2025-10-26 17:00:24 +01:00

64 lines
1.4 KiB
Elixir

defmodule ClaperWeb.LayoutView do
import Phoenix.Component
use ClaperWeb, :view
# Phoenix LiveDashboard is available only in development by default,
# so we instruct Elixir to not warn if the dashboard route is missing.
@compile {:no_warn_undefined, {Routes, :live_dashboard_path, 2}}
def active_class(conn, path) do
current_path = Path.join(["/" | conn.path_info])
if path == current_path do
"bg-gray-900 text-white"
else
""
end
end
def active_live_class(conn, path) do
if path == conn.host_uri do
"bg-gray-900 text-white"
else
""
end
end
def get_section_path(conn) do
section = Enum.at(conn.path_info, 1)
case section do
"users" -> ~p"/admin/users"
"events" -> ~p"/admin/events"
"oidc_providers" -> ~p"/admin/oidc_providers"
_ -> ~p"/admin"
end
end
def active_link(%Plug.Conn{} = conn, text, opts) do
class =
[opts[:class], active_class(conn, opts[:to])]
|> Enum.filter(& &1)
|> Enum.join(" ")
opts =
opts
|> Keyword.put(:class, class)
link(text, opts)
end
def active_link(%Phoenix.LiveView.Socket{} = conn, text, opts) do
class =
[opts[:class], active_live_class(conn, opts[:to])]
|> Enum.filter(& &1)
|> Enum.join(" ")
opts =
opts
|> Keyword.put(:class, class)
link(text, opts)
end
end