50 lines
1.2 KiB
Elixir
50 lines
1.2 KiB
Elixir
defmodule LabelmakerWeb.Home do
|
|
use LabelmakerWeb, :live_view
|
|
import LabelmakerWeb.RadioComponent
|
|
alias LabelmakerWeb.Constants
|
|
alias LabelmakerWeb.Tools
|
|
|
|
def mount(_params, _session, socket) do
|
|
assigns =
|
|
Constants.defaults()
|
|
|> Map.merge(Constants.preview())
|
|
|> Map.put(
|
|
:preview_background,
|
|
Tools.process_preview_background(Constants.preview().preview_background)
|
|
)
|
|
|> Enum.to_list()
|
|
|
|
{
|
|
:ok,
|
|
assign(
|
|
socket,
|
|
assigns
|
|
)
|
|
}
|
|
end
|
|
|
|
def handle_event("update_label", params, socket) do
|
|
assigns =
|
|
socket.assigns
|
|
|> Enum.map(fn {k, v} -> {Atom.to_string(k), v} end)
|
|
|> Map.new()
|
|
|> Map.merge(params)
|
|
|> Tools.process_parameters()
|
|
|> Enum.to_list()
|
|
|
|
{:noreply, assign(socket, assigns)}
|
|
end
|
|
|
|
def handle_event("update_preview", %{"bg" => bg}, socket) do
|
|
{:noreply, assign(socket, :preview_background, Tools.process_preview_background(bg))}
|
|
end
|
|
|
|
def handle_event("update_alignment", %{"option" => option}, socket) do
|
|
{:noreply, assign(socket, :align, option)}
|
|
end
|
|
|
|
def handle_event("make_label", params, socket) do
|
|
{:noreply, redirect(socket, to: ~p"/#{params["label"]}?#{Map.drop(params, ["label"])}")}
|
|
end
|
|
end
|