diff options
Diffstat (limited to 'lib/waev_web')
-rw-r--r-- | lib/waev_web/controllers/exports_controller.ex | 13 | ||||
-rw-r--r-- | lib/waev_web/router.ex | 1 | ||||
-rw-r--r-- | lib/waev_web/templates/exports/show.html.eex | 8 |
3 files changed, 20 insertions, 2 deletions
diff --git a/lib/waev_web/controllers/exports_controller.ex b/lib/waev_web/controllers/exports_controller.ex index a3dde48..fd776a9 100644 --- a/lib/waev_web/controllers/exports_controller.ex +++ b/lib/waev_web/controllers/exports_controller.ex @@ -13,4 +13,17 @@ defmodule WaevWeb.ExportsController do |> render("404.html") end end + + def get_attachment(conn, %{"id" => id, "at_id" => at_id}) do + case Waev.Export.Message.File.path(id, at_id) do + {:ok, path} -> + send_download(conn, {:file, path}, filename: at_id) + + :error -> + conn + |> put_status(:not_found) + |> put_view(WaevWeb.ErrorView) + |> render("404.html") + end + end end diff --git a/lib/waev_web/router.ex b/lib/waev_web/router.ex index edd2c69..54667a8 100644 --- a/lib/waev_web/router.ex +++ b/lib/waev_web/router.ex @@ -19,6 +19,7 @@ defmodule WaevWeb.Router do get "/", PageController, :index # index,edit,new,show,create,update resources "/exports", ExportsController, only: [:show] + get "/exports/:id/attachments/:at_id", ExportsController, :get_attachment end # Other scopes may use custom stacks. diff --git a/lib/waev_web/templates/exports/show.html.eex b/lib/waev_web/templates/exports/show.html.eex index 2d72e2e..77727a8 100644 --- a/lib/waev_web/templates/exports/show.html.eex +++ b/lib/waev_web/templates/exports/show.html.eex @@ -20,8 +20,12 @@ ID: <%= @id %> <div class="column wa-message column-50 column-offset-25"> <% end %> <%= case message.attachment do %> - <% %Waev.Export.Message.File{filename: filename} -> %> - <a href="#"><%= filename %></a> + <% %Waev.Export.Message.File{filename: filename} = file -> %> + <%= if file.available do %> + <a href="<%= Routes.exports_path(@conn, :get_attachment, @id, filename) %>"><%= filename %></a> + <% else %> + <i><%= filename %></i> (fichero adjunto no disponible) + <% end %> <% nil -> %> <% end %> <%= message.text %> |