Better beiträge view

This commit is contained in:
Simon Martens
2025-09-19 22:37:28 +02:00
parent 2e6803afbe
commit b39a7fa7ee
8 changed files with 154 additions and 86 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 MiB

After

Width:  |  Height:  |  Size: 102 KiB

BIN
Screenshot2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 134 KiB

View File

@@ -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 {

View File

@@ -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
}
}

File diff suppressed because one or more lines are too long

View File

@@ -98,7 +98,7 @@
<a
href="{{ GetPieceURL $individualPiece.PieceByIssue.Reference.When.Year $individualPiece.PieceByIssue.Reference.Nr $individualPiece.PieceByIssue.Reference.Von }}"
class="">
Alle
Ganzer Beitrag
</a>
</div>
{{ end }}
@@ -233,7 +233,7 @@
<a
href="{{ GetPieceURL $individualPiece.PieceByIssue.Reference.When.Year $individualPiece.PieceByIssue.Reference.Nr $individualPiece.PieceByIssue.Reference.Von }}"
class="">
Alle
Ganzer Beitrag
</a>
</div>
{{ end }}

View File

@@ -2,10 +2,10 @@
<div class="w-full hyphens-auto">
<div class="space-y-4">
<!-- Header with icon and type (small) -->
<div class="flex items-center gap-2 mb-2">
<!-- Header with icon and type -->
<div class="flex items-center gap-2 mb-4">
<i class="ri-file-text-line text-slate-600"></i>
<h3 class="text-sm font-medium text-slate-600">Einzelbeitrag</h3>
<h3 class="text-base font-semibold text-slate-800">Einzelbeitrag</h3>
</div>
<!-- Main piece entry -->
@@ -27,29 +27,75 @@
<!-- Summary with boxed numbers -->
<div class="mb-4">
<p class="text-sm text-slate-600">
<p class="text-slate-600">
<span class="inline-flex items-center gap-1">
<span class="bg-slate-800 text-white px-1.5 py-0.5 rounded text-xs font-bold">{{ $model.TotalPageCount }}</span>
<span class="font-bold">{{ $model.TotalPageCount }}</span>
Seiten in
<span class="bg-slate-800 text-white px-1.5 py-0.5 rounded text-xs font-bold">{{ len $model.IssueContexts }}</span>
<span class="font-bold">{{ len $model.IssueContexts }}</span>
Ausgaben gefunden:
</span>
</p>
</div>
<!-- Issue and page links with highlighting data attributes -->
<div class="space-y-1">
<div class="space-y-6">
{{ range $pageEntry := $model.AllPages }}
<!-- Find the issue ref for this page to get date -->
{{ range $issueRef := $model.AllIssueRefs }}
{{ if and (eq $issueRef.When.Year $pageEntry.IssueYear) (eq $issueRef.Nr $pageEntry.IssueNumber) (le $issueRef.Von $pageEntry.PageNumber) (ge $issueRef.Bis $pageEntry.PageNumber) }}
<div class="inhalts-entry issue-link-entry pl-4 border-l-4 border-slate-300 hover:bg-slate-100">
<a href="/{{ $pageEntry.IssueYear }}/{{ $pageEntry.IssueNumber }}/{{ $pageEntry.PageNumber }}"
class="page-number-inhalts text-slate-700 hover:text-red-700 text-sm hover:underline transition-colors duration-200 bg-blue-50 hover:bg-blue-100 relative"
data-page-number="{{ $pageEntry.PageNumber }}">
{{ if $issueRef.When.Day }}{{ $issueRef.When.Day }}.{{ end }}{{ if $issueRef.When.Month }}{{ $issueRef.When.Month }}.{{ end }}{{ $issueRef.When.Year }} [Nr. {{ $pageEntry.IssueNumber }}], {{ $pageEntry.PageNumber }}
{{ template "_page_link_indicator" (dict "pageNumber" $pageEntry.PageNumber "targetPage" $.targetPage) }}
</a>
<!-- Individual page entry matching issue view style -->
<div class="mb-4 pl-4 border-l-4 border-slate-300 page-entry {{ if not $pageEntry.OtherPieces }}py-2{{ end }}"
data-page-container="{{ $pageEntry.PageNumber }}">
<div class="flex items-center justify-between gap-2 {{ if $pageEntry.OtherPieces }}mb-2{{ end }}">
<div class="flex items-center gap-2">
<span class="part-number bg-transparent text-slate-800 text-sm font-bold px-1.5 py-0.5 rounded border border-slate-400 flex items-center justify-center">
{{ $pageEntry.PartNumber }}
</span>
<button onclick="document.getElementById('piece-page-{{ $pageEntry.PageNumber }}').scrollIntoView({ behavior: 'smooth', block: 'start' })"
class="page-number-inhalts font-bold text-slate-700 bg-slate-100 px-2 py-1 rounded text-sm transition-colors duration-200 hover:bg-slate-200 cursor-pointer relative"
data-page-number="{{ $pageEntry.PageNumber }}">
<span class="page-label">
{{- $issueKey := printf "%d-%d" $pageEntry.IssueYear $pageEntry.IssueNumber -}}
{{- $issueData := GetIssue $issueKey -}}
{{- if $issueData -}}
{{ $issueData.Datum.When.Day }}.{{ $issueData.Datum.When.Month }}.{{ $issueData.Datum.When.Year }} [Nr. {{ $pageEntry.IssueNumber }}], {{ $pageEntry.PageNumber }}
{{- else -}}
{{ $pageEntry.IssueYear }} [Nr. {{ $pageEntry.IssueNumber }}], {{ $pageEntry.PageNumber }}
{{- end -}}
</span>
{{ template "_page_link_indicator" (dict "pageNumber" $pageEntry.PageNumber "targetPage" $.targetPage) }}
</button>
<a href="/{{ $pageEntry.IssueYear }}/{{ $pageEntry.IssueNumber }}"
class="w-6 h-6 bg-blue-100 hover:bg-blue-200 text-blue-700 border border-blue-300 rounded flex items-center justify-center transition-colors duration-200 cursor-pointer no-underline"
title="Zur Ausgabe {{ $pageEntry.IssueYear }}/{{ $pageEntry.IssueNumber }} wechseln">
<i class="ri-book-open-line text-xs"></i>
</a>
</div>
<button class="page-permalink-btn text-slate-400 hover:text-slate-700 text-xs p-1 rounded hover:bg-slate-100 transition-colors duration-200"
title="Link zu dieser Seite kopieren"
onclick="copyPagePermalink('{{ $pageEntry.PageNumber }}', this)"
data-page="{{ $pageEntry.PageNumber }}">
<i class="ri-link text-sm"></i>
</button>
</div>
<!-- Content area -->
<div class="space-y-0">
{{ if $pageEntry.OtherPieces }}
{{ range $otherPiece := $pageEntry.OtherPieces }}
<div class="inhalts-entry py-1 px-0 bg-slate-50 rounded hover:bg-slate-100 transition-colors duration-200"
data-page="{{ $pageEntry.PageNumber }}">
<div class="italic text-slate-600 text-xs mb-1">Außerdem:</div>
{{ template "_inhaltsverzeichnis_eintrag" $otherPiece.PieceByIssue }}
</div>
{{ end }}
{{ else }}
<!-- Empty but visible entry to prevent JS from hiding the page -->
<div class="inhalts-entry py-0 px-0" style="height: 1px; visibility: hidden;">
<!-- This empty but visible element prevents updatePageEntryVisibility() from hiding the page -->
</div>
{{ end }}
</div>
</div>
{{ break }}
{{ end }}
@@ -58,4 +104,4 @@
</div>
</div>
</div>
</div>
</div>

