From c0dda6ec01aa1d9471f9ebc74b920d5da082f7c4 Mon Sep 17 00:00:00 2001 From: emielvdveen Date: Tue, 26 Sep 2023 19:04:50 +0200 Subject: [PATCH] Create app_view component and made app_page a Stripped page --- .../controllers/layouts/stripped/component.ex | 2 +- .../feldspar/{internal.ex => _private.ex} | 2 +- core/systems/feldspar/_public.ex | 2 +- core/systems/feldspar/app_page.ex | 51 ++++++++++++------- core/systems/feldspar/app_view.ex | 19 +++++++ core/systems/feldspar/{plugs.ex => plug.ex} | 2 +- core/test/systems/feldspar/app_page_test.exs | 2 +- 7 files changed, 57 insertions(+), 23 deletions(-) rename core/systems/feldspar/{internal.ex => _private.ex} (74%) create mode 100644 core/systems/feldspar/app_view.ex rename core/systems/feldspar/{plugs.ex => plug.ex} (91%) diff --git a/core/lib/core_web/controllers/layouts/stripped/component.ex b/core/lib/core_web/controllers/layouts/stripped/component.ex index c9cc6c7eb..e2e393548 100644 --- a/core/lib/core_web/controllers/layouts/stripped/component.ex +++ b/core/lib/core_web/controllers/layouts/stripped/component.ex @@ -70,7 +70,7 @@ defmodule CoreWeb.Layouts.Stripped.Component do <% end %>
-
+
<%= render_slot(@inner_block) %> diff --git a/core/systems/feldspar/internal.ex b/core/systems/feldspar/_private.ex similarity index 74% rename from core/systems/feldspar/internal.ex rename to core/systems/feldspar/_private.ex index edaf4f6a3..105ec0036 100644 --- a/core/systems/feldspar/internal.ex +++ b/core/systems/feldspar/_private.ex @@ -1,4 +1,4 @@ -defmodule Systems.Feldspar.Internal do +defmodule Systems.Feldspar.Private do def get_backend do :core |> Application.fetch_env!(:feldspar) diff --git a/core/systems/feldspar/_public.ex b/core/systems/feldspar/_public.ex index 053e0edb7..b951b1491 100644 --- a/core/systems/feldspar/_public.ex +++ b/core/systems/feldspar/_public.ex @@ -6,7 +6,7 @@ defmodule Systems.Feldspar.Public do Feldspar } - import Feldspar.Internal, only: [get_backend: 0] + import Feldspar.Private, only: [get_backend: 0] def get_tool!(id, preload \\ []) do from(tool in Feldspar.ToolModel, preload: ^preload) diff --git a/core/systems/feldspar/app_page.ex b/core/systems/feldspar/app_page.ex index 6f2eae6cf..25756e600 100644 --- a/core/systems/feldspar/app_page.ex +++ b/core/systems/feldspar/app_page.ex @@ -1,37 +1,52 @@ defmodule Systems.Feldspar.AppPage do alias Systems.Feldspar use CoreWeb, :live_view + use CoreWeb.Layouts.Stripped.Component, :projects + + import Feldspar.AppView @impl true def mount(%{"id" => app_id}, _session, socket) do app_url = Feldspar.Public.get_public_url(app_id) <> "/index.html" - {:ok, assign(socket, app_url: app_url, error: nil)} + { + :ok, + socket + |> update_menus() + |> assign(app_url: app_url, error: nil) + } end - @impl true - def handle_uri(socket), do: socket - @impl true def render(assigns) do ~H""" -
- <%!-- Ensure that updates don't alter the hierarchy in front of the iframe. - Changing the preceding siblings of the iframe would result in a reload of the iframe - due to Morphdom (https://github.com/patrick-steele-idem/morphdom/issues/200). - --%> -
-
<%= @error %>
-
-
- -
-
+ <.stripped menus={@menus}> + <.app_view url={@app_url} /> + """ end @impl true - def handle_event("app_event", params, socket) do - {:noreply, assign(socket, :error, "Unsupported message: #{inspect(params)}")} + def handle_event("app_event", %{"__type__" => type, "json_string" => event}, socket) do + { + :noreply, + socket |> handle(type, event) + } + end + + @impl true + def handle_event("app_event", event, socket) do + { + :noreply, + socket |> handle(nil, inspect(event)) + } + end + + defp handle(socket, "CommandSystemDonate", event) do + Frameworks.Pixel.Flash.put_error(socket, "Unsupported donation " <> event) + end + + defp handle(socket, _, event) do + Frameworks.Pixel.Flash.put_error(socket, "Unsupported " <> event) end end diff --git a/core/systems/feldspar/app_view.ex b/core/systems/feldspar/app_view.ex new file mode 100644 index 000000000..360c1d112 --- /dev/null +++ b/core/systems/feldspar/app_view.ex @@ -0,0 +1,19 @@ +defmodule Systems.Feldspar.AppView do + use CoreWeb, :html + + attr(:url, :string, required: true) + + def app_view(assigns) do + ~H""" +
+ <%!-- Ensure that updates don't alter the hierarchy in front of the iframe. + Changing the preceding siblings of the iframe would result in a reload of the iframe + due to Morphdom (https://github.com/patrick-steele-idem/morphdom/issues/200). + --%> +
+ +
+
+ """ + end +end diff --git a/core/systems/feldspar/plugs.ex b/core/systems/feldspar/plug.ex similarity index 91% rename from core/systems/feldspar/plugs.ex rename to core/systems/feldspar/plug.ex index 3fa8a29e0..98df4f44c 100644 --- a/core/systems/feldspar/plugs.ex +++ b/core/systems/feldspar/plug.ex @@ -20,7 +20,7 @@ defmodule Systems.Feldspar.Plug do conn, options ) do - call(Systems.Feldspar.Internal.get_backend(), conn, options) + call(Systems.Feldspar.Private.get_backend(), conn, options) end def call(Systems.Feldspar.LocalFS, conn, options) do diff --git a/core/test/systems/feldspar/app_page_test.exs b/core/test/systems/feldspar/app_page_test.exs index 6f4cfb42a..573f8c474 100644 --- a/core/test/systems/feldspar/app_page_test.exs +++ b/core/test/systems/feldspar/app_page_test.exs @@ -15,7 +15,7 @@ defmodule Systems.Feldspar.AppPageTest do {:ok, view, _html} = live(conn, ~p"/apps/test") assert render_hook(view, :app_event, %{unexpected_key: "some data"}) =~ - "Unsupported message:" + "Unsupported " end end end