prevent params drop on admin user pagination (derpibooru/philomena#153)

This commit is contained in:
byte[] 2020-09-14 19:44:47 -04:00
parent ff5c01ce07
commit 218607b208
2 changed files with 16 additions and 1 deletions

View file

@ -10,7 +10,7 @@ h1 Users
=> link "2FA users", to: Routes.admin_user_path(@conn, :index, twofactor: 1) => link "2FA users", to: Routes.admin_user_path(@conn, :index, twofactor: 1)
- route = fn p -> Routes.admin_user_path(@conn, :index, p) end - route = fn p -> Routes.admin_user_path(@conn, :index, p) end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @users, route: route, conn: @conn, params: [q: @conn.params["q"]] - pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @users, route: route, conn: @conn, params: page_params(@conn.params)
.block .block
.block__header .block__header

View file

@ -1,6 +1,21 @@
defmodule PhilomenaWeb.Admin.UserView do defmodule PhilomenaWeb.Admin.UserView do
use PhilomenaWeb, :view use PhilomenaWeb, :view
def page_params(params) do
[]
|> page_param(params, "q", :q)
|> page_param(params, "staff", :staff)
|> page_param(params, "twofactor", :twofactor)
end
defp page_param(list, params, key, key_atom) do
case params[key] do
nil -> list
"" -> list
val -> [{key_atom, val} | list]
end
end
def checkbox_mapper(form, field, input_opts, role, _label_opts, _opts) do def checkbox_mapper(form, field, input_opts, role, _label_opts, _opts) do
input_id = "user_roles_#{role.id}" input_id = "user_roles_#{role.id}"
label_opts = [for: input_id] label_opts = [for: input_id]