Compare commits
2 Commits
3a2769eed1
...
3fe4a331ac
| Author | SHA1 | Date | |
|---|---|---|---|
| 3fe4a331ac | |||
| 6d0ae825d8 |
@ -28,7 +28,7 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation
|
|||||||
where: t.public == true and t.language == ^language,
|
where: t.public == true and t.language == ^language,
|
||||||
order_by: [desc: t.date]
|
order_by: [desc: t.date]
|
||||||
Repo.all(q)
|
Repo.all(q)
|
||||||
|> Enum.map(fn rec -> Enum.into(rec, %{}) end)
|
# |> Enum.map(fn rec -> Enum.into(rec, %{}) end)
|
||||||
|> Enum.map(fn map -> struct(Artikel, map) end)
|
|> Enum.map(fn map -> struct(Artikel, map) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -50,7 +50,7 @@ implement to_param protocol (no more needed for Outlook.Translations.Translation
|
|||||||
where: t.id == ^id and t.public == true
|
where: t.id == ^id and t.public == true
|
||||||
case Repo.one(q) do
|
case Repo.one(q) do
|
||||||
nil -> {:error, "Artikel does not exist, or isn't public."}
|
nil -> {:error, "Artikel does not exist, or isn't public."}
|
||||||
artikel -> {:ok, struct(Artikel, artikel |> Enum.into(%{}))}
|
artikel -> {:ok, struct(Artikel, artikel)}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@ defmodule Outlook.Translations.Translation do
|
|||||||
|
|
||||||
alias Outlook.Accounts.User
|
alias Outlook.Accounts.User
|
||||||
alias Outlook.Articles.Article
|
alias Outlook.Articles.Article
|
||||||
alias Outlook.Translations.{TranslationUnitsMap,Translation}
|
alias Outlook.Translations.TranslationUnitsMap
|
||||||
|
|
||||||
schema "translations" do
|
schema "translations" do
|
||||||
field :content, TranslationUnitsMap
|
field :content, TranslationUnitsMap
|
||||||
@ -32,30 +32,4 @@ defmodule Outlook.Translations.Translation do
|
|||||||
name: :article_id_lang_unique_index)
|
name: :article_id_lang_unique_index)
|
||||||
|> foreign_key_constraint(:article_id)
|
|> foreign_key_constraint(:article_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def translate_unicode(str) do
|
|
||||||
mapping = %{"Ä" => "Ae",
|
|
||||||
"Ö" => "Oe",
|
|
||||||
"Ü" => "Ue",
|
|
||||||
"ä" => "ae",
|
|
||||||
"ö" => "oe",
|
|
||||||
"ü" => "ue",
|
|
||||||
"ß" => "ss"}
|
|
||||||
{:ok, re} = "[#{Map.keys(mapping) |> Enum.join}]" |> Regex.compile("u")
|
|
||||||
Regex.replace(re, str, fn(c) -> mapping[c] end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def spit_title(title) do
|
|
||||||
title
|
|
||||||
|> translate_unicode()
|
|
||||||
# |> String.replace(~r/[^-0-9A-Za-z ]/u, "_")
|
|
||||||
|> String.replace(~r/[^\w\s-]/u, "")
|
|
||||||
|> String.replace(~r/(\s|-)+/u, "-")
|
|
||||||
end
|
|
||||||
|
|
||||||
defimpl Phoenix.Param, for: Translation do
|
|
||||||
def to_param(%{id: id, title: title}) do
|
|
||||||
"#{Translation.spit_title(title)}--#{Integer.to_string(id, 36) |> String.downcase()}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
@ -13,7 +13,7 @@ defmodule OutlookWeb.PublicComponents do
|
|||||||
|
|
||||||
def autor(assigns) do
|
def autor(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<a href={"/autoren/#{@autor.id}"}>
|
<a href={~p"/autoren/#{@autor}"}>
|
||||||
<div class="p-4 my-2 border rounded-lg border-stone-400 text-stone-800 dark:text-stone-300 ">
|
<div class="p-4 my-2 border rounded-lg border-stone-400 text-stone-800 dark:text-stone-300 ">
|
||||||
<div class="font-bold"><%= @autor.name %></div>
|
<div class="font-bold"><%= @autor.name %></div>
|
||||||
<div class=""><%= @autor.description |> tidy_raw %></div>
|
<div class=""><%= @autor.description |> tidy_raw %></div>
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<.table id="translations" rows={@article.translations} row_click={&JS.navigate(~p"/translations/#{(&1).id}")}>
|
<.table id="translations" rows={@article.translations} row_click={&JS.navigate(~p"/translations/#{&1}")}>
|
||||||
<:col :let={translation} label="Language"><%= translation.language %></:col>
|
<:col :let={translation} label="Language"><%= translation.language %></:col>
|
||||||
<:col :let={translation} label="Title"><%= translation.title %></:col>
|
<:col :let={translation} label="Title"><%= translation.title %></:col>
|
||||||
<:col :let={translation} label="Teaser"><%= translation.teaser |> tidy_raw %></:col>
|
<:col :let={translation} label="Teaser"><%= translation.teaser |> tidy_raw %></:col>
|
||||||
@ -24,9 +24,9 @@
|
|||||||
<:col :let={translation} label="Public"><%= translation.public %></:col>
|
<:col :let={translation} label="Public"><%= translation.public %></:col>
|
||||||
<:action :let={translation}>
|
<:action :let={translation}>
|
||||||
<div class="sr-only">
|
<div class="sr-only">
|
||||||
<.link navigate={~p"/translations/#{translation.id}"}>Show</.link>
|
<.link navigate={~p"/translations/#{translation}"}>Show</.link>
|
||||||
</div>
|
</div>
|
||||||
<.link navigate={~p"/translations/#{translation.id}/edit"}>Edit</.link>
|
<.link navigate={~p"/translations/#{translation}/edit"}>Edit</.link>
|
||||||
</:action>
|
</:action>
|
||||||
<:action :let={translation}>
|
<:action :let={translation}>
|
||||||
<.link phx-click={JS.push("delete_translation", value: %{id: translation.id})} data-confirm="Are you sure?">
|
<.link phx-click={JS.push("delete_translation", value: %{id: translation.id})} data-confirm="Are you sure?">
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
Listing Translations
|
Listing Translations
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<.table id="translations" rows={@translations} row_click={&JS.navigate(~p(/translations/#{(&1).id}))}>
|
<.table id="translations" rows={@translations} row_click={&JS.navigate(~p(/translations/#{&1}))}>
|
||||||
<:col :let={translation} label="Language"><%= translation.language %></:col>
|
<:col :let={translation} label="Language"><%= translation.language %></:col>
|
||||||
<:col :let={translation} label="Title"><%= translation.title %></:col>
|
<:col :let={translation} label="Title"><%= translation.title %></:col>
|
||||||
<:col :let={translation} label="Teaser"><%= translation.teaser |> tidy_raw %></:col>
|
<:col :let={translation} label="Teaser"><%= translation.teaser |> tidy_raw %></:col>
|
||||||
@ -12,9 +12,9 @@
|
|||||||
<:col :let={translation} label="Unauthorized"><%= translation.unauthorized %></:col>
|
<:col :let={translation} label="Unauthorized"><%= translation.unauthorized %></:col>
|
||||||
<:action :let={translation}>
|
<:action :let={translation}>
|
||||||
<div class="sr-only">
|
<div class="sr-only">
|
||||||
<.link navigate={~p"/translations/#{translation.id}"}>Show</.link>
|
<.link navigate={~p"/translations/#{translation}"}>Show</.link>
|
||||||
</div>
|
</div>
|
||||||
<.link navigate={~p"/translations/#{translation.id}/edit"}>Edit</.link>
|
<.link navigate={~p"/translations/#{translation}/edit"}>Edit</.link>
|
||||||
</:action>
|
</:action>
|
||||||
<:action :let={translation}>
|
<:action :let={translation}>
|
||||||
<.link phx-click={JS.push("delete", value: %{id: translation.id})} data-confirm="Are you sure?">
|
<.link phx-click={JS.push("delete", value: %{id: translation.id})} data-confirm="Are you sure?">
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
Translation <%= @translation.id %>
|
Translation <%= @translation.id %>
|
||||||
<:subtitle>This is a translation record from your database.</:subtitle>
|
<:subtitle>This is a translation record from your database.</:subtitle>
|
||||||
<:actions>
|
<:actions>
|
||||||
<.link navigate={~p"/translations/#{@translation.id}/edit"} phx-click={JS.push_focus()}>
|
<.link navigate={~p"/translations/#{@translation}/edit"} phx-click={JS.push_focus()}>
|
||||||
<.button>Edit translation</.button>
|
<.button>Edit translation</.button>
|
||||||
</.link>
|
</.link>
|
||||||
</:actions>
|
</:actions>
|
||||||
|
|||||||
Reference in New Issue
Block a user