Add a workspace for tagging technique themes by family (#194)

An admin picks a technique theme and sees candidate endgames grouped by Key
with counts. Expanding a family previews its boards without starting a puzzle,
and selecting positions applies the theme in bulk as curated. Large families are
paginated so a 600-endgame group stays usable, and curated links can be removed
from the same surface.

Removal is scoped to curated links, so derived and community links are never
deleted by hand. Material themes are refused because derivation owns them.

Closes #187
This commit is contained in:
2026-11-17 21:55:37 +01:00
committed by GitHub
parent 946fc38756
commit e6f08e0ca6
8 changed files with 775 additions and 4 deletions
+28
View File
@@ -1,6 +1,8 @@
defmodule Chesstrainer.EndgamesTest do
use Chesstrainer.DataCase
import Chesstrainer.EndgamesFixtures
alias Chesstrainer.Endgames
alias Chesstrainer.Endgames.Endgame
alias Chesstrainer.Themes
@@ -387,4 +389,30 @@ defmodule Chesstrainer.EndgamesTest do
assert Endgames.curated_endgames() == []
end
end
describe "theme filters and pagination" do
test "groups endgames by whether they carry a theme" do
{:ok, theme} = Themes.create_theme(%{name: "Lucena", category: :endgame})
tagged = create_endgame!(@kr)
create_endgame!(@kq)
{:ok, _} = Endgames.update_endgame(tagged, %{}, [theme])
assert Endgames.list_key_groups(%{with_theme: {theme.id, :curated}}) == [{"KR v K", 1}]
assert Endgames.list_key_groups(%{without_theme: theme.id}) == [{"KQ v K", 1}]
end
test "paginates the endgames in one key group" do
endgames = for _ <- 1..3, do: endgame_fixture()
first = Endgames.list_endgames_for_key("K v K", %{}, limit: 2, offset: 0)
second = Endgames.list_endgames_for_key("K v K", %{}, limit: 2, offset: 2)
assert length(first) == 2
assert length(second) == 1
ids = Enum.map(first ++ second, & &1.id)
assert Enum.sort(ids) == Enum.sort(Enum.map(endgames, & &1.id))
assert length(Enum.uniq(ids)) == 3
end
end
end
+37
View File
@@ -218,6 +218,43 @@ defmodule Chesstrainer.ThemesTest do
end
end
describe "tag_endgames/3 and untag_endgame/3" do
test "adds curated links without duplicating them" do
theme = theme_fixture()
first = endgame_fixture()
second = endgame_fixture()
assert {:ok, 2} = Themes.tag_endgames(theme, [first.id, second.id])
assert {:ok, 2} = Themes.tag_endgames(theme, [first.id, second.id])
assert link_sources(first.id) == %{theme.id => "curated"}
assert link_sources(second.id) == %{theme.id => "curated"}
end
test "never overwrites a derived link" do
theme = theme_fixture()
endgame = endgame_fixture()
:ok = Themes.sync_derived_themes(endgame.id, [theme.id])
assert {:ok, 1} = Themes.tag_endgames(theme, [endgame.id])
assert link_sources(endgame.id) == %{theme.id => "derived"}
end
test "removes only the requested source" do
theme = theme_fixture()
curated = endgame_fixture()
community = endgame_fixture()
{:ok, _} = Themes.tag_endgames(theme, [curated.id], :curated)
{:ok, _} = Themes.tag_endgames(theme, [community.id], :community)
assert {:ok, 1} = Themes.untag_endgame(theme, curated.id, :curated)
assert link_sources(curated.id) == %{}
assert link_sources(community.id) == %{theme.id => "community"}
end
end
defp link_rows(endgame_id) do
Repo.all(
from l in "endgames_themes",