Replace uuids with "nanoid"s
This commit is contained in:
@ -39,13 +39,13 @@ defmodule Outlook.InternalTree.Html do
|
||||
end
|
||||
|
||||
def to_html([%TranslationUnit{} = tunit | rest]) do
|
||||
~s(<span class="tunit" uuid="#{tunit.uuid}" tu-status="#{tunit.status}">#{tunit.content}</span>) <> to_html(rest)
|
||||
~s(<span class="tunit" nid="#{tunit.nid}" tu-status="#{tunit.status}">#{tunit.content}</span>) <> to_html(rest)
|
||||
end
|
||||
|
||||
def to_html([]), do: ""
|
||||
|
||||
def to_html_preview([ %InternalNode{type: :element} = node | rest], target_id) do
|
||||
attr_string = Map.put(node.attributes, :uuid, node.uuid)
|
||||
attr_string = Map.put(node.attributes, :nid, node.nid)
|
||||
|> Enum.map_join(" ", fn {k,v} -> "#{k}=\"#{v}\"" end)
|
||||
"<#{node.name} #{attr_string}>" <>
|
||||
to_html_preview(node.content, target_id) <>
|
||||
@ -54,16 +54,16 @@ defmodule Outlook.InternalTree.Html do
|
||||
end
|
||||
|
||||
def to_html_preview([ %InternalNode{type: :text} = node | rest], target_id) do
|
||||
~s(<span uuid="#{node.uuid}">#{node.content}</span>) <> to_html_preview(rest, target_id)
|
||||
~s(<span nid="#{node.nid}">#{node.content}</span>) <> to_html_preview(rest, target_id)
|
||||
end
|
||||
|
||||
def to_html_preview([ %InternalNode{type: :comment} = node | rest], target_id) do
|
||||
~s(<span uuid="#{node.uuid}"><!--#{node.content}--></span>) <> to_html_preview(rest, target_id)
|
||||
~s(<span nid="#{node.nid}"><!--#{node.content}--></span>) <> to_html_preview(rest, target_id)
|
||||
end
|
||||
|
||||
def to_html_preview([ %TranslationUnit{} = tunit | rest], target_id) do
|
||||
~s|<span class="tunit" uuid="#{tunit.uuid}" tu-status="#{tunit.status}" phx-click="select_current_tunit"
|
||||
phx-value-uuid="#{tunit.uuid}" phx-target="#{target_id}">#{tunit.content}</span>| <> to_html_preview(rest, target_id)
|
||||
~s|<span class="tunit" nid="#{tunit.nid}" tu-status="#{tunit.status}" phx-click="select_current_tunit"
|
||||
phx-value-nid="#{tunit.nid}" phx-target="#{target_id}">#{tunit.content}</span>| <> to_html_preview(rest, target_id)
|
||||
end
|
||||
|
||||
def to_html_preview([], _target_id), do: ""
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
defmodule Outlook.InternalTree.InternalNode do
|
||||
@derive Jason.Encoder
|
||||
defstruct name: "", attributes: %{}, type: :atom, uuid: "", content: [], eph: %{}
|
||||
defstruct name: "", attributes: %{}, type: :atom, nid: "", content: [], eph: %{}
|
||||
end
|
||||
|
||||
@ -49,7 +49,7 @@ defmodule Outlook.InternalTree.InternalTree do
|
||||
end
|
||||
|
||||
defp set_attributes(node, atts, ids) do
|
||||
if node.uuid in ids do
|
||||
if node.nid in ids do
|
||||
set_attributes(node, atts)
|
||||
else
|
||||
node
|
||||
@ -63,7 +63,7 @@ defmodule Outlook.InternalTree.InternalTree do
|
||||
Map.put(attributes, "phx-click",atts.phx.click)
|
||||
# TODO: only convert to string if present
|
||||
|> Map.put("phx-target", atts.phx.target |> to_string)
|
||||
|> Map.put("phx-value-uuid", node.uuid)
|
||||
|> Map.put("phx-value-nid", node.nid)
|
||||
end
|
||||
%{node | eph: Map.put(node.eph, :attributes, attributes)}
|
||||
end
|
||||
|
||||
@ -4,7 +4,6 @@ defmodule Outlook.InternalTree.RawInternalBasic do
|
||||
Html and before splitting textnodes into %TranslationUnit{}s.
|
||||
"""
|
||||
|
||||
alias Ecto.UUID
|
||||
alias Outlook.InternalTree.InternalNode
|
||||
alias Outlook.InternalTree.TranslationUnit
|
||||
alias Outlook.InternalTree.Html
|
||||
@ -59,7 +58,7 @@ defmodule Outlook.InternalTree.RawInternalBasic do
|
||||
%TranslationUnit{
|
||||
content: Html.to_html(sentence),
|
||||
status: :untranslated,
|
||||
uuid: UUID.generate()
|
||||
nid: Nanoid.generate()
|
||||
}
|
||||
end
|
||||
)
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
defmodule Outlook.InternalTree.TranslationUnit do
|
||||
@derive Jason.Encoder
|
||||
defstruct status: :atom, uuid: "", content: "", eph: %{}
|
||||
defstruct status: :atom, nid: "", content: "", eph: %{}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user