diff --git a/lib/kaffy/resource_admin.ex b/lib/kaffy/resource_admin.ex index 8e7c15b5..2c07bccb 100644 --- a/lib/kaffy/resource_admin.ex +++ b/lib/kaffy/resource_admin.ex @@ -446,8 +446,17 @@ defmodule Kaffy.ResourceAdmin do ) end - def collect_widgets(conn) do - Enum.reduce(Kaffy.Utils.contexts(conn), [], fn c, all -> + def collect_widgets(conn, context \\ :kaffy_dashboard) do + IO.inspect(context, label: "coming from context") + main_dashboard? = context == :kaffy_dashboard + show_context_dashboard? = Kaffy.Utils.show_context_dashboard?() + + conn + |> Kaffy.Utils.contexts() + |> Enum.filter(fn c -> main_dashboard? or (show_context_dashboard? and c == context) end) + |> Enum.reduce([], fn c, all -> + IO.inspect(c, label: "collect_widgets context") + widgets = Enum.reduce(Kaffy.Utils.schemas_for_context(conn, c), [], fn {_, resource}, all -> all ++ Kaffy.ResourceAdmin.widgets(resource, conn) diff --git a/lib/kaffy/routes.ex b/lib/kaffy/routes.ex index 4240df95..0f2b0e1b 100644 --- a/lib/kaffy/routes.ex +++ b/lib/kaffy/routes.ex @@ -35,6 +35,11 @@ defmodule Kaffy.Routes do get("/dashboard", HomeController, :dashboard, as: :kaffy_dashboard) get("/tasks", TaskController, :index, as: :kaffy_task) get("/p/:slug", PageController, :index, as: :kaffy_page) + + if Kaffy.Utils.show_context_dashboard?() do + get("/:context", ResourceController, :dashboard, as: :kaffy_context_dashboard) + end + get("/:context/:resource", ResourceController, :index, as: :kaffy_resource) post("/:context/:resource", ResourceController, :create, as: :kaffy_resource) diff --git a/lib/kaffy/utils.ex b/lib/kaffy/utils.ex index dd023c20..2e22c6d5 100644 --- a/lib/kaffy/utils.ex +++ b/lib/kaffy/utils.ex @@ -390,6 +390,10 @@ defmodule Kaffy.Utils do ) end + def show_context_dashboard?() do + env(:enable_context_dashboard, true) + end + defp env(key, default \\ nil) do Application.get_env(:kaffy, key, default) end diff --git a/lib/kaffy_web/controllers/home_controller.ex b/lib/kaffy_web/controllers/home_controller.ex index 40830ce9..20d344b7 100644 --- a/lib/kaffy_web/controllers/home_controller.ex +++ b/lib/kaffy_web/controllers/home_controller.ex @@ -8,6 +8,9 @@ defmodule KaffyWeb.HomeController do end def dashboard(conn, _params) do - render(conn, "index.html", layout: {KaffyWeb.LayoutView, "app.html"}) + render(conn, "index.html", + layout: {KaffyWeb.LayoutView, "app.html"}, + context: :kaffy_dashboard + ) end end diff --git a/lib/kaffy_web/controllers/resource_controller.ex b/lib/kaffy_web/controllers/resource_controller.ex index 61f99d7b..c4e8dfae 100644 --- a/lib/kaffy_web/controllers/resource_controller.ex +++ b/lib/kaffy_web/controllers/resource_controller.ex @@ -5,6 +5,13 @@ defmodule KaffyWeb.ResourceController do use Phoenix.HTML alias Kaffy.Pagination + def dashboard(conn, %{"context" => context}) do + render(conn, "dashboard.html", + layout: {KaffyWeb.LayoutView, "app.html"}, + context: String.to_existing_atom(context) + ) + end + def index( conn, %{ diff --git a/lib/kaffy_web/templates/home/index.html.eex b/lib/kaffy_web/templates/home/index.html.eex index 9d671f49..2a612650 100644 --- a/lib/kaffy_web/templates/home/index.html.eex +++ b/lib/kaffy_web/templates/home/index.html.eex @@ -1,5 +1,5 @@ -<% widgets = Kaffy.ResourceAdmin.collect_widgets(@conn) %> +<% widgets = Kaffy.ResourceAdmin.collect_widgets(@conn, @context) %> <%= if Enum.empty?(widgets) do %> diff --git a/lib/kaffy_web/templates/layout/app.html.eex b/lib/kaffy_web/templates/layout/app.html.eex index 83616969..a82550ea 100644 --- a/lib/kaffy_web/templates/layout/app.html.eex +++ b/lib/kaffy_web/templates/layout/app.html.eex @@ -100,6 +100,9 @@