Bandsuche

This commit is contained in:
Simon Martens
2025-02-26 22:18:34 +01:00
parent cf6d4a59ed
commit 7f43044f34
8 changed files with 769 additions and 87 deletions

View File

@@ -1,12 +1,9 @@
{{ $model := . }}
{{/* .parameters
type Parameters struct {
Extended bool
Collection string
Query string
}
type SimpleParameters struct {
type SearchParameters struct {
Parameters
Sort string
Annotations bool
Persons bool
Title bool
@@ -15,9 +12,61 @@
Places bool
Refs bool
Year bool
AnnotationsString string
PersonsString string
TitleString string
AlmString string
SeriesString string
PlacesString string
RefsString string
YearString string
TypeFilter string
}
type Parameters struct {
Query string
Collection string
Extended bool
}
type SearchResultBaende struct {
// these are the sorted IDs for hits
Hits []string
Series map[string]*dbmodels.Series // <- Key: Series ID
Entries map[string]*dbmodels.Entry // <- Key: Entry ID
Places map[string]*dbmodels.Place // <- All places, Key: Place IDs
Agents map[string]*dbmodels.Agent // <- Key: Agent IDs
EntriesSeries map[string][]*dbmodels.REntriesSeries // <- Key: Whatever the Hit IDs are
SeriesEntries map[string][]*dbmodels.REntriesSeries // <- Key: Whatever the Hit IDs are
EntriesAgents map[string][]*dbmodels.REntriesAgents // <- Key: Entry ID
}
*/}}
{{ $isAlm := false }}
{{ $isTitle := false }}
{{ $isRefs := false }}
{{ $isPlaces := false }}
{{ $isYear := false }}
{{ $isSeries := false }}
{{ $isPersons := false }}
{{ $isAnnotations := false }}
{{ if $model.parameters.Query }}
{{- $isAlm = or $model.parameters.Alm $model.parameters.AlmString -}}
{{- $isTitle = or $model.parameters.Title $model.parameters.TitleString -}}
{{- $isRefs = or $model.parameters.Refs $model.parameters.RefsString -}}
{{- $isPlaces = or $model.parameters.Places $model.parameters.PlacesString -}}
{{- $isYear = or $model.parameters.Year $model.parameters.YearString -}}
{{- $isSeries = or $model.parameters.Series $model.parameters.SeriesString -}}
{{- $isPersons = or $model.parameters.Persons $model.parameters.PersonsString -}}
{{- $isAnnotations = or $model.parameters.Annotations $model.parameters.AnnotationsString -}}
{{ end }}
{{- $isBase := not (or $isAlm $isTitle $isRefs $isPlaces $isYear $isSeries $isPersons
$isAnnotations)
-}}
<div id="searchcontrol" class="container-normal">
{{- template "_heading" $model.parameters -}}
@@ -37,35 +86,79 @@
{{ template "_searchboxsimple" Arr $model.parameters true $q }}
<fieldset class="selectgroup">
<div class="selectgroup-option">
<input type="checkbox" name="alm" id="alm" checked />
<input
type="checkbox"
name="alm"
id="alm"
{{ if or $isBase $isAlm -}}checked{{- end -}} />
<label for="alm">Almanach-Nr.</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="title" id="title" checked />
<input
type="checkbox"
name="title"
id="title"
{{ if or $isBase $isTitle -}}checked{{- end -}} />
<label for="title">Titel</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="series" id="series" checked />
<input
type="checkbox"
name="series"
id="series"
{{ if or $isBase $isSeries -}}checked{{- end -}} />
<label for="series">Reihentitel</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="persons" id="persons" checked />
<input
type="checkbox"
name="persons"
id="persons"
{{ if or $isBase
$isPersons
-}}
checked
{{- end -}} />
<label for="persons">Personen &amp; Verlage</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="pubdata" id="pubdata" checked />
<label for="pubdata">Orte</label>
<input
type="checkbox"
name="places"
id="places"
{{ if or $isBase $isPlaces -}}checked{{- end -}} />
<label for="places">Orte</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="year" id="year" checked />
<input
type="checkbox"
name="year"
id="year"
{{ if or $isBase $isYear -}}checked{{- end -}} />
<label for="year">Jahr</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="references" id="references" checked />
<input
type="checkbox"
name="references"
id="references"
{{ if or $isBase
$isRefs
-}}
checked
{{- end -}} />
<label for="references">Nachweise</label>
</div>
<div class="selectgroup-option">
<input type="checkbox" name="annotations" id="annotations" checked />
<input
type="checkbox"
name="annotations"
id="annotations"
{{ if or $isBase
$isAnnotations
-}}
checked
{{- end -}} />
<label for="annotations">Anmerkungen</label>
</div>
</fieldset>
@@ -77,3 +170,94 @@
</div>
{{- template "_fieldscript" -}}
{{- if $model.parameters.Query -}}
<div class="container-normal" id="searchresults">
<div class="border-b border-zinc-300 flex flex-row justify-between">
<div>
Suche nach <b>»{{ $model.parameters.Query }}«</b> &middot;
<i class="ri-book-line"></i>
{{ if eq $model.result.Count 1 -}}
Ein Band
{{ else -}}
{{ $model.result.Count }} Bände
{{- end }}
in
{{ if eq ($model.result.Series | len) 1 -}}
einer Reihe
{{ else -}}
{{ $model.result.Series | len }} Reihen
{{- end -}}
</div>
<div>
<label
for="sort"
class="align-baseline h-min self-end pb-1 mr-2 text-sm font-sans
text-stone-700"
>Sortierung</label
>
{{/* INFO: We always redrect to letter = A bc some letters dont exist for other professions */}}
<select
class="h-min pb-1 border-b-4 border-zinc-300 px-1.5"
name="sort"
id="sort"
hx-get="{{- $model.parameters.ToQueryParams -}}"
trigger="change"
hx-push-url="true"
hx-select="main"
auto-complete="off"
hx-target="main">
<option
value="year"
{{ if eq $model.parameters.Sort "year" -}}
selected
{{- end -}}>
Erscheinungsjahr
</option>
<option value="series" {{ if eq $model.parameters.Sort "series" -}}selected{{- end -}}>
Reihentitel A-Z
</option>
</select>
</div>
</div>
{{- if $model.result.Hits -}}
{{- if eq .parameters.Sort "series" -}}
<div class="mt-4">
{{- range $_, $hit := $model.result.Hits -}}
{{- $series := index $model.result.Series $hit -}}
<div class="font-serif font-bold py-1 border border-zinc-300 px-3 mt-6">
<span class="text-base font-sans pr-2 border-zinc-300">Reihe</span>
<span class="pl-2">{{ $series.Title }}</span>
</div>
{{- range $_, $rel := index $model.result.SeriesEntries $hit -}}
{{- $entry := index $model.result.Entries $rel.Entry -}}
{{- template "band" (Arr $model $entry $series.Id) -}}
{{- end -}}
{{- end -}}
</div>
{{- else -}}
{{- range $_, $hit := $model.result.Hits -}}
{{- $entry := index $model.result.Entries $hit -}}
{{- template "band" (Arr $model $entry false) -}}
{{- end -}}
{{- end -}}
{{- end -}}
<script type="module">
let elements = document.querySelectorAll('.search-text');
let mark_instance = new Mark(elements);
// INFO: we wait a little bit before marking, to settle everything
setTimeout(() => {
mark_instance.mark('{{ $model.parameters.Query }}', {
"seperateWordSearch": true,
});
}, 200);
</script>
</div>
{{- if not $model.result.Hits -}}
Keine Bände gefunden.
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,192 @@
{{- $model := index . 0 -}}
{{- $entry := index . 1 -}}
{{- $series := index . 2 -}}
{{/* .parameters
type SearchParameters struct {
Parameters
Sort string
Annotations bool
Persons bool
Title bool
Alm bool
Series bool
Places bool
Refs bool
Year bool
AnnotationsString string
PersonsString string
TitleString string
AlmString string
SeriesString string
PlacesString string
RefsString string
YearString string
TypeFilter string
}
type Parameters struct {
Query string
Collection string
Extended bool
}
type SearchResultBaende struct {
// these are the sorted IDs for hits
Hits []string
Series map[string]*dbmodels.Series // <- Key: Series ID
Entries map[string]*dbmodels.Entry // <- Key: Entry ID
Places map[string]*dbmodels.Place // <- All places, Key: Place IDs
Agents map[string]*dbmodels.Agent // <- Key: Agent IDs
EntriesSeries map[string][]*dbmodels.REntriesSeries // <- Key: Whatever the Hit IDs are
EntriesAgents map[string][]*dbmodels.REntriesAgents // <- Key: Entry ID
}
*/}}
{{- $isAlm := or $model.parameters.Alm $model.parameters.AlmString -}}
{{- $isTitle := or $model.parameters.Title $model.parameters.TitleString -}}
{{- $isRefs := or $model.parameters.Refs $model.parameters.RefsString -}}
{{- $isPlaces := or $model.parameters.Places $model.parameters.PlacesString -}}
{{- $isYear := or $model.parameters.Year $model.parameters.YearString -}}
{{- $isSeries := or $model.parameters.Series $model.parameters.SeriesString -}}
{{- $isPersons := or $model.parameters.Persons $model.parameters.PersonsString -}}
{{- $isAnnotations := or $model.parameters.Annotations $model.parameters.AnnotationsString -}}
<div class="flex flex-row max-w-[60rem]">
<div class="w-32 grow-0 shrink-0 border-r border-zinc-300 pr-3 pt-4">
<div class="flex flex-col items-end pt-1">
<div class="flex flex-row gap-x-1">
<div class="inline-block ml-1 whitespace-nowrap">
{{- if not $entry.TitleStmt -}}
<tool-tip position="right">
<i class="ri-forbid-line"></i>
<div class="data-tip">Keine nähere Erfassung</div>
</tool-tip>
{{- else if eq $entry.EditState "Edited" -}}
<tool-tip position="right">
<i class="ri-checkbox-circle-line"></i>
<div class="data-tip">Mit erfassten Beiträgen</div>
</tool-tip>
{{- else -}}
<tool-tip position="right">
<i class="ri-information-line"></i>
<div class="data-tip">Mit genaueren Titelangaben</div>
</tool-tip>
{{- end -}}
</div>
<div
class="px-2 font-sans font-bold text-sm bg-stone-100 py-0.5 w-max rounded
{{ if $isAlm }}search-text{{- end -}}">
<a
href="/almanach/{{ $entry.MusenalmID }}"
class="no-underline rounded bg-stone-100 px-1.5">
Alm
{{ $entry.MusenalmID -}}
</a>
</div>
</div>
{{ if $entry.References }}
<div
class="text-sm font-sans px-2 py-1 bg-stone-100 mt-1.5
{{ if $isRefs -}}
search-text
{{- end -}}">
{{ $entry.References }}
</div>
{{ end }}
</div>
</div>
<div class="font-serif ml-3 pt-4">
<div class="font-bold">
<a href="/almanach/{{ $entry.MusenalmID }}" class="no-underline rounded ">
{{- $entry.PreferredTitle -}}
</a>
</div>
{{- if $entry.TitleStmt -}}
<div class="italic {{ if $isTitle -}}search-text{{- end -}}">{{- $entry.TitleStmt -}}</div>
{{- end -}}
{{- if and $entry.ResponsibilityStmt (not (eq $entry.ResponsibilityStmt "unbezeichnet")) -}}
<div class="italic {{ if $isPersons -}}search-text{{- end -}}">
{{ $entry.ResponsibilityStmt -}}
</div>
{{- end -}}
<div class="">
{{- if $entry.Places -}}
{{- range $_, $placeid := $entry.Places -}}
{{- $place := index $model.result.Places $placeid -}}
{{- if $place -}}
<div class="inline pr-1 {{ if $isPlaces -}}search-text{{- end -}}">
<a href="/reihen?place={{ $place.Id }}&hidden=true">{{ $place.Name }}</a>,
</div>
{{- end -}}
{{- end -}}
{{- end -}}
<a href="/reihen/?year={{ $entry.Year }}&hidden=true">
{{- if $entry.Year -}}
<div class="inline {{ if $isYear -}}search-text{{- end -}}">{{ $entry.Year }}</div>
{{- else -}}
<div class="inline">o.J.</div>
{{- end -}}
</a>
</div>
{{- $srels := index $model.result.EntriesSeries $entry.Id -}}
{{- if $srels -}}
<div class="flex flex-row flex-wrap py-1 gap-y-1">
{{- range $_, $srel := $srels -}}
{{- $series := index $model.result.Series $srel.Series -}}
{{- if $series -}}
<div class="inline-flex flex-row text-base font-sans px-2 bg-zinc-100 rounded mr-2">
<span class="border-r pr-2 border-gray-300">Reihentitel</span
><a
href="/reihe/{{ $series.MusenalmID }}"
class="no-underline pl-2 block {{ if
$isSeries
-}}
search-text
{{- end -}}">
<b>{{- $series.Title -}}</b>
</a>
</div>
{{- end -}}
{{- end -}}
</div>
{{- end -}}
{{- $arels := index $model.result.EntriesAgents $entry.Id -}}
{{- if $arels -}}
<div class="flex flex-row flex-wrap py-1 gap-y-1">
{{- range $_, $arel := $arels -}}
{{- $agent := index $model.result.Agents $arel.Agent -}}
{{- if $agent -}}
<div class="inline-block text-base font-sans bg-slate-100 rounded mr-2">
<span class="border-r px-2 border-gray-300"> {{- $arel.Type -}} </span
><a
href="/person/{{ $agent.Id }}"
class="no-underline px-1.5 {{ if
$isPersons
-}}
search-text
{{- end -}}">
<b>{{- $agent.Name -}}</b>
</a>
</div>
{{- end -}}
{{- end -}}
</div>
{{- end -}}
{{- if $entry.Annotation -}}
<div class="text-base hyphens-auto">
<b>Anm.: </b
><span class="{{- if $isAnnotations -}}search-text{{- end -}}"
>{{- Safe
(ReplaceSlashParenSlash $entry.Annotation)
-}}</span
>
</div>
{{- end -}}
<div class="pb-4"></div>
</div>
</div>

View File

@@ -5,7 +5,7 @@
<label for="q" class="hidden">Suchbegriffe</label>
<input
{{ if $q }}value="{{ $q }}"{{- end -}}
{{ if $q }}value="{{ $q }}"{{- end }}
type="search"
name="q"
minlength="3"