Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/modules/emails/web/emails.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
</button>

<.link
navigate={Routes.path("/admin/modules/emails/templates")}
navigate={Routes.path("/admin/emails/templates")}
class="btn btn-outline btn-secondary btn-sm"
>
<.icon name="hero-document-text" class="w-4 h-4" />
Expand Down
8 changes: 4 additions & 4 deletions lib/modules/emails/web/template_editor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ defmodule PhoenixKit.Modules.Emails.Web.TemplateEditor do

## Routes

- `/admin/modules/emails/templates/new` - Create new template
- `/admin/modules/emails/templates/:id/edit` - Edit existing template
- `/admin/emails/templates/new` - Create new template
- `/admin/emails/templates/:id/edit` - Edit existing template

## Permissions

Expand Down Expand Up @@ -64,7 +64,7 @@ defmodule PhoenixKit.Modules.Emails.Web.TemplateEditor do
{:noreply,
socket
|> put_flash(:error, "Template not found")
|> push_navigate(to: Routes.path("/admin/modules/emails/templates"))}
|> push_navigate(to: Routes.path("/admin/emails/templates"))}

template ->
changeset = Template.changeset(template, %{})
Expand Down Expand Up @@ -378,7 +378,7 @@ defmodule PhoenixKit.Modules.Emails.Web.TemplateEditor do
socket
|> assign(:saving, false)
|> put_flash(:info, "Template '#{template.name}' created successfully")
|> push_navigate(to: Routes.path("/admin/modules/emails/templates"))}
|> push_navigate(to: Routes.path("/admin/emails/templates"))}

{:error, changeset} ->
{:noreply,
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/emails/web/template_editor.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<header class="w-full relative mb-6">
<%!-- Back Button (Left aligned) --%>
<.link
navigate={Routes.path("/admin/modules/emails/templates")}
navigate={Routes.path("/admin/emails/templates")}
class="btn btn-outline btn-primary btn-sm absolute left-0 top-0 -mb-12"
>
<.icon_arrow_left /> Back to Templates
Expand Down Expand Up @@ -383,7 +383,7 @@

<div class="flex gap-2">
<.link
navigate={Routes.path("/admin/modules/emails/templates")}
navigate={Routes.path("/admin/emails/templates")}
class="btn btn-ghost"
>
Cancel
Expand Down
12 changes: 5 additions & 7 deletions lib/modules/emails/web/templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ defmodule PhoenixKit.Modules.Emails.Web.Templates do

## Route

This LiveView is mounted at `{prefix}/admin/modules/emails/templates` and requires
This LiveView is mounted at `{prefix}/admin/emails/templates` and requires
appropriate admin permissions.

Note: `{prefix}` is your configured PhoenixKit URL prefix (default: `/phoenix_kit`).
Expand Down Expand Up @@ -110,14 +110,14 @@ defmodule PhoenixKit.Modules.Emails.Web.Templates do

{:noreply,
socket
|> push_patch(to: Routes.path("/admin/modules/emails/templates?#{new_params}"))}
|> push_patch(to: Routes.path("/admin/emails/templates?#{new_params}"))}
end

@impl true
def handle_event("clear_filters", _params, socket) do
{:noreply,
socket
|> push_patch(to: Routes.path("/admin/modules/emails/templates"))}
|> push_patch(to: Routes.path("/admin/emails/templates"))}
end

@impl true
Expand Down Expand Up @@ -188,9 +188,7 @@ defmodule PhoenixKit.Modules.Emails.Web.Templates do
|> assign(:show_clone_modal, false)
|> assign(:clone_template, nil)
|> put_flash(:info, "Template cloned successfully as '#{new_template.name}'")
|> push_navigate(
to: Routes.path("/admin/modules/emails/templates/#{new_template.uuid}/edit")
)}
|> push_navigate(to: Routes.path("/admin/emails/templates/#{new_template.uuid}/edit"))}

{:error, _changeset} ->
{:noreply,
Expand All @@ -213,7 +211,7 @@ defmodule PhoenixKit.Modules.Emails.Web.Templates do
def handle_event("edit_template", %{"uuid" => template_uuid}, socket) do
{:noreply,
socket
|> push_navigate(to: Routes.path("/admin/modules/emails/templates/#{template_uuid}/edit"))}
|> push_navigate(to: Routes.path("/admin/emails/templates/#{template_uuid}/edit"))}
end

@impl true
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/emails/web/templates.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<%!-- Action Buttons --%>
<div class="flex justify-end gap-2 mb-6">
<.link
navigate={Routes.path("/admin/modules/emails/templates/new")}
navigate={Routes.path("/admin/emails/templates/new")}
class="btn btn-primary btn-sm"
>
<.icon name="hero-plus" class="w-4 h-4 mr-1" /> New Template
Expand Down Expand Up @@ -316,7 +316,7 @@
<.pagination
current_page={@page}
total_pages={@total_pages}
base_path="/admin/modules/emails/templates"
base_path="/admin/emails/templates"
params={
%{
"search" => @filters.search,
Expand Down
77 changes: 77 additions & 0 deletions lib/modules/entities/entity_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,83 @@ defmodule PhoenixKit.Modules.Entities.EntityData do
"""
def update_data(entity_data, attrs), do: __MODULE__.update(entity_data, attrs)

@doc """
Bulk updates the status of multiple records by UUIDs.

Returns a tuple with the count of updated records and nil.

## Examples

iex> PhoenixKit.Modules.Entities.EntityData.bulk_update_status(["uuid1", "uuid2"], "archived")
{2, nil}
"""
def bulk_update_status(uuids, status) when is_list(uuids) and status in @valid_statuses do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)

from(d in __MODULE__, where: d.uuid in ^uuids)
|> repo().update_all(set: [status: status, date_updated: now])
end

@doc """
Bulk updates the category of multiple records by UUIDs.

Since category is stored in the JSONB data column, this requires
fetching and updating each record individually.

Returns a tuple with the count of updated records and nil.

## Examples

iex> PhoenixKit.Modules.Entities.EntityData.bulk_update_category(["uuid1", "uuid2"], "New Category")
{2, nil}
"""
def bulk_update_category(uuids, category) when is_list(uuids) do
now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second)

records = from(d in __MODULE__, where: d.uuid in ^uuids) |> repo().all()

Enum.each(records, fn record ->
updated_data = Map.put(record.data || %{}, "category", category)
changeset = changeset(record, %{data: updated_data, date_updated: now})
repo().update(changeset)
end)

{length(records), nil}
end

@doc """
Bulk deletes multiple records by UUIDs.

Returns a tuple with the count of deleted records and nil.

## Examples

iex> PhoenixKit.Modules.Entities.EntityData.bulk_delete(["uuid1", "uuid2"])
{2, nil}
"""
def bulk_delete(uuids) when is_list(uuids) do
from(d in __MODULE__, where: d.uuid in ^uuids)
|> repo().delete_all()
end

@doc """
Extracts unique categories from a list of entity data records.

Returns a sorted list of unique category values, excluding nil and empty strings.

## Examples

iex> PhoenixKit.Modules.Entities.EntityData.extract_unique_categories(records)
["Category A", "Category B", "Category C"]
"""
def extract_unique_categories(entity_data_records) when is_list(entity_data_records) do
entity_data_records
|> Enum.map(fn r -> get_in(r.data, ["category"]) end)
|> Enum.reject(&(&1 == nil || &1 == ""))
|> Enum.uniq()
|> Enum.sort()
end

@doc """
Gets statistical data about entity data records.

Expand Down
Loading
Loading