additional pagination fixes (fixes philomena-dev/philomena#117)

This commit is contained in:
byte[] 2021-05-15 13:50:26 -04:00
parent 80d3cb5cd1
commit 952d7bca4f
7 changed files with 29 additions and 42 deletions

View file

@ -1,7 +1,7 @@
h1 Fingerprint Bans h1 Fingerprint Bans
- route = fn p -> Routes.admin_fingerprint_ban_path(@conn, :index, p) end - route = fn p -> Routes.admin_fingerprint_ban_path(@conn, :index, p) end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @fingerprint_bans, route: route, params: [q: @conn.params["q"]] - pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @fingerprint_bans, route: route, params: page_params(@conn.params)
= form_for :fingerprint_ban, Routes.admin_fingerprint_ban_path(@conn, :index), [method: "get", class: "hform"], fn f -> = form_for :fingerprint_ban, Routes.admin_fingerprint_ban_path(@conn, :index), [method: "get", class: "hform"], fn f ->
.field .field

View file

@ -1,7 +1,7 @@
h1 Subnet Bans h1 Subnet Bans
- route = fn p -> Routes.admin_subnet_ban_path(@conn, :index, p) end - route = fn p -> Routes.admin_subnet_ban_path(@conn, :index, p) end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @subnet_bans, route: route, params: [q: @conn.params["q"]] - pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @subnet_bans, route: route, params: page_params(@conn.params)
= form_for :subnet_ban, Routes.admin_subnet_ban_path(@conn, :index), [method: "get", class: "hform"], fn f -> = form_for :subnet_ban, Routes.admin_subnet_ban_path(@conn, :index), [method: "get", class: "hform"], fn f ->
.field .field

View file

@ -1,7 +1,7 @@
h1 User Bans h1 User Bans
- route = fn p -> Routes.admin_user_ban_path(@conn, :index, p) end - route = fn p -> Routes.admin_user_ban_path(@conn, :index, p) end
- pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @user_bans, route: route, params: [q: @conn.params["q"]] - pagination = render PhilomenaWeb.PaginationView, "_pagination.html", page: @user_bans, route: route, params: page_params(@conn.params)
= form_for :user_ban, Routes.admin_user_ban_path(@conn, :index), [method: "get", class: "hform"], fn f -> = form_for :user_ban, Routes.admin_user_ban_path(@conn, :index), [method: "get", class: "hform"], fn f ->
.field .field

View file

@ -0,0 +1,23 @@
defmodule PhilomenaWeb.Admin.BanView do
alias PhilomenaWeb.ProfileView
def user_abbrv(conn, user),
do: ProfileView.user_abbrv(conn, user)
def ban_row_class(%{valid_until: until, enabled: enabled}) do
now = DateTime.utc_now()
case enabled and DateTime.diff(until, now) > 0 do
true -> "success"
_false -> "danger"
end
end
def page_params(params) do
case params["q"] do
nil -> []
"" -> []
q -> [q: q]
end
end
end

View file

@ -1,17 +1,5 @@
defmodule PhilomenaWeb.Admin.FingerprintBanView do defmodule PhilomenaWeb.Admin.FingerprintBanView do
use PhilomenaWeb, :view use PhilomenaWeb, :view
alias PhilomenaWeb.ProfileView import PhilomenaWeb.Admin.BanView
defp user_abbrv(conn, user),
do: ProfileView.user_abbrv(conn, user)
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
now = DateTime.utc_now()
case enabled and DateTime.diff(until, now) > 0 do
true -> "success"
_false -> "danger"
end
end
end end

View file

@ -1,17 +1,5 @@
defmodule PhilomenaWeb.Admin.SubnetBanView do defmodule PhilomenaWeb.Admin.SubnetBanView do
use PhilomenaWeb, :view use PhilomenaWeb, :view
alias PhilomenaWeb.ProfileView import PhilomenaWeb.Admin.BanView
defp user_abbrv(conn, user),
do: ProfileView.user_abbrv(conn, user)
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
now = DateTime.utc_now()
case enabled and DateTime.diff(until, now) > 0 do
true -> "success"
_false -> "danger"
end
end
end end

View file

@ -1,17 +1,5 @@
defmodule PhilomenaWeb.Admin.UserBanView do defmodule PhilomenaWeb.Admin.UserBanView do
use PhilomenaWeb, :view use PhilomenaWeb, :view
alias PhilomenaWeb.ProfileView import PhilomenaWeb.Admin.BanView
defp user_abbrv(conn, user),
do: ProfileView.user_abbrv(conn, user)
defp ban_row_class(%{valid_until: until, enabled: enabled}) do
now = DateTime.utc_now()
case enabled and DateTime.diff(until, now) > 0 do
true -> "success"
_false -> "danger"
end
end
end end