2019-11-29 22:47:41 +01:00
|
|
|
defmodule PhilomenaWeb.DnpEntryController do
|
|
|
|
use PhilomenaWeb, :controller
|
|
|
|
|
|
|
|
# alias Philomena.DnpEntries
|
|
|
|
alias Philomena.DnpEntries.DnpEntry
|
|
|
|
alias Philomena.Textile.Renderer
|
|
|
|
alias Philomena.Tags.Tag
|
|
|
|
alias Philomena.Repo
|
|
|
|
import Ecto.Query
|
|
|
|
|
2019-11-29 22:49:09 +01:00
|
|
|
plug :load_and_authorize_resource, model: DnpEntry, only: [:show], preload: [:tag]
|
2019-11-29 22:47:41 +01:00
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
dnp_entries =
|
|
|
|
DnpEntry
|
|
|
|
|> where(aasm_state: "listed")
|
|
|
|
|> join(:inner, [d], t in Tag, on: d.tag_id == t.id)
|
|
|
|
|> preload([:tag])
|
|
|
|
|> order_by([d, t], asc: t.name_in_namespace)
|
|
|
|
|> Repo.paginate(conn.assigns.scrivener)
|
|
|
|
|
|
|
|
bodies =
|
|
|
|
dnp_entries
|
|
|
|
|> Enum.map(&%{body: &1.conditions || "-"})
|
2019-12-01 18:11:00 +01:00
|
|
|
|> Renderer.render_collection(conn)
|
2019-11-29 22:47:41 +01:00
|
|
|
|
|
|
|
dnp_entries =
|
|
|
|
%{dnp_entries | entries: Enum.zip(bodies, dnp_entries.entries)}
|
|
|
|
|
|
|
|
render(conn, "index.html", layout_class: "layout--medium", dnp_entries: dnp_entries)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show(conn, _params) do
|
|
|
|
dnp_entry = conn.assigns.dnp_entry
|
|
|
|
|
|
|
|
[conditions, reason, instructions] =
|
2019-12-01 18:11:00 +01:00
|
|
|
Renderer.render_collection(
|
|
|
|
[
|
|
|
|
%{body: dnp_entry.conditions || "-"},
|
|
|
|
%{body: dnp_entry.reason || "-"},
|
|
|
|
%{body: dnp_entry.instructions || "-"}
|
|
|
|
],
|
|
|
|
conn
|
|
|
|
)
|
2019-11-29 22:47:41 +01:00
|
|
|
|
|
|
|
render(conn, "show.html", dnp_entry: dnp_entry, conditions: conditions, reason: reason, instructions: instructions)
|
|
|
|
end
|
|
|
|
end
|