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

further refinings

parent 708ed3a8
xquery version "3.1";
import module namespace console="http://exist-db.org/xquery/console" at "java:org.exist.console.xquery.ConsoleModule";
import module namespace config="http://textgrid.de/ns/SADE/config" at "modules/config/config.xqm";
declare variable $exist:path external;
......@@ -10,26 +9,27 @@ declare variable $exist:prefix external;
declare variable $exist:root external;
let $project := tokenize( $exist:path, "/" )[. != ""][not(ends-with(., "html"))][1]
let $project := config:list-projects()[1]
let $test := console:log("@@@@@@@ NEW REQUEST @@@@@@")
let $test := console:log($exist:path)
let $test := console:log($exist:resource)
let $test := console:log($exist:controller)
let $listproject := config:list-projects()[1]
return
if ($exist:path eq '') then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{request:get-uri()}/"/>
</dispatch>
else if ($project = ()) then
else if (empty($project)) then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="{config:list-projects()[1]}/{request:get-uri()}/"/>
<redirect url="{config:list-projects()[1]}/index.html"/>
</dispatch>
else if ($exist:path eq "/") then
else if (ends-with($exist:path, "/") or empty($exist:resource)) then
(: forward root path to index.xql :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<redirect url="index.html"/>
</dispatch>
else if (tokenize($exist:path, '/') = "rest") then
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<forward url="/../sade-projects/{$project}/data/xml/{substring-after($exist:path, "/rest/")}" >
</forward>
</dispatch>
else if (ends-with($exist:resource, ".html")) then
let $doc-path := $config:projects-dir || $project || config:get("template") || $exist:resource
return
......@@ -53,11 +53,13 @@ else if (contains($exist:path, "/$shared/")) then
</forward>
</dispatch>
else
(: check if the resource comes from the template or the data
we try to leave the template manipulation as minimal as
possible
:)
let $path := "/../sade-projects/"|| $project || "/" || config:get("data-dir") || "/" || substring-after($exist:path, $project)
let $path := if( doc-available( $path ) ) then $path else "/../sade-projects/"|| $project || config:get("template") || substring-after($exist:path, $project)
return
(: everything else is passed through :)
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
<cache-control cache="yes"/>
<forward url="{$path}">
......
......@@ -258,3 +258,263 @@ declare function f-misc:list($datadir, $param, $num as xs:integer) {
</div>
</div>
};
declare function f-misc:content($node as node(), $model as map(*), $id, $page){
<div id="nb-title" class="col-xs-3 col-md-2">
<h1 class="animated slideInLeft">
<span>{f-misc:nbTitle(request:get-parameter('id', ''), $model)}
{if(matches($page, '\d+(r|v)')) then ': '||$page else ()}</span>
</h1>
</div>,
<div id="facsBtn" class="col-xs-1 col-md-2{ if(contains(request:get-cookie-value('facs'), 'inactive')) then ' inactive' else ()}">
<h1 class="animated slideInLeft">
<span class="hidden-md hidden-lg"><i class="fa fa-file-image-o"></i></span>
<span class="hidden-sm hidden-xs">Faksimile</span>
</h1>
</div>,
<div id="transBtn" class="col-xs-1 col-md-2 col-md-offset-1 { if(contains(request:get-cookie-value('trans'), 'inactive')) then ' inactive' else ()} ">
<h1 class="animated slideInLeft">
<span class="hidden-md hidden-lg"><i class="fa fa-file-text-o"></i></span>
<span class="hidden-sm hidden-xs">Transkription</span>
</h1>
</div>,
<div id="xmlBtn" class="col-xs-1 col-md-2 col-md-offset-1 {if(contains(request:get-cookie-value('xml'), 'inactive')) then ' inactive' else ()}">
<h1 class="animated slideInLeft">
<span class="hidden-md hidden-lg"><i class="fa fa-file-code-o"></i></span>
<span class="hidden-sm hidden-xs">XML</span>
</h1>
</div>
};
declare function f-misc:buttons($node as node(), $model as map(*)){
let $cookies := request:get-cookie-names()
let $pagenum := request:get-parameter('page', 'outer_front_cover')
let $pagenum := if ($pagenum = '') then 'outer_front_cover' else $pagenum
let $page := doc( config:get("data-dir") || request:get-parameter('id', '/xml/data/16b00.xml'))//tei:surface[@n = $pagenum]
let $entities := distinct-values($page//tei:rs/substring-before(@ref, ':'))
let $rslistItems := for $e in $entities
order by $e
return
switch($e)
case 'psn' return <li class="psn rsHigh">Personen</li>
case 'plc' return <li class="plc rsHigh">Orte</li>
case 'wrk' return <li class="wrk rsHigh">Werke</li>
case 'eve' return <li class="eve rsHigh">Ereignisse</li>
case 'org' return <li class="org rsHigh">Institutionen</li>
default return <li class="none">Keine</li>
let $datelistItems := if($page//tei:date) then for $item in distinct-values( $page//tei:date/string(@when-iso) ) return <li>{$item}</li> else <li class="none">Keine</li>
let $reflistItems := if($page//tei:ref[not(parent::tei:figDesc)]) then for $item in distinct-values( $page//tei:ref[not(parent::tei:figDesc)]/string-join(., ' ') ) return <li>{$item}</li> else <li class="none">Keine</li>
return
switch ( config:get('sade.develop') )
case "true" return
<div class="row">
<div id="rsBtn" class="col-xs-4{ if(not(request:get-cookie-names() = 'rs') or contains(request:get-cookie-value('rs'), 'inactive')) then ' inactive' else ()}">
<h1 class="animated slideInLeft">
<span>Entitäten</span>
</h1>
<div id="rsBtnRefine">
<ul>
{$rslistItems}
</ul>
</div>
</div>
<div id="dateBtn" class="col-xs-4{ if(not(request:get-cookie-names() = 'date') or contains(request:get-cookie-value('date'), 'inactive')) then ' inactive' else ()}">
<h1 class="animated slideInLeft">
<span>Datierung</span>
</h1>
<div id="dateBtnRefine">
<ul>
{$datelistItems}
</ul>
</div>
</div>
<div id="refBtn" class="col-xs-4{ if(not(request:get-cookie-names() = 'ref') or contains(request:get-cookie-value('ref'), 'none')) then ' inactive' else ()}">
<h1 class="animated slideInLeft">
<span>Referenzierungen</span>
</h1>
<div id="refBtnRefine">
<ul>
{$reflistItems}
</ul>
</div>
</div>
<div id="rotateBtn" class="col-xs-2">
<input
id="RotateSlide"
type="range"
min="0"
max="359"
step="5"
defaultValue="0"
style="height:0;"/>
</div>
</div>
default return
<div class="row">
<div id="rsBtn" class="col-xs-3{ if(not(request:get-cookie-names() = 'rs') or contains(request:get-cookie-value('rs'), 'inactive')) then ' inactive' else ()}">
<h1 class="animated slideInLeft">
<span>Entitäten</span>
</h1>
<div id="rsBtnRefine">
<ul>
{$rslistItems}
</ul>
</div>
</div>
<div id="dateBtn" class="col-xs-3{ if(not(request:get-cookie-names() = 'date') or contains(request:get-cookie-value('date'), 'inactive')) then ' inactive' else ()}">
<h1 class="animated slideInLeft">
<span>Datierung</span>
</h1>
<div id="dateBtnRefine">
<ul>
{$datelistItems}
</ul>
</div>
</div>
<div id="refBtn" class="col-xs-4{ if(not(request:get-cookie-names() = 'ref') or contains(request:get-cookie-value('ref'), 'none')) then ' inactive' else ()}">
<h1 class="animated slideInLeft">
<span>Referenzierungen</span>
</h1>
<div id="refBtnRefine">
<ul>
{$reflistItems}
</ul>
</div>
</div>
<div id="rotateBtn" class="col-xs-2">
<input
id="RotateSlide"
type="range"
min="0"
max="359"
step="5"
defaultValue="0"
style="height:0;"/>
</div>
</div>
};
declare function f-misc:mirador($node as node(), $model as map(*), $n){
if((string-length($n) lt 4) and matches($n, "^[A-Ea-e]\d+"))
then <iframe src="https://fontane-nb.dariah.eu/public/mirador/{replace(lower-case($n), '0(\d)', '$1')}.html" height="100%" width="100%"/>
else "Die Digitalisate zum gesuchten Notizbuch sind noch nicht verfügbar oder die Anfrage ist ungültig."
};
declare function f-misc:debug( $node as node(), $model as map(*) ){
<meta name="debug" content="{ request:get-url() }"/>
};
declare function f-misc:ToolbarExtended($node as node(), $model as map(*)) {
let $develop := config:get('sade.develop')
return
switch ($develop)
case "true" return
<div id="ToolbarExtended">
<button class="btn btn-default{ if(not(request:get-cookie-names() = 'hi') or contains(request:get-cookie-value('hi'), 'inactive')) then ' inactive' else ()}" id="hiBtn">hi</button>
<button class="btn btn-default{ if(not(request:get-cookie-names() = 'del') or contains(request:get-cookie-value('del'), 'inactive')) then ' inactive' else ()}" id="delBtn">del</button>
<button class="btn btn-default{ if(not(request:get-cookie-names() = 'add') or contains(request:get-cookie-value('add'), 'inactive')) then ' inactive' else ()}" id="addBtn">add</button>
<button class="btn btn-default{ if(not(request:get-cookie-names() = 'mod') or contains(request:get-cookie-value('mod'), 'inactive')) then ' inactive' else ()}" id="modBtn">mod</button>
<button class="btn btn-default{ if(not(request:get-cookie-names() = 'latn') or contains(request:get-cookie-value('latn'), 'inactive')) then ' inactive' else ()}" id="latnBtn">Latn</button>
<button class="btn btn-default{ if(not(request:get-cookie-names() = 'script') or contains(request:get-cookie-value('script'), 'inactive')) then ' inactive' else ()}" id="scriptBtn">script
<div class="BtnExt">
<ul>
<li class="clean">clean</li>
<li class="hasty">hasty</li>
<li class="angular">angular</li>
</ul>
</div>
</button>
<button class="btn btn-default{ if(not(request:get-cookie-names() = 'med') or contains(request:get-cookie-value('med'), 'inactive')) then ' inactive' else ()} disabled" id="medBtn">medium</button>
</div>
default return <!-- develop feature -->
};
declare function f-misc:textgridStatus($node as node(), $model as map(*)) {
let $col := "/db/sade-projects/textgrid"
let $res := "tgstatus.xml"
let $lastMod := xmldb:last-modified($col, $res)
let $doc := doc( $col || "/" || $res )
let $active := not( exists( $doc//ok ) )
let $getStatus :=
if( not( $active ) and $lastMod < (current-dateTime() - xs:dayTimeDuration("PT12H")) )
then
let $status := httpclient:get(xs:anyURI("https://raw.githubusercontent.com/DARIAH-DE/textgridrep-status/master/repstatus.html"), false(), ())//xhtml:div[contains(@class, 'repstatus')][not( contains(@class, 'ok') )]
let $status := if( exists( $status ) ) then $status else <ok/>
return
xmldb:store($col, $res, $status)
else if($active and $lastMod < (current-dateTime() - xs:dayTimeDuration("PT2H")))
then
let $status := httpclient:get(xs:anyURI("https://raw.githubusercontent.com/DARIAH-DE/textgridrep-status/master/repstatus.html"), false(), ())//xhtml:div[contains(@class, 'repstatus')][not( contains(@class, 'ok') )]
let $status := if( exists( $status ) ) then $status else <ok/>
return
xmldb:store($col, $res, $status)
else ()
let $doc := doc( $col || "/" || $res )
return
if( $doc//ok ) then () else
<div class="alert alert-danger">
<h4>TextGrid-Statusmeldung</h4>
<p>Es liegt eine aktuelle Meldung zum TextGrid Repository vor. Einige
Funktionen, z.Bsp die Darstellung der Faksimiles, sind vom TextGrid
Repository abhängig und daher evtl. davon betroffen. Hier folgt die
Meldung von TextGrid.</p>
<h5>Status: {$doc/xhtml:div[@class]/tokenize(@class, '\s+')[last()]}</h5>
{$doc/xhtml:div//xhtml:p[@lang="de"]}
</div>
};
declare function f-misc:nbTitle($id as xs:string, $model as map(*)){
let $doc := doc( config:get("data-dir") || $id)
let $title := $doc//tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title/string(.)
let $beta := if(contains(($doc//tei:revisionDesc/tei:change)[last()]/text(), 'Version 0.')) then <xhtml:sup>beta</xhtml:sup> else ()
return (
(: <xhtml:span class="hidden-sm hidden-xs">{substring-before($title, ' ')}</xhtml:span>,:)
<xhtml:span>{' '||substring-after($title, ' ')}</xhtml:span>,
$beta
)
};
declare function f-misc:pageNav($node as node(), $model as map(*), $id){
if(request:get-parameter-names() = 'page')
then
let $page := if(request:get-parameter('page', '') = '') then 'outer_front_cover' else request:get-parameter('page', '')
let $doc:= doc('/db/sade-projects/textgrid/data'||$id)/tei:TEI
let $pagelist := $doc//tei:sourceDoc//tei:surface[parent::tei:sourceDoc or @type="clipping"]/string(@n)
let $page := if ($page = '') then 'outer_front_cover' else $page
let $index := index-of($pagelist, $page)
let $return :=
(
(
if ( $index gt 1 )
then
<a id="navPrev" href="edition.html?id={$id}&amp;page={$pagelist[$index - 1]}">
<!-- slash needed in LIVE? -->
<i class="fa fa-chevron-left"></i>
<span id="navPrevInfo"> vorige Seite </span>
</a> else ()
)
,
(
if ( $index lt count($pagelist) )
then
<a id="navNext" href="edition.html?id={$id}&amp;page={$pagelist[$index + 1]}">
<!-- slash needed in LIVE? -->
<span id="navNextInfo"> nächste Seite </span>
<i class="fa fa-chevron-right"></i>
</a>
else ()
),
element script {
'$(document).keyup(function(e){
var next = jQuery.isEmptyObject( $("#navNext").attr("href") );
var prev = jQuery.isEmptyObject( $("#navPrev").attr("href") );
if ( (e.keyCode == 37) &amp;&amp; prev == false )
{location.href = $( "#navPrev" ).attr("href"); }
else if (e.keyCode == 39 &amp;&amp; next == false )
{location.href = $( "#navNext" ).attr("href"); }
});'
}
)
return $return
else ()
};
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