mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Add theme slugs, kinds and link provenance (#192)
* add function for upgrading a user's plan in interactive Elixir * Add theme slugs, kinds and link provenance Themes gain a stable slug, an optional description and a kind so the app can tell material, motif and technique labels apart. Slugs are generated from the name on first save and keep their value when the theme is renamed, so links to a theme stay valid. Endgame-to-theme links now record their source (derived, curated or community) and creation time. Existing links are backfilled as curated. A derived pass can therefore replace only its own links, leaving human work untouched. The admin index shows each theme's kind and its coverage across the library. Creating a theme name requires the manage_themes capability, and members get an unauthorized error instead, ahead of the suggestion flow. Closes #185
This commit is contained in:
@@ -11,6 +11,12 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.Form do
|
||||
{"Tactic", "tactic"}
|
||||
]
|
||||
|
||||
@kind_options [
|
||||
{"Technique", "technique"},
|
||||
{"Motif", "motif"},
|
||||
{"Material", "material"}
|
||||
]
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
@@ -21,18 +27,31 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.Form do
|
||||
{@page_title}
|
||||
<:subtitle>
|
||||
Themes group endgames for filtering. Names must be unique within a category,
|
||||
ignoring case.
|
||||
ignoring case. The slug is generated from the name and stays fixed afterwards,
|
||||
so links to a theme keep working when it is renamed.
|
||||
</:subtitle>
|
||||
</.header>
|
||||
|
||||
<.form for={@form} id="theme-form" phx-change="validate" phx-submit="save">
|
||||
<.input field={@form[:name]} type="text" label="Name" autocomplete="off" required />
|
||||
<.input
|
||||
field={@form[:kind]}
|
||||
type="select"
|
||||
label="Kind"
|
||||
options={@kind_options}
|
||||
/>
|
||||
<.input
|
||||
field={@form[:category]}
|
||||
type="select"
|
||||
label="Category"
|
||||
options={@category_options}
|
||||
/>
|
||||
<.input
|
||||
field={@form[:description]}
|
||||
type="textarea"
|
||||
label="Description"
|
||||
rows="3"
|
||||
/>
|
||||
|
||||
<footer>
|
||||
<.button phx-disable-with="Saving..." variant="primary">Save theme</.button>
|
||||
@@ -54,6 +73,7 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.Form do
|
||||
socket
|
||||
|> assign(:page_title, "New theme")
|
||||
|> assign(:theme, theme)
|
||||
|> assign(:kind_options, @kind_options)
|
||||
|> assign(:category_options, @category_options)
|
||||
|> assign(:form, to_form(Themes.change_theme(theme)))
|
||||
end
|
||||
@@ -64,6 +84,7 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.Form do
|
||||
socket
|
||||
|> assign(:page_title, "Edit theme")
|
||||
|> assign(:theme, theme)
|
||||
|> assign(:kind_options, @kind_options)
|
||||
|> assign(:category_options, @category_options)
|
||||
|> assign(:form, to_form(Themes.change_theme(theme)))
|
||||
end
|
||||
@@ -87,13 +108,16 @@ defmodule ChesstrainerWeb.Admin.ThemeLive.Form do
|
||||
end
|
||||
|
||||
defp save_theme(socket, :new, theme_params) do
|
||||
case Themes.create_theme(theme_params) do
|
||||
case Themes.create_theme(socket.assigns.current_scope, theme_params) do
|
||||
{:ok, _theme} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Theme created successfully.")
|
||||
|> push_navigate(to: ~p"/admin/themes")}
|
||||
|
||||
{:error, :unauthorized} ->
|
||||
{:noreply, put_flash(socket, :error, "You are not authorized to manage themes.")}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign(socket, :form, to_form(changeset, action: :insert))}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user