From 96d8f720c0dca0f3b186c394661a3999173ebfab Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Wed, 18 Sep 2024 21:48:22 +0100 Subject: [PATCH 1/7] Feat: update list_unarchived_links_by_index --- lib/cesium_link/links.ex | 6 +++++- lib/cesium_link/links/link.ex | 3 ++- .../migrations/20240918181533_add_link_scheduling.exs | 9 +++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 priv/repo/migrations/20240918181533_add_link_scheduling.exs diff --git a/lib/cesium_link/links.ex b/lib/cesium_link/links.ex index 9d05aa4..5d32da7 100644 --- a/lib/cesium_link/links.ex +++ b/lib/cesium_link/links.ex @@ -64,7 +64,11 @@ defmodule CesiumLink.Links do """ def list_unarchived_links_by_index do - Repo.all(from l in Link, where: l.archived == false, order_by: [asc: l.index]) + Link + |> where([l], fragment("? > now()", l.publish_at)) + |> where([l], l.archived == false ) + |> order_by([l], asc: l.index) + |> Repo.all() end @doc """ diff --git a/lib/cesium_link/links/link.ex b/lib/cesium_link/links/link.ex index e30d9d5..c9f8d39 100644 --- a/lib/cesium_link/links/link.ex +++ b/lib/cesium_link/links/link.ex @@ -5,7 +5,7 @@ defmodule CesiumLink.Links.Link do use CesiumLink.Schema @required_fields ~w(name emoji url attention edited_at)a - @optional_fields ~w(index archived visits)a + @optional_fields ~w(index archived visits publish_at)a schema "links" do field :archived, :boolean, default: false @@ -16,6 +16,7 @@ defmodule CesiumLink.Links.Link do field :url, :string field :visits, :integer, default: 0 field :edited_at, :utc_datetime + field :publish_at, :utc_datetime timestamps(type: :utc_datetime) end diff --git a/priv/repo/migrations/20240918181533_add_link_scheduling.exs b/priv/repo/migrations/20240918181533_add_link_scheduling.exs new file mode 100644 index 0000000..2fd3685 --- /dev/null +++ b/priv/repo/migrations/20240918181533_add_link_scheduling.exs @@ -0,0 +1,9 @@ +defmodule CesiumLink.Repo.Migrations.AddLinkScheduling do + use Ecto.Migration + + def change do + alter table(:links) do + add :publish_at, :utc_datetime + end + end +end From 994214819f68954534b444bf69663341e084a5e8 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Wed, 18 Sep 2024 21:51:14 +0100 Subject: [PATCH 2/7] Code Format --- lib/cesium_link/links.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cesium_link/links.ex b/lib/cesium_link/links.ex index 5d32da7..edab53a 100644 --- a/lib/cesium_link/links.ex +++ b/lib/cesium_link/links.ex @@ -66,7 +66,7 @@ defmodule CesiumLink.Links do def list_unarchived_links_by_index do Link |> where([l], fragment("? > now()", l.publish_at)) - |> where([l], l.archived == false ) + |> where([l], l.archived == false) |> order_by([l], asc: l.index) |> Repo.all() end From 3f115897703978f5f61c679c1a8fb654054ef286 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Wed, 18 Sep 2024 22:48:14 +0100 Subject: [PATCH 3/7] Feat:fregment update --- lib/cesium_link/links.ex | 2 +- lib/cesium_link_web/live/link_live/form_component.ex | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/cesium_link/links.ex b/lib/cesium_link/links.ex index edab53a..b194f77 100644 --- a/lib/cesium_link/links.ex +++ b/lib/cesium_link/links.ex @@ -65,7 +65,7 @@ defmodule CesiumLink.Links do """ def list_unarchived_links_by_index do Link - |> where([l], fragment("? > now()", l.publish_at)) + |> where([l], fragment("? <= now() OR ? IS NULL", l.publish_at, l.publish_at)) |> where([l], l.archived == false) |> order_by([l], asc: l.index) |> Repo.all() diff --git a/lib/cesium_link_web/live/link_live/form_component.ex b/lib/cesium_link_web/live/link_live/form_component.ex index dff7386..ec75d1d 100644 --- a/lib/cesium_link_web/live/link_live/form_component.ex +++ b/lib/cesium_link_web/live/link_live/form_component.ex @@ -19,6 +19,7 @@ defmodule CesiumLinkWeb.LinkLive.FormComponent do <.input field={@form[:emoji]} type="emoji" label="Emoji" /> <.input field={@form[:url]} type="text" label="URL" /> <.input field={@form[:attention]} type="checkbox" label="Attention" /> + <.input field={@form[:publish_at]} type="datetime-local" label="Publish At" /> <:actions> <.button phx-disable-with="Saving...">Save Link From 4c774262d919507edc4070a9ab42ab9b4a49fc9f Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Sun, 22 Sep 2024 20:24:41 +0100 Subject: [PATCH 4/7] requested changes links.ex --- lib/cesium_link/links.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cesium_link/links.ex b/lib/cesium_link/links.ex index b194f77..b2c8e13 100644 --- a/lib/cesium_link/links.ex +++ b/lib/cesium_link/links.ex @@ -66,7 +66,7 @@ defmodule CesiumLink.Links do def list_unarchived_links_by_index do Link |> where([l], fragment("? <= now() OR ? IS NULL", l.publish_at, l.publish_at)) - |> where([l], l.archived == false) + |> where([l], not l.archived) |> order_by([l], asc: l.index) |> Repo.all() end From 426dc0f4155d39ae4032bdddc08dd060f4bc8c70 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Sun, 22 Sep 2024 20:47:13 +0100 Subject: [PATCH 5/7] Fix:time input shows up when link is going to be created --- lib/cesium_link_web/live/link_live/form_component.ex | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/cesium_link_web/live/link_live/form_component.ex b/lib/cesium_link_web/live/link_live/form_component.ex index ec75d1d..9f1e0a7 100644 --- a/lib/cesium_link_web/live/link_live/form_component.ex +++ b/lib/cesium_link_web/live/link_live/form_component.ex @@ -19,7 +19,9 @@ defmodule CesiumLinkWeb.LinkLive.FormComponent do <.input field={@form[:emoji]} type="emoji" label="Emoji" /> <.input field={@form[:url]} type="text" label="URL" /> <.input field={@form[:attention]} type="checkbox" label="Attention" /> - <.input field={@form[:publish_at]} type="datetime-local" label="Publish At" /> + <%= if @action == :new do %> + <.input field={@form[:publish_at]} type="datetime-local" label="Publish At" /> + <% end %> <:actions> <.button phx-disable-with="Saving...">Save Link From 5a1be77f5c2b674bb8fef5b063b90b27c19f9e7c Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Fri, 27 Sep 2024 23:16:37 +0100 Subject: [PATCH 6/7] feat: opacity in schedul link --- .../live/link_live/index.html.heex | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index 3be9618..f80fb76 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -15,30 +15,46 @@ <.table id="links" rows={@streams.links} phx-hook="Sorting"> - <:col :let={{_id, _link}}><.icon name="hero-bars-3 cursor-pointer ml-4" class="handle w-5 h-5" /> + <:col :let={{_id, _link}}> + <% publish_future = _link.publish_at && DateTime.compare(_link.publish_at, DateTime.utc_now()) == :gt %> + <.icon name="hero-bars-3 cursor-pointer ml-4" class={"handle w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> + <:col :let={{_id, link}} label="Name"> -

<%= link.name %>

+ <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> +

<%= link.name %>

<:col :let={{_id, link}} label="Emoji"> - <.emoji code={link.emoji} /> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + + <.emoji code={link.emoji} /> + <:col :let={{_id, link}} label="URL"> - <.link target="_blank" class="hover:text-brand hover:underline" navigate={link.url}> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <.link target="_blank" class={"hover:text-brand hover:underline #{if publish_future, do: "opacity-50"}"} navigate={link.url}> <%= truncate_elipsis(link.url, 50) %> - <:col :let={{_id, link}} label="Clicks"><%= link.visits %> +<:col :let={{_id, link}} label="Clicks"> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> +

+ <%= link.visits %> +

+ <:col :let={{_id, link}} label="Attention"> - + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> + <:action :let={{_id, link}}> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> <.link patch={~p"/admin/links/#{link}/edit"}> - <.icon name="hero-pencil" class="w-5 h-5" /> + <.icon name="hero-pencil" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> <:action :let={{_id, link}}> + <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %> <.link patch={~p"/admin/links/#{link}/archive"}> - <.icon name="hero-archive-box" class="w-5 h-5" /> + <.icon name="hero-archive-box" class={"w-5 h-5 #{if publish_future, do: "opacity-50"}"} /> From e5227e0d7756f0633ca8a611c815a330d682e1e4 Mon Sep 17 00:00:00 2001 From: Afonso Martins Date: Fri, 27 Sep 2024 23:19:42 +0100 Subject: [PATCH 7/7] format code --- lib/cesium_link_web/live/link_live/index.html.heex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cesium_link_web/live/link_live/index.html.heex b/lib/cesium_link_web/live/link_live/index.html.heex index f80fb76..7c5d6f1 100644 --- a/lib/cesium_link_web/live/link_live/index.html.heex +++ b/lib/cesium_link_web/live/link_live/index.html.heex @@ -35,7 +35,7 @@ <%= truncate_elipsis(link.url, 50) %> -<:col :let={{_id, link}} label="Clicks"> + <:col :let={{_id, link}} label="Clicks"> <% publish_future = link.publish_at && DateTime.compare(link.publish_at, DateTime.utc_now()) == :gt %>

<%= link.visits %>