From 86e09c84d424af2e4c738d41044efc7b89149ce5 Mon Sep 17 00:00:00 2001 From: Antoine Augusti Date: Wed, 11 Sep 2024 10:57:44 +0200 Subject: [PATCH] Resource#details: link to explore.data.gouv.fr (#4173) --- .../templates/resource/details.html.heex | 27 +++++++++++++++---- .../lib/transport_web/views/resource_view.ex | 11 ++++++++ .../priv/gettext/en/LC_MESSAGES/resource.po | 12 +++++++++ .../priv/gettext/fr/LC_MESSAGES/resource.po | 12 +++++++++ apps/transport/priv/gettext/resource.pot | 12 +++++++++ .../controllers/resource_controller_test.exs | 11 ++++++++ 6 files changed, 80 insertions(+), 5 deletions(-) diff --git a/apps/transport/lib/transport_web/templates/resource/details.html.heex b/apps/transport/lib/transport_web/templates/resource/details.html.heex index a66701673a..89fddb1057 100644 --- a/apps/transport/lib/transport_web/templates/resource/details.html.heex +++ b/apps/transport/lib/transport_web/templates/resource/details.html.heex @@ -6,15 +6,32 @@
- <%= dgettext("validations", "File name") %><%= dgettext("helper", ":") %> - <%= @resource.title %> - + <%= dgettext("validations", "File name") %><%= dgettext("helper", ":") %> + <%= @resource.title %>
<%= dgettext("resource", "Format:") %> <%= @resource.format %>
+
+ <%= dgettext("resource", "Size:") %> <%= Map.fetch!(@resource_history.payload, "filesize") + |> Sizeable.filesize() %> +
+
<%= description(@resource) %>
diff --git a/apps/transport/lib/transport_web/views/resource_view.ex b/apps/transport/lib/transport_web/views/resource_view.ex index 16962cb3b6..8326046b20 100644 --- a/apps/transport/lib/transport_web/views/resource_view.ex +++ b/apps/transport/lib/transport_web/views/resource_view.ex @@ -327,4 +327,15 @@ defmodule TransportWeb.ResourceView do def yes_no_icon(nil), do: "" def yes_no_icon(value) when value > 0, do: "✅" def yes_no_icon(_), do: "❌" + + def eligible_for_explore?(%DB.Resource{format: format}) do + format in ["geojson", "csv", "ods", "xlsx", "xls"] + end + + def explore_url(%DB.Resource{ + datagouv_id: resource_datagouv_id, + dataset: %DB.Dataset{datagouv_id: dataset_datagouv_id} + }) do + "https://explore.data.gouv.fr/fr/datasets/#{dataset_datagouv_id}/#/resources/#{resource_datagouv_id}" + end end diff --git a/apps/transport/priv/gettext/en/LC_MESSAGES/resource.po b/apps/transport/priv/gettext/en/LC_MESSAGES/resource.po index 3bc5aafc0a..671e1a1315 100644 --- a/apps/transport/priv/gettext/en/LC_MESSAGES/resource.po +++ b/apps/transport/priv/gettext/en/LC_MESSAGES/resource.po @@ -164,3 +164,15 @@ msgstr "" #, elixir-autogen, elixir-format msgid "The resource has been deleted" msgstr "" + +#, elixir-autogen, elixir-format +msgid "Download" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "Open with explore.data.gouv.fr" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "Size:" +msgstr "" diff --git a/apps/transport/priv/gettext/fr/LC_MESSAGES/resource.po b/apps/transport/priv/gettext/fr/LC_MESSAGES/resource.po index f06e657c68..91b4d21162 100644 --- a/apps/transport/priv/gettext/fr/LC_MESSAGES/resource.po +++ b/apps/transport/priv/gettext/fr/LC_MESSAGES/resource.po @@ -164,3 +164,15 @@ msgstr "Souhaitez-vous mettre à jour la ressource ou la supprimer définitiveme #, elixir-autogen, elixir-format msgid "The resource has been deleted" msgstr "La ressource a été supprimée" + +#, elixir-autogen, elixir-format +msgid "Download" +msgstr "Télécharger" + +#, elixir-autogen, elixir-format +msgid "Open with explore.data.gouv.fr" +msgstr "Ouvrir dans explore.data.gouv.fr" + +#, elixir-autogen, elixir-format +msgid "Size:" +msgstr "Taille :" diff --git a/apps/transport/priv/gettext/resource.pot b/apps/transport/priv/gettext/resource.pot index 42076c6a95..f11fb383b9 100644 --- a/apps/transport/priv/gettext/resource.pot +++ b/apps/transport/priv/gettext/resource.pot @@ -164,3 +164,15 @@ msgstr "" #, elixir-autogen, elixir-format msgid "The resource has been deleted" msgstr "" + +#, elixir-autogen, elixir-format +msgid "Download" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "Open with explore.data.gouv.fr" +msgstr "" + +#, elixir-autogen, elixir-format +msgid "Size:" +msgstr "" diff --git a/apps/transport/test/transport_web/controllers/resource_controller_test.exs b/apps/transport/test/transport_web/controllers/resource_controller_test.exs index b7ed8fc1c7..ce7c813f4e 100644 --- a/apps/transport/test/transport_web/controllers/resource_controller_test.exs +++ b/apps/transport/test/transport_web/controllers/resource_controller_test.exs @@ -855,6 +855,17 @@ defmodule TransportWeb.ResourceControllerTest do # We would just check that import_data works correctly, while this is already tested elsewhere. end + test "resource size and link to explore.data.gouv.fr are displayed", %{conn: conn} do + resource = insert(:resource, format: "csv", dataset: insert(:dataset, is_active: true)) + insert(:resource_history, resource_id: resource.id, payload: %{"filesize" => "1024"}) + + html_response = conn |> get(resource_path(conn, :details, resource.id)) |> html_response(200) + assert html_response =~ "Taille : 1 KB" + + assert TransportWeb.ResourceView.eligible_for_explore?(resource) + assert html_response =~ "https://explore.data.gouv.fr" + end + defp test_remote_download_error(%Plug.Conn{} = conn, mock_status_code) do resource = DB.Resource |> DB.Repo.get_by(datagouv_id: "2") refute DB.Resource.can_direct_download?(resource)