Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pb-browse-docs: sort on modification date returns a request execution error #72

Open
emmamorlock opened this issue Sep 7, 2021 · 1 comment

Comments

@emmamorlock
Copy link

emmamorlock commented Sep 7, 2021

There's an error on the demo for <pb-browse-docs> ("passing parameters from a custom form") when one tries to sort the list by "modification date" . The French dialog is "Erreur d’exécution de la requête.: undefined".

See https://unpkg.com/@teipublisher/[email protected]/dist/api.html#pb-browse-docs.2

I might think it comes from the .html, where the sort options are listed.

sort-options='[{"label": "browse.title", "value": "title"},{"label": "browse.author", "value": "author"},{"label": "browse.modificationDate", "value": "default"}]'

the value is 'default' but should be a date of some sort I guess.

On a standalone app, I was able to get it running, but I wasn't able to get a proper date sort (even though I defined the date option as an xs:date in the index.xql...
Ex. :

case "date" return
               xs:date($header//tei:sourceDesc/(tei:bibl|tei:biblFull)/tei:date/@when)
@emmamorlock
Copy link
Author

Rectification

I finally did more testing and must correct the previous post.
The error comes from the fact that the value indexed is not a xs:date (or at least a "yyyy-mm-dd" date). "yyyy" or "yyyy-mm" will fail in nav:sort, hence the error message.

Concerning the demo, maybe the indexed value may be checked?

As a dates in @when can be formatted as "yyyy" or "yyyy-mm" as well as "yyyy-mm-dd", this response may not be understood by the user.

To prevent it in my standalone webapp, I just add the following function in index.xql.

declare function idx:formatDate($input as xs:string?) as xs:date? {
    if(empty($input))
        then ()
        else
        	let $i := normalize-space(replace($input, '&#160;', ' '))
        	let $date := if (matches($i,'^(\d{4}-\d{2}-\d{2}).*')) 
                    then xs:date($i) 
                    else if (matches($i,'^(\d{4})$')) then xs:date($i || '-01-01')
                        else if (matches($i,'^(\d{4}-\d{2})$')) then xs:date($i || '-01')
                            else ()
    return $date
};

Will work only for @when, and there may be stronger ways to handle that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant