Compare commits

..

2 Commits

Author SHA1 Message Date
895860baa6 Update Public.get_autor! to only display public Artikel
Also get rid of the superfluous additional loop over articles/translations.
2023-03-03 22:05:52 +01:00
5319785855 Update continue_edit() to reload Translation
Reloading is necessary to detect changes in the changeset. Otherwise
simple changes like changing the value of translation.public wouldn't
get noticed and not being saved to db.
2023-03-03 21:57:09 +01:00
3 changed files with 25 additions and 7 deletions

View File

@ -67,7 +67,28 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation
end end
def get_autor!(id) do def get_autor!(id) do
Repo.get!(Author, id) q = from au in Author,
|> Repo.preload([articles: [:translations]]) select: %Autor{
name: au.name,
description: au.description,
homepage_name: au.homepage_name,
homepage_url: au.homepage_url,
},
where: au.id == ^id
autor = Repo.one(q)
q2 = from a in Article,
join: t in Translation, on: t.article_id == a.id,
select: %Artikel{
title: t.title,
date: t.date,
teaser: t.teaser,
id: t.id,
date_org: a.date
},
where: a.author_id == ^id and t.public == true
artikel = Repo.all(q2)
%Autor{autor | artikel: artikel}
end end
end end

View File

@ -4,10 +4,6 @@
<:subtitle><.link href={@autor.homepage_url}><%= @autor.homepage_name %></.link></:subtitle> <:subtitle><.link href={@autor.homepage_url}><%= @autor.homepage_name %></.link></:subtitle>
</.header> </.header>
<.artikel :for={artikel <- @autor.artikel} artikel={artikel} show_autor={false} />
<%= for article <- @autor.articles do %>
<.artikel :for={translation <- article.translations} artikel={translation} show_autor={false} />
<% end %>
<.back navigate={~p"/autoren"}>Back to autoren</.back> <.back navigate={~p"/autoren"}>Back to autoren</.back>

View File

@ -187,6 +187,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
defp continue_edit(socket, :edit, %{"continue_edit" => "true"}) do defp continue_edit(socket, :edit, %{"continue_edit" => "true"}) do
socket socket
|> assign(:translation, Translations.get_translation!(socket.assigns.translation.id))
end end
defp continue_edit(socket, :new, %{"continue_edit" => "true"} = params) do defp continue_edit(socket, :new, %{"continue_edit" => "true"} = params) do
socket |> push_patch(to: ~p(/translations/#{params["id"]}/edit)) socket |> push_patch(to: ~p(/translations/#{params["id"]}/edit))