eeditiones / tei-publisher-components

Web components used by TEI Publisher and apps generated by it
https://cdn.tei-publisher.com/
GNU General Public License v3.0
18 stars 14 forks source link

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

Open emmamorlock opened 3 years ago

emmamorlock commented 3 years ago

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/pb-components@1.24.18/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 commented 3 years ago

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.