Skip to content

Commit

Permalink
Trim down and harmonize the amount of assigns
Browse files Browse the repository at this point in the history
  • Loading branch information
dersmon committed Jul 24, 2024
1 parent 3215965 commit b5145a8
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Generic do
~H"""
<div>
<.document_heading>
<DocumentLink.show project={@project_name} date={@draft_date} lang={@lang} doc={@doc} />
<DocumentLink.show
project={@publication.project_name}
date={@publication.draft_date}
lang={@lang}
doc={@doc}
/>
</.document_heading>
<div class="flex flex-row">
<div class="basis-2/3">
<ViewSelection.render
project={@project_name}
date={@draft_date}
project={@publication.project_name}
date={@publication.draft_date}
lang={@lang}
uuid={@uuid}
current={:detail}
Expand Down Expand Up @@ -71,13 +76,15 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Generic do
<div class="overflow-auto overscroll-contain grid grid-cols-3 gap-1 mt-2 max-h-[300px] mb-5">
<%= for doc <- depicted_in["values"] do %>
<.link
patch={~p"/projects/#{@project_name}/#{@draft_date}/#{@lang}/#{doc["id"]}"}
patch={
~p"/projects/#{@publication.project_name}/#{@draft_date}/#{@lang}/#{doc["id"]}"
}
class="p-1"
>
<div class="max-w-[250px]">
<Image.show
size="^250,"
project={@project_name}
project={@publication.project_name}
uuid={doc["id"]}
alt_text={"Project image '#{doc["identifier"]}' (#{I18n.select_translation(%{values: doc["category"]["labels"]}) |> then(fn {_, text} -> text end)})"}
/>
Expand All @@ -95,8 +102,8 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Generic do
<div class="overflow-auto overscroll-contain max-h-[200px]">
<%= for doc <- other_relation["values"] do %>
<DocumentLink.show
project={@project_name}
date={@draft_date}
project={@publication.project_name}
date={@publication.draft_date}
lang={@lang}
doc={doc}
image_count={2}
Expand All @@ -110,15 +117,15 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Generic do
<a
class="mb-1"
target="_blank"
href={~p"/api/raw/csv/#{@project_name}/#{@draft_date}/#{@uuid}"}
href={~p"/api/raw/csv/#{@publication.project_name}/#{@publication.draft_date}/#{@uuid}"}
>
<.icon name="hero-table-cells-solid" /> Download CSV
</a>
<br />
<a
class="mb-1"
target="_blank"
href={~p"/api/json/raw/#{@project_name}/#{@draft_date}/#{@uuid}"}
href={~p"/api/json/raw/#{@publication.project_name}/#{@publication.draft_date}/#{@uuid}"}
>
<span class="text-center inline-block w-[20px]" style="block">{}</span> Download JSON
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Image do
~H"""
<div>
<.document_heading>
<DocumentLink.show project={@project_name} date={@draft_date} lang={@lang} doc={@doc} />
<DocumentLink.show
project={@publication.project_name}
date={@publication.draft_date}
lang={@lang}
doc={@doc}
/>
</.document_heading>
<div class="flex flex-row">
Expand All @@ -30,8 +35,8 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Image do
<div class="overflow-auto overscroll-contain max-h-[200px]">
<%= for doc <- relations["values"] do %>
<DocumentLink.show
project={@project_name}
date={@draft_date}
project={@publication.project_name}
date={@publication.draft_date}
lang={@lang}
doc={doc}
image_count={0}
Expand Down Expand Up @@ -67,17 +72,30 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Image do
</.group_heading>
<ul class="ml-0 list-none">
<li>
<a download={@doc["identifier"]} href={~p"/api/image/raw/#{@project_name}/#{@uuid}"}>
<a
download={@doc["identifier"]}
href={~p"/api/image/raw/#{@publication.project_name}/#{@uuid}"}
>
<.icon name="hero-photo-solid" /> Download original
</a>
</li>
<li>
<a target="_blank" href={~p"/api/raw/csv/#{@project_name}/#{@draft_date}/#{@uuid}"}>
<a
target="_blank"
href={
~p"/api/raw/csv/#{@publication.project_name}/#{@publication.draft_date}/#{@uuid}"
}
>
<.icon name="hero-table-cells-solid" /> Download CSV
</a>
</li>
<li>
<a target="_blank" href={~p"/api/json/raw/#{@project_name}/#{@draft_date}/#{@uuid}"}>
<a
target="_blank"
href={
~p"/api/json/raw/#{@publication.project_name}/#{@publication.draft_date}/#{@uuid}"
}
>
<span class="text-center inline-block w-[20px]" style="block">{}</span> Download JSON
</a>
</li>
Expand All @@ -88,7 +106,7 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Image do
</a>
<.live_component
id="iiif-link"
copy_value={"#{FieldPublicationWeb.Endpoint.url()}/#{IIIFViewer.construct_url(@project_name, @uuid)}"}
copy_value={"#{FieldPublicationWeb.Endpoint.url()}/#{IIIFViewer.construct_url(@publication.project_name, @uuid)}"}
module={ClipboardCopy}
>
Copy IIIF link
Expand All @@ -101,7 +119,7 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Image do
<.live_component
class="h-full"
id="iiif_viewer"
project={@project_name}
project={@publication.project_name}
uuid={@uuid}
module={IIIFViewer}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Project do
<div class="float-left overflow-auto overscroll-contain max-h-[310px] mr-3 mb-2">
<%= for doc <- depicted_in["values"] do %>
<.link
patch={~p"/projects/#{@project_name}/#{@draft_date}/#{@lang}/#{doc["id"]}"}
patch={
~p"/projects/#{@publication.project_name}/#{@publication.draft_date}/#{@lang}/#{doc["id"]}"
}
class="p-1"
>
<div class="w-[300px] pr-1">
<Image.show size="^300," project={@project_name} uuid={doc["id"]} />
<Image.show size="^300," project={@publication.project_name} uuid={doc["id"]} />
</div>
</.link>
<% end %>
Expand All @@ -45,7 +47,14 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Project do
<%= gettext("project_doc_about_publication") %>
</.header>
<div class="bg-slate-50 p-2 rounded">
<I18n.markdown values={@publication_comments} lang={@lang} />
<I18n.markdown
values={
@publication.comments
|> Enum.map(fn %{language: lang, text: text} -> {lang, text} end)
|> Enum.into(%{})
}
lang={@lang}
/>
</div>
</div>
Expand All @@ -61,7 +70,7 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Project do
additional_layer_documents={[]}
highlighted_geometry_documents={[]}
additional_geometry_documents={[]}
project_name={@project_name}
project_name={@publication.project_name}
/>
</div>
<% end %>
Expand Down Expand Up @@ -119,7 +128,12 @@ defmodule FieldPublicationWeb.Presentation.DocumentComponents.Project do
<%= gettext("Main documents") %>
</.group_heading>
<%= for doc <- @top_level_docs do %>
<DocumentLink.show project={@project_name} date={@draft_date} lang={@lang} doc={doc} />
<DocumentLink.show
project={@publication.project_name}
date={@publication.draft_date}
lang={@lang}
doc={doc}
/>
<% end %>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@ defmodule FieldPublicationWeb.Presentation.DocumentLive do

