Unify PDF pagination system and rename templates

This commit is contained in:
2025-12-21 22:19:48 +01:00
parent 59fe69d35d
commit 53bdca87d5
2 changed files with 7 additions and 7 deletions
+3 -3
View File
@@ -20,12 +20,12 @@ func GenerateContinuationTemplateName(originalTemplate string, pageNum int) stri
// Pattern: page_N.html where N is a number // Pattern: page_N.html where N is a number
ext := ".html" ext := ".html"
base := strings.TrimSuffix(originalTemplate, ext) base := strings.TrimSuffix(originalTemplate, ext)
// Check if it's already a continuation (has .2 in it) // Check if it's already a continuation (has .2 in it)
if strings.Contains(base, ".2") { if strings.Contains(base, ".2") {
return originalTemplate return originalTemplate
} }
// Append .2 before .html // Append .2 before .html
return fmt.Sprintf("%s.2%s", base, ext) return fmt.Sprintf("%s.2%s", base, ext)
} }
@@ -42,7 +42,7 @@ func ExtractBaseTemplateName(templateName string) string {
// Remove .html // Remove .html
base := strings.TrimSuffix(templateName, ext) base := strings.TrimSuffix(templateName, ext)
// Find the last dot // Find the last dot
lastDotIdx := strings.LastIndex(base, ".") lastDotIdx := strings.LastIndex(base, ".")
if lastDotIdx == -1 { if lastDotIdx == -1 {
+4 -4
View File
@@ -166,9 +166,9 @@ func TestPaginateMultiList_WithOverflow(t *testing.T) {
for _, dist := range distributions { for _, dist := range distributions {
for blockName, data := range dist.Data { for blockName, data := range dist.Data {
// Only count skill blocks to avoid counting the same skills multiple times // Only count skill blocks to avoid counting the same skills multiple times
if skillsList, ok := data.([]SkillViewModel); ok && if skillsList, ok := data.([]SkillViewModel); ok &&
(blockName == "skills_column1" || blockName == "skills_column2" || (blockName == "skills_column1" || blockName == "skills_column2" ||
blockName == "skills_column3" || blockName == "skills_column4") { blockName == "skills_column3" || blockName == "skills_column4") {
totalSkills += len(skillsList) totalSkills += len(skillsList)
} }
} }
@@ -837,7 +837,7 @@ func TestCalculatePagesNeeded(t *testing.T) {
{"10 skills on page1", "page_1.html", "skills", 10, 1}, {"10 skills on page1", "page_1.html", "skills", 10, 1},
{fmt.Sprintf("%d skills on page1", skillCapacity), "page_1.html", "skills", skillCapacity, 1}, {fmt.Sprintf("%d skills on page1", skillCapacity), "page_1.html", "skills", skillCapacity, 1},
{fmt.Sprintf("%d skills on page1", skillCapacity+1), "page_1.html", "skills", skillCapacity + 1, 2}, {fmt.Sprintf("%d skills on page1", skillCapacity+1), "page_1.html", "skills", skillCapacity + 1, 2},
{"100 skills on page1", "page_1.html", "skills", 100, (100 + skillCapacity - 1) / skillCapacity}, // Dynamic calculation {"100 skills on page1", "page_1.html", "skills", 100, (100 + skillCapacity - 1) / skillCapacity}, // Dynamic calculation
{"10 weapons on page2", "page_2.html", "weapons", 10, (10 + weaponCapacity - 1) / weaponCapacity}, // Dynamic calculation {"10 weapons on page2", "page_2.html", "weapons", 10, (10 + weaponCapacity - 1) / weaponCapacity}, // Dynamic calculation
{fmt.Sprintf("%d weapons on page2", weaponCapacity), "page_2.html", "weapons", weaponCapacity, 1}, {fmt.Sprintf("%d weapons on page2", weaponCapacity), "page_2.html", "weapons", weaponCapacity, 1},
{fmt.Sprintf("%d weapons on page2", weaponCapacity+1), "page_2.html", "weapons", weaponCapacity + 1, 2}, {fmt.Sprintf("%d weapons on page2", weaponCapacity+1), "page_2.html", "weapons", weaponCapacity + 1, 2},