neiam
/lambent_ex
Lambent Aether 5
public · Issues · Pulls 1 · Labels · Forks · Compare · Actions success · Badges · Packages
⭐
Log in to mark this repository.
push the cronos changes to force a rebuild
946604c · gmorell · 2023-07-14 13:19
Files changed
modified
lib/lambent_ex/cronos.ex
+5
−0
@@ -11,6 +11,11 @@ defmodule LambentEx.Cronos do
| 11 | 11 | |
| 12 | 12 | Process.send_after(self(), :work, :timer.seconds(60 - DateTime.utc_now().second + 1)) |
| 13 | 13 | {zone, result} = System.cmd("date", ["+%Z"]) |
| 14 | + zone = zone |> String.trim | |
| 15 | + zone = case zone do | |
| 16 | + "EDT" -> "America/New_York" | |
| 17 | + _otherwise -> zone | |
| 18 | + end | |
| 14 | 19 | |
| 15 | 20 | Logger.info( |
| 16 | 21 | "#{@s} Cronos uses the system timezone to determine when to tick and when to sleep, we've found this to be '#{zone}'" |
added
lib/lambent_ex/schema/cronos.ex
+19
−0
@@ -0,0 +1,19 @@
| 1 | +defmodule LambentEx.Schema.Cronos do | |
| 2 | + @moduledoc false | |
| 3 | + | |
| 4 | + use Ecto.Schema | |
| 5 | + import Ecto.Changeset | |
| 6 | + | |
| 7 | + embedded_schema do | |
| 8 | + field(:name, :string) | |
| 9 | + | |
| 10 | + field(:action, :string) | |
| 11 | + field(:targets, {:array, :string}) | |
| 12 | + end | |
| 13 | + | |
| 14 | + def changeset(source, params) do | |
| 15 | + source | |
| 16 | + |> cast(params, ~w(name action targets)a) | |
| 17 | + |> validate_required([:name, :action, :targets]) | |
| 18 | + end | |
| 19 | +end |
modified
lib/lambent_ex_web/live/services/cronos_form_component.ex
+8
−3
@@ -1,20 +1,21 @@
| 1 | 1 | defmodule LambentEx.ServicesLive.CronosFormComponent do |
| 2 | 2 | use LambentExWeb, :live_component |
| 3 | 3 | |
| 4 | − alias LambentEx.Schema.LinksB | |
| 4 | + alias LambentEx.Schema.Cronos | |
| 5 | 5 | alias LambentEx.Names |
| 6 | 6 | |
| 7 | 7 | @impl true |
| 8 | 8 | def update(assigns, socket) do |
| 9 | −# changeset = LinksB.change_link(link) | |
| 9 | + changeset = Cronos.changeset(assigns[:cronos], %{}) | |
| 10 | 10 | |
| 11 | 11 | {:ok, |
| 12 | 12 | socket |
| 13 | 13 | |> assign(assigns) |
| 14 | −# |> assign(:changeset, changeset) | |
| 14 | + |> assign(:changeset, changeset) | |
| 15 | 15 | } |
| 16 | 16 | end |
| 17 | 17 | |
| 18 | + | |
| 18 | 19 | @impl true |
| 19 | 20 | def handle_event("validate", %{"links_b" => links_params}, socket) do |
| 20 | 21 | changeset = |
@@ -40,4 +41,8 @@ defmodule LambentEx.ServicesLive.CronosFormComponent do
| 40 | 41 | # save_testyyyy(socket, socket.assigns.action, testyyyy_params) |
| 41 | 42 | # :ok |
| 42 | 43 | end |
| 44 | + | |
| 45 | + defp is_machine_action?(action) do | |
| 46 | + true | |
| 47 | + end | |
| 43 | 48 | end |
modified
lib/lambent_ex_web/live/services/cronos_form_component.html.heex
+33
−0
@@ -1,3 +1,36 @@
| 1 | 1 | <div> |
| 2 | 2 | <h1 class="text-3xl font-bold">Cronos Configuration</h1> |
| 3 | + <div> | |
| 4 | + <%= form_for @changeset, "#", [phx_change: "submit", phx_submit: "save"] do %> | |
| 5 | + <div> | |
| 6 | + <%= label :actions, "Select an action:" %> | |
| 7 | + <%= select :actions, @machine_actions ++ @link_actions, selected: Map.get(@changeset.data, :action), phx_change: "select_action" %> | |
| 8 | + </div> | |
| 9 | + <div class="mt-4"> | |
| 10 | + <% if is_machine_action?(@changeset.data) do %> | |
| 11 | + <%= label :targets, "Select a machine:" %> | |
| 12 | + <%= select :targets, @machine_targets, selected: Map.get(@changeset.data, :target), phx_change: "select_target" %> | |
| 13 | + <% else %> | |
| 14 | + <%= label :targets, "Select a link:" %> | |
| 15 | + <%= select :targets, @link_targets, selected: Map.get(@changeset.data, :target), phx_change: "select_target" %> | |
| 16 | + <% end %> | |
| 17 | + </div> | |
| 18 | + <div class="mt-4"> | |
| 19 | + <%= label :times, "Select times:" %> | |
| 20 | + <div class="flex flex-wrap -mx-2"> | |
| 21 | + <%= for time <- @times do %> | |
| 22 | + <div class="w-1/4 px-2"> | |
| 23 | + <label class="inline-flex items-center"> | |
| 24 | + <%= checkbox :times, time, checked: Map.has_key?(@changeset.data, time), phx_change: "check" %> | |
| 25 | + <span class="ml-2 text-gray-700"><%= time %></span> | |
| 26 | + </label> | |
| 27 | + </div> | |
| 28 | + <% end %> | |
| 29 | + </div> | |
| 30 | + </div> | |
| 31 | + <div class="mt-4"> | |
| 32 | + <%= submit "Save", phx_disable_with: "Saving..." %> | |
| 33 | + </div> | |
| 34 | + <% end %> | |
| 35 | + </div> | |
| 3 | 36 | </div> |
Parents: 277de6a