Grupperiung seiten

This commit is contained in:
Simon Martens
2025-09-17 11:53:43 +02:00
parent 9bfebe5828
commit 96a87ad7b6
6 changed files with 92 additions and 34 deletions

View File

@@ -1,12 +1,19 @@
package controllers package controllers
import ( import (
"github.com/Theodor-Springmann-Stiftung/lenz-web/xmlmodels"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
"strconv"
) )
const DEFAULT_YEAR = 1765 const DEFAULT_YEAR = 1765
func GetIndex(c *fiber.Ctx) error { type DateRange struct {
return c.Redirect(LETTERS_URL + "?year=" + strconv.Itoa(DEFAULT_YEAR)) Label string
Start int
End int
Letters []xmlmodels.Meta
}
func GetIndex(c *fiber.Ctx) error {
return c.Redirect(LETTERS_URL + "?range=all")
} }

View File

@@ -1,23 +1,48 @@
package controllers package controllers
import ( import (
"strconv"
"github.com/Theodor-Springmann-Stiftung/lenz-web/xmlmodels" "github.com/Theodor-Springmann-Stiftung/lenz-web/xmlmodels"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
func GetLetters(c *fiber.Ctx) error { func GetLetters(c *fiber.Ctx) error {
lib := xmlmodels.Get() lib := xmlmodels.Get()
years, yearmap := lib.Years() _, yearmap := lib.Years()
y := c.Query(YEAR_PARAM, strconv.Itoa(DEFAULT_YEAR)) rangeParam := c.Query("range", "")
// TODO: does not work ATM // TODO: does not work ATM
c.Locals("path", c.Path()) c.Locals("path", c.Path())
year, err := strconv.Atoi(y) // Define the date ranges
if _, ok := yearmap[year]; (err != nil || !ok) && y != "all" { ranges := []DateRange{
return c.SendStatus(fiber.StatusNotFound) {Label: "17561770", Start: 1756, End: 1770, Letters: []xmlmodels.Meta{}},
{Label: "17711775", Start: 1771, End: 1775, Letters: []xmlmodels.Meta{}},
{Label: "1776", Start: 1776, End: 1776, Letters: []xmlmodels.Meta{}},
{Label: "17771779", Start: 1777, End: 1779, Letters: []xmlmodels.Meta{}},
{Label: "17801792", Start: 1780, End: 1792, Letters: []xmlmodels.Meta{}},
} }
return c.Render(LETTERS_URL+"/", fiber.Map{"years": years, "yearmap": yearmap, "year": year, "all": y == "all"}) // Group letters by date ranges
for year, letters := range yearmap {
for i := range ranges {
if year >= ranges[i].Start && year <= ranges[i].End {
ranges[i].Letters = append(ranges[i].Letters, letters...)
break
}
}
}
// Handle specific range selection
selectedRange := -1
for i, r := range ranges {
if r.Label == rangeParam {
selectedRange = i
break
}
}
return c.Render(LETTERS_URL+"/", fiber.Map{
"ranges": ranges,
"selectedRange": selectedRange,
"all": rangeParam == "all",
})
} }

File diff suppressed because one or more lines are too long

View File

@@ -1,41 +1,45 @@
{{ $model := . }} {{ $model := . }}
<nav class="print:hidden"> <nav class="print:hidden">
{{- range $y := .years -}} {{- range $i, $range := .ranges -}}
<a {{- if $range.Letters -}}
class="inline-block stdlink px-0.5" <a
href="/briefe?year={{ $y }}" class="inline-block stdlink px-0.5"
{{ if eq $model.year $y -}}aria-current="page"{{- end }} href="/briefe?range={{ $range.Label }}"
>{{ $y }}</a {{ if eq $model.selectedRange $i -}}aria-current="page"{{- end }}
> >{{ $range.Label }}</a
>
{{- end -}}
{{- end -}} {{- end -}}
<a <a
class="inline-block stdlink px-0.5" class="inline-block stdlink px-0.5"
href="/briefe?year=all" href="/briefe?range=all"
{{ if .all -}}aria-current="page"{{- end }} {{ if .all -}}aria-current="page"{{- end }}
>Alle</a >Alle</a
> >
</nav> </nav>
{{- if .years -}} {{- if .ranges -}}
{{- if .year -}} {{- if ne .selectedRange -1 -}}
{{- $letters := index $model.yearmap $model.year -}} {{- $selectedRangeData := index .ranges .selectedRange -}}
<div class="flex flex-row gap-x-1"> <div class="flex flex-row gap-x-1">
<div>Briefe für das Jahr {{- .year }}</div> <div>Briefe für {{ $selectedRangeData.Label }}</div>
<div>({{- len $letters }})</div> <div>({{ len $selectedRangeData.Letters }})</div>
</div> </div>
{{ template "_letterlist" $letters -}} {{ template "_letterlist" $selectedRangeData.Letters -}}
{{- end -}} {{- end -}}
{{- if .all -}} {{- if .all -}}
{{- range $y := .years -}} {{- range $range := .ranges -}}
<div class=""> {{- if $range.Letters -}}
{{- $y -}} <div class="mb-8">
{{- $letters := index $model.yearmap $y -}} <div class="flex flex-row gap-x-1 mb-4">
<div>({{- len $letters }})</div> <div class="font-semibold">{{ $range.Label }}</div>
{{ template "_letterlist" $letters -}} <div>({{ len $range.Letters }})</div>
</div> </div>
{{ template "_letterlist" $range.Letters -}}
</div>
{{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}

View File

@@ -0,0 +1,20 @@
{{ $model := . }}
<div class="space-y-8">
<div class="prose max-w-none">
<h1>Lenz-Briefe</h1>
<p>Digitale Edition der Briefe von Jakob Michael Reinhold Lenz</p>
</div>
<div class="space-y-6">
{{- range $range := .ranges -}}
{{- if $range.Letters -}}
<div class="border-l-4 border-gray-300 pl-4">
<h2 class="text-xl font-semibold mb-3">{{ $range.Label }}</h2>
<div class="text-sm text-gray-600 mb-3">({{ len $range.Letters }} {{ if eq (len $range.Letters) 1 }}Brief{{ else }}Briefe{{ end }})</div>
{{ template "_letterlist" $range.Letters }}
</div>
{{- end -}}
{{- end -}}
</div>
</div>

View File

@@ -0,0 +1,2 @@
<title>Lenz-Briefe</title>
<meta name="description" content="Digitale Edition der Briefe von Jakob Michael Reinhold Lenz" />