Skip to content

Commit e6cfc31

Browse files
committed
Initial commit of hsg shell app based on tei-simple.
0 parents  commit e6cfc31

31 files changed

+15242
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# hsg-shell

bower.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"name": "hsg-shell",
3+
"version": "0.0.1",
4+
"authors": [
5+
"Wolfgang Meier <[email protected]>"
6+
],
7+
"description": "history.state.gov Redesign",
8+
"main": "index.html",
9+
"license": "MIT",
10+
"dependencies": {
11+
"bootstrap": "~3.3.5",
12+
"animate.css": "~3.3.0"
13+
}
14+
}

build.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project default="xar" name="hsg-shell">
3+
<xmlproperty file="expath-pkg.xml"/>
4+
<property name="project.version" value="${package(version)}"/>
5+
<property name="project.app" value="hsg-shell"/>
6+
<property name="build.dir" value="build"/>
7+
<target name="xar">
8+
<mkdir dir="${build.dir}"/>
9+
<zip basedir="." destfile="${build.dir}/${project.app}-${project.version}.xar" excludes="${build.dir}/*"/>
10+
</target>
11+
</project>

collection.xconf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<collection xmlns="http://exist-db.org/collection-config/1.0">
3+
<index xmlns:xs="http://www.w3.org/2001/XMLSchema">
4+
<fulltext default="none" attributes="false"/>
5+
</index>
6+
</collection>

controller.xql

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
xquery version "3.0";
2+
3+
declare variable $exist:path external;
4+
declare variable $exist:resource external;
5+
declare variable $exist:controller external;
6+
declare variable $exist:prefix external;
7+
declare variable $exist:root external;
8+
9+
if ($exist:path eq '') then
10+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
11+
<redirect url="{request:get-uri()}/"/>
12+
</dispatch>
13+
14+
else if ($exist:path eq "/") then
15+
(: forward root path to index.xql :)
16+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
17+
<redirect url="{request:get-uri()}/frus1948v01p1"/>
18+
</dispatch>
19+
20+
21+
else if (ends-with($exist:resource, ".html")) then
22+
(: the html page is run through view.xql to expand templates :)
23+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
24+
<view>
25+
<forward url="{$exist:controller}/modules/view.xql"/>
26+
</view>
27+
<error-handler>
28+
<forward url="{$exist:controller}/error-page.html" method="get"/>
29+
<forward url="{$exist:controller}/modules/view.xql"/>
30+
</error-handler>
31+
</dispatch>
32+
33+
else if (ends-with($exist:resource, ".xql")) then
34+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
35+
</dispatch>
36+
37+
else if (contains($exist:path, "/resources/") or contains($exist:path, "/bower_components/")) then
38+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
39+
<forward url="{$exist:controller}/{replace($exist:path, '^.*((resources|bower_components).*)$', '$1')}"/>
40+
</dispatch>
41+
42+
(: Resource paths starting with $shared are loaded from the shared-resources app :)
43+
else if (contains($exist:path, "/$shared/")) then
44+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
45+
<forward url="/shared-resources/{substring-after($exist:path, '/$shared/')}">
46+
<set-header name="Cache-Control" value="max-age=3600, must-revalidate"/>
47+
</forward>
48+
</dispatch>
49+
50+
else
51+
let $match := analyze-string($exist:path, "^/([^/]+)/?(.*)$")
52+
let $volume := $match//fn:group[@nr = "1"]/string()
53+
let $id := $match//fn:group[@nr = "2"]/string()
54+
return
55+
<dispatch xmlns="http://exist.sourceforge.net/NS/exist">
56+
<forward url="{$exist:controller}/index.html"/>
57+
<view>
58+
<forward url="{$exist:controller}/modules/view.xql">
59+
<add-parameter name="volume" value="{$volume}"/>
60+
<add-parameter name="id" value="{$id}"/>
61+
</forward>
62+
</view>
63+
<error-handler>
64+
<forward url="{$exist:controller}/error-page.html" method="get"/>
65+
<forward url="{$exist:controller}/modules/view.xql"/>
66+
</error-handler>
67+
</dispatch>

