Add first step of creating an Article
This commit is contained in:
@ -1,9 +1,6 @@
|
||||
<.header>
|
||||
Listing Articles
|
||||
<:actions>
|
||||
<.link patch={~p"/articles/new"}>
|
||||
<.button>New Article</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
|
||||
55
lib/outlook_web/live/article_live/new.ex
Normal file
55
lib/outlook_web/live/article_live/new.ex
Normal file
@ -0,0 +1,55 @@
|
||||
defmodule OutlookWeb.ArticleLive.New do
|
||||
use OutlookWeb, :live_view
|
||||
|
||||
import OutlookWeb.ArticleLive.NewComponents
|
||||
|
||||
alias Outlook.{Articles,Authors,HtmlPreparations}
|
||||
alias Articles.{Article,RawHtmlInput}
|
||||
|
||||
require Logger
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:page_title, "New Article")
|
||||
|> assign(:article, %Article{})
|
||||
|> assign(:raw_html_input, %RawHtmlInput{})
|
||||
|> assign(:changeset, Articles.change_raw_html_input(%RawHtmlInput{}))
|
||||
|> assign(:selected_els, [])
|
||||
|> assign(:step, :import_raw_html)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(%{"author_id" => author_id}, _, socket) do
|
||||
author = Authors.get_author!(author_id)
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:author, author)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("validate_raw_html_input", %{"raw_html_input" => raw_html_input_params}, socket) do
|
||||
changeset = validate_raw_html_input(raw_html_input_params, socket)
|
||||
{:noreply, assign(socket, :changeset, changeset)}
|
||||
end
|
||||
|
||||
def handle_event("convert_raw_html_input", %{"raw_html_input" => raw_html_input_params}, socket) do
|
||||
changeset = validate_raw_html_input(raw_html_input_params, socket)
|
||||
case changeset.valid? do
|
||||
true ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:raw_internal_tree, HtmlPreparations.convert_raw_html_input(raw_html_input_params["content"]))
|
||||
|> assign(:step, :review_raw_internaltree)}
|
||||
false ->
|
||||
{:noreply, assign(socket, :changeset, changeset)}
|
||||
end
|
||||
end
|
||||
|
||||
defp validate_raw_html_input(raw_html_input_params, socket) do
|
||||
socket.assigns.raw_html_input
|
||||
|> Articles.change_raw_html_input(raw_html_input_params)
|
||||
|> Map.put(:action, :validate)
|
||||
end
|
||||
end
|
||||
9
lib/outlook_web/live/article_live/new.html.heex
Normal file
9
lib/outlook_web/live/article_live/new.html.heex
Normal file
@ -0,0 +1,9 @@
|
||||
<.header>
|
||||
New article for <%= @author.name %>
|
||||
</.header>
|
||||
|
||||
<.import_raw_html :if={@step == :import_raw_html} changeset={@changeset}></.import_raw_html>
|
||||
<.review_raw_internaltree :if={@step == :review_raw_internaltree}></.review_raw_internaltree>
|
||||
<.review_translation_units :if={@step == :review_translation_units}></.review_translation_units>
|
||||
|
||||
<.back navigate={~p"/authors/#{@author}"}>Back to author</.back>
|
||||
37
lib/outlook_web/live/article_live/new_components.ex
Normal file
37
lib/outlook_web/live/article_live/new_components.ex
Normal file
@ -0,0 +1,37 @@
|
||||
defmodule OutlookWeb.ArticleLive.NewComponents do
|
||||
use OutlookWeb, :html
|
||||
|
||||
def import_raw_html(assigns) do
|
||||
~H"""
|
||||
<div>
|
||||
<div>Import article</div>
|
||||
|
||||
<.simple_form
|
||||
:let={f}
|
||||
for={@changeset}
|
||||
id="raw-html-input-form"
|
||||
phx-change="validate_raw_html_input"
|
||||
phx-submit="convert_raw_html_input"
|
||||
>
|
||||
<.input field={{f, :content}} type="textarea" label="text to import" phx-debounce="500" />
|
||||
<:actions>
|
||||
<.button phx-disable-with="Importing...">HTML importieren</.button>
|
||||
</:actions>
|
||||
</.simple_form>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
def review_raw_internaltree(assigns) do
|
||||
~H"""
|
||||
<div>Review Raw InternalTree</div>
|
||||
|
||||
"""
|
||||
end
|
||||
|
||||
def review_translation_units(assigns) do
|
||||
~H"""
|
||||
<div>Review Translation Units</div>
|
||||
"""
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user