misc.xqm 31.2 KB
Newer Older
Mathias Goebel's avatar
Mathias Goebel committed
1
2
3
4
5
6
xquery version "3.1";

module namespace f-misc="http://fontane-nb.dariah.eu/ns/SADE/misc";
import module namespace config="http://textgrid.de/ns/SADE/config" at "../config/config.xqm";

declare namespace tei="http://www.tei-c.org/ns/1.0";
Mathias Goebel's avatar
Mathias Goebel committed
7
declare namespace test="http://exist-db.org/xquery/xqsuite";
8
declare namespace tgmd="http://textgrid.info/namespaces/metadata/core/2010";
Mathias Goebel's avatar
Mathias Goebel committed
9
10
declare namespace xhtml="http://www.w3.org/1999/xhtml";

Mathias Goebel's avatar
Mathias Goebel committed
11
12
declare variable $f-misc:metadata-collection :=  collection("/db/sade-projects/textgrid/data/xml/meta");

Mathias Goebel's avatar
Mathias Goebel committed
13
14
15
16
17
18
19
20
declare
  %test:arg("baseUri","textgrid:16b00") %test:assertEquals("Notizbuch C7")
  %test:arg("baseUri","") %test:assertEquals("")
function f-misc:get-title-by-baseUri($baseUri as xs:string)
as xs:string? {
  if($baseUri = "") then () else
  $f-misc:metadata-collection//tgmd:textgridUri[starts-with(string(.), $baseUri)]/ancestor::tgmd:object//tgmd:title/string()
  => replace("([A-E])0(\d)", "$1$2")
21
22
};

23
declare function f-misc:nb-param-to-title($node as node(), $model as map(*), $nb as xs:string?)
24
as xs:string? {
25
  if(string($nb) = "")
26
27
  then ""
  else f-misc:get-title-by-baseUri( "textgrid:" || $nb )
Mathias Goebel's avatar
Mathias Goebel committed
28
29
};

30
31
(:~
 : Translates tei:surface/@n to German
Mathias Goebel's avatar
Mathias Goebel committed
32
 : @param $n A valid @tei:n value
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
 : @return the German version, e.g. outer_front_cover translates to "vordere Einbanddecke außen"
 : :)
declare function f-misc:n-translate($n as xs:string)
as xs:string{
if(contains($n, 'endpaper'))
then
    let $seq := tokenize($n, '_')
    return
        ((switch($seq[1])
            case "front" return 'vorderes'
            case "back" return 'hinteres'
            default return 'ungültiger Wert in @n')
        || ' Vorsatzblatt ' || $seq[last()])
else
    switch ($n)
       case "outer_front_cover" return "vordere Einbanddecke außen"
       case "inner_front_cover" return "vordere Einbanddecke innen"
       case "inner_back_cover" return "hintere Einbanddecke innen"
       case "outer_back_cover" return "hintere Einbanddecke außen"
       case "spine" return "Buchrücken"
       default return $n
};

