defmodule Observer.Web.Layouts do @moduledoc """ This module provides layouts ## References: * https://github.com/oban-bg/oban_web/blob/main/lib/oban/web/components/layouts.ex """ use Observer.Web, :html embed_templates "layouts/*" alias Observer.Web.Assets alias Observer.Web.Components.Icons defp asset_path(conn, asset) when asset in [:css, :js] do hash = Assets.current_hash(asset) {_dash, _routing, meta} = conn.private.phoenix_live_view prefix = get_in(meta, [:extra, :session, Access.elem(2), Access.at(0)]) Phoenix.VerifiedRoutes.unverified_path( conn, conn.private.phoenix_router, "#{prefix}/#{asset}-#{hash}" ) end attr :params, :map, required: true attr :path, :string, default: nil def logo(assigns) do ~H"""

Observer WEB

""" end attr :params, :map, required: true attr :page, :atom, required: true attr :socket, :map, required: true attr :custom_pages, :list, default: [] def nav(assigns) do ~H""" """ end def footer(assigns) do assigns = assign(assigns, oss_version: Application.spec(:observer_web, :vsn) ) ~H""" """ end attr :name, :string attr :version, :string defp version(assigns) do ~H""" {@name} {if @version, do: "v#{@version}", else: "–"} """ end defp link_class(curr, page) do base = "flex items-center px-4 py-2.5 text-sm font-bold transition-all duration-200 text-gray-900 dark:text-white rounded-lg group" if curr == page do base <> " bg-gray-100 dark:bg-gray-700" else base <> " hover:text-black dark:hover:text-white hover:bg-cyan-500 dark:hover:bg-cyan-800" end end # Crashdump sits last since it is an occasional-use tool (see ObserverWeb.Crashdump). defp list_pages_by_params(%{"iframe" => "true"}) do [ :system, :tracing, :profiling, :processes, :applications, :network, :ets, :metrics, :logs, :crashdump ] end defp list_pages_by_params(_params) do [ :root, :system, :tracing, :profiling, :processes, :applications, :network, :ets, :metrics, :logs, :crashdump ] end @doc """ Renders flash notices. ## Examples <.flash kind={:info} flash={@flash} /> <.flash kind={:info} phx-mounted={show("#flash")}>Welcome Back! """ attr :id, :string, doc: "the optional id of flash container" attr :flash, :map, default: %{}, doc: "the map of flash messages to display" attr :title, :string, default: nil attr :kind, :atom, values: [:info, :error], doc: "used for styling and flash lookup" attr :rest, :global, doc: "the arbitrary HTML attributes to add to the flash container" slot :inner_block, doc: "the optional inner block that renders the flash message" def flash(assigns) do assigns = assign_new(assigns, :id, fn -> "flash-#{assigns.kind}" end) ~H"""
hide("##{@id}")} role="alert" class="fixed z-40 inset-0 flex items-end justify-center pointer-events-none md:py-3 md:px-4 sm:p-6 sm:items-start sm:justify-end" {@rest} >
<%= if @kind == :error do %>
<% else %>
<% end %>

{msg}

""" end def hide(js \\ %JS{}, selector) do JS.hide(js, to: selector, time: 200, transition: {"transition-all transform ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"} ) end end