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
|
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 {
|
func (p *GNDProvider) writePersons(folder string) error {
|
||||||
info, err := os.Stat(folder)
|
info, err := os.Stat(folder)
|
||||||
if err == os.ErrNotExist {
|
if err == os.ErrNotExist {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package xmlprovider
|
package xmlprovider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"slices"
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -135,24 +134,20 @@ func (p *XMLProvider[T]) Cleanup(latest ParseMeta) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *XMLProvider[T]) ReverseLookup(item XMLItem) ([]Resolved[T], error) {
|
func (p *XMLProvider[T]) ReverseLookup(item XMLItem) []Resolved[T] {
|
||||||
keys := item.Keys()
|
|
||||||
|
|
||||||
if len(keys) == 0 {
|
|
||||||
return nil, fmt.Errorf("Item has no keys")
|
|
||||||
}
|
|
||||||
|
|
||||||
// INFO: this runs just once for the first key
|
// INFO: this runs just once for the first key
|
||||||
ret := make([]Resolved[T], 0)
|
ret := make([]Resolved[T], 0)
|
||||||
|
keys := item.Keys()
|
||||||
|
|
||||||
for _, key := range keys {
|
for _, key := range keys {
|
||||||
r, err := p.Resolver.Get(item.Name(), key)
|
r, err := p.Resolver.Get(item.Name(), key)
|
||||||
if err != nil {
|
if err == nil {
|
||||||
return ret, err
|
ret = append(ret, r...)
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
ret = append(ret, r...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *XMLProvider[T]) String() string {
|
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("GetPiece", app.Library.Pieces.Item)
|
||||||
e.AddFunc("GetGND", app.GND.Person)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,30 +5,18 @@ import (
|
|||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/providers/xmlprovider"
|
|
||||||
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
"github.com/Theodor-Springmann-Stiftung/kgpz_web/xmlmodels"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AgentsListView struct {
|
type AgentsListView struct {
|
||||||
Search string
|
Search string
|
||||||
AvailableLetters []string
|
AvailableLetters []string
|
||||||
Agents map[string]AgentView
|
Agents map[string]xmlmodels.Agent
|
||||||
Sorted []string
|
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 {
|
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)
|
av := make(map[string]bool)
|
||||||
|
|
||||||
if len(letterorid) == 1 {
|
if len(letterorid) == 1 {
|
||||||
@@ -37,7 +25,7 @@ func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
|||||||
av[strings.ToUpper(a.ID[:1])] = true
|
av[strings.ToUpper(a.ID[:1])] = true
|
||||||
if strings.HasPrefix(a.ID, letterorid) {
|
if strings.HasPrefix(a.ID, letterorid) {
|
||||||
res.Sorted = append(res.Sorted, a.ID)
|
res.Sorted = append(res.Sorted, a.ID)
|
||||||
res.Agents[a.ID] = AgentView{Agent: a}
|
res.Agents[a.ID] = a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -46,30 +34,12 @@ func AgentsView(letterorid string, lib *xmlmodels.Library) *AgentsListView {
|
|||||||
av[strings.ToUpper(a.ID[:1])] = true
|
av[strings.ToUpper(a.ID[:1])] = true
|
||||||
if a.ID == letterorid {
|
if a.ID == letterorid {
|
||||||
res.Sorted = append(res.Sorted, a.ID)
|
res.Sorted = append(res.Sorted, a.ID)
|
||||||
res.Agents[a.ID] = AgentView{Agent: a}
|
res.Agents[a.ID] = a
|
||||||
break
|
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))
|
res.AvailableLetters = slices.Collect(maps.Keys(av))
|
||||||
slices.Sort(res.AvailableLetters)
|
slices.Sort(res.AvailableLetters)
|
||||||
slices.Sort(res.Sorted)
|
slices.Sort(res.Sorted)
|
||||||
|
|||||||
@@ -42,9 +42,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{{- if ne (len $a.Works) 0 -}}
|
{{ $works := LookupWorks $a }}
|
||||||
|
{{- if ne (len $works) 0 -}}
|
||||||
<div>
|
<div>
|
||||||
{{ range $_, $w := $a.Works }}
|
{{ range $_, $w := $works }}
|
||||||
{{- if ne (len $w.Item.Citation.InnerXML ) 0 -}}
|
{{- if ne (len $w.Item.Citation.InnerXML ) 0 -}}
|
||||||
<script type="application/xml" xslt-template="transform-citation" xslt-onload>
|
<script type="application/xml" xslt-template="transform-citation" xslt-onload>
|
||||||
<xml>
|
<xml>
|
||||||
@@ -52,13 +53,19 @@
|
|||||||
</xml>
|
</xml>
|
||||||
</script>
|
</script>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
{{ range $_, $url := $w.Item.URLs }}
|
||||||
|
<div>
|
||||||
|
<a href="{{ $url.Address }}" target="_blank">{{ $url.Chardata }}</a>
|
||||||
|
</div>
|
||||||
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
{{- if ne (len $a.Pieces) 0 -}}
|
{{ $pieces := LookupPieces $a }}
|
||||||
|
{{- if ne (len $pieces) 0 -}}
|
||||||
<div>
|
<div>
|
||||||
{{ range $_, $p := $a.Pieces }}
|
{{ range $_, $p := $pieces }}
|
||||||
{{- range $_, $i := $p.Item.IssueRefs -}}
|
{{- range $_, $i := $p.Item.IssueRefs -}}
|
||||||
<div>
|
<div>
|
||||||
<a href="/{{ $i.When }}/{{ $i.Nr }}">{{ $i.Nr }}/{{ $i.When }}</a>
|
<a href="/{{ $i.When }}/{{ $i.Nr }}">{{ $i.Nr }}/{{ $i.When }}</a>
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ type URL struct {
|
|||||||
XMLName xml.Name `xml:"url"`
|
XMLName xml.Name `xml:"url"`
|
||||||
Address string `xml:"address,attr"`
|
Address string `xml:"address,attr"`
|
||||||
Value
|
Value
|
||||||
|
Inner
|
||||||
}
|
}
|
||||||
|
|
||||||
type AnnotationNote struct {
|
type AnnotationNote struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user