Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ paths:
$ref: "./openapi/paths/application-newID.yaml"
/facets/{facet}:
$ref: "./openapi/paths/facets.yaml"
/timeline:
$ref: "./openapi/paths/timeline.yaml"
/timeline/{docType}:
$ref: "./openapi/paths/timeline-docType.yaml"
/timeline/{docType}/{docID}:
$ref: "./openapi/paths/timeline-docType-docID.yaml"
components:
schemas:
Document:
Expand Down
40 changes: 40 additions & 0 deletions api/v1/openapi/paths/timeline-docType-docID.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# /timeline/docType/docID path
get:
tags:
- Facets
summary: Returns timeline for a specific document type
description: |
This endpoint returns a timeline object according to
https://cdn.tei-publisher.com/@2.23.2/dist/api.html#pb-timeline.0
for a specific WeGA document type related to the given document identifier
(i.e. the works, letters, or writings associated with the given person or organization).
parameters:
- name: docType
in: path
description: The WeGA document type
required: true
style: form
explode: false
schema:
$ref: '../schemas/docTypes.yaml'
- name: docID
in: path
description: The document identifier to search for
required: true
schema:
type: string
default: A002068
responses:
200:
description: A timeline object according to https://cdn.tei-publisher.com/@2.23.2/dist/api.html#pb-timeline.0
headers:
totalrecordcount:
description: The total size of the result set
schema:
type: integer
content:
application/json:
schema:
type: object
default:
$ref: '../responses/unexpectedError.yaml'
31 changes: 31 additions & 0 deletions api/v1/openapi/paths/timeline-docType.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# /timeline/docType path
get:
tags:
- Facets
summary: Returns timeline for a specific document type
description: |
This endpoint returns a timeline object according to
https://cdn.tei-publisher.com/@2.23.2/dist/api.html#pb-timeline.0 for a specific WeGA document type
parameters:
- name: docType
in: path
description: The WeGA document type
required: true
style: form
explode: false
schema:
$ref: '../schemas/docTypes.yaml'
responses:
200:
description: A timeline object according to https://cdn.tei-publisher.com/@2.23.2/dist/api.html#pb-timeline.0
headers:
totalrecordcount:
description: The total size of the result set
schema:
type: integer
content:
application/json:
schema:
type: object
default:
$ref: '../responses/unexpectedError.yaml'
22 changes: 22 additions & 0 deletions api/v1/openapi/paths/timeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# /timeline path
get:
tags:
- Facets
summary: Returns timeline
description: |
This endpoint returns a timeline object according to
https://cdn.tei-publisher.com/@2.23.2/dist/api.html#pb-timeline.0
responses:
200:
description: A timeline object according to https://cdn.tei-publisher.com/@2.23.2/dist/api.html#pb-timeline.0
headers:
totalrecordcount:
description: The total size of the result set
schema:
type: integer
content:
application/json:
schema:
type: object
default:
$ref: '../responses/unexpectedError.yaml'
50 changes: 50 additions & 0 deletions modules/api.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,38 @@ declare function api:facets($model as map(*)) as map(*) {
)
};

(:~
: Return a timeline object for driving the TEIPublisher pb-timeline component
: see https://cdn.tei-publisher.com/@2.23.2/dist/api.html#pb-timeline.0
:)
declare function api:timeline($model as map(*)) as map(*) {
let $docID :=
if($model?docID)
then $model?docID
else 'indices'
let $documents :=
for $docType in api:resolve-docTypes($model)
return search:results(<span/>, map { 'docID' : $docID }, $docType)?search-results
(:if(empty(($model?start, $model?end)))
then core:getOrCreateColl($docType, $docID, true())
else wdt:lookup($docType, core:getOrCreateColl($docType, $docID, true()))?filter-by-date($model?start, $model?end) :)
let $dates :=
map:merge(
for $doc in $documents
group by $date := query:get-normalized-date($doc)
let $key :=
if(exists($date)) then $date
else '?'
return
map:entry($key, count($doc))
)
return
map {
'totalRecordCount': count(map:keys($dates)),
'results': $dates
}
};

