From eab4b5503eecec64f42101ed1ef7d27a7770dbc9 Mon Sep 17 00:00:00 2001 From: Esdras Eduardo Date: Tue, 1 Aug 2023 15:25:03 +0800 Subject: [PATCH] Add layouts and Phoenix.VerifiedRoutes --- lib/ash_admin/components/layouts.ex | 61 - lib/ash_admin/layouts.ex | 24 + lib/ash_admin/layouts/root.html.heex | 29 + .../resource_live/index.ex} | 207 +- .../live/resource_live/index.html.heex | 41 + lib/ash_admin/router.ex | 57 +- lib/ash_admin/web.ex | 77 +- priv/static/assets/app.css | 2329 ++++++- priv/static/assets/app.js | 5900 ++++++++++++++++- test/page_live_test.exs | 2 +- 10 files changed, 8463 insertions(+), 264 deletions(-) delete mode 100644 lib/ash_admin/components/layouts.ex create mode 100644 lib/ash_admin/layouts.ex create mode 100644 lib/ash_admin/layouts/root.html.heex rename lib/ash_admin/{pages/page_live.ex => live/resource_live/index.ex} (81%) create mode 100644 lib/ash_admin/live/resource_live/index.html.heex diff --git a/lib/ash_admin/components/layouts.ex b/lib/ash_admin/components/layouts.ex deleted file mode 100644 index bfc3140..0000000 --- a/lib/ash_admin/components/layouts.ex +++ /dev/null @@ -1,61 +0,0 @@ -defmodule AshAdmin.Layouts do - @moduledoc false - use AshAdmin.Web, :html - use Phoenix.Component - - js_path = Path.join(__DIR__, "../../../priv/static/assets/app.js") - css_path = Path.join(__DIR__, "../../../priv/static/assets/app.css") - - @external_resource js_path - @external_resource css_path - - @app_js File.read!(js_path) - @app_css File.read!(css_path) - - def render("app.js", _), do: @app_js - def render("app.css", _), do: @app_css - - def render("root.html", assigns) do - ~H""" - - - - - - - <%= Phoenix.HTML.Tag.csrf_meta_tag() %> - <%= assigns[:page_title] || "Ash Admin" %> - - - - - - - - <%= @inner_content %> - - - - """ - end - - def render(assigns) do - ~H""" - ... - """ - end - - def live_socket_path(conn) do - [Enum.map(conn.script_name, &["/" | &1]) | conn.private.live_socket_path] - end -end diff --git a/lib/ash_admin/layouts.ex b/lib/ash_admin/layouts.ex new file mode 100644 index 0000000..ae9e430 --- /dev/null +++ b/lib/ash_admin/layouts.ex @@ -0,0 +1,24 @@ +defmodule AshAdmin.Layouts do + use AshAdmin.Web, :html + + embed_templates "layouts/*" + + def live_socket_path(conn) do + [Enum.map(conn.script_name, &["/" | &1]) | conn.private.live_socket_path] + end + + def asset_hash("/statics/" <> path) do + file = Application.app_dir(:ash_admin, ["priv", "static", path]) + |> File.read!() + + :crypto.hash(:md5, file) + |> Base.encode16(case: :lower) + end + + def asset_path(conn, asset) do + hash = asset_hash(asset) + + ash_admin_path(conn, "#{asset}?vsn=#{hash}") + end + +end diff --git a/lib/ash_admin/layouts/root.html.heex b/lib/ash_admin/layouts/root.html.heex new file mode 100644 index 0000000..649c409 --- /dev/null +++ b/lib/ash_admin/layouts/root.html.heex @@ -0,0 +1,29 @@ + + + + + + + + <%= assigns[:page_title] || "Ash Admin" %> + + + + + +