Commit ddef5751 authored by Mathias Goebel's avatar Mathias Goebel 🎠
Browse files

more dynamic page creation with a map{}, speeds up about 1.5 seconds

parent 1dbb640a
......@@ -17,6 +17,7 @@ declare namespace xhtml="http://www.w3.org/1999/xhtml";
declare variable $f-register:metaCollection := '/db/sade-projects/textgrid/data/xml/meta/';
declare variable $f-register:targetStart := "http://textgridrep.org/textgrid:";
declare variable $f-register:getEntity := request:get-parameter('e', '');
declare variable $f-register:getIndex := request:get-parameter('i', '');
declare variable $f-register:getNotebook := $f-register:targetStart || request:get-parameter('nb', '');
(:~
......@@ -250,89 +251,121 @@ as element(xhtml:li) {
declare function f-register:register()
as element(xhtml:div) {
let $agg := '253st.xml' (: TextGrid Aggregation containing all index files :)
let $uris := doc('/db/sade-projects/textgrid/data/xml/agg/' || $agg)//ore:aggregates/substring-after(@rdf:resource, 'textgrid:')
let $meta :=
for $uri in $uris
where doc-available( '/db/sade-projects/textgrid/data/xml/data/' || $uri || '.xml')
return
doc('/db/sade-projects/textgrid/data/xml/meta/' || $uri || '.xml')
let $docs := $meta//tgmd:textgridUri/tokenize(., ':|\.')[2] ! doc('/db/sade-projects/textgrid/data/xml/data/' || . || '.xml')
let $uris := (doc('/db/sade-projects/textgrid/data/xml/agg/' || $agg)
//ore:aggregates/substring-after(@rdf:resource, 'textgrid:')
)[. != "25547"] (: omit the bibliography here :)
let $docs := $uris ! doc('/db/sade-projects/textgrid/data/xml/data/' || . || '.xml')
let $nodes :=
( $docs//tei:body/tei:listEvent,
$docs//tei:body/tei:listOrg,
$docs//tei:body/tei:listPerson,
$docs//tei:body/tei:listPlace,
$docs//tei:body//tei:list[@type="works"],
$docs//tei:body//tei:list[@type="periodicals"],
$docs//tei:body//tei:list[@type="Fontane"] )
let $map :=
map:new(
for $node in $nodes
let $docMeta := doc($node/base-uri() => replace("xml/data/", "xml/meta/"))
let $title := string($docMeta//tgmd:title)
let $tabName := switch($title)
case "Register der Werke"
return
switch($node/@type)
case "periodicals" return "Periodika"
case "Fontane" return "Fontanes Werke"
default return "Werke"
default
return $title
let $localId := string-join(($node/local-name(), $node/@type), "-")
let $active :=
if ($f-register:getIndex = $localId)
then true()
else if (local:check-entity($node) = "active")
then true()
else false()
let $class :=
if ($active)
then attribute class { "active" }
else ()
let $li := element xhtml:li {
$class,
element xhtml:a {
attribute href { "#" || $localId },
attribute data-toggle { "tab" },
$tabName
}
}
let $content :=
switch ($node/local-name())
case "listEvent" return f-register:events($node, $active)
case "listOrg" return f-register:orgs($node, $active)
case "listPerson" return f-register:persons($node, $active)
case "listPlace" return f-register:places($node, $active)
case "list" return f-register:works($node, $active)
default return error(QName("FONTANE", "INDEX1"), "unknown node-name: " || $node/local-name())
return
map:entry(
$localId,
map:new((
map:entry( "active", $class = "active" ),
map:entry( "tab", $li ),
map:entry( "content", $content )
))
)
)
let $tabs :=
<ul class="nav nav-tabs" style="font-size: smaller;">
{for $i at $pos in $meta
let $uri := $i//tgmd:textgridUri/tokenize(., ':|\.')[2]
let $doc := doc('/db/sade-projects/textgrid/data/xml/data/' || $uri || '.xml')
where not(matches($uri,"25547|253t3"))
return
<li>
{ attribute class { local:check-entity($doc/*) } }
<a data-toggle="tab" href="#r{ $uri }">{$i//tgmd:title/text()}</a>
</li>,
(: need to hardcode stuff comming from a singe tei file: :)
<li>
{ attribute class { local:check-entity($docs//tei:body//tei:list[@type="works"]) } }
<a data-toggle="tab" href="#r253t3-works">Werke</a>
</li>,
<li>
{ attribute class { local:check-entity($docs//tei:body//tei:list[@type="periodicals"]) } }
<a data-toggle="tab" href="#r253t3-Fontane">Fontanes Werke</a>
</li>,
<li>
{ attribute class { local:check-entity($docs//tei:body//tei:list[@type="Fontane"]) } }
<a data-toggle="tab" href="#r253t3-periodicals">Periodika</a>
</li>
}
{ $map?("listEvent")?("tab") }
{ $map?("listOrg")?("tab") }
{ $map?("listPerson")?("tab") }
{ $map?("listPlace")?("tab") }
{ $map?("list-works")?("tab") }
{ $map?("list-Fontane")?("tab") }
{ $map?("list-periodicals")?("tab") }
</ul>
return
<div class="container">
{$tabs}
<div class="tab-content">
{ f-register:events( $docs//tei:body/tei:listEvent ),
f-register:orgs( $docs//tei:body/tei:listOrg ),
f-register:persons( $docs//tei:body/tei:listPerson ),
f-register:places( $docs//tei:body/tei:listPlace ),
f-register:works( $docs//tei:body//tei:list[@type="works"] ),
f-register:works( $docs//tei:body//tei:list[@type="periodicals"] ),
f-register:works( $docs//tei:body//tei:list[@type="Fontane"] )
}
{ $map?*?("content") }
</div>
</div>
};
(:~
: parser for listEvents/event entities
: @param $eventDoc – the tei:listEvent containing all entries
: @param $active – true if the tab should be active (any containing Id in the request)
: :)
declare function f-register:events($eventDoc as element(tei:listEvent))
declare function f-register:events($eventDoc as element(tei:listEvent), $active as xs:boolean)
as element(xhtml:div) {
let $eventDocUri := tokenize($eventDoc/base-uri(), '/|\.')[8]
return
(: main tab :)
<div id="r{ $eventDocUri }" class="tab-pane {local:check-entity($eventDoc)}">
<div id="accordion{ $eventDocUri }" class="panel-group" aria-multiselectable="true" role="tablist">
{for $eventList in $eventDoc/tei:listEvent
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">{$eventList/tei:head/text()}</h4>
</div>
<div class="panel-body">
<div id="{ string-join(($eventDoc/local-name(), $eventDoc/@type), "-") }" class="tab-pane{if($active) then " active" else ()}">
<div class="panel-group" aria-multiselectable="true" role="tablist">
{for $eventList in $eventDoc/tei:listEvent
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">{$eventList/tei:head/text()}</h4>
</div>
<div class="panel-body">
<ul class="listEvent">
{
if($f-register:getNotebook = $f-register:targetStart)
then $eventList/tei:event ! local:prepare-event(.)
else $eventList/tei:event
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]] ! local:prepare-event(.)
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]] ! local:prepare-event(.)
}
</ul>
</div>
</div>
}
</div>
}
</div>
</div>
};
declare function local:prepare-event($event as element(tei:event))
......@@ -416,34 +449,31 @@ return
(:~
: parser for tei:listOrg, returns the index of orgnaisations.
: :)
declare function f-register:orgs($orgDoc as element(tei:listOrg)+)
declare function f-register:orgs($orgDoc as element(tei:listOrg)+, $active as xs:boolean)
as element(xhtml:div) {
let $orgURI := tokenize($orgDoc/base-uri(), '/|\.')[8]
return
(: main tab :)
<div id="r{ $orgURI }" class="tab-pane {local:check-entity($orgDoc)}">
<div id="accordion{ $orgURI }" class="panel-group" aria-multiselectable="true" role="tablist">
{for $orgList in $orgDoc
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">{ $orgList/tei:head/text() }</h4>
</div>
<div class="panel-body">
<div id="{ string-join(($orgDoc/local-name(), $orgDoc/@type), "-") }" class="tab-pane{if($active) then " active" else ()}">
<div class="panel-group" aria-multiselectable="true" role="tablist">
{for $orgList in $orgDoc
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">{ $orgList/tei:head/text() }</h4>
</div>
<div class="panel-body">
<ul class="listOrg">
{
if($f-register:getNotebook = $f-register:targetStart)
then $orgList/tei:org ! local:prepare-org(.)
else $orgList/tei:org
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]] ! local:prepare-org(.)
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]] ! local:prepare-org(.)
}
</ul>
</div>
</div>
}
</div>
}
</div>
</div>
};
(:~
......@@ -519,35 +549,33 @@ return
(:~
: parser for tei:listPerson, returns the index of persons
: :)
declare function f-register:persons($persDoc as element(tei:listPerson))
declare function f-register:persons($persDoc as element(tei:listPerson), $active as xs:boolean)
as element(xhtml:div) {
let $persURI := tokenize($persDoc/base-uri(), '/|\.')[8]
return
(: main tab :)
<div id="r{ $persURI }" class="tab-pane {local:check-entity($persDoc)}">
<div id="accordion{ $persURI }" class="panel-group" aria-multiselectable="true" role="tablist">
{for $persList in $persDoc
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">Personen und Werke</a>
</h4>
</div>
<div class="panel-body">
<div id="{ string-join(($persDoc/local-name(), $persDoc/@type), "-") }" class="tab-pane{if($active) then " active" else ()}">
<div class="panel-group" aria-multiselectable="true" role="tablist">
{for $persList in $persDoc
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">Personen und Werke</a>
</h4>
</div>
<div class="panel-body">
<ul class="listPerson">
{
if($f-register:getNotebook = $f-register:targetStart)
then $persList/tei:* ! local:prepare-person(.)
else $persList/tei:*
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]] ! local:prepare-person(.)
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]] ! local:prepare-person(.)
}
</ul>
</div>
</div>
}
</div>
}
</div>
</div>
};
declare function local:prepare-person($pers as element(*)+)
......@@ -650,32 +678,29 @@ else
(:~
: prepares the index of geographical references
: :)
declare function f-register:places($listPlace as element(tei:listPlace))
declare function f-register:places($listPlace as element(tei:listPlace), $active as xs:boolean)
as element(xhtml:div) {
let $geoURI := tokenize($listPlace/base-uri(), '/|\.')[8]
return
(: main tab :)
<div id="r{ $geoURI }" class="tab-pane {local:check-entity($listPlace)}">
<div id="accordion{ $geoURI }" class="panel-group" aria-multiselectable="true" role="tablist">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">Geographisches Register</a>
</h4>
</div>
<div class="panel-body">
<div id="{ string-join(($listPlace/local-name(), $listPlace/@type), "-") }" class="tab-pane {if($active) then "active" else ()}">
<div class="panel-group" aria-multiselectable="true" role="tablist">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">Geographisches Register</a>
</h4>
</div>
<div class="panel-body">
<ul class="listPlace">
{
if($f-register:getNotebook = $f-register:targetStart)
then $listPlace/tei:place ! local:prepare-place(.)
else $listPlace/tei:place
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]] ! local:prepare-place(.)
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]] ! local:prepare-place(.)
}
</ul>
</div>
</div>
</div>
</div>
</div>
};
(:~
......@@ -758,42 +783,39 @@ else
(:~
: prepares the list of works :)
declare function f-register:works($wrkDoc)
declare function f-register:works($wrkDoc as element(tei:list), $active as xs:boolean)
as element(xhtml:div) {
let $wrkURI := tokenize($wrkDoc/base-uri(), '/|\.')[8]
return
(: main tab :)
<div id="r{ $wrkURI }-{$wrkDoc/string(@type)}" class="tab-pane {local:check-entity($wrkDoc)}">
<div id="accordion{ $wrkURI }" class="panel-group" aria-multiselectable="true" role="tablist">
{for $wrkList in $wrkDoc
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">{$wrkList/tei:head/text()}</a>
</h4>
</div>
<div class="panel-body">
<ul class="workList">
<div id="{ string-join(($wrkDoc/local-name(), $wrkDoc/@type), "-") }" class="tab-pane{if($active) then " active" else ()}">
<div class="panel-group" aria-multiselectable="true" role="tablist">
{for $wrkList in $wrkDoc
return
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title"><a href="#collapse1-1" data-parent="#accordion" data-toggle="collapse">{$wrkList/tei:head/text()}</a>
</h4>
</div>
<div class="panel-body">
<ul class="workList">
{
if($f-register:getNotebook = $f-register:targetStart)
then
for $i in $wrkList//tei:item[not(tei:list)]
order by lower-case(($i/tei:name[not(@type)]/text())[1])
return local:prepare-work($i)
for $i in $wrkList//tei:item[not(tei:list)]
order by lower-case(($i/tei:name[not(@type)]/text())[1])
return local:prepare-work($i)
else
for $i in $wrkList//tei:item
[not(tei:list)]
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]]
order by lower-case(($i/tei:name[not(@type)]/text())[1])
return local:prepare-work($i)
for $i in $wrkList//tei:item
[not(tei:list)]
[tei:linkGrp/tei:link
[starts-with(@target, $f-register:getNotebook)]]
order by lower-case(($i/tei:name[not(@type)]/text())[1])
return local:prepare-work($i)
}
</ul>
</div>
</ul>
</div>
}
</div>
}
</div>
</div>
};
(:~
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment