mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
some bug fixes
This commit is contained in:
@@ -35,34 +35,23 @@ func (i Issue) Keys() []string {
|
||||
}
|
||||
|
||||
res := make([]string, 2)
|
||||
date := i.Datum.When
|
||||
date := i.Datum.When.String()
|
||||
if date != "" {
|
||||
res = append(res, date)
|
||||
}
|
||||
|
||||
if ref, err := i.Reference(); err == nil {
|
||||
res = append(res, ref)
|
||||
}
|
||||
|
||||
res = append(res, i.Reference())
|
||||
i.keys = res
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
// TODO: We could even cache this
|
||||
func (i Issue) Year() (int, error) {
|
||||
if date := i.Datum.Date(); date != nil {
|
||||
return date.Year(), nil
|
||||
}
|
||||
return 0, InvalidDateError
|
||||
func (i Issue) Year() int {
|
||||
return i.Datum.When.Year
|
||||
}
|
||||
|
||||
func (i Issue) Reference() (string, error) {
|
||||
if date := i.Datum.Date(); date != nil {
|
||||
return strconv.Itoa(date.Year()) + "-" + strconv.Itoa(i.Number.No), nil
|
||||
}
|
||||
|
||||
return "", InvalidDateError
|
||||
func (i Issue) Reference() string {
|
||||
return strconv.Itoa(i.Number.No) + "-" + i.Datum.When.String()
|
||||
}
|
||||
|
||||
func (i Issue) String() string {
|
||||
|
||||
@@ -41,21 +41,17 @@ func (p Piece) Keys() []string {
|
||||
uid := uuid.New()
|
||||
|
||||
for _, i := range p.IssueRefs {
|
||||
if d := i.Date(); d != nil {
|
||||
ret = append(ret, strconv.Itoa(d.Year())+"-"+strconv.Itoa(i.Nr)+"-"+uid.String())
|
||||
}
|
||||
ret = append(ret, strconv.Itoa(i.When.Year)+"-"+strconv.Itoa(i.Nr)+"-"+uid.String())
|
||||
}
|
||||
|
||||
p.keys = ret
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p Piece) ReferencesIssue(y, no int) (*IssueRef, bool) {
|
||||
for _, i := range p.IssueRefs {
|
||||
if i.Nr == no {
|
||||
d := i.Date()
|
||||
if d != nil && d.Year() == y {
|
||||
if i.When.Year == y {
|
||||
return &i, true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,19 +53,13 @@ func NewSingleIssueView(y string, no string, lib *xmlprovider.Library) (*IssueVM
|
||||
}
|
||||
|
||||
func PiecesForIsssue(lib *xmlprovider.Library, issue xmlprovider.Issue) (*PiecesByPage, *PiecesByPage, error) {
|
||||
date := issue.Datum.Date()
|
||||
if date == nil {
|
||||
return nil, nil, fmt.Errorf("Issue has no date")
|
||||
}
|
||||
|
||||
year := date.Year()
|
||||
year := issue.Datum.When.Year
|
||||
|
||||
ppi := PiecesByPage{Items: make(map[int][]PieceListitemVM)}
|
||||
ppa := PiecesByPage{Items: make(map[int][]PieceListitemVM)}
|
||||
|
||||
slog.Debug(fmt.Sprintf("Checking piece for year %v, number %v", year, issue.Number.No))
|
||||
for _, piece := range lib.Pieces.Array {
|
||||
|
||||
if d, ok := piece.ReferencesIssue(year, issue.Number.No); ok {
|
||||
slog.Debug(fmt.Sprintf("Found piece %v in issue %v-%v", piece, year, issue.Number.No))
|
||||
p := PieceListitemVM{Piece: piece, Reference: *d}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package viewmodels
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||
)
|
||||
|
||||
@@ -17,16 +15,11 @@ type IssueListitemVM struct {
|
||||
}
|
||||
|
||||
func ListitemFromIssue(i xmlprovider.Issue) (*IssueListitemVM, error) {
|
||||
t, err := time.Parse(TLAYOUT, i.Datum.When)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &IssueListitemVM{
|
||||
No: i.Number.No,
|
||||
Issue: i,
|
||||
Day: t.Day(),
|
||||
Month: int(t.Month()),
|
||||
Year: t.Year(),
|
||||
Day: i.Datum.When.Day,
|
||||
Month: i.Datum.When.Month,
|
||||
Year: i.Datum.When.Year,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -31,12 +31,11 @@ func YearView(year int, lib *xmlprovider.Library) (*YearVM, error) {
|
||||
|
||||
lib.Issues.Lock()
|
||||
for _, issue := range lib.Issues.Array {
|
||||
if y, err := issue.Year(); err == nil {
|
||||
years[y] = true
|
||||
if y == year {
|
||||
if issuevm, err := ListitemFromIssue(issue); err == nil {
|
||||
issues[issuevm.Month] = append(issues[issuevm.Month], *issuevm)
|
||||
}
|
||||
y := issue.Datum.When.Year
|
||||
years[y] = true
|
||||
if y == year {
|
||||
if issuevm, err := ListitemFromIssue(issue); err == nil {
|
||||
issues[issuevm.Month] = append(issues[issuevm.Month], *issuevm)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user