add selection UI
This commit is contained in:
parent
3a5e8e5e07
commit
004f9fa69b
6 changed files with 53 additions and 7 deletions
|
|
@ -3328,6 +3328,12 @@ config :pleroma, :config_description, [
|
||||||
description:
|
description:
|
||||||
"A map containing available frontends and parameters for their installation.",
|
"A map containing available frontends and parameters for their installation.",
|
||||||
children: frontend_options
|
children: frontend_options
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
key: :pickable,
|
||||||
|
type: {:list, :string},
|
||||||
|
description:
|
||||||
|
"A list containing all frontends users can pick as their preference, format is :name/:ref, e.g pleroma-fe/stable."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
defmodule Pleroma.Web.FrontendSwitcher.FrontendSwitcherController do
|
||||||
|
use Pleroma.Web, :controller
|
||||||
|
alias Pleroma.Config
|
||||||
|
|
||||||
|
@doc "GET /frontend_switcher"
|
||||||
|
def switch(conn, _params) do
|
||||||
|
pickable = Config.get([:frontends, :pickable], [])
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_view(Pleroma.Web.FrontendSwitcher.FrontendSwitcherView)
|
||||||
|
|> render("switch.html", choices: pickable)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc "POST /frontend_switcher"
|
||||||
|
def do_switch(conn, params) do
|
||||||
|
conn
|
||||||
|
|> put_resp_cookie("preferred_frontend", params["frontend"])
|
||||||
|
|> html("<meta http-equiv=\"refresh\" content=\"0; url=/\">")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule Pleroma.Web.FrontendSwitcher.FrontendSwitcherView do
|
||||||
|
use Pleroma.Web, :view
|
||||||
|
end
|
||||||
|
|
@ -49,6 +49,7 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, opts) do
|
def call(conn, opts) do
|
||||||
|
IO.inspect("OPTS: #{inspect(opts)}")
|
||||||
with false <- api_route?(conn.path_info),
|
with false <- api_route?(conn.path_info),
|
||||||
false <- invalid_path?(conn.path_info),
|
false <- invalid_path?(conn.path_info),
|
||||||
fallback_frontend_type <- Map.get(opts, :frontend_type, :primary),
|
fallback_frontend_type <- Map.get(opts, :frontend_type, :primary),
|
||||||
|
|
@ -69,16 +70,26 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
|
||||||
Map.get(cookies, @frontend_cookie_name)
|
Map.get(cookies, @frontend_cookie_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def preferred_or_fallback(conn, fallback) do
|
# Only override primary frontend
|
||||||
|
def preferred_or_fallback(conn, :primary) do
|
||||||
case preferred_frontend(conn) do
|
case preferred_frontend(conn) do
|
||||||
nil ->
|
nil ->
|
||||||
fallback
|
:primary
|
||||||
|
|
||||||
frontend ->
|
frontend ->
|
||||||
frontend
|
frontend
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
|
=======
|
||||||
|
def preferred_or_fallback(conn, fallback), do: fallback
|
||||||
|
|
||||||
|
defp enabled?(if_opt) when is_function(if_opt), do: if_opt.()
|
||||||
|
defp enabled?(true), do: true
|
||||||
|
defp enabled?(_), do: false
|
||||||
|
|
||||||
|
>>>>>>> de64c6c54a (add selection UI)
|
||||||
defp invalid_path?(list) do
|
defp invalid_path?(list) do
|
||||||
invalid_path?(list, :binary.compile_pattern(["/", "\\", ":", "\0"]))
|
invalid_path?(list, :binary.compile_pattern(["/", "\\", ":", "\0"]))
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -637,11 +637,6 @@ defmodule Pleroma.Web.Router do
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/api/v1/pleroma", Pleroma.Web.MastodonAPI do
|
scope "/api/v1/pleroma", Pleroma.Web.MastodonAPI do
|
||||||
pipe_through(:api)
|
|
||||||
get("/accounts/:id/endorsements", AccountController, :endorsements)
|
|
||||||
end
|
|
||||||
|
|
||||||
scope "/api/v2/pleroma", Pleroma.Web.PleromaAPI do
|
|
||||||
scope [] do
|
scope [] do
|
||||||
pipe_through(:authenticated_api)
|
pipe_through(:authenticated_api)
|
||||||
get("/chats", ChatController, :index2)
|
get("/chats", ChatController, :index2)
|
||||||
|
|
@ -901,7 +896,11 @@ defmodule Pleroma.Web.Router do
|
||||||
|
|
||||||
scope "/", Pleroma.Web do
|
scope "/", Pleroma.Web do
|
||||||
pipe_through(:browser)
|
pipe_through(:browser)
|
||||||
|
|
||||||
get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
|
get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
|
||||||
|
|
||||||
|
get("/frontend_switcher", FrontendSwitcher.FrontendSwitcherController, :switch)
|
||||||
|
post("/frontend_switcher", FrontendSwitcher.FrontendSwitcherController, :do_switch)
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :ap_service_actor do
|
pipeline :ap_service_actor do
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
<h2>Switch Frontend</h2>
|
||||||
|
|
||||||
|
<%= form_for @conn, Routes.frontend_switcher_path(@conn, :do_switch), fn f -> %>
|
||||||
|
<%= select(f, :frontend, @choices) %>
|
||||||
|
|
||||||
|
<%= submit do: "submit" %>
|
||||||
|
<% end %>
|
||||||
Loading…
Add table
Add a link
Reference in a new issue