Skip to content

Commit

Permalink
Ne montrer que les 3 plus récentes resources historisées (#3358)
Browse files Browse the repository at this point in the history
* fold resource history

* move resource history to own template

* mix format

---------

Co-authored-by: Antoine Augusti <[email protected]>
  • Loading branch information
vdegove and AntoineAugusti authored Jul 28, 2023
1 parent 4a869b4 commit 3814dbb
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,7 @@ hr {
border-bottom: 1px solid var(--theme-border-lighter);
}

.discussion .displayMore {
text-align: center;
margin-bottom: 1em;
}

#notifications-sent .displayMore {
.discussion, #notifications-sent, #backed-up-resources .displayMore {
text-align: center;
margin-bottom: 1em;
}
2 changes: 0 additions & 2 deletions apps/transport/lib/transport_web/live/discussions_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ defmodule TransportWeb.DiscussionsLive do

def render(assigns) do
~H"""
<script src={TransportWeb.Endpoint.static_path("/js/utils.js")} />
<script>
window.addEventListener('phx:discussions-loaded', (event) => {
event.detail.ids.forEach(id =>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<% has_validity_period_col = has_validity_period?(@history_resources) %>
<section class="white pt-48" id="backed-up-resources">
<h3><%= dgettext("page-dataset-details", "Backed up resources") %></h3>
<div class="panel">
<div id="backed-up-resources-see-more-wrapper">
<table class="table">
<thead>
<tr>
<th><%= dgettext("page-dataset-details", "File") %></th>
<th><%= dgettext("page-dataset-details", "Publication date") %></th>
<%= if has_validity_period_col do %>
<th>
<%= dgettext("page-dataset-details", "Validity period") %>
</th>
<% end %>
<th><%= dgettext("page-dataset-details", "Format") %></th>
</tr>
</thead>
<tbody>
<%= for resource_history <- @history_resources do %>
<tr>
<td>
<%= link(resource_history.payload["title"],
to: resource_history.payload["permanent_url"],
rel: "nofollow"
) %>
</td>
<td><%= resource_history.inserted_at |> DateTimeDisplay.format_datetime_to_date(@locale) %></td>
<%= if has_validity_period_col do %>
<%= if has_validity_period?(resource_history) do %>
<td>
<%= dgettext(
"page-dataset-details",
"%{start} to %{end}",
start:
resource_history
|> validity_period()
|> Map.get("start_date")
|> DateTimeDisplay.format_date(@locale),
end:
resource_history
|> validity_period()
|> Map.get("end_date")
|> DateTimeDisplay.format_date(@locale)
) %>
</td>
<% else %>
<td></td>
<% end %>
<% end %>
<td><span class="label"><%= resource_history.payload["format"] %></span></td>
</tr>
<% end %>
</tbody>
</table>

<%= if Enum.count(@history_resources) == max_nb_history_resources() do %>
<p class="small">
<%= dgettext("page-dataset-details", "Displaying the last %{nb} backed up resources.",
nb: max_nb_history_resources()
) %>
</p>
<% end %>
</div>
</div>
</section>

<script>
document.addEventListener("DOMContentLoaded", function() {
addSeeMore("280px",
"#backed-up-resources-see-more-wrapper",
"<%= dgettext("page-dataset-details", "Display more") %>",
"<%= dgettext("page-dataset-details", "Display less") %>"
)
})
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
</div>
</section>

<script src={static_path(@conn, "/js/utils.js")} />
<script>
document.addEventListener("DOMContentLoaded", function() {
addSeeMore("15em",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,69 +228,7 @@
</section>
<% end %>
<%= unless @history_resources == [] do %>
<% has_validity_period_col = has_validity_period?(@history_resources) %>
<section class="white pt-48" id="backed-up-resources">
<h3><%= dgettext("page-dataset-details", "Backed up resources") %></h3>
<div class="panel">
<table class="table">
<thead>
<tr>
<th><%= dgettext("page-dataset-details", "File") %></th>
<th><%= dgettext("page-dataset-details", "Publication date") %></th>
<%= if has_validity_period_col do %>
<th>
<%= dgettext("page-dataset-details", "Validity period") %>
</th>
<% end %>
<th><%= dgettext("page-dataset-details", "Format") %></th>
</tr>
</thead>
<tbody>
<%= for resource_history <- @history_resources do %>
<tr>
<td>
<%= link(resource_history.payload["title"],
to: resource_history.payload["permanent_url"],
rel: "nofollow"
) %>
</td>
<td><%= resource_history.inserted_at |> DateTimeDisplay.format_datetime_to_date(locale) %></td>
<%= if has_validity_period_col do %>
<%= if has_validity_period?(resource_history) do %>
<td>
<%= dgettext(
"page-dataset-details",
"%{start} to %{end}",
start:
resource_history
|> validity_period()
|> Map.get("start_date")
|> DateTimeDisplay.format_date(locale),
end:
resource_history
|> validity_period()
|> Map.get("end_date")
|> DateTimeDisplay.format_date(locale)
) %>
</td>
<% else %>
<td></td>
<% end %>
<% end %>
<td><span class="label"><%= resource_history.payload["format"] %></span></td>
</tr>
<% end %>
</tbody>
</table>
<%= if Enum.count(@history_resources) == max_nb_history_resources() do %>
<p class="small">
<%= dgettext("page-dataset-details", "Displaying the last %{nb} backed up resources.",
nb: max_nb_history_resources()
) %>
</p>
<% end %>
</div>
</section>
<%= render("_dataset_resources_history.html", history_resources: @history_resources, locale: locale, conn: @conn) %>
<% end %>
<%= unless is_nil(@other_datasets) or @other_datasets == [] do %>
<section class="pt-48" id="dataset-other-datasets">
Expand Down Expand Up @@ -384,3 +322,4 @@
</script>
<script defer type="text/javascript" src={static_path(@conn, "/js/app.js")}>
</script>
<script src={static_path(@conn, "/js/utils.js")} />

0 comments on commit 3814dbb

Please sign in to comment.