error-page.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<div xmlns="http://www.w3.org/1999/xhtml" class="templates:surround?with=templates/page.html&amp;at=content">
3+
<h1>An error has occurred</h1>
4+
<p>An error has been generated by the application.</p>
5+
<pre class="error templates:error-description"/>
6+
<div class="source-links">
7+
<p>View source: <a href="login.html" class="templates:load-source">this page</a>.</p>
8+
</div>
9+
</div>

expath-pkg.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<package xmlns="http://expath.org/ns/pkg" name="http://history.state.gov/ns/site/hsg" abbrev="hsg-shell" version="0.1" spec="1.0">
3+
<title>Historical Documents</title>
4+
<dependency package="http://exist-db.org/apps/shared"/>
5+
</package>

index.html

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<div xmlns="http://www.w3.org/1999/xhtml" data-template="templates:surround" data-template-with="templates/page.html" data-template-at="content">
3+
<div class="row" data-template="pages:load">
4+
<div class="col-md-3">
5+
<div class="row">
6+
<div id="sections" class="col-md-12 panel panel-default">
7+
<h2>Historical Documents</h2>
8+
<label for="select-volume">Volumes</label>
9+
<select id="select-volume" name="volumes" data-template="app:volumes" class="form-control">
10+
<option>Choose Volume</option>
11+
</select>
12+
<label for="select-administration">Browse by Administration</label>
13+
<select id="select-administration" name="administrations" data-template="app:administrations" class="form-control">
14+
<option>Choose Administration</option>
15+
</select>
16+
</div>
17+
</div>
18+
<div class="row">
19+
<div id="toc" class="col-md-12 panel panel-default">
20+
<div class="toc-inner" data-template="toc:table-of-contents"/>
21+
</div>
22+
</div>
23+
</div>
24+
<div class="col-md-9" data-template="pages:navigation">
25+
<div class="navigation-top">
26+
<a data-template="pages:navigation-link" data-template-direction="next" class="nav-next page-nav">
27+
<i class="glyphicon glyphicon-chevron-right"/>
28+
</a>
29+
<a data-template="pages:navigation-link" data-template-direction="previous" class="nav-prev page-nav">
30+
<i class="glyphicon glyphicon-chevron-left"/>
31+
</a>
32+
<h5 id="navigation-title" data-template="pages:navigation-title"/>
33+
</div>
34+
<div id="content-inner">
35+
<div id="content-container">
36+
<div class="content" data-template="pages:view"/>
37+
</div>
38+
</div>
39+
</div>
40+
</div>
41+
<script type="text/javascript" src="resources/scripts/app.js"/>
42+
</div>

modules/ajax.xql

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
xquery version "3.0";
2+
3+
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
4+
declare namespace tei="http://www.tei-c.org/ns/1.0";
5+
6+
import module namespace console="http://exist-db.org/xquery/console" at "java:org.exist.console.xquery.ConsoleModule";
7+
import module namespace pages="http://history.state.gov/ns/site/hsg/pages" at "pages.xql";
8+
import module namespace toc="http://history.state.gov/ns/site/hsg/toc" at "toc.xql";
9+
import module namespace app="http://history.state.gov/ns/site/hsg/templates" at "app.xql";
10+
import module namespace config="http://history.state.gov/ns/site/hsg/config" at "config.xqm";
11+
12+
declare option output:method "json";
13+
declare option output:media-type "application/json";
14+
15+
(:
16+
: This module is called from Javascript when the user wants to navigate to the next/previous
17+
: page.
18+
:)
19+
let $url := request:get-parameter("url", ())
20+
let $toc := boolean(request:get-parameter("toc", "false"))
21+
let $match := analyze-string($url, "^/([^/]+)/?(.*)$")
22+
let $volume := $match//fn:group[@nr = "1"]/string()
23+
let $id := $match//fn:group[@nr = "2"]/string()
24+
let $xml := pages:load-xml("div", $id, $volume)
25+
return
26+
if ($xml) then
27+
let $parent := $xml/ancestor::tei:div[not(*[1] instance of element(tei:div))][1]
28+
let $prevDiv := $xml/preceding::tei:div[1]
29+
let $prev := pages:get-previous(if ($parent and (empty($prevDiv) or $xml/.. >> $prevDiv)) then $xml/.. else $prevDiv)
30+
let $next := pages:get-next($xml)
31+
let $html := pages:process-content($config:odd, pages:get-content($xml))
32+
let $doc := replace($volume, "^.*/([^/]+)$", "$1")
33+
return
34+
map {
35+
"doc": $doc,
36+
"odd": $config:odd,
37+
"next":
38+
if ($next) then
39+
$next/@xml:id/string()
40+
else (),
41+
"previous":
42+
if ($prev) then
43+
$prev/@xml:id/string()
44+
else (),
45+
"title": pages:title($xml/ancestor-or-self::tei:TEI),
46+
"toc": if ($toc) then toc:toc($xml, ()) else (),
47+
"content": $html
48+
}
49+
else
50+
map { "error": "Not found" }

