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
20 changes: 17 additions & 3 deletions lib/modules/maintenance/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@ defmodule PhoenixKitWeb.Live.Modules.Maintenance.Settings do

alias PhoenixKit.Modules.Maintenance
alias PhoenixKit.Settings
alias PhoenixKit.Utils.Routes

def mount(params, _session, socket) do
# Set locale for LiveView process FIRST - preserve from params or socket assigns
locale = params["locale"] || socket.assigns[:current_locale]

if locale do
Gettext.put_locale(PhoenixKitWeb.Gettext, locale)
Process.put(:phoenix_kit_current_locale, locale)
end

# Get current path for navigation (after locale is set)
current_path = Routes.path("/admin/settings/maintenance")

def mount(_params, _session, socket) do
# Get current settings
config = Maintenance.get_config()

socket =
socket
|> assign(:page_title, "Maintenance Mode Settings")
|> assign(:project_title, Settings.get_setting("project_title", "PhoenixKit"))
|> assign(:current_path, current_path)
|> assign(:current_locale, locale)
|> assign(:header, config.header)
|> assign(:subtext, config.subtext)
|> assign(:enabled, config.enabled)
Expand Down Expand Up @@ -108,9 +122,9 @@ defmodule PhoenixKitWeb.Live.Modules.Maintenance.Settings do
flash={@flash}
phoenix_kit_current_scope={assigns[:phoenix_kit_current_scope]}
page_title="{@project_title} - Maintenance Mode Settings"
current_path={@url_path}
current_path={@current_path}
project_title={@project_title}
current_locale={assigns[:current_locale] || "en"}
current_locale={@current_locale}
>
<div class="container mx-auto px-4 py-6">
<%!-- Header Section --%>
Expand Down
157 changes: 96 additions & 61 deletions lib/phoenix_kit/modules/languages.ex

Large diffs are not rendered by default.

52 changes: 28 additions & 24 deletions lib/phoenix_kit/settings/settings.ex
Original file line number Diff line number Diff line change
Expand Up @@ -740,30 +740,34 @@ defmodule PhoenixKit.Settings do
],
"time_zone" => [
{"UTC-12 (Baker Island)", "-12"},
{"UTC-11 (American Samoa)", "-11"},
{"UTC-10 (Hawaii)", "-10"},
{"UTC-9 (Alaska)", "-9"},
{"UTC-8 (Pacific Time)", "-8"},
{"UTC-7 (Mountain Time)", "-7"},
{"UTC-6 (Central Time)", "-6"},
{"UTC-5 (Eastern Time)", "-5"},
{"UTC-4 (Atlantic Time)", "-4"},
{"UTC-3 (Argentina)", "-3"},
{"UTC-2 (Mid-Atlantic)", "-2"},
{"UTC-1 (Cape Verde)", "-1"},
{"UTC+0 (GMT/London)", "0"},
{"UTC+1 (Central Europe)", "1"},
{"UTC+2 (Eastern Europe)", "2"},
{"UTC+3 (Moscow)", "3"},
{"UTC+4 (Dubai)", "4"},
{"UTC+5 (Pakistan)", "5"},
{"UTC+6 (Bangladesh)", "6"},
{"UTC+7 (Thailand)", "7"},
{"UTC+8 (China/Singapore)", "8"},
{"UTC+9 (Japan/Korea)", "9"},
{"UTC+10 (Australia East)", "10"},
{"UTC+11 (Solomon Islands)", "11"},
{"UTC+12 (New Zealand)", "12"}
{"UTC-11 (Pago Pago, Niue)", "-11"},
{"UTC-10 (Honolulu, Tahiti)", "-10"},
{"UTC-9 (Anchorage, Juneau)", "-9"},
{"UTC-8 (Los Angeles, Vancouver, Seattle)", "-8"},
{"UTC-7 (Denver, Phoenix, Calgary)", "-7"},
{"UTC-6 (Chicago, Mexico City, Guatemala)", "-6"},
{"UTC-5 (New York, Toronto, Bogotá, Lima)", "-5"},
{"UTC-4 (Halifax, Caracas, Santiago)", "-4"},
{"UTC-3 (Buenos Aires, São Paulo, Montevideo)", "-3"},
{"UTC-2 (South Georgia)", "-2"},
{"UTC-1 (Azores, Cape Verde)", "-1"},
{"UTC+0 (London, Dublin, Lisbon, Accra)", "0"},
{"UTC+1 (Paris, Berlin, Rome, Madrid, Lagos)", "1"},
{"UTC+2 (Kyiv, Athens, Helsinki, Cairo, Johannesburg)", "2"},
{"UTC+3 (Istanbul, Riyadh, Nairobi, Baghdad, Moscow)", "3"},
{"UTC+4 (Dubai, Baku, Tbilisi)", "4"},
{"UTC+5 (Karachi, Tashkent, Yekaterinburg)", "5"},
{"UTC+5:30 (Mumbai, Delhi, Kolkata, Colombo)", "5.5"},
{"UTC+6 (Dhaka, Almaty, Bishkek)", "6"},
{"UTC+7 (Bangkok, Jakarta, Ho Chi Minh City)", "7"},
{"UTC+8 (Beijing, Singapore, Hong Kong, Perth)", "8"},
{"UTC+9 (Tokyo, Seoul, Pyongyang)", "9"},
{"UTC+9:30 (Adelaide, Darwin)", "9.5"},
{"UTC+10 (Sydney, Melbourne, Brisbane)", "10"},
{"UTC+11 (Honiara, Noumea)", "11"},
{"UTC+12 (Auckland, Fiji, Wellington)", "12"},
{"UTC+13 (Nuku'alofa, Apia)", "13"},
{"UTC+14 (Kiritimati)", "14"}
],
"date_format" => UtilsDate.get_date_format_options(),
"time_format" => UtilsDate.get_time_format_options()
Expand Down
1 change: 0 additions & 1 deletion lib/phoenix_kit/utils/routes.ex
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ defmodule PhoenixKit.Utils.Routes do

case locale do
:none -> "#{base_path}#{url_path}"
"en" -> "#{base_path}#{url_path}"
locale_value -> "#{base_path}/#{locale_value}#{url_path}"
end
else
Expand Down
19 changes: 14 additions & 5 deletions lib/phoenix_kit_web/components/admin_nav.ex
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ defmodule PhoenixKitWeb.Components.AdminNav do
attr(:nested, :boolean, default: false)
attr(:disable_active, :boolean, default: false)
attr(:exact_match_only, :boolean, default: false)
attr(:submenu_open, :boolean, default: false)

def admin_nav_item(assigns) do
active =
Expand All @@ -64,10 +65,16 @@ defmodule PhoenixKitWeb.Components.AdminNav do
navigate={@href}
class={[
"flex items-center py-2 rounded-lg text-sm font-medium transition-colors group",
if(@active,
do: "bg-primary text-primary-content hover:bg-primary/90",
else: "text-base-content hover:bg-base-200 hover:text-primary"
),
cond do
@active ->
"bg-primary text-primary-content hover:bg-primary/90"

@submenu_open ->
"bg-base-200/50 text-base-content hover:bg-base-200 hover:text-primary"

true ->
"text-base-content hover:bg-base-200 hover:text-primary"
end,
if(@mobile, do: "w-full", else: ""),
if(@nested, do: "pl-8 pr-3", else: "px-3")
]}
Expand Down Expand Up @@ -131,6 +138,8 @@ defmodule PhoenixKitWeb.Components.AdminNav do
<.icon name="hero-wrench-screwdriver" class="w-5 h-5" />
<% "storage" -> %>
<.icon name="hero-folder" class="w-5 h-5" />
<% "photo" -> %>
<.icon name="hero-photo" class="w-5 h-5" />
<% _ -> %>
<.icon name="hero-squares-2x2" class="w-5 h-5" />
<% end %>
Expand Down Expand Up @@ -588,7 +597,7 @@ defmodule PhoenixKitWeb.Components.AdminNav do
end

defp locale_candidate?(locale) do
String.length(locale) in 2..5 and Regex.match?(~r/^[a-z]{2}(?:-[A-Za-z0-9]{2,})?$/, locale)
String.length(locale) in 2..6 and Regex.match?(~r/^[a-z]{2}(?:-[A-Z]{2})?$/, locale)
end

# Helper function to get admin languages from settings
Expand Down
42 changes: 40 additions & 2 deletions lib/phoenix_kit_web/components/layout_wrapper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,15 @@ defmodule PhoenixKitWeb.Components.LayoutWrapper do
label="Users"
current_path={@current_path || ""}
disable_active={true}
submenu_open={
submenu_open?(@current_path, [
"/admin/users",
"/admin/users/live_sessions",
"/admin/users/sessions",
"/admin/users/roles",
"/admin/users/referral-codes"
])
}
/>

<%= if submenu_open?(@current_path, ["/admin/users", "/admin/users/live_sessions", "/admin/users/sessions", "/admin/users/roles", "/admin/users/referral-codes"]) do %>
Expand Down Expand Up @@ -309,6 +318,15 @@ defmodule PhoenixKitWeb.Components.LayoutWrapper do
label="Emails"
current_path={@current_path || ""}
disable_active={true}
submenu_open={
submenu_open?(@current_path, [
"/admin/emails",
"/admin/emails/dashboard",
"/admin/modules/emails/templates",
"/admin/emails/queue",
"/admin/emails/blocklist"
])
}
/>

<%= if submenu_open?(@current_path, ["/admin/emails", "/admin/emails/dashboard", "/admin/modules/emails/templates", "/admin/emails/queue", "/admin/emails/blocklist"]) do %>
Expand Down Expand Up @@ -365,6 +383,7 @@ defmodule PhoenixKitWeb.Components.LayoutWrapper do
label="Entities"
current_path={@current_path || ""}
disable_active={true}
submenu_open={submenu_open?(@current_path, ["/admin/entities"])}
/>

<%= if submenu_open?(@current_path, ["/admin/entities"]) do %>
Expand Down Expand Up @@ -405,6 +424,7 @@ defmodule PhoenixKitWeb.Components.LayoutWrapper do
label="Blogging"
current_path={@current_path || ""}
exact_match_only={true}
submenu_open={submenu_open?(@current_path, ["/admin/blogging"])}
/>

<%= if submenu_open?(@current_path, ["/admin/blogging"]) do %>
Expand Down Expand Up @@ -436,6 +456,21 @@ defmodule PhoenixKitWeb.Components.LayoutWrapper do
label="Settings"
current_path={@current_path || ""}
disable_active={true}
submenu_open={
submenu_open?(@current_path, [
"/admin/settings",
"/admin/settings/users",
"/admin/settings/referral-codes",
"/admin/settings/emails",
"/admin/settings/languages",
"/admin/settings/entities",
"/admin/settings/media",
"/admin/settings/storage/dimensions",
"/admin/settings/maintenance",
"/admin/settings/blogging",
"/admin/settings/seo"
])
}
/>

<%= if submenu_open?(@current_path, ["/admin/settings", "/admin/settings/users", "/admin/settings/referral-codes", "/admin/settings/emails", "/admin/settings/languages", "/admin/settings/entities", "/admin/settings/media", "/admin/settings/storage/dimensions", "/admin/settings/maintenance", "/admin/settings/blogging", "/admin/settings/seo"]) do %>
Expand Down Expand Up @@ -522,7 +557,7 @@ defmodule PhoenixKitWeb.Components.LayoutWrapper do
<%!-- Media section with submenu --%>
<.admin_nav_item
href={Routes.locale_aware_path(assigns, "/admin/settings/media")}
icon="storage"
icon="photo"
label="Media"
current_path={@current_path || ""}
nested={true}
Expand Down Expand Up @@ -840,7 +875,10 @@ defmodule PhoenixKitWeb.Components.LayoutWrapper do
end
end

defp looks_like_locale?(locale), do: String.length(locale) <= 3
defp looks_like_locale?(locale) do
# Match 2-letter codes (en, es) or regional variants (en-US, es-ES, zh-CN)
String.length(locale) <= 6 and String.match?(locale, ~r/^[a-z]{2}(-[A-Z]{2})?$/)
end

defp path_matches_any?(normalized_path, paths) do
Enum.any?(paths, fn path ->
Expand Down
11 changes: 11 additions & 0 deletions lib/phoenix_kit_web/live/modules/languages.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ defmodule PhoenixKitWeb.Live.Modules.Languages do
|> assign(:language_count, length(display_languages))
|> assign(:enabled_count, Enum.count(display_languages, & &1["is_enabled"]))
|> assign(:default_language, Enum.find(display_languages, & &1["is_default"]))
|> assign(:unknown_language_codes, get_unknown_language_codes(display_languages))
|> assign(
:available_languages_for_selection,
Languages.get_available_languages_for_selection()
Expand Down Expand Up @@ -285,6 +286,7 @@ defmodule PhoenixKitWeb.Live.Modules.Languages do
|> assign(:language_count, length(display_languages))
|> assign(:enabled_count, Enum.count(display_languages, & &1["is_enabled"]))
|> assign(:default_language, Enum.find(display_languages, & &1["is_default"]))
|> assign(:unknown_language_codes, get_unknown_language_codes(display_languages))
end

# Helper function to generate the language switcher code based on current settings
Expand All @@ -308,4 +310,13 @@ defmodule PhoenixKitWeb.Live.Modules.Languages do
nil -> "🌐"
end
end

# Helper function to identify unknown/deprecated language codes
defp get_unknown_language_codes(languages) do
languages
|> Enum.map(& &1["code"])
|> Enum.filter(fn code ->
Languages.get_predefined_language(code) == nil
end)
end
end
7 changes: 5 additions & 2 deletions lib/phoenix_kit_web/live/modules/languages.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@
<%= if language["is_default"] do %>
<span class="badge badge-primary badge-sm">Default</span>
<% end %>
<%= if language["code"] in @unknown_language_codes do %>
<span class="badge badge-warning badge-sm">Unknown</span>
<% end %>
</div>
<div class="flex items-center gap-2">
<%!-- Move buttons only in configured mode --%>
Expand Down Expand Up @@ -170,8 +173,8 @@
</button>
<% end %>

<%!-- Remove Button (only in configured mode, and not the default language) --%>
<%= if @in_configured_mode and not language["is_default"] do %>
<%!-- Remove Button (show for unknown codes or in configured mode, but not for default language) --%>
<%= if (language["code"] in @unknown_language_codes and not language["is_default"]) or (@in_configured_mode and not language["is_default"]) do %>
<button
class="btn btn-error btn-xs"
phx-click="remove_language"
Expand Down
42 changes: 42 additions & 0 deletions lib/phoenix_kit_web/live/settings.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,49 @@
class="dropdown-content z-[1] menu p-2 shadow-lg bg-base-100 rounded-box w-full mt-2 max-h-96 overflow-y-auto border border-base-300"
>
<ul class="space-y-1">
<%!-- Unknown/Deprecated Languages Section (if any exist) --%>
<% unknown_selected_codes =
Enum.filter(@admin_languages, fn code ->
PhoenixKit.Modules.Languages.get_predefined_language(code) == nil
end) %>

<%= if not Enum.empty?(unknown_selected_codes) do %>
<li class="menu-title">
<span class="text-warning">⚠️ Unknown/Deprecated Languages</span>
</li>
<%= for language_code <- unknown_selected_codes do %>
<li>
<a
class="flex items-center gap-3 p-3 rounded hover:bg-base-200 bg-warning/10"
phx-click="remove_admin_language_from_form"
phx-value-code={language_code}
>
<div class="flex-shrink-0">
<input
type="checkbox"
class="checkbox checkbox-warning pointer-events-none"
checked={true}
/>
</div>
<div class="flex-1 flex flex-wrap items-center gap-2">
<span class="text-xl">🌐</span>
<div class="flex flex-col">
<span class="font-medium">{language_code}</span>
<span class="text-xs text-warning">
Unknown code - click to remove
</span>
</div>
</div>
</a>
</li>
<% end %>
<div class="divider my-1"></div>
<% end %>

<%!-- Popular Languages Section --%>
<li class="menu-title">
<span>Available Languages</span>
</li>
<%= for language <- Enum.filter(PhoenixKit.Modules.Languages.get_available_languages(), & &1.code in PhoenixKit.Modules.Languages.get_default_language_codes()) do %>
<% is_selected = language.code in @admin_languages %>
<li>
Expand Down
15 changes: 9 additions & 6 deletions lib/phoenix_kit_web/live/settings/storage.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ defmodule PhoenixKitWeb.Live.Settings.Storage do
alias PhoenixKit.Utils.Routes

def mount(params, session, socket) do
# Get current path for navigation
current_path = get_current_path(socket, session)
# Set locale for LiveView process FIRST - preserve from params or socket assigns
locale = params["locale"] || socket.assigns[:current_locale]

if locale do
Gettext.put_locale(PhoenixKitWeb.Gettext, locale)
Process.put(:phoenix_kit_current_locale, locale)
end

# Set locale for LiveView process
locale = params["locale"] || socket.assigns[:current_locale] || "en"
Gettext.put_locale(PhoenixKitWeb.Gettext, locale)
Process.put(:phoenix_kit_current_locale, locale)
# Get current path for navigation (after locale is set)
current_path = get_current_path(socket, session)

# Get project title from settings
project_title = Settings.get_setting("project_title", "PhoenixKit")
Expand Down
Loading