Mathias Goebel's avatar
Mathias Goebel committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
declare function f-misc:cite($node as node(), $model as map(*)) {
let $url := request:get-url(),
    $res := tokenize($url, '/')[last()],
    $id := request:get-parameter('id', ''),
    $page := request:get-parameter('page', 'outer_front_cover'),
    $page := if($page = '') then 'outer_front_cover' else $page,
    $page := switch ($page)
               case "outer_front_cover" return "vordere Einbanddecke außen"
               case "inner_front_cover" return "vordere Einbanddecke innen"
               case "inner_back_cover" return "hintere Einbanddecke außen"
               case "outer_back_cover" return "hintere Einbanddecke innen"
               case "spine" return "Buchrücken"
               default return 'Blatt '||$page,
    $doc := doc( config:get("data-dir")||$id),
    $title := $doc//tei:TEI/tei:teiHeader/tei:fileDesc/tei:titleStmt/tei:title/string(),
71
    $version := string( ($doc//tei:TEI/tei:teiHeader/tei:revisionDesc/tei:change[last()]/text())[1] ),
Mathias Goebel's avatar
Mathias Goebel committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
    $date := current-date(),
    $date := day-from-date($date)||'.'||month-from-date($date)||'.'||year-from-date($date),
    $url := replace($url, 'localhost:8080/exist/apps/SADE/textgrid', 'fontane-nb.dariah.eu') ||(if (request:get-query-string()) then '?' || request:get-query-string() else '')

return
    switch ($res)
    case 'edition.html'
        return
            <span>
                <a href="#" data-toggle="modal" data-target="#citation">Zitationsempfehlung</a>
                <!-- Modal window: -->
                <div class="modal fade" id="citation" tabindex="-1" role="dialog" aria-labelledby="citationrecommendation" aria-hidden="true">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
                        <h4 class="modal-title">Zitationsempfehlung</h4>
                        <div class="clearfix"></div>
                      </div>
                      <div class="modal-body">
                        Theodor Fontane: {$title}. Hrsg. von Gabriele Radecke.
                        In: Theodor Fontane: Notizbücher. Digitale genetisch-kritische und kommentierte Edition.
94
95
96
97
98
                        Hrsg. von Gabriele Radecke,
                        Blatt {$page}.
                        {$url}.
                        {$version},
                        abgerufen am {$date}
Mathias Goebel's avatar
Mathias Goebel committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
                      </div>
                    </div><!-- /.modal-content -->
                  </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->
                <!-- End of modal window -->
            </span>
    case 'inhalt.html'
        return
            <span>
                <a href="#" data-toggle="modal" data-target="#citation">Zitationsempfehlung</a>
                <!-- Modal window: -->
                <div class="modal fade" id="citation" tabindex="-1" role="dialog" aria-labelledby="citationrecommendation" aria-hidden="true">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
                        <h4 class="modal-title">Zitationsempfehlung</h4>
                        <div class="clearfix"></div>
                      </div>
                      <div class="modal-body">
                        Theodor Fontane: {$title} (Inhaltsverzeichnis). Hrsg. von Gabriele Radecke.
                        {$url},
                        abgerufen am: {$date}
                      </div>
                    </div><!-- /.modal-content -->
                  </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->
                <!-- End of modal window -->
            </span>
    case 'doku.html'
        return
            <span>
                <a href="#" data-toggle="modal" data-target="#citation">Zitationsempfehlung</a>
                <!-- Modal window: -->
                <div class="modal fade" id="citation" tabindex="-1" role="dialog" aria-labelledby="citationrecommendation" aria-hidden="true">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
                        <h4 class="modal-title">Zitationsempfehlung</h4>
                        <div class="clearfix"></div>
                      </div>
                      <div class="modal-body">
                        Gabriele Radecke unter Mitarbeit von Martin de la Iglesia und Mathias Göbel: Editorische Gesamtdokumentation.
                        Editorische Assistenz: Rahel Rami und Judith Michaelis. In: Theodor Fontane: Notizbücher. Digitale
                        genetisch-kritische und kommentierte Edition. Hrsg. von Gabriele Radecke.
                        {$url}, abgerufen am {$date}
                      </div>
                    </div><!-- /.modal-content -->
                  </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->
                <!-- End of modal window -->
            </span>
    default
        return
            <span>
                <a href="#" data-toggle="modal" data-target="#citation">Zitationsempfehlung</a>
                <!-- Modal window: -->
                <div class="modal fade" id="citation" tabindex="-1" role="dialog" aria-labelledby="citationrecommendation" aria-hidden="true">
                  <div class="modal-dialog">
                    <div class="modal-content">
                      <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><i class="fa fa-times"></i></button>
                        <h4 class="modal-title">Zitationsempfehlung</h4>
                        <div class="clearfix"></div>
                      </div>
                      <div class="modal-body">
                        Theodor Fontane: Notizbücher. Hrsg. von Gabriele Radecke.<br/>
                        {$url}<br/>
                        abgerufen am: {$date}
                      </div>
                    </div><!-- /.modal-content -->
                  </div><!-- /.modal-dialog -->
                </div><!-- /.modal -->
                <!-- End of modal window -->
            </span>
};

declare function f-misc:kaesten($node as node(), $model as map(*)){
Mathias Goebel's avatar
Mathias Goebel committed
178
179
180
181
    let $n := request:get-parameter('n', 'a0')
    let $num := if(matches($n, "\d+$")) then number(substring($n, 2)) else 0
    let $k := lower-case(substring($n, 1, 1))
    let $q := $k || $num
Mathias Goebel's avatar
Mathias Goebel committed
182
183
184
185
186
187
    let $data-dir := config:get("data-dir")
return

    (<ul class="nav nav-tabs">
        {for $kasten in (('a', 'b', 'c', 'd', 'e'))
        return
Mathias Goebel's avatar
Mathias Goebel committed
188
            if ($k = $kasten)
Mathias Goebel's avatar
Mathias Goebel committed
189
190
191
192
193
194
195
196
197
198
199
200
201
202
            then
                <li class="active">
                    <a href="#{$kasten}" data-toggle="tab">Kasten {upper-case($kasten)}</a>
                </li>
            else
                <li>
                    <a href="#{$kasten}" data-toggle="tab">Kasten {upper-case($kasten)}</a>
                </li>
        }
    </ul>,
    <div class="tab-content">
    {
        for $kasten in (('a', 'b', 'c', 'd', 'e'))
            return
Mathias Goebel's avatar
Mathias Goebel committed
203
                if ($k = $kasten)
Mathias Goebel's avatar
Mathias Goebel committed
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
            then
        <div class="tab-pane active" id="{$kasten}">
            <div class="panel-group" id="accordion{upper-case($kasten)}" role="tablist" aria-multiselectable="true">
                    {f-misc:list( $data-dir || '/xml/meta', upper-case($kasten), $num)}
            </div>
        </div>
        else
        <div class="tab-pane" id="{$kasten}">
            <div class="panel-group" id="accordion{upper-case($kasten)}" role="tablist" aria-multiselectable="true">
                {f-misc:list($data-dir || '/xml/meta', upper-case($kasten), $num)}
            </div>
        </div>
    }
    </div>)
};

Mathias Goebel's avatar
Mathias Goebel committed
220
221
222
223
224
225
226
227
228
229
230
231
232
declare function f-misc:list($datadir, $param, $num as xs:integer)
as element(xhtml:div)+ {

    let $tgnav := doc("/db/sade-projects/textgrid/data/xml/data/3qnsx.xml")
    let $tgnavObjects := $tgnav//object[starts-with(./@title, 'Notizbuch ' || $param)]/string(@title)
                => distinct-values()

    for $item at $pos in $tgnavObjects
    let $uri:= $tgnav//object[string(@title) = $item]/substring-after(@uri, 'textgrid:')
    let $teiDoc := doc("/db/sade-projects/textgrid/data/xml/data/" || $uri || ".xml")
    let $title := if (matches($item, '0\d')) then $item => replace('0', '') else $item
    let $beta := if(contains(($teiDoc//tei:revisionDesc/tei:change)[last()]/text(), 'Version 0.')) then <xhtml:sup>beta</xhtml:sup> else ()
    let $thisIn := (request:get-parameter('n', '') => replace("0(\d)", "$1") => upper-case()) = $param||$pos
Mathias Goebel's avatar
Mathias Goebel committed
233
234
    return
        <div class="panel panel-dark">
Mathias Goebel's avatar
Mathias Goebel committed
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
          <div class="panel-heading" role="tab" id="heading{$param||$pos}">
          <h3 class="panel-title">
          <a role="button" data-toggle="collapse" data-parent="#accordion{$param}" href="#collapse{$param||$pos}" aria-expanded="false" aria-controls="collapse{$param||$pos}">
          {$title}
          {$beta}
            </a>
          </h3>
        </div>
        <div id="collapse{$param||$pos}" class="panel-collapse collapse{if ($thisIn) then ' in' else ()}" role="tabpanel" aria-labelledby="heading{$param||$pos}">
        <div class="panel-body">
        <div class="row">
            <div class="col-md-9">
                <a href="edition.html?id=/xml/data/{$uri[last()]}.xml&amp;page=">Synoptische Ansicht</a>
                <span style="margin-left:20px;"/>
                <form class="form-inline" style="display:inline;" action="edition.html" metod="get">
                    <input type="hidden" name="id" value="/xml/data/{$uri[last()]}.xml"/>
                    <div class="form-group">
Mathias Goebel's avatar
Mathias Goebel committed
252

Mathias Goebel's avatar
Mathias Goebel committed
253
254
                    <input name="page" type="text" style="border-radius:0;border-style:solid;width:40px;" placeholder="1r" data-toggle="tooltip" data-placement="bottom" title="Blattnummer"/>
                    <button type="submit" class="btn btn-default"><i class="fa fa-chevron-right"></i></button>
Mathias Goebel's avatar
Mathias Goebel committed
255

Mathias Goebel's avatar
Mathias Goebel committed
256
257
258
259
260
261
262
                    </div>
                </form>
              <br/>
                <ul>
                    <li><a href="mirador.html?n={$param||$pos}">Digitalisate</a></li>
                    <li><a href="edition.html?id=/xml/data/{$uri[last()]}.xml&amp;page="
                    onclick="goldenState('trans')">Transkriptionsansicht</a></li>
mrodzis's avatar
mrodzis committed
263
                    <li><a href="edierter-text.html?id=/xml/data/{$uri[last()]}.xml&amp;page=">Edierter Text</a>/Textkritischer Apparat</li>
Mathias Goebel's avatar
Mathias Goebel committed
264
265
266
267
268
269
270
                    <li>TEI/XML-Ansicht: <a href="edition.html?id=/xml/data/{$uri[last()]}.xml&amp;page="
                    onclick="goldenState('code')"><i title="seitenweise" class="fa fa-file-o"></i></a> | <a href="xml.html?id=/xml/data/{$uri[last()]}.xml"><i title="gesamtes XML auf der Webseite betrachten" class="fa fa-file-code-o"></i></a> |<a target="_blank" href="/rest/data/{$uri[last()]}.xml">REST</a></li>
                    <li>Kommentare und Register
                        <ul>
                            <li><a href="ueberblickskommentar.html?id=/xml/data/{$uri[last()]}.xml">Überblickskommentar</a></li>
                            <li>Stellenkommentar</li>
                            <li>Register
Mathias Goebel's avatar
Mathias Goebel committed
271
                                <ul>
Mathias Goebel's avatar
Mathias Goebel committed
272
273
274
275
276
277
278
                                    <li><a href="register-listPerson.html?nb={$uri[last()]}">Register der Personen und Werke</a></li>
                                    <li><a href="register-list-works.html?nb={$uri[last()]}">Register der Werke</a></li>
                                    <li><a href="register-list-Fontane.html?nb={$uri[last()]}">Register der Werke Theodor Fontanes</a></li>
                                    <li><a href="register-list-periodicals.html?nb={$uri[last()]}">Register der Periodika</a></li>
                                    <li><a href="register-listPlace.html?nb={$uri[last()]}">Geographisches Register</a></li>
                                    <li><a href="register-listEvent.html?nb={$uri[last()]}">Register der Ereignisse</a></li>
                                    <li><a href="register-listOrg.html?nb={$uri[last()]}">Register der Institutionen und Körperschaften</a></li>
Mathias Goebel's avatar
Mathias Goebel committed
279
                                </ul>
Mathias Goebel's avatar
Mathias Goebel committed
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
                            </li>
                        </ul>
                    </li>
                    <li><a href="inhalt.html?id=/xml/data/{$uri[last()]}.xml">Inhaltsverzeichnis</a></li>
                </ul>
            </div>
            <div class="col-md-3">
                <div id="thumb">{
                    let $img := "digilib/"||substring-after($item, ' ')||"_001.jpg?dh=350&amp;mo=jpg"
                    return
                    element xhtml:img {
                        attribute class {"imgLazy"},
                        attribute src {
                            if ($thisIn) then $img else "/public/img/loader.svg"
                        },
                        if(not($thisIn)) then
                            attribute data-original {$img}
                        else ()
                        }
                    }
                </div>
            </div>
        </div>
        </div>
        </div>
      </div>
Mathias Goebel's avatar
Mathias Goebel committed
306
};
Mathias Goebel's avatar
Mathias Goebel committed
307
308

declare function f-misc:content($node as node(), $model as map(*), $id, $page){
Mathias Goebel's avatar
Mathias Goebel committed
309
<div id="nb-title" class="col-xs-3 col-md-2" title="reset layout">
Mathias Goebel's avatar
Mathias Goebel committed
310
311
    <h1 class="animated slideInLeft">
        <span>{f-misc:nbTitle(request:get-parameter('id', ''), $model)}
Mathias Goebel's avatar
Mathias Goebel committed
312
{if(matches($page, '\d+(r|v)')) then ': '||replace($page, "-alt", "") else ()}</span>
Mathias Goebel's avatar
Mathias Goebel committed
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
    </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>
};
mrodzis's avatar
mrodzis committed
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358


declare function f-misc:editedTextContent($node as node(), $model as map(*), $id) {
    let $xml := request:get-parameter-names()
    let $xml := request:get-parameter("page", "")
    let $util:= util:log-system-out($xml)
    let $util:= util:log-system-out($id)
    return
        <div id="optionsBtn" class="col-xs-1 col-md-2 col-md-offset-3 dropdown">
            <h1 class="animated slideInLeft edited-text-nav-btn">
                <span class="hidden-md hidden-lg"><i class="fa fa-file-image-o"></i></span>
                <span class="hidden-sm hidden-xs">Optionen <i class="fa fa-chevron-down"></i></span>
            </h1>
        </div>,
        <div id="synBtn" class="col-xs-1 col-md-3 col-md-offset-2">
            <a href="edition.html?id={$id}&amp;page=" onclick="goldenState('code')">
                <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">Zur synoptischen Ansicht</span>
                </h1>
            </a>
        </div>
};


Mathias Goebel's avatar
Mathias Goebel committed
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
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>
		default return
		<div class="row">
Mathias Goebel's avatar
Mathias Goebel committed
415
			<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 ()}">
Mathias Goebel's avatar
Mathias Goebel committed
416
417
418
419
420
421
422
423
424
				<h1 class="animated slideInLeft">
				    <span>Entitäten</span>
				</h1>
				<div id="rsBtnRefine">
				    <ul>
				        {$rslistItems}
				    </ul>
				</div>
			</div>
Mathias Goebel's avatar
Mathias Goebel committed
425
			<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 ()}">
Mathias Goebel's avatar
Mathias Goebel committed
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
				<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>
};

declare function f-misc:mirador($node as node(), $model as map(*), $n){
449
450
451
452
453
454
let $sandbox := doc( "/db/sade-projects/textgrid/data/xml" || "/sandbox-iiif.xml" )
let $url := "https://textgridlab.org/1.0/iiif/mirador/?uri="
let $book := if(string-length($n) = 2) then substring($n, 1, 1) || "0" || substring($n, 2, 1)  else $n
let $uri := string($sandbox//tgmd:title[matches(., "Notizbuch_" || $book || "-IIIF")]/ancestor::tgmd:generic//tgmd:textgridUri)
return
    <iframe src="{$url || $uri}" height="100%" width="100%"/>
Mathias Goebel's avatar
Mathias Goebel committed
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
};

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>
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
471
            <button class="btn btn-default{ if(not(request:get-cookie-names() = 'seq') or contains(request:get-cookie-value('seq'), 'inactive')) then ' inactive' else ()}" id="seqBtn">seq</button>
Mathias Goebel's avatar
Mathias Goebel committed
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
            <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(*)) {
Mathias Goebel's avatar
Mathias Goebel committed
488
489
490
491
492
493
494
  let $col := "/db/sade-projects/textgrid"
  let $res := "tgstatus.xml"
  let $url := "https://dariah-de.github.io/status/textgrid/repstatus.html"
  let $lastMod := xmldb:last-modified($col, $res)
  let $path := $col || "/" || $res
  let $doc := doc( $path )
  let $active := not( exists( $doc//ok ) )
495
  let $needUpdate := not(doc-available($path)) or $lastMod < (current-dateTime() - xs:dayTimeDuration("PT6H"))
Mathias Goebel's avatar
Mathias Goebel committed
496
497
498
  let $getStatus :=
      if( $needUpdate )
      then
Mathias Goebel's avatar
misc    
Mathias Goebel committed
499
        let $status := httpclient:get(xs:anyURI($url), false(), ())//xhtml:div[contains(@class, 'repstatus')][not( contains(@class, 'ok') )]
Mathias Goebel's avatar
Mathias Goebel committed
500
501
        let $status := if( exists( $status ) ) then $status else <ok/>
        return
502
            (xmldb:login($col, config:get("sade.user"), config:get("sade.password")),
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
503
504
            xmldb:store($col, $res, $status))
    else if($active and $lastMod < (current-dateTime() - xs:dayTimeDuration("PT2H")))
Mathias Goebel's avatar
Mathias Goebel committed
505
        then
Mathias Goebel's avatar
misc    
Mathias Goebel committed
506
            let $status := httpclient:get(xs:anyURI($url), false(), ())//xhtml:div[contains(@class, 'repstatus')][not( contains(@class, 'ok') )]
Mathias Goebel's avatar
Mathias Goebel committed
507
508
            let $status := if( exists( $status ) ) then $status else <ok/>
            return
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
509
              (xmldb:login($col, config:get("sade.user"), config:get("sade.password")), xmldb:store($col, $res, $status))
Mathias Goebel's avatar
Mathias Goebel committed
510
511
512
    else ()
let $doc := doc( $col || "/" || $res )
return
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
513
    let $status := $doc/xhtml:div[@class]/tokenize(@class, '\s+')[last()]
Mathias Goebel's avatar
Mathias Goebel committed
514
    return
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
515
    if( $doc//ok ) then () else
Mathias Goebel's avatar
Mathias Goebel committed
516
        <div class="alert alert-{if($status = "error") then "danger" else $status}">
Mathias Goebel's avatar
Mathias Goebel committed
517
            <h4>TextGrid-Statusmeldung</h4>
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
518
            <p>Es liegt eine aktuelle Meldung zum TextGrid Repository vor. Einige
Mathias Goebel's avatar
Mathias Goebel committed
519
520
            Funktionen, z.Bsp die Darstellung der Faksimiles, sind vom TextGrid
            Repository abhängig und daher evtl. davon betroffen. Hier folgt die
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
521
            Meldung von TextGrid.</p>
522
            <h5>Status: {$status}</h5>
Mathias Goebel's avatar
mod@seq    
Mathias Goebel committed
523
            {for $i at $pos in $doc/xhtml:div//xhtml:p[@lang="de"] return (if($pos gt 1) then <hr/> else (),$i)}
Mathias Goebel's avatar
Mathias Goebel committed
524
525
526
        </div>
};

Mathias Goebel's avatar
Mathias Goebel committed
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
declare function f-misc:serverStatus($node as node(), $model as map(*)) {
  let $col := "/db/sade-projects/textgrid"
  let $res := "serverstatus.xml"
  let $url := "https://dariah-de.github.io/status/index.html"
  let $lastMod := xmldb:last-modified($col, $res)
  let $path := $col || "/" || $res
  let $doc := doc( $path )
  let $active := not( exists( $doc//ok ) )
  let $needUpdate := not(doc-available($path)) or $lastMod < (current-dateTime() - xs:dayTimeDuration("PT6H"))
  let $getStatus :=
      if( $needUpdate )
      then
        let $status := httpclient:get(xs:anyURI($url), false(), ())//*:li[contains(., "Fontane")]/ancestor::*:div[contains(@class, "alert")]
        let $status := if( exists( $status ) ) then $status else <ok/>
        return
            (xmldb:login($col, config:get("sade.user"), config:get("sade.password")),
            xmldb:store($col, $res, $status))
    else if($active and $lastMod < (current-dateTime() - xs:dayTimeDuration("PT2H")))
        then
            let $status := httpclient:get(xs:anyURI($url), false(), ())//*:li[contains(., "Fontane")]/ancestor::*:div[contains(@class, "alert")]
            let $status := if( exists( $status ) ) then $status else <ok/>
            return
              (xmldb:login($col, config:get("sade.user"), config:get("sade.password")), xmldb:store($col, $res, $status))
    else ()
let $doc := doc( $col || "/" || $res )
return
    let $status := $doc/*:div[@class]/tokenize(@class, '\s+')[last()]
    return
    if( $doc//ok ) then () else
        <div class="alert {$status}">
            <h4>Statusmeldung</h4>
            <p>Es liegt eine aktuelle Meldung zum Betrieb dieses Servers vor.</p>
            <h5>Status: {substring-after($status, "-")}<br/>
                Datum: {string-join( ($doc//*:time/string(@datetime)), ";")}</h5>
561
              <!-- at DARIAH-DE status page no p[@lang='de'] available -->
Mathias Goebel's avatar
Mathias Goebel committed
562
563
564
565
            <p>Die vollständige Statusmeldung finden Sie unter <a href="https://dariah-de.github.io/status/">dariah-de.github.io/status/</a></p>
        </div>
};

Mathias Goebel's avatar
Mathias Goebel committed
566
567
568
569
570
571
572
573
574
575
576
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
    )
};

Mathias Goebel's avatar
Mathias Goebel committed
577
578
declare function f-misc:pageNav($node as node(), $model as map(*), $id as xs:string, $page as xs:string)
as element()* {
Mathias Goebel's avatar
Mathias Goebel committed
579
580
if(request:get-parameter-names() = 'page')
    then
Mathias Goebel's avatar
Mathias Goebel committed
581
582
583
584
        let $uri := $id => substring-after("/xml/data") => substring-before(".xml")
        let $page := if($page = '') then 'outer_front_cover' else $page
        let $indexFile := doc('/db/sade-projects/textgrid/data/xml/xhtml/' || $uri || "/toc.xml" )
        let $pageList2 := $indexFile//@data-page/string()
Mathias Goebel's avatar
Mathias Goebel committed
585
        let $index2 := (index-of($pageList2, $page))[1]
Mathias Goebel's avatar
Mathias Goebel committed
586
587
588
        let $return :=
        (
            (
Mathias Goebel's avatar
Mathias Goebel committed
589
            if ( $index2 gt 1 )
Mathias Goebel's avatar
Mathias Goebel committed
590
            then
Mathias Goebel's avatar
Mathias Goebel committed
591
            <a id="navPrev" href="edition.html?id={$id}&amp;page={$pageList2[$index2 - 1]}">
Mathias Goebel's avatar
Mathias Goebel committed
592
593
594
595
596
597
598
			<!-- slash needed in LIVE?  -->
                <i class="fa fa-chevron-left"></i>
                <span id="navPrevInfo"> vorige Seite </span>
            </a> else ()
            )
            ,
            (
Mathias Goebel's avatar
Mathias Goebel committed
599
            if ( $index2 lt count($pageList2) )
Mathias Goebel's avatar
Mathias Goebel committed
600
            then
Mathias Goebel's avatar
Mathias Goebel committed
601
            <a id="navNext" href="edition.html?id={$id}&amp;page={$pageList2[$index2 + 1]}">
Mathias Goebel's avatar
Mathias Goebel committed
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
			<!-- 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 ()
};
mrodzis's avatar
mrodzis committed
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637


declare function f-misc:notebookNav($node as node(), $model as map(*)) {
    <a id="navPrev" href="">
	<!-- slash needed in LIVE?  -->
        <i class="fa fa-chevron-left"></i>
        <span id="navPrevInfo"> voriges Notizbuch </span>
    </a>,
    <a id="navNext" href="">
	<!-- slash needed in LIVE?  -->
        <span id="navNextInfo"> nächstes Notizbuch </span>
        <i class="fa fa-chevron-right"></i>
    </a>
};


638
639
640
641
642
643
644
declare function f-misc:tocHeader($node as node(), $model as map(*)){
<div id="nb-title" class="col-xs-4 col-md-2">
    <h1 class="animated slideInLeft">
        <span>{f-misc:nbTitle(request:get-parameter('id', ''), $model)}</span>
    </h1>
</div>
};