diff --git a/controllers/ausgabe_controller.go b/controllers/ausgabe_controller.go index 97afaad..ad74f9b 100644 --- a/controllers/ausgabe_controller.go +++ b/controllers/ausgabe_controller.go @@ -3,6 +3,7 @@ package controllers import ( "fmt" "strconv" + "strings" "github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging" "github.com/Theodor-Springmann-Stiftung/kgpz_web/viewmodels" @@ -31,16 +32,39 @@ func GetIssue(kgpz *xmlmodels.Library) fiber.Handler { return c.SendStatus(fiber.StatusNotFound) } - // Handle optional page parameter + // Handle optional page parameter (supports regular pages and Beilage format like b1-1, b2-2) pageParam := c.Params("page") var targetPage int + var beilageNumber int + var isBeilage bool if pageParam != "" { - pi, err := strconv.Atoi(pageParam) - if err != nil || pi < 1 { - logging.Error(err, "Page is not a valid number") - return c.SendStatus(fiber.StatusNotFound) + if strings.HasPrefix(pageParam, "b") { + // Handle Beilage format: b1-1, b2-2, etc. + parts := strings.Split(pageParam[1:], "-") + if len(parts) == 2 { + beilageNum, beilageErr := strconv.Atoi(parts[0]) + pageNum, pageErr := strconv.Atoi(parts[1]) + if beilageErr == nil && pageErr == nil && beilageNum > 0 && pageNum > 0 { + beilageNumber = beilageNum + targetPage = pageNum + isBeilage = true + } else { + logging.Error(nil, "Beilage page format is invalid") + return c.SendStatus(fiber.StatusNotFound) + } + } else { + logging.Error(nil, "Beilage page format is invalid") + return c.SendStatus(fiber.StatusNotFound) + } + } else { + // Handle regular page number + pi, err := strconv.Atoi(pageParam) + if err != nil || pi < 1 { + logging.Error(err, "Page is not a valid number") + return c.SendStatus(fiber.StatusNotFound) + } + targetPage = pi } - targetPage = pi } issue, err := viewmodels.NewSingleIssueView(yi, di, kgpz) @@ -52,12 +76,20 @@ func GetIssue(kgpz *xmlmodels.Library) fiber.Handler { // If a page was specified, validate it exists in this issue if targetPage > 0 { - if targetPage < issue.Issue.Von || targetPage > issue.Issue.Bis { - logging.Debug(fmt.Sprintf("Page %d not found in issue %d/%d (range: %d-%d)", targetPage, yi, di, issue.Issue.Von, issue.Issue.Bis)) - return c.SendStatus(fiber.StatusNotFound) + if isBeilage { + // For Beilage pages, check if the issue has supplements and validate the page range + // This validation is more complex as it depends on the actual Beilage structure + // For now, we'll accept any valid Beilage format and let the template handle validation + logging.Debug(fmt.Sprintf("Accessing Beilage %d, page %d in issue %d/%d", beilageNumber, targetPage, yi, di)) + } else { + // For regular pages, validate against the issue's page range + if targetPage < issue.Issue.Von || targetPage > issue.Issue.Bis { + logging.Debug(fmt.Sprintf("Page %d not found in issue %d/%d (range: %d-%d)", targetPage, yi, di, issue.Issue.Von, issue.Issue.Bis)) + return c.SendStatus(fiber.StatusNotFound) + } } } - return c.Render("/ausgabe/", fiber.Map{"model": issue, "year": yi, "issue": di, "targetPage": targetPage}, "fullwidth") + return c.Render("/ausgabe/", fiber.Map{"model": issue, "year": yi, "issue": di, "targetPage": targetPage, "beilageNumber": beilageNumber, "isBeilage": isBeilage}, "fullwidth") } } diff --git a/controllers/piece_controller.go b/controllers/piece_controller.go index 7b7d8fb..a26079e 100644 --- a/controllers/piece_controller.go +++ b/controllers/piece_controller.go @@ -63,16 +63,39 @@ func GetPieceWithPage(kgpz *xmlmodels.Library) fiber.Handler { return c.SendStatus(fiber.StatusNotFound) } - // Handle optional page parameter + // Handle optional page parameter (supports regular pages and Beilage format like b1-1, b2-2) pageParam := c.Params("page") var targetPage int + var beilageNumber int + var isBeilage bool if pageParam != "" { - pi, err := strconv.Atoi(pageParam) - if err != nil || pi < 1 { - logging.Error(err, "Page is not a valid number") - return c.SendStatus(fiber.StatusNotFound) + if strings.HasPrefix(pageParam, "b") { + // Handle Beilage format: b1-1, b2-2, etc. + parts := strings.Split(pageParam[1:], "-") + if len(parts) == 2 { + beilageNum, beilageErr := strconv.Atoi(parts[0]) + pageNum, pageErr := strconv.Atoi(parts[1]) + if beilageErr == nil && pageErr == nil && beilageNum > 0 && pageNum > 0 { + beilageNumber = beilageNum + targetPage = pageNum + isBeilage = true + } else { + logging.Error(nil, "Beilage page format is invalid") + return c.SendStatus(fiber.StatusNotFound) + } + } else { + logging.Error(nil, "Beilage page format is invalid") + return c.SendStatus(fiber.StatusNotFound) + } + } else { + // Handle regular page number + pi, err := strconv.Atoi(pageParam) + if err != nil || pi < 1 { + logging.Error(err, "Page is not a valid number") + return c.SendStatus(fiber.StatusNotFound) + } + targetPage = pi } - targetPage = pi } // Parse the generated ID format: YYYY-NNN-PPP @@ -108,20 +131,27 @@ func GetPieceWithPage(kgpz *xmlmodels.Library) fiber.Handler { // If a page was specified, validate it exists in this piece if targetPage > 0 { - pageExists := false - for _, pageEntry := range pieceView.AllPages { - if pageEntry.PageNumber == targetPage { - pageExists = true - break + if isBeilage { + // For Beilage pages, validation is more complex + // For now, we'll accept any valid Beilage format and let the template handle validation + logging.Debug(fmt.Sprintf("Accessing Beilage %d, page %d in piece %s", beilageNumber, targetPage, id)) + } else { + // For regular pages, validate against the piece's page range + pageExists := false + for _, pageEntry := range pieceView.AllPages { + if pageEntry.PageNumber == targetPage { + pageExists = true + break + } + } + if !pageExists { + logging.Debug(fmt.Sprintf("Page %d not found in piece %s", targetPage, id)) + return c.SendStatus(fiber.StatusNotFound) } - } - if !pageExists { - logging.Debug(fmt.Sprintf("Page %d not found in piece %s", targetPage, id)) - return c.SendStatus(fiber.StatusNotFound) } } - return c.Render("/piece/", fiber.Map{"model": pieceView, "pieceId": id, "targetPage": targetPage}, "fullwidth") + return c.Render("/piece/", fiber.Map{"model": pieceView, "pieceId": id, "targetPage": targetPage, "beilageNumber": beilageNumber, "isBeilage": isBeilage}, "fullwidth") } } diff --git a/views/routes/ausgabe/components/_inhaltsverzeichnis.gohtml b/views/routes/ausgabe/components/_inhaltsverzeichnis.gohtml index 6b4de6e..feb0a83 100644 --- a/views/routes/ausgabe/components/_inhaltsverzeichnis.gohtml +++ b/views/routes/ausgabe/components/_inhaltsverzeichnis.gohtml @@ -163,7 +163,7 @@ {{ end }} {{ $page }} diff --git a/views/routes/components/_akteur_beitraege.gohtml b/views/routes/components/_akteur_beitraege.gohtml index 864253f..d0481cf 100644 --- a/views/routes/components/_akteur_beitraege.gohtml +++ b/views/routes/components/_akteur_beitraege.gohtml @@ -48,22 +48,7 @@ {{ " " }}{{- range $groupIndex, $groupItem := $groupedItems -}} {{- range $issueIndex, $issue := $groupItem.Item.IssueRefs -}} {{- if or (gt $groupIndex 0) (gt $issueIndex 0) }}, {{ end -}} - {{ $issueData := GetIssue (printf "%d-%d" $issue.When.Year $issue.Nr) }} - {{- $url := printf "/%s/%d" $issue.When $issue.Nr -}} - {{- if $issue.Von -}} - {{- if $issue.Beilage -}} - {{- $url = printf "%s#beilage-%d-page-%d" $url $issue.Beilage $issue.Von -}} - {{- else -}} - {{- $url = printf "%s/%d" $url $issue.Von -}} - {{- end -}} - {{- end -}} - - {{- if $issueData -}} - {{ $issueData.Datum.When.Day }}.{{ $issueData.Datum.When.Month }}.{{ $issueData.Datum.When.Year }}/{{ $issue.Nr }}, S. {{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) }}-{{ $issue.Bis }}{{ end }} - {{- else -}} - {{ $issue.When.Day }}.{{ $issue.When.Month }}.{{ $issue.When.Year }}/{{ $issue.Nr }}, S. {{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) }}-{{ $issue.Bis }}{{ end }} - {{- end -}} - + {{ template "_citation" $issue }} {{- end -}} {{- end -}} {{- /* Add "Ganzer Beitrag" link if piece spans multiple issues */ -}} diff --git a/views/routes/components/_akteur_werke.gohtml b/views/routes/components/_akteur_werke.gohtml index c848772..eb2ecf1 100644 --- a/views/routes/components/_akteur_werke.gohtml +++ b/views/routes/components/_akteur_werke.gohtml @@ -182,22 +182,7 @@ {{ " " }}{{- range $pieceIndex, $p := $categoryPieces -}} {{- range $issueIndex, $issue := $p.Item.IssueRefs -}} {{- if or (gt $pieceIndex 0) (gt $issueIndex 0) }}, {{ end -}} - {{ $issueData := GetIssue (printf "%d-%d" $issue.When.Year $issue.Nr) }} - {{- $url := printf "/%s/%d" $issue.When $issue.Nr -}} - {{- if $issue.Von -}} - {{- if $issue.Beilage -}} - {{- $url = printf "%s#beilage-%d-page-%d" $url $issue.Beilage $issue.Von -}} - {{- else -}} - {{- $url = printf "%s/%d" $url $issue.Von -}} - {{- end -}} - {{- end -}} - - {{- if $issueData -}} - {{ $issueData.Datum.When.Day }}.{{ $issueData.Datum.When.Month }}.{{ $issueData.Datum.When.Year }}/{{ $issue.Nr }}, S. {{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) }}-{{ $issue.Bis }}{{ end }} - {{- else -}} - {{ $issue.When.Day }}.{{ $issue.When.Month }}.{{ $issue.When.Year }}/{{ $issue.Nr }}, S. {{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) }}-{{ $issue.Bis }}{{ end }} - {{- end -}} - + {{ template "_citation" $issue }} {{- end -}} {{- end -}} {{- /* Add "Ganzer Beitrag" link if piece spans multiple issues */ -}} @@ -319,22 +304,7 @@ {{ " " }}{{- range $pieceIndex, $p := $categoryPieces -}} {{- range $issueIndex, $issue := $p.Item.IssueRefs -}} {{- if or (gt $pieceIndex 0) (gt $issueIndex 0) }}, {{ end -}} - {{ $issueData := GetIssue (printf "%d-%d" $issue.When.Year $issue.Nr) }} - {{- $url := printf "/%s/%d" $issue.When $issue.Nr -}} - {{- if $issue.Von -}} - {{- if $issue.Beilage -}} - {{- $url = printf "%s#beilage-%d-page-%d" $url $issue.Beilage $issue.Von -}} - {{- else -}} - {{- $url = printf "%s/%d" $url $issue.Von -}} - {{- end -}} - {{- end -}} - - {{- if $issueData -}} - {{ $issueData.Datum.When.Day }}.{{ $issueData.Datum.When.Month }}.{{ $issueData.Datum.When.Year }}/{{ $issue.Nr }}, S. {{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) }}-{{ $issue.Bis }}{{ end }} - {{- else -}} - {{ $issue.When.Day }}.{{ $issue.When.Month }}.{{ $issue.When.Year }}/{{ $issue.Nr }}, S. {{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) }}-{{ $issue.Bis }}{{ end }} - {{- end -}} - + {{ template "_citation" $issue }} {{- end -}} {{- end -}} {{- /* Add "Ganzer Beitrag" link if piece spans multiple issues */ -}} diff --git a/views/routes/components/_citation.gohtml b/views/routes/components/_citation.gohtml index 3ac071c..fb6165d 100644 --- a/views/routes/components/_citation.gohtml +++ b/views/routes/components/_citation.gohtml @@ -19,7 +19,7 @@ {{- $url := printf "/%s/%d" $issue.When $issue.Nr -}} {{- if $issueData -}} -{{ $issueData.Datum.When.Day }}.{{ $issueData.Datum.When.Month }}.{{ $issueData.Datum.When.Year }} +{{ $issueData.Datum.When.Day }}.{{ $issueData.Datum.When.Month }}.{{ $issueData.Datum.When.Year }}/{{ $issue.Nr }} {{- else -}} -{{ $issue.When.Year }} Nr. {{ $issue.Nr }} +{{ $issue.When.Year }}/{{ $issue.Nr }} {{- end -}} -{{- if $issue.Von }} S. {{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) -}} +{{- if $issue.Von }}, {{ if $issue.Beilage }}Beil. {{ end }}{{ $issue.Von }}{{- if and $issue.Bis (ne $issue.Von $issue.Bis) -}} -{{ $issue.Bis }} {{- end -}} {{- end -}}