mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
Better beiträge view
This commit is contained in:
@@ -41,14 +41,14 @@ type IndividualPiecesByPage struct {
|
||||
}
|
||||
|
||||
type IssuePage struct {
|
||||
PageNumber int
|
||||
ImagePath string
|
||||
Available bool
|
||||
GridColumn int // 1 or 2 for left/right positioning
|
||||
GridRow int // Row number in grid
|
||||
HasHeader bool // Whether this page has a double-spread header
|
||||
HeaderText string // Text for double-spread header
|
||||
PageIcon string // Icon type: "first", "last", "even", "odd"
|
||||
PageNumber int
|
||||
ImagePath string
|
||||
Available bool
|
||||
GridColumn int // 1 or 2 for left/right positioning
|
||||
GridRow int // Row number in grid
|
||||
HasHeader bool // Whether this page has a double-spread header
|
||||
HeaderText string // Text for double-spread header
|
||||
PageIcon string // Icon type: "first", "last", "even", "odd"
|
||||
}
|
||||
|
||||
type IssueImages struct {
|
||||
@@ -78,12 +78,12 @@ var imageRegistry *ImageRegistry
|
||||
// TODO: Next & Prev
|
||||
type IssueVM struct {
|
||||
xmlmodels.Issue
|
||||
Next *xmlmodels.Issue
|
||||
Prev *xmlmodels.Issue
|
||||
Pieces IndividualPiecesByPage
|
||||
AdditionalPieces IndividualPiecesByPage
|
||||
Images IssueImages
|
||||
HasBeilageButton bool // Whether to show beilage navigation button
|
||||
Next *xmlmodels.Issue
|
||||
Prev *xmlmodels.Issue
|
||||
Pieces IndividualPiecesByPage
|
||||
AdditionalPieces IndividualPiecesByPage
|
||||
Images IssueImages
|
||||
HasBeilageButton bool // Whether to show beilage navigation button
|
||||
}
|
||||
|
||||
func NewSingleIssueView(y, no int, lib *xmlmodels.Library) (*IssueVM, error) {
|
||||
@@ -108,19 +108,10 @@ func NewSingleIssueView(y, no int, lib *xmlmodels.Library) (*IssueVM, error) {
|
||||
return nil, fmt.Errorf("No issue found for %v-%v", y, no)
|
||||
}
|
||||
|
||||
var Next *xmlmodels.Issue = nil
|
||||
var Prev *xmlmodels.Issue = nil
|
||||
if next != nil {
|
||||
Next = &*next
|
||||
}
|
||||
if prev != nil {
|
||||
Prev = &*prev
|
||||
}
|
||||
|
||||
sivm := IssueVM{Issue: *issue, Next: Next, Prev: Prev}
|
||||
sivm := IssueVM{Issue: *issue, Next: next, Prev: prev}
|
||||
|
||||
lib.Issues.Unlock()
|
||||
ppi, ppa, err := PiecesForIsssue(lib, *issue)
|
||||
ppi, ppa, err := PiecesForIssue(lib, *issue)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -142,13 +133,12 @@ func NewSingleIssueView(y, no int, lib *xmlmodels.Library) (*IssueVM, error) {
|
||||
return &sivm, nil
|
||||
}
|
||||
|
||||
func PiecesForIsssue(lib *xmlmodels.Library, issue xmlmodels.Issue) (PiecesByPage, PiecesByPage, error) {
|
||||
func PiecesForIssue(lib *xmlmodels.Library, issue xmlmodels.Issue) (PiecesByPage, PiecesByPage, error) {
|
||||
year := issue.Datum.When.Year
|
||||
|
||||
ppi := PiecesByPage{Items: make(map[int][]PieceByIssue)}
|
||||
ppa := PiecesByPage{Items: make(map[int][]PieceByIssue)}
|
||||
|
||||
// TODO: will we have to lock this, if we shutdown the server while loading the library?
|
||||
lib.Pieces.Lock()
|
||||
defer lib.Pieces.Unlock()
|
||||
|
||||
@@ -382,18 +372,18 @@ func determinePageIcon(pageNum int, allPages []int) string {
|
||||
|
||||
// Newspaper layout logic based on physical page positioning
|
||||
if pageNum == firstPage {
|
||||
return "first" // Front page - normal icon
|
||||
return "first" // Front page - normal icon
|
||||
} else if pageNum == lastPage {
|
||||
return "last" // Back page - mirrored icon
|
||||
return "last" // Back page - mirrored icon
|
||||
} else {
|
||||
// For middle pages in a 4-page newspaper layout:
|
||||
// Page 2 (left side of middle spread) should be "even"
|
||||
// Page 3 (right side of middle spread) should be "odd"
|
||||
// But we need to consider the actual page position in layout
|
||||
if pageNum == firstPage+1 {
|
||||
return "even" // Page 2 - black + mirrored grey
|
||||
return "even" // Page 2 - black + mirrored grey
|
||||
} else if pageNum == lastPage-1 {
|
||||
return "odd" // Page 3 - grey + black
|
||||
return "odd" // Page 3 - grey + black
|
||||
} else {
|
||||
// For newspapers with more than 4 pages, use alternating pattern
|
||||
if pageNum%2 == 0 {
|
||||
|
||||
@@ -16,6 +16,7 @@ type PiecePageEntry struct {
|
||||
IssueContext string // "1764 Nr. 37" for display
|
||||
Available bool
|
||||
OtherPieces []IndividualPieceByIssue // Other pieces on the same page
|
||||
PartNumber int // Which part of the piece (1, 2, 3, etc.)
|
||||
}
|
||||
|
||||
type PieceImages struct {
|
||||
@@ -25,14 +26,14 @@ type PieceImages struct {
|
||||
|
||||
type PieceVM struct {
|
||||
xmlmodels.Piece
|
||||
AllIssueRefs []xmlmodels.IssueRef // All issues containing this piece
|
||||
AllPages []PiecePageEntry // Flattened chronological page list
|
||||
ContinuousPages IndividualPiecesByPage // For template compatibility
|
||||
Images PieceImages // All page images across issues
|
||||
TotalPageCount int
|
||||
Title string // Extracted piece title
|
||||
MainCategory string // Primary category
|
||||
IssueContexts []string // List of issue contexts for display
|
||||
AllIssueRefs []xmlmodels.IssueRef // All issues containing this piece
|
||||
AllPages []PiecePageEntry // Flattened chronological page list
|
||||
ContinuousPages IndividualPiecesByPage // For template compatibility
|
||||
Images PieceImages // All page images across issues
|
||||
TotalPageCount int
|
||||
Title string // Extracted piece title
|
||||
MainCategory string // Primary category
|
||||
IssueContexts []string // List of issue contexts for display
|
||||
}
|
||||
|
||||
func NewPieceView(piece xmlmodels.Piece, lib *xmlmodels.Library) (*PieceVM, error) {
|
||||
@@ -77,8 +78,9 @@ func NewPieceView(piece xmlmodels.Piece, lib *xmlmodels.Library) (*PieceVM, erro
|
||||
IssueNumber: issueRef.Nr,
|
||||
IsContinuation: pageNum > issueRef.Von || partIndex > 0,
|
||||
IssueContext: issueContext,
|
||||
Available: true, // Will be updated when we load images
|
||||
Available: true, // Will be updated when we load images
|
||||
OtherPieces: []IndividualPieceByIssue{}, // Will be populated later
|
||||
PartNumber: partIndex + 1, // Part number (1-based)
|
||||
}
|
||||
|
||||
// Get actual image path from registry
|
||||
@@ -123,7 +125,7 @@ func (pvm *PieceVM) loadImages() error {
|
||||
issuePage := IssuePage{
|
||||
PageNumber: pageEntry.PageNumber,
|
||||
ImagePath: pageEntry.ImagePath,
|
||||
Available: true, // Assume available for now
|
||||
Available: true, // Assume available for now
|
||||
PageIcon: "single", // Simplified icon for piece view
|
||||
}
|
||||
|
||||
@@ -214,7 +216,7 @@ func getImagePathFromRegistry(year, page int) string {
|
||||
|
||||
// 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.ID)
|
||||
fmt.Printf("DEBUG: Starting populateOtherPieces for piece %s\n", pvm.Piece.Identifier.ID)
|
||||
for i, pageEntry := range pvm.AllPages {
|
||||
fmt.Printf("DEBUG: Processing page %d from issue %d/%d\n", pageEntry.PageNumber, pageEntry.IssueYear, pageEntry.IssueNumber)
|
||||
|
||||
@@ -235,14 +237,17 @@ func (pvm *PieceVM) populateOtherPieces(lib *xmlmodels.Library) error {
|
||||
}
|
||||
|
||||
// Get all pieces for this issue using the same approach as the ausgabe view
|
||||
piecesForIssue, _, err := PiecesForIsssue(lib, *issue)
|
||||
piecesForIssue, _, err := PiecesForIssue(lib, *issue)
|
||||
if err != nil {
|
||||
fmt.Printf("DEBUG: Error getting pieces for issue: %v\n", err)
|
||||
continue
|
||||
}
|
||||
fmt.Printf("DEBUG: Found %d total pieces for issue %d/%d\n", len(piecesForIssue.Pages), pageEntry.IssueYear, pageEntry.IssueNumber)
|
||||
|
||||
// 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)
|
||||
|
||||
// Get pieces that appear on this specific page
|
||||
if individualPiecesOnPage, exists := individualPieces.Items[pageEntry.PageNumber]; exists {
|
||||
@@ -250,14 +255,47 @@ func (pvm *PieceVM) populateOtherPieces(lib *xmlmodels.Library) error {
|
||||
otherPieces := []IndividualPieceByIssue{}
|
||||
|
||||
for _, individualPiece := range individualPiecesOnPage {
|
||||
fmt.Printf("DEBUG: Checking piece %s (current: %s)\n", individualPiece.PieceByIssue.Piece.ID, pvm.Piece.ID)
|
||||
// Skip the current piece itself
|
||||
if individualPiece.PieceByIssue.Piece.ID == pvm.Piece.ID {
|
||||
fmt.Printf("DEBUG: Skipping current piece\n")
|
||||
continue
|
||||
// Debug piece information
|
||||
pieceTitle := "no title"
|
||||
if len(individualPiece.PieceByIssue.Piece.Title) > 0 {
|
||||
pieceTitle = individualPiece.PieceByIssue.Piece.Title[0]
|
||||
} else if len(individualPiece.PieceByIssue.Piece.Incipit) > 0 {
|
||||
pieceTitle = individualPiece.PieceByIssue.Piece.Incipit[0]
|
||||
}
|
||||
|
||||
fmt.Printf("DEBUG: Adding other piece %s\n", individualPiece.PieceByIssue.Piece.ID)
|
||||
currentTitle := "no title"
|
||||
if len(pvm.Piece.Title) > 0 {
|
||||
currentTitle = pvm.Piece.Title[0]
|
||||
} else if len(pvm.Piece.Incipit) > 0 {
|
||||
currentTitle = pvm.Piece.Incipit[0]
|
||||
}
|
||||
|
||||
fmt.Printf("DEBUG: Checking piece title='%s' (current title='%s')\n", pieceTitle, currentTitle)
|
||||
|
||||
// Skip the current piece itself - use content-based comparison
|
||||
// Compare by title/incipit and issue references
|
||||
if pieceTitle == currentTitle && pieceTitle != "no title" {
|
||||
// Same title, now check if they have the same issue references
|
||||
foundPieceRef := individualPiece.PieceByIssue.Reference
|
||||
isSamePiece := false
|
||||
|
||||
for _, currentRef := range pvm.Piece.IssueRefs {
|
||||
if currentRef.When.Year == foundPieceRef.When.Year &&
|
||||
currentRef.Nr == foundPieceRef.Nr &&
|
||||
currentRef.Von == foundPieceRef.Von &&
|
||||
currentRef.Bis == foundPieceRef.Bis {
|
||||
isSamePiece = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if isSamePiece {
|
||||
fmt.Printf("DEBUG: Skipping current piece (title and issue reference match)\n")
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("DEBUG: Adding other piece title='%s'\n", pieceTitle)
|
||||
otherPieces = append(otherPieces, individualPiece)
|
||||
}
|
||||
|
||||
@@ -269,4 +307,5 @@ func (pvm *PieceVM) populateOtherPieces(lib *xmlmodels.Library) error {
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user