add page number

pull/1812/head
Ayrat Badykov 6 years ago
parent d733a5d0f2
commit e22ef81457
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 20
      apps/block_scout_web/lib/block_scout_web/controllers/address_controller.ex
  2. 2
      apps/block_scout_web/lib/block_scout_web/templates/address/index.html.eex

@ -15,13 +15,24 @@ defmodule BlockScoutWeb.AddressController do
{addresses_page, next_page} = split_list_by_page(addresses) {addresses_page, next_page} = split_list_by_page(addresses)
cur_page_number =
cond do
!params["prev_page_number"] -> 1
params["next_page"] -> String.to_integer(params["prev_page_number"]) + 1
params["prev_page"] -> String.to_integer(params["prev_page_number"]) - 1
end
next_page_path = next_page_path =
case next_page_params(next_page, addresses_page, params) do case next_page_params(next_page, addresses_page, params) do
nil -> nil ->
nil nil
next_page_params -> next_page_params ->
next_params = Map.put(next_page_params, "prev_page_path", cur_page_path(conn, params)) next_params =
next_page_params
|> Map.put("prev_page_path", cur_page_path(conn, params))
|> Map.put("next_page", true)
|> Map.put("prev_page_number", cur_page_number)
address_path( address_path(
conn, conn,
@ -37,7 +48,8 @@ defmodule BlockScoutWeb.AddressController do
exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(), exchange_rate: Market.get_exchange_rate(Explorer.coin()) || Token.null(),
total_supply: Chain.total_supply(), total_supply: Chain.total_supply(),
next_page_path: next_page_path, next_page_path: next_page_path,
prev_page_path: params["prev_page_path"] prev_page_path: params["prev_page_path"],
cur_page_number: cur_page_number
) )
end end
@ -54,10 +66,12 @@ defmodule BlockScoutWeb.AddressController do
end end
defp cur_page_path(conn, %{"hash" => _hash, "fetched_coin_balance" => _balance} = params) do defp cur_page_path(conn, %{"hash" => _hash, "fetched_coin_balance" => _balance} = params) do
new_params = Map.put(params, "next_page", false)
address_path( address_path(
conn, conn,
:index, :index,
params new_params
) )
end end

@ -8,6 +8,8 @@
<%= gettext " addresses of" %> <%= gettext " addresses of" %>
<%= Cldr.Number.to_string!(@address_count, format: "#,###") %> <%= Cldr.Number.to_string!(@address_count, format: "#,###") %>
<%= gettext "total addresses with a balance" %> <%= gettext "total addresses with a balance" %>
<%= gettext " (page" %>
<%= Cldr.Number.to_string!(@cur_page_number, format: "#,###)") %>
<%= if @next_page_path do %> <%= if @next_page_path do %>
<a href="<%= "#{@next_page_path}" %>" class="button button-secondary button-small float-right mt-0 ml-1"> <a href="<%= "#{@next_page_path}" %>" class="button button-secondary button-small float-right mt-0 ml-1">

Loading…
Cancel
Save