Start of the machine form, and accounting of Lambent Machine candidates to port

052b2dd · gmorell · 2022-12-17 06:48

12 files +67 -7

Files changed

modified lib/lambent_ex/link.ex
+1 −1
@@ -1,6 +1,6 @@
1 1 defmodule LambentEx.Link do
2 2 @moduledoc false
3 − use Parent.GenServer
3 + use GenServer
4 4
5 5 @pubsub_name LambentEx.PubSub
6 6 @pubsub_topic "machine-"
modified lib/lambent_ex/schema/machines.ex
+41 −4
@@ -3,17 +3,54 @@ defmodule LambentEx.Schema.Machines do
3 3
4 4 use Ecto.Schema
5 5 import Ecto.Changeset
6 + import PolymorphicEmbed, only: [cast_polymorphic_embed: 3]
6 7
7 − alias LambentEx.Schema.Machines
8 + alias LambentEx.Schema.Machines
9 +
10 + @values %{
11 + gen_solid: "Solid",
12 + gen_solid_h: "Solid",
13 + gen_color_cycle: "Color Cycler",
14 + gen_chaser: "Chaser",
15 + gen_chaser_h: "Chaser (HSV)",
16 + gen_chaser_m: "Multi-Chaser",
17 + gen_chaser_mh: "Multi-Chaser (HSV)",
18 + gen_growth: "Growth",
19 + gen_rocker: "Rocker",
20 + gen_rainbows: "Rainbow",
21 + gen_scape: "Scape",
22 + gen_twinkler: "LA3PortTwinler",
23 + rcv_fft: "FFT Receiver",
24 + rcv_gsi: "GSI Receiver"
25 + }
8 26
9 27 embedded_schema do
10 − field :name, :string
28 + field(:name, :string)
29 +
30 + field(:type, Ecto.Enum,
31 + values:
32 + @values |> Map.keys()
33 + )
34 +
35 + field(:class, PolymorphicEmbed,
36 + types: [
37 + static: RoomSanctum.Configuration.Queries.AQI,
38 + chase: RoomSanctum.Configuration.Queries.Calendar
39 + ],
40 + on_type_not_found: :raise,
41 + on_replace: :update
42 + )
43 + end
44 +
45 + def values do
46 + @values
11 47 end
12 48
13 49 def changeset(source, params) do
14 50 source
15 − |> cast(params, ~w(name)a)
16 − |> validate_required([:name])
51 + |> cast(params, ~w(name type)a)
52 + |> cast_polymorphic_embed(:class, required: true)
53 + |> validate_required([:name, :type])
17 54 end
18 55
19 56 def change_machine(%Machines{} = machine, attrs \\ %{}) do
modified lib/lambent_ex_web/live/machines/form_component.ex
+12 −0
@@ -14,4 +14,16 @@ defmodule LambentEx.MachinesLive.FormComponent do
14 14 |> assign(:changeset, changeset)}
15 15 end
16 16
17 + @impl true
18 + def handle_event("validate", %{"machines" => machine_params}, socket) do
19 + changeset =
20 + socket.assigns.machine
21 + |> Machines.change_machine(machine_params)
22 + |> Map.put(:action, :validate)
23 + |> IO.inspect()
24 +
25 + {:noreply, assign(socket, :changeset, changeset)}
26 + end
27 +
28 + defp values, do: LambentEx.Schema.Machines.values |> Enum.map(fn {k,v} -> {v,k} end) |> Map.new
17 29 end
modified lib/lambent_ex_web/live/machines/form_component.html.heex
+9 −2
@@ -8,10 +8,17 @@
8 8 phx-change="validate"
9 9 phx-submit="save"
10 10 >
11 −
11 + <div class="flex">
12 + <div class="flex-none">
13 + <.input field={{f, :type}} type="select" label="Class" options={values} />
14 + </div>
15 + <div class="flex-auto">
16 + The Form For <%= @changeset.changes |> Map.get(:type)%>
17 + </div>
18 + </div>
12 19
13 20 <:actions>
14 − <.button phx-disable-with="Saving...">Create Machine</.button>
21 + <.button phx-disable-with="Creating...">Create Machine</.button>
15 22 </:actions>
16 23 </.simple_form>
17 24 </div>
modified mix.exs
+2 −0
@@ -52,6 +52,7 @@ defmodule LambentEx.MixProject do
52 52 {:telemetry_poller, "~> 1.0"},
53 53 {:gettext, "~> 0.20"},
54 54 {:jason, "~> 1.2"},
55 + {:poison, "~> 5.0"},
55 56 {:plug_cowboy, "~> 2.5"},
56 57 #
57 58 {:httpoison, "~> 1.8"},
@@ -63,6 +64,7 @@ defmodule LambentEx.MixProject do
63 64
64 65 {:ecto, "~> 3.0"},
65 66 {:phoenix_ecto, "~> 4.0"},
67 + {:polymorphic_embed, "~> 2.0.0"},
66 68 ]
67 69 end
68 70
modified mix.lock
+2 −0
@@ -33,6 +33,8 @@
33 33 "plug": {:hex, :plug, "1.14.0", "ba4f558468f69cbd9f6b356d25443d0b796fbdc887e03fa89001384a9cac638f", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "bf020432c7d4feb7b3af16a0c2701455cbbbb95e5b6866132cb09eb0c29adc14"},
34 34 "plug_cowboy": {:hex, :plug_cowboy, "2.6.0", "d1cf12ff96a1ca4f52207c5271a6c351a4733f413803488d75b70ccf44aebec2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "073cf20b753ce6682ed72905cd62a2d4bd9bad1bf9f7feb02a1b8e525bd94fa6"},
35 35 "plug_crypto": {:hex, :plug_crypto, "1.2.3", "8f77d13aeb32bfd9e654cb68f0af517b371fb34c56c9f2b58fe3df1235c1251a", [:mix], [], "hexpm", "b5672099c6ad5c202c45f5a403f21a3411247f164e4a8fab056e5cd8a290f4a2"},
36 + "poison": {:hex, :poison, "5.0.0", "d2b54589ab4157bbb82ec2050757779bfed724463a544b6e20d79855a9e43b24", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "11dc6117c501b80c62a7594f941d043982a1bd05a1184280c0d9166eb4d8d3fc"},
37 + "polymorphic_embed": {:hex, :polymorphic_embed, "2.0.1", "dadda9c6362054b9d82c58f70d5b3ade23775209990e79ee41fc662d1c255edf", [:mix], [{:ecto, "~> 3.8", [hex: :ecto, repo: "hexpm", optional: false]}, {:jason, "~> 1.3", [hex: :jason, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14 or ~> 3.2", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "337716c36aa6539729f738eb6e0555659b1d38b70225641274a67eb17570b820"},
36 38 "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
37 39 "ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.6", "cf344f5692c82d2cd7554f5ec8fd961548d4fd09e7d22f5b62482e5aeaebd4b0", [:make, :mix, :rebar3], [], "hexpm", "bdb0d2471f453c88ff3908e7686f86f9be327d065cc1ec16fa4540197ea04680"},
38 40 "tailwind": {:hex, :tailwind, "0.1.9", "25ba09d42f7bfabe170eb67683a76d6ec2061952dc9bd263a52a99ba3d24bd4d", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}], "hexpm", "9213f87709c458aaec313bb5f2df2b4d2cedc2b630e4ae821bf3c54c47a56d0b"},

Parents: d9e496f