mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
Better structure of files; introduced XML models
This commit is contained in:
@@ -5,7 +5,7 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
||||
)
|
||||
|
||||
type AgentsListView struct {
|
||||
@@ -16,22 +16,28 @@ type AgentsListView struct {
|
||||
}
|
||||
|
||||
type AgentView struct {
|
||||
xmlprovider.Agent
|
||||
xmlmodels.Agent
|
||||
Works []WorkByAgent
|
||||
Pieces []PieceByAgent
|
||||
}
|
||||
|
||||
type WorkByAgent struct {
|
||||
xmlprovider.Work
|
||||
Reference xmlprovider.AgentRef
|
||||
xmlmodels.Work
|
||||
Pieces []PieceByWork
|
||||
Reference xmlmodels.AgentRef
|
||||
}
|
||||
|
||||
type PieceByAgent struct {
|
||||
xmlprovider.Piece
|
||||
Reference xmlprovider.AgentRef
|
||||
xmlmodels.Piece
|
||||
Reference xmlmodels.AgentRef
|
||||
}
|
||||
|
||||
func AgentsView(letterorid string, lib *xmlprovider.Library) *AgentsListView {
|
||||
type PieceByWork struct {
|
||||
xmlmodels.Piece
|
||||
Reference xmlmodels.WorkRef
|
||||
}
|
||||
|
||||
func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
||||
res := AgentsListView{Search: letterorid, Agents: make(map[string]AgentView)}
|
||||
av := make(map[string]bool)
|
||||
|
||||
@@ -56,7 +62,7 @@ func AgentsView(letterorid string, lib *xmlprovider.Library) *AgentsListView {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: We won't need to lock the library if we take down all routes during parsing
|
||||
// TODO: We won't need to lock the library if we take down the server during parsing
|
||||
lib.Works.Lock()
|
||||
for _, w := range lib.Works.Array {
|
||||
if ref, ok := w.ReferencesAgent(letterorid); ok {
|
||||
@@ -76,6 +82,15 @@ func AgentsView(letterorid string, lib *xmlprovider.Library) *AgentsListView {
|
||||
res.Agents[ref.Ref] = entry
|
||||
}
|
||||
}
|
||||
|
||||
// PERF: This is really slow: resolve all backlinks after parse?
|
||||
for _, a := range res.Agents {
|
||||
for _, w := range a.Works {
|
||||
if ref, ok := p.ReferencesWork(w.ID); ok {
|
||||
w.Pieces = append(w.Pieces, PieceByWork{Piece: p, Reference: *ref})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
lib.Pieces.Unlock()
|
||||
|
||||
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"slices"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/functions"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
||||
)
|
||||
|
||||
type PieceByIssue struct {
|
||||
xmlprovider.Piece
|
||||
xmlmodels.Piece
|
||||
// TODO: this is a bit hacky, but it refences the page number of the piece in the issue
|
||||
Reference xmlprovider.IssueRef
|
||||
Reference xmlmodels.IssueRef
|
||||
}
|
||||
|
||||
type PiecesByPage struct {
|
||||
@@ -22,12 +22,12 @@ type PiecesByPage struct {
|
||||
|
||||
// TODO: Next & Prev
|
||||
type IssueVM struct {
|
||||
xmlprovider.Issue
|
||||
xmlmodels.Issue
|
||||
Pieces PiecesByPage
|
||||
AdditionalPieces PiecesByPage
|
||||
}
|
||||
|
||||
func NewSingleIssueView(y string, no string, lib *xmlprovider.Library) (*IssueVM, error) {
|
||||
func NewSingleIssueView(y string, no string, lib *xmlmodels.Library) (*IssueVM, error) {
|
||||
issue := lib.Issues.Item(no + "-" + y)
|
||||
if issue == nil {
|
||||
return nil, fmt.Errorf("No issue found for %v-%v", y, no)
|
||||
@@ -48,7 +48,7 @@ func NewSingleIssueView(y string, no string, lib *xmlprovider.Library) (*IssueVM
|
||||
return &sivm, nil
|
||||
}
|
||||
|
||||
func PiecesForIsssue(lib *xmlprovider.Library, issue xmlprovider.Issue) (PiecesByPage, PiecesByPage, error) {
|
||||
func PiecesForIsssue(lib *xmlmodels.Library, issue xmlmodels.Issue) (PiecesByPage, PiecesByPage, error) {
|
||||
year := issue.Datum.When.Year
|
||||
|
||||
ppi := PiecesByPage{Items: make(map[int][]PieceByIssue)}
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"sort"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/functions"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
||||
)
|
||||
|
||||
type IssuesByMonth map[int][]xmlprovider.Issue
|
||||
type IssuesByMonth map[int][]xmlmodels.Issue
|
||||
|
||||
func (ibm *IssuesByMonth) Sort() {
|
||||
for _, issues := range *ibm {
|
||||
@@ -26,7 +26,7 @@ type YearVM struct {
|
||||
Issues IssuesByMonth
|
||||
}
|
||||
|
||||
func YearView(year int, lib *xmlprovider.Library) (*YearVM, error) {
|
||||
func YearView(year int, lib *xmlmodels.Library) (*YearVM, error) {
|
||||
issues := make(IssuesByMonth, 12)
|
||||
years := make(map[int]bool)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user