add selection UI
This commit is contained in:
parent
643b8c5f15
commit
de64c6c54a
6 changed files with 49 additions and 2 deletions
|
@ -3148,6 +3148,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."
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
20
lib/pleroma/web/akkoma_api/controllers/frontend_switcher.ex
Normal file
20
lib/pleroma/web/akkoma_api/controllers/frontend_switcher.ex
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
defmodule Pleroma.Web.AkkomaAPI.FrontendSwitcherController do
|
||||||
|
use Pleroma.Web, :controller
|
||||||
|
alias Pleroma.Config
|
||||||
|
|
||||||
|
@doc "GET /akkoma/frontend"
|
||||||
|
def switch(conn, _params) do
|
||||||
|
pickable = Config.get([:frontends, :pickable], [])
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> put_view(Pleroma.Web.AkkomaAPI.FrontendSwitcherView)
|
||||||
|
|> render("switch.html", choices: pickable)
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc "POST /akkoma/frontend"
|
||||||
|
def do_switch(conn, params) do
|
||||||
|
conn
|
||||||
|
|> put_resp_cookie("preferred_frontend", params["frontend"])
|
||||||
|
|> html("<meta http-equiv=\"refresh\" content=\"0; url=/\">")
|
||||||
|
end
|
||||||
|
end
|
3
lib/pleroma/web/akkoma_api/views/frontend_switcher.ex
Normal file
3
lib/pleroma/web/akkoma_api/views/frontend_switcher.ex
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
defmodule Pleroma.Web.AkkomaAPI.FrontendSwitcherView do
|
||||||
|
use Pleroma.Web, :view
|
||||||
|
end
|
|
@ -50,6 +50,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),
|
||||||
true <- enabled?(opts[:if]),
|
true <- enabled?(opts[:if]),
|
||||||
|
@ -71,16 +72,19 @@ 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
|
||||||
|
|
||||||
|
def preferred_or_fallback(conn, fallback), do: fallback
|
||||||
|
|
||||||
defp enabled?(if_opt) when is_function(if_opt), do: if_opt.()
|
defp enabled?(if_opt) when is_function(if_opt), do: if_opt.()
|
||||||
defp enabled?(true), do: true
|
defp enabled?(true), do: true
|
||||||
defp enabled?(_), do: false
|
defp enabled?(_), do: false
|
||||||
|
|
|
@ -466,6 +466,13 @@ defmodule Pleroma.Web.Router do
|
||||||
put("/statuses/:id/emoji_reactions/:emoji", EmojiReactionController, :create)
|
put("/statuses/:id/emoji_reactions/:emoji", EmojiReactionController, :create)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
scope "/akkoma/", Pleroma.Web.AkkomaAPI do
|
||||||
|
pipe_through(:browser)
|
||||||
|
|
||||||
|
get("/frontend", FrontendSwitcherController, :switch)
|
||||||
|
post("/frontend", FrontendSwitcherController, :do_switch)
|
||||||
|
end
|
||||||
|
|
||||||
scope "/api/v1/akkoma", Pleroma.Web.AkkomaAPI do
|
scope "/api/v1/akkoma", Pleroma.Web.AkkomaAPI do
|
||||||
pipe_through(:api)
|
pipe_through(:api)
|
||||||
|
|
||||||
|
|
|
@ -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…
Reference in a new issue