Replace new.ex and edit.ex with new_edit.ex in translations_live
This commit is contained in:
@ -1,28 +0,0 @@
|
|||||||
defmodule OutlookWeb.TranslationLive.Edit do
|
|
||||||
use OutlookWeb, :live_view
|
|
||||||
|
|
||||||
alias Outlook.Articles
|
|
||||||
alias Outlook.Translations
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
def render(assigns) do
|
|
||||||
~H"""
|
|
||||||
<.live_component
|
|
||||||
module={OutlookWeb.TranslationLive.FormComponent}
|
|
||||||
id={:new}
|
|
||||||
title="New Translation"
|
|
||||||
action={@live_action}
|
|
||||||
translation={@translation}
|
|
||||||
translation_content={@translation_content}
|
|
||||||
navigate={~p"/translations"}
|
|
||||||
/>
|
|
||||||
"""
|
|
||||||
end
|
|
||||||
|
|
||||||
@impl true
|
|
||||||
def mount(%{"id" => id} = _params, _session, socket) do
|
|
||||||
socket = socket
|
|
||||||
|> assign_new(:translation, fn -> Translations.get_translation!(id) end)
|
|
||||||
{:ok, assign_new(socket, :translation_content, fn -> socket.assigns.translation.content end)}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,15 +1,18 @@
|
|||||||
defmodule OutlookWeb.TranslationLive.New do
|
defmodule OutlookWeb.TranslationLive.NewEdit do
|
||||||
use OutlookWeb, :live_view
|
use OutlookWeb, :live_view
|
||||||
|
|
||||||
alias Outlook.Articles
|
alias Outlook.{Articles,Translations}
|
||||||
alias Outlook.Translations.{Translation,Basic}
|
alias Outlook.Translations.{Translation,Basic}
|
||||||
|
alias OutlookWeb.TranslationLive.FormComponent
|
||||||
|
|
||||||
|
@form_cmpnt_id "formkomponente"
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
<.live_component
|
<.live_component
|
||||||
module={OutlookWeb.TranslationLive.FormComponent}
|
module={OutlookWeb.TranslationLive.FormComponent}
|
||||||
id={:new}
|
id={@form_cmpnt_id}
|
||||||
title="New Translation"
|
title="New Translation"
|
||||||
action={@live_action}
|
action={@live_action}
|
||||||
translation={@translation}
|
translation={@translation}
|
||||||
@ -20,7 +23,7 @@ defmodule OutlookWeb.TranslationLive.New do
|
|||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def mount(%{"article_id" => article_id} = _params, _session, socket) do
|
def mount(%{"article_id" => article_id} = _params, _session, socket) when socket.assigns.live_action == :new do
|
||||||
socket = socket
|
socket = socket
|
||||||
|> assign_new(:translation, fn ->
|
|> assign_new(:translation, fn ->
|
||||||
%Translation{
|
%Translation{
|
||||||
@ -28,11 +31,23 @@ defmodule OutlookWeb.TranslationLive.New do
|
|||||||
article: get_article(article_id)
|
article: get_article(article_id)
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|> common_assigns()
|
||||||
{:ok, assign_new(socket, :translation_content, fn ->
|
{:ok, assign_new(socket, :translation_content, fn ->
|
||||||
Basic.internal_tree_to_tunit_map(socket.assigns.translation.article.content) end)}
|
Basic.internal_tree_to_tunit_map(socket.assigns.translation.article.content) end)}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def mount(%{"id" => id} = _params, _session, socket) when socket.assigns.live_action == :edit do
|
||||||
|
socket = socket
|
||||||
|
|> assign_new(:translation, fn -> Translations.get_translation!(id) end)
|
||||||
|
|> common_assigns()
|
||||||
|
{:ok, assign_new(socket, :translation_content, fn -> socket.assigns.translation.content end)}
|
||||||
|
end
|
||||||
|
|
||||||
defp get_article(article_id) do
|
defp get_article(article_id) do
|
||||||
Articles.get_article!(article_id)
|
Articles.get_article!(article_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp common_assigns(socket) do
|
||||||
|
assign(socket, form_cmpnt_id: @form_cmpnt_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
@ -87,9 +87,8 @@ defmodule OutlookWeb.Router do
|
|||||||
|
|
||||||
live "/translations", TranslationLive.Index, :index
|
live "/translations", TranslationLive.Index, :index
|
||||||
|
|
||||||
live "/translations/new", TranslationLive.New, :new
|
live "/translations/new", TranslationLive.NewEdit, :new
|
||||||
|
live "/translations/:id/edit", TranslationLive.NewEdit, :edit
|
||||||
live "/translations/:id/edit", TranslationLive.Edit, :edit
|
|
||||||
|
|
||||||
live "/translations/:id", TranslationLive.Show, :show
|
live "/translations/:id", TranslationLive.Show, :show
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user