Repository navigation
Expand file tree
/
Copy pathposts.xq
More file actions
96 lines (86 loc) · 3.72 KB
/
Copy pathposts.xq
File metadata and controls
96 lines (86 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
xquery version "3.0";
import module namespace gsh="http://history.state.gov/ns/xquery/geospatialhistory" at "/db/apps/gsh/modules/gsh.xqm";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "html5";
declare option output:media-type "text/html";
declare function local:landing-page-breadcrumbs() {
<li><a href="{$gsh:posts-home}">Posts</a></li>
};
declare function local:post-in-territory-breadcrumbs($territory-id) {
(
local:landing-page-breadcrumbs(),
<li><a href="{gsh:link-to-post($territory-id)}">Posts in {gsh:territory-id-to-short-name($territory-id)}</a></li>
)
};
declare function local:posts-landing-page($show-all-posts as xs:boolean) {
let $title := 'Posts By Territory'
let $breadcrumbs := local:landing-page-breadcrumbs()
let $content :=
<div>
{gsh:breadcrumbs($breadcrumbs)}
<p>Select a territory from the list below { if ($show-all-posts) then <a href="?">(Show only territory names)</a> else <a href="?show-all-posts=true">(Show all posts)</a>}:</p>
<ul>{
for $territory in $gsh:territories/territory[exists-on-todays-map = 'true']
let $locales := $gsh:locales[current-territory = $territory/id]
let $posts := $gsh:posts[locale-id = $locales/id]
let $ordered-posts :=
(: don't bother sorting unless necessary :)
if ($show-all-posts) then
for $post in $posts
order by $post/locale-id
return
$post
else
$posts
order by $territory/id
return
<li><a href="?territory={$territory/id}">{$territory/short-form-name/string()}</a> {if ($show-all-posts and count($posts) ge 1) then gsh:posts-to-table($ordered-posts) else concat(' (', count($posts), ' posts)')}</li>
}</ul>
</div>
return
gsh:wrap-html($content, $title)
};
declare function local:show-posts-in-territory($territory-id as xs:string) {
let $territory := $gsh:territories[id = $territory-id]
let $locales := $gsh:locales[current-territory = $territory-id]
let $posts := $gsh:posts[locale-id = $locales/id]
let $ordered-posts :=
for $post in $posts
order by $post/locale-id
return
$post
let $table := gsh:posts-to-table($ordered-posts)
let $breadcrumbs := local:post-in-territory-breadcrumbs($territory-id)
let $content :=
<div>
{gsh:breadcrumbs($breadcrumbs)}
<p>{count($posts)} posts in {$territory/short-form-name/string()}:</p>
{$table}
</div>
let $title := concat('Posts in ', $territory/short-form-name)
return
gsh:wrap-html($content, $title)
};
declare function local:show-post($locale-id as xs:string) {
let $post := $gsh:posts[locale-id = $locale-id]
let $locale := $gsh:locales[id = $locale-id]
let $table := gsh:posts-to-table($post)
let $content :=
<div>
<p>Return to list of <a href="{$gsh:posts-home}">Posts by Territory</a></p>
{$table}
</div>
let $title := $locale/name/string()
return
gsh:wrap-html($content, $title)
};
let $show-all-posts := xs:boolean(request:get-parameter('show-all-posts', false()))
let $territory-id := request:get-parameter('territory', ())
let $locale-id := request:get-parameter('locale', ())
return
if ($locale-id) then
local:show-post($locale-id)
else if ($territory-id ne '') then
local:show-posts-in-territory($territory-id)
else
local:posts-landing-page($show-all-posts)