From bd2f7d90548ac7258bd291cb7400b03fd78f2b3c Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Fri, 14 Feb 2020 10:02:59 +0100 Subject: Pagination --- assets/css/app.css | 9 +++-- lib/waev/export.ex | 22 ++++++------ lib/waev_web/controllers/exports_controller.ex | 2 +- lib/waev_web/templates/exports/show.html.eex | 4 +-- lib/waev_web/views/exports_view.ex | 49 ++++++++++++++++++++++---- 5 files changed, 63 insertions(+), 23 deletions(-) diff --git a/assets/css/app.css b/assets/css/app.css index 6b5c4a6..8b221d0 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -50,12 +50,15 @@ body { } .row { - margin-top: 6px; + margin-top: 4px; display: flex; - align-items: center; + flex-direction: row; /* Milligram only does this in mid-big screens */ } .row--padded { - margin-top: 12px; + margin-top: 10px; +} +.row-center { + justify-content: center } .row-left { flex-direction: row; diff --git a/lib/waev/export.ex b/lib/waev/export.ex index 2fd80f5..72ed00d 100644 --- a/lib/waev/export.ex +++ b/lib/waev/export.ex @@ -52,7 +52,7 @@ defmodule Waev.Export do end end - defstruct id: nil, left: nil, right: nil, messages: [] + defstruct id: nil, left: nil, right: nil, messages: [], pagination: nil def list do case File.ls(path()) do @@ -124,15 +124,17 @@ defmodule Waev.Export do end end) - {:ok, - %{ - e - | messages: - e.messages - |> Enum.reverse() - |> Enum.drop((page - 1) * size) - |> Enum.take(size) - }} + pagination = + {:ok, + %{ + e + | messages: + e.messages + |> Enum.reverse() + |> Enum.drop((page - 1) * size) + |> Enum.take(size), + pagination: %{page: page, size: size, pages: ceil(Enum.count(e.messages) / size)} + }} false -> :error diff --git a/lib/waev_web/controllers/exports_controller.ex b/lib/waev_web/controllers/exports_controller.ex index 8d16cb5..a5a1f51 100644 --- a/lib/waev_web/controllers/exports_controller.ex +++ b/lib/waev_web/controllers/exports_controller.ex @@ -7,7 +7,7 @@ defmodule WaevWeb.ExportsController do case Waev.Export.get(id, page, size) do {:ok, export} -> - render(conn, "show.html", id: id, export: export, page: page, size: size) + render(conn, "show.html", id: id, export: export) :error -> conn diff --git a/lib/waev_web/templates/exports/show.html.eex b/lib/waev_web/templates/exports/show.html.eex index 948c125..ef35265 100644 --- a/lib/waev_web/templates/exports/show.html.eex +++ b/lib/waev_web/templates/exports/show.html.eex @@ -11,7 +11,7 @@ <% else %> <%= for {date, blocks} <- process_messages(@export.messages) do %> -