Viewer & Icon enhancements

This commit is contained in:
Simon Martens
2025-09-23 01:44:47 +02:00
parent b579539e66
commit fc5e8ae8a4
12 changed files with 497 additions and 281 deletions

View File

@@ -143,23 +143,31 @@ func PiecesForIssue(lib *xmlmodels.Library, issue xmlmodels.Issue) (PiecesByPage
defer lib.Pieces.Unlock()
for _, piece := range lib.Pieces.Array {
if d, ok := piece.ReferencesIssue(year, issue.Number.No); ok {
// Add main entry on starting page
p := PieceByIssue{Piece: piece, Reference: *d, IsContinuation: false}
if d.Beilage > 0 {
functions.MapArrayInsert(ppa.Items, d.Von, p)
} else {
functions.MapArrayInsert(ppi.Items, d.Von, p)
}
// Process ALL IssueRefs for this piece, not just the first match
for _, issueRef := range piece.IssueRefs {
if issueRef.Nr == issue.Number.No && issueRef.When.Year == year {
// DEBUG: Log piece details for specific issue
if year == 1771 && issue.Number.No == 29 {
fmt.Printf("DEBUG PiecesForIssue: Piece ID=%s, Von=%d, Bis=%d, Beilage=%d\n", piece.Identifier.ID, issueRef.Von, issueRef.Bis, issueRef.Beilage)
}
// Add continuation entries for subsequent pages (if Bis > Von)
if d.Bis > d.Von {
for page := d.Von + 1; page <= d.Bis; page++ {
pContinuation := PieceByIssue{Piece: piece, Reference: *d, IsContinuation: true}
if d.Beilage > 0 {
functions.MapArrayInsert(ppa.Items, page, pContinuation)
} else {
functions.MapArrayInsert(ppi.Items, page, pContinuation)
// Add main entry on starting page
p := PieceByIssue{Piece: piece, Reference: issueRef, IsContinuation: false}
if issueRef.Beilage > 0 {
functions.MapArrayInsert(ppa.Items, issueRef.Von, p)
} else {
functions.MapArrayInsert(ppi.Items, issueRef.Von, p)
}
// Add continuation entries for subsequent pages (if Bis > Von)
if issueRef.Bis > issueRef.Von {
for page := issueRef.Von + 1; page <= issueRef.Bis; page++ {
pContinuation := PieceByIssue{Piece: piece, Reference: issueRef, IsContinuation: true}
if issueRef.Beilage > 0 {
functions.MapArrayInsert(ppa.Items, page, pContinuation)
} else {
functions.MapArrayInsert(ppi.Items, page, pContinuation)
}
}
}
}
@@ -273,6 +281,7 @@ func CreateIndividualPagesWithMetadata(pieces PiecesByPage, lib *xmlmodels.Libra
for _, page := range pieces.Pages {
pageItems := pieces.Items[page]
// Sort pieces according to the ordering rules
sortedPageItems := sortPiecesOnPage(pageItems, page)
@@ -366,9 +375,12 @@ func determinePageIcon(pageNum int, allPages []int) string {
return "first"
}
slices.Sort(allPages)
firstPage := allPages[0]
lastPage := allPages[len(allPages)-1]
// Create a copy to avoid modifying the original slice
sortedPages := make([]int, len(allPages))
copy(sortedPages, allPages)
slices.Sort(sortedPages)
firstPage := sortedPages[0]
lastPage := sortedPages[len(sortedPages)-1]
// Newspaper layout logic based on physical page positioning
if pageNum == firstPage {

View File

@@ -44,6 +44,13 @@ func NewPieceView(piece xmlmodels.Piece, lib *xmlmodels.Library) (*PieceVM, erro
IssueContexts: []string{},
}
// DEBUG: Log piece details
fmt.Printf("DEBUG PieceView: Creating view for piece ID=%s\n", piece.Identifier.ID)
fmt.Printf("DEBUG PieceView: Piece has %d IssueRefs\n", len(piece.IssueRefs))
for i, ref := range piece.IssueRefs {
fmt.Printf("DEBUG PieceView: IssueRef[%d]: Year=%d, Nr=%d, Von=%d, Bis=%d, Beilage=%d\n", i, ref.When.Year, ref.Nr, ref.Von, ref.Bis, ref.Beilage)
}
// Extract title from piece
if len(piece.Title) > 0 {
pvm.Title = piece.Title[0]
@@ -71,7 +78,13 @@ func NewPieceView(piece xmlmodels.Piece, lib *xmlmodels.Library) (*PieceVM, erro
pvm.IssueContexts = append(pvm.IssueContexts, issueContext)
// Add pages for this issue reference
for pageNum := issueRef.Von; pageNum <= issueRef.Bis; pageNum++ {
// Handle case where Bis=0 (should be treated as single page at Von)
bis := issueRef.Bis
if bis == 0 {
bis = issueRef.Von
}
for pageNum := issueRef.Von; pageNum <= bis; pageNum++ {
pageEntry := PiecePageEntry{
PageNumber: pageNum,
IssueYear: issueRef.When.Year,
@@ -84,7 +97,7 @@ func NewPieceView(piece xmlmodels.Piece, lib *xmlmodels.Library) (*PieceVM, erro
}
// Get actual image path from registry
pageEntry.ImagePath = getImagePathFromRegistry(issueRef.When.Year, pageNum)
pageEntry.ImagePath = getImagePathFromRegistryWithBeilage(issueRef.When.Year, issueRef.Nr, pageNum, issueRef.Beilage > 0)
pvm.AllPages = append(pvm.AllPages, pageEntry)
}
@@ -92,6 +105,10 @@ func NewPieceView(piece xmlmodels.Piece, lib *xmlmodels.Library) (*PieceVM, erro
pvm.TotalPageCount = len(pvm.AllPages)
// DEBUG: Log final counts
fmt.Printf("DEBUG PieceView: Final counts - %d issue contexts, %d total pages\n", len(pvm.IssueContexts), pvm.TotalPageCount)
fmt.Printf("DEBUG PieceView: Issue contexts: %v\n", pvm.IssueContexts)
// Load images and update availability
if err := pvm.loadImages(); err != nil {
return nil, fmt.Errorf("failed to load images: %w", err)
@@ -214,6 +231,39 @@ func getImagePathFromRegistry(year, page int) string {
return fmt.Sprintf("/static/pictures/%d/seite_%d.jpg", year, page)
}
// getImagePathFromRegistryWithBeilage gets the actual image path, handling both regular and Beilage pages
func getImagePathFromRegistryWithBeilage(year, issue, page int, isBeilage bool) string {
// Initialize registry if needed
if err := initImageRegistry(); err != nil {
return ""
}
// For regular pages, use the old method
if !isBeilage {
key := fmt.Sprintf("%d-%d", year, page)
if imageFile, exists := imageRegistry.ByYearPage[key]; exists {
return imageFile.Path
}
// Fallback for regular pages
return fmt.Sprintf("/static/pictures/%d/seite_%d.jpg", year, page)
}
// For Beilage pages, search through all files for this year-issue
yearIssueKey := fmt.Sprintf("%d-%d", year, issue)
if issueFiles, exists := imageRegistry.ByYearIssue[yearIssueKey]; exists {
for _, file := range issueFiles {
if file.IsBeilage && file.Page == page {
fmt.Printf("DEBUG: Found Beilage image for year=%d, issue=%d, page=%d: %s\n", year, issue, page, file.Path)
return file.Path
}
}
}
// Fallback for Beilage pages
fmt.Printf("DEBUG: No Beilage image found for year=%d, issue=%d, page=%d\n", year, issue, page)
return fmt.Sprintf("/static/pictures/%d/%db-beilage-seite_%d.jpg", year, issue, page)
}
// populateOtherPieces finds and populates other pieces that appear on the same pages as this piece
func (pvm *PieceVM) populateOtherPieces(lib *xmlmodels.Library) error {
fmt.Printf("DEBUG: Starting populateOtherPieces for piece %s\n", pvm.Piece.Identifier.ID)
@@ -243,12 +293,21 @@ func (pvm *PieceVM) populateOtherPieces(lib *xmlmodels.Library) error {
continue
}
fmt.Printf("DEBUG: Found %d total pieces for issue %d/%d\n", len(piecesForIssue.Pages), pageEntry.IssueYear, pageEntry.IssueNumber)
fmt.Printf("DEBUG: PiecesForIssue.Pages = %v\n", piecesForIssue.Pages)
// Create IndividualPiecesByPage using the same function as ausgabe view
individualPieces := CreateIndividualPagesWithMetadata(piecesForIssue, lib)
fmt.Printf("DEBUG: CreateIndividualPagesWithMetadata created %d pages with pieces\n", len(individualPieces.Pages))
fmt.Printf("DEBUG: Pages with pieces: %v\n", individualPieces.Pages)
// DEBUG: Show what pages are available in the map
if pageEntry.PageNumber == 113 {
fmt.Printf("DEBUG: Available pages in individualPieces.Items: %v\n", individualPieces.Pages)
for pageNum := range individualPieces.Items {
fmt.Printf("DEBUG: Page %d has %d pieces\n", pageNum, len(individualPieces.Items[pageNum]))
}
}
// Get pieces that appear on this specific page
if individualPiecesOnPage, exists := individualPieces.Items[pageEntry.PageNumber]; exists {
fmt.Printf("DEBUG: Found %d pieces on page %d\n", len(individualPiecesOnPage), pageEntry.PageNumber)