diff --git a/lib/outlook/articles.ex b/lib/outlook/articles.ex index 999f493..12bfd8d 100644 --- a/lib/outlook/articles.ex +++ b/lib/outlook/articles.ex @@ -40,6 +40,12 @@ defmodule Outlook.Articles do |> Repo.preload([:author]) end + def get_article_with_translations!(id) do + Repo.get!(Article, id) + |> Repo.preload([:author]) + |> Repo.preload([:translations]) + end + @doc """ Creates a article. diff --git a/lib/outlook_web/live/article_live/show.ex b/lib/outlook_web/live/article_live/show.ex index 8c42719..75f15b4 100644 --- a/lib/outlook_web/live/article_live/show.ex +++ b/lib/outlook_web/live/article_live/show.ex @@ -14,7 +14,7 @@ defmodule OutlookWeb.ArticleLive.Show do {:noreply, socket |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:article, Articles.get_article!(id))} + |> assign(:article, Articles.get_article_with_translations!(id))} end defp page_title(:show), do: "Show Article" diff --git a/lib/outlook_web/live/article_live/show.html.heex b/lib/outlook_web/live/article_live/show.html.heex index bf111a3..a3acdcf 100644 --- a/lib/outlook_web/live/article_live/show.html.heex +++ b/lib/outlook_web/live/article_live/show.html.heex @@ -10,13 +10,35 @@ <.link patch={~p"/articles/#{@article}/show/edit"} phx-click={JS.push_focus()}> <.button>Edit article + <.link patch={~p"/translations/new?article_id=#{@article}"}> + <.button>New Translation + +<.table id="translations" rows={@article.translations} row_click={&JS.navigate(~p"/translations/#{&1}")}> + <:col :let={translation} label="Lang"><%= translation.lang %> + <:col :let={translation} label="Title"><%= translation.title %> + <:col :let={translation} label="Teaser"><%= translation.teaser %> + <:col :let={translation} label="Date"><%= translation.date %> + <:col :let={translation} label="Public"><%= translation.public %> + <:action :let={translation}> +
+ <.link navigate={~p"/translations/#{translation}"}>Show +
+ <.link navigate={~p"/translations/#{translation}/edit"}>Edit + + <%!-- <:action :let={translation}> + <.link phx-click={JS.push("delete", value: %{id: translation.id})} data-confirm="Are you sure?"> + Delete + + --%> + +
-show boundaries -hide boundaries - <%= InternalTree.render_html(@article.content) |> raw %> + show boundaries + hide boundaries + <.render_doc tree={@article.content} />
<.link navigate={~p"/translations/new?article_id=#{@article.id}"}>New Translation