image_categories = Publications.Data.get_all_subcategories(current_publication, "Image")

relations_with_geometry =
Map.get(doc, "relations", [])
|> Enum.map(fn %{"values" => rel_docs} ->
rel_docs
end)
|> List.flatten()
|> Enum.filter(fn rel ->
Data.get_field(rel, "geometry") != nil
end)

{
:noreply,
socket
Expand All @@ -70,7 +60,6 @@ defmodule FieldPublicationWeb.Presentation.DocumentLive do
|> assign(:selected_lang, language)
|> assign(:uuid, uuid)
|> assign(:image_categories, image_categories)
|> assign(:relations_with_geometry, relations_with_geometry)
|> assign(:project_map_layers, project_map_layers)
|> assign(
:page_title,
Expand Down Expand Up @@ -108,18 +97,12 @@ defmodule FieldPublicationWeb.Presentation.DocumentLive do

top_level_docs = Data.get_extended_documents(top_level_uuids, current_publication)

publication_comments =
current_publication.comments
|> Enum.map(fn %{language: lang, text: text} -> {lang, text} end)
|> Enum.into(%{})

{
:noreply,
socket
|> assign(:doc, project_doc)
|> assign(:publication, current_publication)
|> assign(:selected_lang, language)
|> assign(:publication_comments, publication_comments)
|> assign(:top_level_docs, top_level_docs)
|> assign(:project_map_layers, project_map_layers)
|> assign(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
<%= cond do
category == "Project" ->
DocumentComponents.Project.render(%{
project_name: @project_name,
draft_date: @publication.draft_date,
publication_comments: @publication_comments,
doc: @doc,
publication: @publication,
lang: @selected_lang,
Expand All @@ -37,8 +34,7 @@
category in @image_categories ->
DocumentComponents.Image.render(%{
doc: @doc,
project_name: @project_name,
draft_date: @publication.draft_date,
publication: @publication,
lang: @selected_lang,
uuid: @uuid
})
Expand All @@ -47,12 +43,8 @@
DocumentComponents.Generic.render(%{
doc: @doc,
publication: @publication,
project_name: @publication.project_name,
draft_date: @publication.draft_date,
lang: @selected_lang,
uuid: @uuid,
relations_with_geometry: @relations_with_geometry,
project_map_layers: @project_map_layers
uuid: @uuid
})
end %>
</div>

0 comments on commit b5145a8

Please sign in to comment.