defmodule SyntropyWeb.Layouts do use SyntropyWeb, :html embed_templates "layouts/*" @local_platform_url "http://127.0.0.1:3103" def platform_url(path \\ "/") do base_url() |> append_path(path) end def operator_nav_class(assigns, path) do if current_path(assigns) == path do "operator-nav-link operator-nav-link--active" else "operator-nav-link" end end defp current_path(assigns) do cond do is_binary(assigns[:current_path]) -> assigns.current_path match?(%{request_path: request_path} when is_binary(request_path), assigns[:conn]) -> assigns.conn.request_path true -> current_path_from_live_view(assigns[:socket]) end end defp current_path_from_live_view(%{view: SyntropyWeb.LatticeLive}), do: "/" defp current_path_from_live_view(%{view: SyntropyWeb.TasksLive}), do: "/tasks" defp current_path_from_live_view(%{view: SyntropyWeb.HistoryLive}), do: "/history" defp current_path_from_live_view(%{view: SyntropyWeb.AgentLive}), do: "/" defp current_path_from_live_view(_socket), do: nil defp base_url do configured = :syntropy |> Application.get_env(SyntropyWeb.Navigation, []) |> Keyword.get(:platform_url) cond do is_binary(configured) and String.trim(configured) != "" -> configured Application.get_env(:syntropy, :environment, :dev) in [:dev, :test] -> @local_platform_url true -> nil end end defp append_path(nil, _path), do: nil defp append_path(url, path) do url |> String.trim_trailing("/") |> Kernel.<>(path) end end