mirror of
https://github.com/Theodor-Springmann-Stiftung/kgpz_web.git
synced 2025-10-28 16:45:32 +00:00
Added Lookup functions to template to do reverse lookups on works, issues and pieces
This commit is contained in:
6
package-lock.json
generated
Normal file
6
package-lock.json
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "kgpz_web",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {}
|
||||
}
|
||||
@@ -109,7 +109,8 @@ func (p *GNDProvider) WriteCache(folder string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// TODO: Dont write persons already written
|
||||
// INFO: this writes all persons to the cache folder
|
||||
// We do that on every fetch, it's easier that way
|
||||
func (p *GNDProvider) writePersons(folder string) error {
|
||||
info, err := os.Stat(folder)
|
||||
if err == os.ErrNotExist {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package xmlprovider
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"slices"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -135,24 +134,20 @@ func (p *XMLProvider[T]) Cleanup(latest ParseMeta) {
|
||||
}
|
||||
}
|
||||
|
||||
func (p *XMLProvider[T]) ReverseLookup(item XMLItem) ([]Resolved[T], error) {
|
||||
keys := item.Keys()
|
||||
|
||||
if len(keys) == 0 {
|
||||
return nil, fmt.Errorf("Item has no keys")
|
||||
}
|
||||
|
||||
func (p *XMLProvider[T]) ReverseLookup(item XMLItem) []Resolved[T] {
|
||||
// INFO: this runs just once for the first key
|
||||
ret := make([]Resolved[T], 0)
|
||||
keys := item.Keys()
|
||||
|
||||
for _, key := range keys {
|
||||
r, err := p.Resolver.Get(item.Name(), key)
|
||||
if err != nil {
|
||||
return ret, err
|
||||
if err == nil {
|
||||
ret = append(ret, r...)
|
||||
return ret
|
||||
}
|
||||
ret = append(ret, r...)
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
return ret
|
||||
}
|
||||
|
||||
func (a *XMLProvider[T]) String() string {
|
||||
|
||||
@@ -67,6 +67,10 @@ func (e *Engine) Funcs(app *app.KGPZ) error {
|
||||
e.AddFunc("GetPiece", app.Library.Pieces.Item)
|
||||
e.AddFunc("GetGND", app.GND.Person)
|
||||
|
||||
e.AddFunc("LookupPieces", app.Library.Pieces.ReverseLookup)
|
||||
e.AddFunc("LookupWorks", app.Library.Works.ReverseLookup)
|
||||
e.AddFunc("LookupIssues", app.Library.Issues.ReverseLookup)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -5,30 +5,18 @@ import (
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
||||
)
|
||||
|
||||
type AgentsListView struct {
|
||||
Search string
|
||||
AvailableLetters []string
|
||||
Agents map[string]AgentView
|
||||
Agents map[string]xmlmodels.Agent
|
||||
Sorted []string
|
||||
}
|
||||
|
||||
type AgentView struct {
|
||||
xmlmodels.Agent
|
||||
Works []WorkByAgent
|
||||
Pieces []xmlprovider.Resolved[xmlmodels.Piece]
|
||||
}
|
||||
|
||||
type WorkByAgent struct {
|
||||
xmlprovider.Resolved[xmlmodels.Work]
|
||||
Pieces []xmlprovider.Resolved[xmlmodels.Piece]
|
||||
}
|
||||
|
||||
func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
||||
res := AgentsListView{Search: letterorid, Agents: make(map[string]AgentView)}
|
||||
res := AgentsListView{Search: letterorid, Agents: make(map[string]xmlmodels.Agent)}
|
||||
av := make(map[string]bool)
|
||||
|
||||
if len(letterorid) == 1 {
|
||||
@@ -37,7 +25,7 @@ func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
||||
av[strings.ToUpper(a.ID[:1])] = true
|
||||
if strings.HasPrefix(a.ID, letterorid) {
|
||||
res.Sorted = append(res.Sorted, a.ID)
|
||||
res.Agents[a.ID] = AgentView{Agent: a}
|
||||
res.Agents[a.ID] = a
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -46,30 +34,12 @@ func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
||||
av[strings.ToUpper(a.ID[:1])] = true
|
||||
if a.ID == letterorid {
|
||||
res.Sorted = append(res.Sorted, a.ID)
|
||||
res.Agents[a.ID] = AgentView{Agent: a}
|
||||
res.Agents[a.ID] = a
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, a := range res.Agents {
|
||||
if works, err := lib.Works.ReverseLookup(a); err == nil {
|
||||
for _, w := range works {
|
||||
if pieces, err := lib.Pieces.ReverseLookup(w.Item); err == nil {
|
||||
// INFO: it makes no sense to append works that have no pieces attached
|
||||
a.Works = append(a.Works, WorkByAgent{Resolved: w, Pieces: pieces})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if pieces, err := lib.Pieces.ReverseLookup(a.Agent); err == nil {
|
||||
a.Pieces = pieces
|
||||
}
|
||||
|
||||
// TODO: sort the things, also for works and pieces above
|
||||
res.Agents[a.ID] = a
|
||||
}
|
||||
|
||||
res.AvailableLetters = slices.Collect(maps.Keys(av))
|
||||
slices.Sort(res.AvailableLetters)
|
||||
slices.Sort(res.Sorted)
|
||||
|
||||
@@ -42,9 +42,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{- if ne (len $a.Works) 0 -}}
|
||||
{{ $works := LookupWorks $a }}
|
||||
{{- if ne (len $works) 0 -}}
|
||||
<div>
|
||||
{{ range $_, $w := $a.Works }}
|
||||
{{ range $_, $w := $works }}
|
||||
{{- if ne (len $w.Item.Citation.InnerXML ) 0 -}}
|
||||
<script type="application/xml" xslt-template="transform-citation" xslt-onload>
|
||||
<xml>
|
||||
@@ -52,13 +53,19 @@
|
||||
</xml>
|
||||
</script>
|
||||
{{- end -}}
|
||||
{{ range $_, $url := $w.Item.URLs }}
|
||||
<div>
|
||||
<a href="{{ $url.Address }}" target="_blank">{{ $url.Chardata }}</a>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
||||
{{- if ne (len $a.Pieces) 0 -}}
|
||||
{{ $pieces := LookupPieces $a }}
|
||||
{{- if ne (len $pieces) 0 -}}
|
||||
<div>
|
||||
{{ range $_, $p := $a.Pieces }}
|
||||
{{ range $_, $p := $pieces }}
|
||||
{{- range $_, $i := $p.Item.IssueRefs -}}
|
||||
<div>
|
||||
<a href="/{{ $i.When }}/{{ $i.Nr }}">{{ $i.Nr }}/{{ $i.When }}</a>
|
||||
|
||||
@@ -30,6 +30,7 @@ type URL struct {
|
||||
XMLName xml.Name `xml:"url"`
|
||||
Address string `xml:"address,attr"`
|
||||
Value
|
||||
Inner
|
||||
}
|
||||
|
||||
type AnnotationNote struct {
|
||||
|
||||
Reference in New Issue
Block a user