mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
revised page sorting
This commit is contained in:
3
go.mod
3
go.mod
@@ -7,8 +7,10 @@ require (
|
|||||||
github.com/go-git/go-git/v5 v5.12.0
|
github.com/go-git/go-git/v5 v5.12.0
|
||||||
github.com/gofiber/fiber/v2 v2.52.5
|
github.com/gofiber/fiber/v2 v2.52.5
|
||||||
github.com/gofiber/storage/memory/v2 v2.0.1
|
github.com/gofiber/storage/memory/v2 v2.0.1
|
||||||
|
github.com/google/uuid v1.6.0
|
||||||
github.com/kelseyhightower/envconfig v1.4.0
|
github.com/kelseyhightower/envconfig v1.4.0
|
||||||
github.com/yalue/merged_fs v1.3.0
|
github.com/yalue/merged_fs v1.3.0
|
||||||
|
golang.org/x/text v0.14.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
@@ -22,7 +24,6 @@ require (
|
|||||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
|
||||||
github.com/go-git/go-billy/v5 v5.5.0 // indirect
|
github.com/go-git/go-billy/v5 v5.5.0 // indirect
|
||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
|
||||||
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
github.com/kevinburke/ssh_config v1.2.0 // indirect
|
||||||
github.com/klauspost/compress v1.17.0 // indirect
|
github.com/klauspost/compress v1.17.0 // indirect
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -44,8 +44,6 @@ github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l
|
|||||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU=
|
|
||||||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
package viewmodels
|
package viewmodels
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"slices"
|
|
||||||
"strconv"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,83 +14,3 @@ type PieceViewModel struct {
|
|||||||
func NewPieceView(p xmlprovider.Piece) (PieceViewModel, error) {
|
func NewPieceView(p xmlprovider.Piece) (PieceViewModel, error) {
|
||||||
return PieceViewModel{Piece: p}, nil
|
return PieceViewModel{Piece: p}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type PieceListViewModel struct {
|
|
||||||
IssuePieces []PieceViewModel
|
|
||||||
AdditionalPieces []PieceViewModel
|
|
||||||
}
|
|
||||||
|
|
||||||
func PieceListViewModelForIssue(lib *xmlprovider.Library, y string, No string) (*PieceListViewModel, error) {
|
|
||||||
p := PieceListViewModel{}
|
|
||||||
err := p.piecesForIsssue(y, No, lib)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return &p, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (plvm *PieceListViewModel) piecesForIsssue(y string, No string, lib *xmlprovider.Library) error {
|
|
||||||
lookfor := y + "-" + No + "-"
|
|
||||||
noi, err := strconv.Atoi(No)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
lib.Pieces.Items.Range(func(key, value interface{}) bool {
|
|
||||||
k := key.(string)
|
|
||||||
if strings.HasPrefix(k, lookfor) {
|
|
||||||
a := value.(xmlprovider.Piece)
|
|
||||||
p, err := NewPieceView(a)
|
|
||||||
if err != nil {
|
|
||||||
logging.ObjErr(&a, err)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
if strings.HasPrefix(k, lookfor+"b-") {
|
|
||||||
for _, i := range p.AdditionalRef {
|
|
||||||
if i.Datum == y && i.Nr == noi {
|
|
||||||
p.Von = i.Von
|
|
||||||
p.Bis = i.Bis
|
|
||||||
}
|
|
||||||
}
|
|
||||||
plvm.AdditionalPieces = append(plvm.AdditionalPieces, p)
|
|
||||||
} else {
|
|
||||||
for _, i := range p.IssueRefs {
|
|
||||||
if i.Datum == y && i.Nr == noi {
|
|
||||||
p.Von = i.Von
|
|
||||||
p.Bis = i.Bis
|
|
||||||
}
|
|
||||||
}
|
|
||||||
plvm.IssuePieces = append(plvm.IssuePieces, p)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
})
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (plvm *PieceListViewModel) Sort(y string, no int) {
|
|
||||||
SortPiecesByPage(&plvm.IssuePieces, y, no)
|
|
||||||
SortPiecesByPage(&plvm.AdditionalPieces, y, no)
|
|
||||||
}
|
|
||||||
|
|
||||||
func SortPiecesByPage(pieces *[]PieceViewModel, y string, no int) {
|
|
||||||
slices.SortFunc(*pieces, func(i, j PieceViewModel) int {
|
|
||||||
if i.Von == j.Von {
|
|
||||||
if i.Bis >= 0 {
|
|
||||||
return 1
|
|
||||||
} else if j.Bis >= 0 {
|
|
||||||
return -1
|
|
||||||
} else {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if i.Von > j.Von {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
|
|
||||||
return -1
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,18 +1,25 @@
|
|||||||
package viewmodels
|
package viewmodels
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/functions"
|
||||||
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/helpers/logging"
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||||
)
|
)
|
||||||
|
|
||||||
type SingleIssueViewModel struct {
|
type SingleIssueViewModel struct {
|
||||||
IssueViewModel
|
IssueViewModel
|
||||||
No int
|
No int
|
||||||
Year string
|
Year string
|
||||||
Pieces PieceListViewModel
|
Pieces map[int][]PieceViewModel
|
||||||
Next IssueViewModel
|
Pages []int
|
||||||
Prev IssueViewModel
|
AdditionalPieces map[int][]PieceViewModel
|
||||||
|
AdditionalPages []int
|
||||||
|
Next IssueViewModel
|
||||||
|
Prev IssueViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSingleIssueView(y string, No string, lib *xmlprovider.Library) (*SingleIssueViewModel, error) {
|
func NewSingleIssueView(y string, No string, lib *xmlprovider.Library) (*SingleIssueViewModel, error) {
|
||||||
@@ -21,7 +28,6 @@ func NewSingleIssueView(y string, No string, lib *xmlprovider.Library) (*SingleI
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pl, err := PieceListViewModelForIssue(lib, y, No)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -31,9 +37,66 @@ func NewSingleIssueView(y string, No string, lib *xmlprovider.Library) (*SingleI
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
sivm := SingleIssueViewModel{IssueViewModel: *ivm, No: no, Year: y, Pieces: *pl}
|
sivm := SingleIssueViewModel{IssueViewModel: *ivm, No: no, Year: y}
|
||||||
|
|
||||||
sivm.Pieces.Sort(y, no)
|
if err := sivm.PiecesForIsssue(lib); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
slices.Sort(sivm.Pages)
|
||||||
|
slices.Sort(sivm.AdditionalPages)
|
||||||
|
|
||||||
return &sivm, nil
|
return &sivm, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (issue *SingleIssueViewModel) PiecesForIsssue(lib *xmlprovider.Library) error {
|
||||||
|
nostr := strconv.Itoa(issue.No)
|
||||||
|
lookfor := issue.Year + "-" + nostr + "-"
|
||||||
|
n := issue.No
|
||||||
|
y := issue.Year
|
||||||
|
|
||||||
|
adp := make(map[int][]PieceViewModel)
|
||||||
|
ip := make(map[int][]PieceViewModel)
|
||||||
|
|
||||||
|
lib.Pieces.Items.Range(func(key, value interface{}) bool {
|
||||||
|
k := key.(string)
|
||||||
|
if strings.HasPrefix(k, lookfor) {
|
||||||
|
a := value.(xmlprovider.Piece)
|
||||||
|
p, err := NewPieceView(a)
|
||||||
|
if err != nil {
|
||||||
|
logging.ObjErr(&a, err)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(k, lookfor+"b-") {
|
||||||
|
for _, i := range p.AdditionalRef {
|
||||||
|
// INFO: Here we find the page number the piece has in THIS issue, same below
|
||||||
|
if i.Datum == y && i.Nr == n {
|
||||||
|
p.Von = i.Von
|
||||||
|
p.Bis = i.Bis
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
functions.MapArrayInsert(adp, p.Von, p)
|
||||||
|
} else {
|
||||||
|
for _, i := range p.IssueRefs {
|
||||||
|
if i.Datum == y && i.Nr == n {
|
||||||
|
p.Von = i.Von
|
||||||
|
p.Bis = i.Bis
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
functions.MapArrayInsert(ip, p.Von, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
issue.Pieces = ip
|
||||||
|
issue.Pages = functions.Keys(ip)
|
||||||
|
|
||||||
|
issue.AdditionalPieces = adp
|
||||||
|
issue.AdditionalPages = functions.Keys(adp)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,38 +1,40 @@
|
|||||||
{{ $page := 0 }}
|
|
||||||
{{ $model := .model }}
|
{{ $model := .model }}
|
||||||
|
|
||||||
|
|
||||||
<div>Inhalt</div>
|
<div>Inhalt</div>
|
||||||
{{ range $piece := .model.Pieces.IssuePieces }}
|
<div>
|
||||||
<div>
|
{{ range $page := $model.Pages }}
|
||||||
{{ if (ne $page $piece.Von) }}
|
<div>
|
||||||
{{ $page = $piece.Von }}
|
|
||||||
<div>Seite {{ $page }}</div>
|
<div>Seite {{ $page }}</div>
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
{{ template "_inhaltsverzeichnis_eintrag" $piece }}
|
{{ range $piece := (index $model.Pieces $page) }}
|
||||||
|
|
||||||
|
{{ template "_inhaltsverzeichnis_eintrag" $piece }}
|
||||||
|
|
||||||
|
|
||||||
<!-- Links zu anderen Teilen: -->
|
<!-- Links zu anderen Teilen: -->
|
||||||
{{ if gt (len $piece.IssueRefs) 1 }}
|
{{ if gt (len $piece.IssueRefs) 1 }}
|
||||||
<div>
|
<div>
|
||||||
{{ len $piece.IssueRefs }} Teile:
|
{{ len $piece.IssueRefs }} Teile:
|
||||||
<ol>
|
<ol>
|
||||||
{{ range $issue := $piece.IssueRefs }}
|
{{ range $issue := $piece.IssueRefs }}
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a
|
||||||
href="/{{- $issue.Datum -}}/{{- $issue.Nr -}}"
|
href="/{{- $issue.Datum -}}/{{- $issue.Nr -}}"
|
||||||
{{ if and (eq $issue.Nr $model.No) (eq $issue.Datum $model.Year) }}
|
{{ if and (eq $issue.Nr $model.No) (eq $issue.Datum $model.Year) }}
|
||||||
aria-current="page"
|
aria-current="page"
|
||||||
{{ end }}>
|
{{ end }}>
|
||||||
{{- $issue.Datum }} Nr.
|
{{- $issue.Datum }} Nr.
|
||||||
{{ $issue.Nr -}}
|
{{ $issue.Nr -}}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</ol>
|
</ol>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
</div>
|
{{ end }}
|
||||||
{{ end }}
|
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user