(:~
: Search WeGA entities (persons, places, works) by name or title respectively
:)
Expand Down Expand Up @@ -764,6 +796,24 @@ declare function api:validate-toDate($model as map(*)) as map(*)? {
else error($api:INVALID_PARAMETER, 'Unsupported date format given: "' || $model('toDate') || '". Should be YYYY-MM-DD.')
};

(:~
: Check parameter start
~:)
declare function api:validate-start($model as map(*)) as map(*)? {
if($model('start') castable as xs:date) then (map:put($model, 'fromDate', $model('start')) => map:remove('start'))
else if($model?start ='') then () (: an empty string is simply dropped :)
else error($api:INVALID_PARAMETER, 'Unsupported date format given: "' || $model('start') || '". Should be YYYY-MM-DD.')
};

(:~
: Check parameter end
~:)
declare function api:validate-end($model as map(*)) as map(*)? {
if($model('end') castable as xs:date) then (map:put($model, 'toDate', $model('end')) => map:remove('end'))
else if($model?end ='') then () (: an empty string is simply dropped :)
else error($api:INVALID_PARAMETER, 'Unsupported date format given: "' || $model('end') || '". Should be YYYY-MM-DD.')
};

(:~
: Check parameter date
~:)
Expand Down
46 changes: 30 additions & 16 deletions modules/app.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -493,22 +493,6 @@ declare
}
};

(:~
: set the maximum dates for the IonRangeSlider
~:)
declare
%templates:default("fromDate", "")
%templates:default("toDate", "")
function app:set-slider-range($node as node(), $model as map(*), $fromDate as xs:string, $toDate as xs:string) as element(xhtml:input) {
element {node-name($node)} {
$node/@*,
attribute data-min-slider {if($model('oldFromDate') castable as xs:date) then $model('oldFromDate') else $model('earliestDate')},
attribute data-max-slider {if($model('oldToDate') castable as xs:date) then $model('oldToDate') else $model('latestDate')},
attribute data-from-slider {if($fromDate castable as xs:date) then $fromDate else $model('earliestDate')},
attribute data-to-slider {if($toDate castable as xs:date) then $toDate else $model('latestDate')}
}
};

declare function app:set-facet-checkbox($node as node(), $model as map(*), $key as xs:string) as element(xhtml:input) {
element {node-name($node)} {
$node/@*,
Expand Down Expand Up @@ -2110,3 +2094,33 @@ declare function app:init-custom-switch($node as node(), $model as map(*)) as el
$node/*
}
};

(:~
: Construct the pb-timeline custom element,
: i.e. update the `@start-date` and `@end-date` attributes
: as well as the `@url` attribute with the API URL.
:)
declare function app:pb-timeline($node as node(), $model as map(*)) as element(xhtml:pb-timeline) {
let $api-base := config:api-base($model?openapi)
let $docType :=
if(count($model?docType) eq 1 and $model?docType = $search:wega-docTypes)
then $model?docType
else ()
let $docID :=
if($model?docID = 'indices')
then ()
else $model?docID
let $url := $api-base || str:join-path-elements(('/timeline', $docType, $docID))
return
element {node-name($node)} {
$node/@* except $node/@start-date except $node/@end-date except $node/@url,
attribute url {$url},
if($model?filters?fromDate castable as xs:date)
then attribute start-date {$model?filters?fromDate}
else (),
if($model?filters?toDate castable as xs:date)
then attribute end-date {$model?filters?toDate}
else (),
$node/*
}
};
4 changes: 3 additions & 1 deletion modules/search.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ declare variable $search:valid-params := (
'undated',
'orderby',
'orderdir',
'orgs'
'orgs',
'start',
'end'
);

(:~
Expand Down
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"flip": "nnattawat/flip",
"fullcalendar": "^6.1.19",
"highlight.js": "^11.11.1",
"ion-rangeslider": "^2",
"jquery": "^3.5.0",
"jquery-ui": "^1.14.2",
"jquery-ui-themes": "^1.12.0",
Expand Down Expand Up @@ -58,7 +57,6 @@
"fittextjs",
"flip/dist",
"fullcalendar",
"ion-rangeslider/{css,img,js}",
"jquery/dist/",
"jquery-ui",
"jquery-ui-themes",
Expand Down
Loading
Loading