Update tunit editor

Now with fancy new radio-buttons.
This commit is contained in:
Thelonius Kort
2023-01-10 23:20:20 +01:00
parent e16710664d
commit 24e58c7d96
5 changed files with 37 additions and 34 deletions

View File

@ -3,4 +3,5 @@
@import "tailwindcss/utilities"; @import "tailwindcss/utilities";
/* This file is for your main application CSS */ /* This file is for your main application CSS */
@import "./article.css" @import "./article.css";
@import "./tunit-editor.css";

View File

@ -0,0 +1,3 @@
.tunit-status input[type="radio"]:checked+label {
@apply opacity-100 text-gray-100
}

View File

@ -3,49 +3,48 @@ defmodule OutlookWeb.TunitEditorComponent do
use Phoenix.Component use Phoenix.Component
import OutlookWeb.CoreComponents import OutlookWeb.CoreComponents
# alias Phoenix.LiveView.JS
defp statuses do
[ {:untranslated, "bg-red-800 col-span-3 disabled:border-gray-600"},
{:passable, "bg-amber-500 col-span-2 disabled:border-gray-600"},
{:done, "bg-green-700 disabled:border-gray-600"} ]
end
attr :current_tunit, :any attr :current_tunit, :any
attr :target, :string attr :target, :string
def tunit_editor(assigns) do def tunit_editor(assigns) do
assigns = unless assigns.current_tunit do
assigns
|> assign(
current_tunit: %Outlook.InternalTree.TranslationUnit{},
disabled: true
)
else
assigns |> assign(disabled: false)
end
~H""" ~H"""
<div id="translation-unit-editor" phx-nohook="tunit_editor"> <div id="translation-unit-editor" phx-nohook="tunit_editor">
<%!-- <div class="h-48 p-2 border border-slate-500 rounded" contenteditable phx-no-change="update_current_tunit"> <%!-- <div class="h-48 p-2 border border-slate-500 rounded" contenteditable phx-no-change="update_current_tunit">
<%= @current_tunit.content |> raw %> <%= @current_tunit.content |> raw %>
</div> --%> </div> --%>
<form phx-change="update_current_tunit" phx-target={@target} disabled={@disabled}> <form phx-change="update_current_tunit" phx-target={@target}>
<textarea name="content" class="h-48 rounded border-slate-500 resize-none w-full"><%= @current_tunit.content %></textarea> <textarea name="content" class="h-48 rounded border-slate-500 resize-none w-full"
disabled={!@current_tunit.status}><%= @current_tunit.content %></textarea>
</form> </form>
<.status_selector target={@target} disabled={!@current_tunit.status} tunit={@current_tunit} />
</div> </div>
<div class="grid grid-cols-scheise gap-3"> """
<div :for={{status, class} <- statuses()}> end
<.status_button class={class} status={status} target={@target} disabled={@current_tunit.status == status}></.status_button>
</div> defp statuses() do
[ {:untranslated, "bg-red-800"},
{:passable, "bg-amber-500"},
{:done, "bg-green-700"} ]
end
defp status_selector(assigns) do
~H"""
<form phx-change="tunit_status" phx-target={@target}>
<div class="tunit-status flex justify-center">
<.status_button :for={{status, class} <- statuses()} forstatus={status}
status={@tunit.status} class={class} disabled={@disabled} />
</div> </div>
</form>
""" """
end end
defp status_button(assigns) do defp status_button(assigns) do
~H""" ~H"""
<.link phx-click="tunit_status" phx-value-status={@status} phx-target={@target}> <input type="radio" name="status" id={@forstatus} value={@forstatus} class="hidden"
<.button class={@class} title="select translation status" disabled={@disabled}><%= @status |> to_string %></.button> disabled={@disabled} checked={@status == @forstatus}>
</.link> <label for={@forstatus} title="change translation status"
class={[@class, "p-2 px-4 mx-4 text-center opacity-30 rounded-lg"]}><%= @forstatus %></label>
""" """
end end
end end

View File

@ -27,7 +27,6 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
options={Application.get_env(:outlook,:deepl)[:target_langs]} /> options={Application.get_env(:outlook,:deepl)[:target_langs]} />
<.input field={{f, :title}} type="text" label="title" /> <.input field={{f, :title}} type="text" label="title" />
<.input field={{f, :teaser}} type="textarea" label="teaser" class="h-28" /> <.input field={{f, :teaser}} type="textarea" label="teaser" class="h-28" />
<%!-- <.input field={{f, :content}} type="text" label="content" /> --%>
<.input field={{f, :date}} type="datetime-local" label="date" /> <.input field={{f, :date}} type="datetime-local" label="date" />
<div class="flex items-center justify-between"> <div class="flex items-center justify-between">
<.input field={{f, :public}} type="checkbox" label="public" /> <.input field={{f, :public}} type="checkbox" label="public" />
@ -56,7 +55,7 @@ defmodule OutlookWeb.TranslationLive.FormComponent do
{:ok, {:ok,
socket socket
|> assign(assigns) |> assign(assigns)
|> assign(:current_tunit, nil) |> assign(:current_tunit, %TranslationUnit{status: nil})
|> assign(:changeset, changeset) |> assign(:changeset, changeset)
|> assign_article_tree(translation) |> assign_article_tree(translation)
|> assign(:deepl_progress, nil)} |> assign(:deepl_progress, nil)}

View File

@ -50,6 +50,7 @@ defmodule OutlookWeb.TranslationLive.NewEdit do
defp common_assigns(socket) do defp common_assigns(socket) do
assign(socket, form_cmpnt_id: @form_cmpnt_id) assign(socket, form_cmpnt_id: @form_cmpnt_id)
|> assign(:page_title, page_title(socket.assigns.live_action))
end end
@impl true @impl true