modules/app.xql

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
xquery version "3.0";
2+
3+
module namespace app="http://history.state.gov/ns/site/hsg/templates";
4+
5+
declare namespace tei="http://www.tei-c.org/ns/1.0";
6+
7+
import module namespace templates="http://exist-db.org/xquery/templates" ;
8+
import module namespace config="http://history.state.gov/ns/site/hsg/config" at "config.xqm";
9+
import module namespace pmu="http://www.tei-c.org/tei-simple/xquery/util" at "/db/apps/tei-simple/content/util.xql";
10+
import module namespace odd="http://www.tei-c.org/tei-simple/odd2odd" at "/db/apps/tei-simple/content/odd2odd.xql";
11+
12+
declare
13+
%templates:wrap
14+
function app:volumes($node as node(), $model as map(*), $volume as xs:string?) {
15+
$node/*,
16+
for $vol in collection($config:VOLUMES_PATH)/tei:TEI[.//tei:body/tei:div]
17+
let $vol-id := substring-before(util:document-name($vol), '.xml')
18+
let $volume-metadata := collection($config:VOLUME_METADATA)/volume[@id = $vol-id]
19+
let $volume-title := $volume-metadata/title[@type='volume']
20+
let $volume-number := $volume-metadata/title[@type='volumenumber']
21+
let $sub-series-n := $volume-metadata/title[@type='sub-series']/@n
22+
let $brief-title :=
23+
if ($volume-number ne '') then
24+
string-join(
25+
(
26+
$sub-series-n,
27+
$volume-number,
28+
replace($volume-title, '^The ', '')
29+
),
30+
', ')
31+
else
32+
string-join(
33+
(
34+
if (matches($sub-series-n, '[^\d–]')) then () else $sub-series-n,
35+
replace($volume-title, '^The ', '')
36+
),
37+
', ')
38+
let $selected := if ($vol-id = $volume) then attribute selected {"selected"} else ()
39+
order by $vol-id
40+
return
41+
<option>{
42+
attribute value { $vol-id || "/" },
43+
$selected,
44+
$brief-title
45+
}</option>
46+
};
47+
48+
declare
49+
%templates:wrap
50+
function app:administrations($node as node(), $model as map(*)) {
51+
$node/*,
52+
let $published-vols := collection($config:VOLUME_METADATA)//volume[publication-status eq 'published']
53+
let $administrations := distinct-values($published-vols//administration)
54+
let $code-table-items := doc('/db/cms/apps/volumes/code-tables/administration-code-table.xml')//item[value = $administrations]
55+
let $choices :=
56+
for $admins in $code-table-items
57+
let $adminname := $admins/*:label
58+
let $admincode := $admins/*:value
59+
return
60+
element option {
61+
attribute value { $admincode },
62+
element label {$adminname/string()}
63+
}
64+
return $choices
65+
};

0 commit comments

Comments
 (0)