View File

@@ -8,14 +8,23 @@
<div class="grid grid-cols-2 gap-4">
{{ range $pageIndex, $page := $model.Images.AllPages }}
{{ $pageEntry := index $model.AllPages $pageIndex }}
{{ $issueContext := printf "%d Nr. %d" $pageEntry.IssueYear $pageEntry.IssueNumber }}
{{- $issueKey := printf "%d-%d" $pageEntry.IssueYear $pageEntry.IssueNumber -}}
{{- $issueData := GetIssue $issueKey -}}
{{- $issueContext := "" -}}
{{- if $issueData -}}
{{- $issueContext = printf "%d.%d.%d Nr. %d" $issueData.Datum.When.Day $issueData.Datum.When.Month $issueData.Datum.When.Year $pageEntry.IssueNumber -}}
{{- else -}}
{{- $issueContext = printf "%d Nr. %d" $pageEntry.IssueYear $pageEntry.IssueNumber -}}
{{- end -}}
<!-- Page container -->
<div class="piece-page-container newspaper-page-container" id="piece-page-{{ $page.PageNumber }}" data-page-container="{{ $page.PageNumber }}">
<!-- Page indicator row -->
<div class="flex justify-start items-center gap-2 mb-3">
<span class="part-number bg-slate-100 text-slate-800 text-sm font-bold px-1.5 py-0.5 rounded border border-slate-400 flex items-center justify-center">
{{ $pageEntry.PartNumber }}
</span>
<span class="page-indicator text-sm font-bold text-slate-600 bg-blue-50 px-2 py-1 rounded transition-all duration-300 flex items-center gap-1 relative" data-page="{{ $page.PageNumber }}">
{{ PageIcon "single" }}
{{ $issueContext }}, {{ $page.PageNumber }}
{{ template "_page_link_indicator" (dict "pageNumber" $page.PageNumber "targetPage" $.targetPage) }}
</span>
@@ -57,22 +66,6 @@
{{ end }}
</div>
<!-- Other pieces on this page -->
{{ if $pageEntry.OtherPieces }}
<div class="mt-4 p-4 bg-blue-50 border border-blue-200 rounded">
<h4 class="text-sm font-semibold text-blue-800 mb-3 flex items-center gap-2">
<i class="ri-file-list-2-line"></i>
Außerdem auf dieser Seite:
</h4>
<div class="space-y-2">
{{ range $otherPiece := $pageEntry.OtherPieces }}
<div class="text-sm">
{{ template "_inhaltsverzeichnis_eintrag" $otherPiece }}
</div>
{{ end }}
</div>
</div>
{{ end }}
</div>
{{ end }}
</div>