Skip to content

Conversation

marmoure
Copy link
Contributor

fixes #111
DB Manager view (File > Manage) now has a Download button to download a selected resource.
This only applies for files at the moment, you select the file then press Download in the toolbar.

image

This open source contribution to the eXide project was commissioned by the Office of the Historian, U.S. Department of State, https://history.state.gov/.

@marmoure
Copy link
Contributor Author

@joewiz i updated the file name ,please take a look at PR

@joewiz
Copy link
Member

joewiz commented Jun 23, 2022

@marmoure Thanks for fixing the call to load.xq! It works well for downloading individual resources. Since this PR doesn't allow download of multiple selected resources or collections (i.e., the operation silently fails), could you either (a) make the download button inactive when multiple resources or collections are selected, or (b) display a notice when the user selects the download button in such a scenario?

@marmoure
Copy link
Contributor Author

hi @joewiz i added a fail message when eXide fail to recognize your selection
and i ll move my comment from the original issue to here
"Hi @joewiz seems like getting selected resources in eXide in the current state doesn't support selecting collections or multiple resources, you can only select one resource"

@joewiz
Copy link
Member

joewiz commented Jun 24, 2022

Thanks! Could you update the text of the warning from:

Error in selection eXide didn't recognize your selection please select a single resource first. current state doesn't support selecting collections or multiple resources

to:

Invalid selection: The Download Selected command requires that only one resource be selected (not multiple resources or collections). Please select a single resource for download.

(In my testing, the copy/paste and cut/paste commands can work on multiple resources. But the commands are somewhat inconsistent in their handling of multiple selections. Your warning dialog is very nice and user-friendly!)

@marmoure
Copy link
Contributor Author

Hi @joewiz i changed the warning message and added few tweaks 😉

@joewiz
Copy link
Member

joewiz commented Jun 26, 2022

@marmoure Works beautifully! Could you change the warning from:

The Download Selected command requires that only resources be selected (not collections). Please select a resources for download.

to:

The Download Selected command only works on resources, not collections. Please select resources for download.

@joewiz
Copy link
Member

joewiz commented Jun 26, 2022

@marmoure Hmm... If we extend the deploy:download() function in modules/deployment.xq to not just create .xar packages but also create .zip files for collections, as follows:

declare function deploy:download($collection as xs:string, $expathConf as element()?, $expand-xincludes as xs:boolean, $indent as xs:boolean, $omit-xml-declaration as xs:boolean) {
    let $name := 
        if ($expathConf) then
            concat($expathConf/@abbrev, "-", $expathConf/@version, ".xar")
        else
            replace($collection, "^.+/([^/]+)$", "$1") || ".zip"
    let $entries :=
        (: compression:zip uses default serialization parameters, so we'll construct entries manually :)
        dbutil:scan(xs:anyURI($collection), function($coll as xs:anyURI, $res as xs:anyURI?) {
            (: compression:zip doesn't seem to store empty collections, so we'll scan for only resources :)
            if (exists($res)) then
                let $relative-path := substring-after($res, $collection || "/")
                return
                    if (util:binary-doc-available($res)) then
                        <entry type="uri" name="{$relative-path}">{$res}</entry>
                    else
                        <entry type="xml" name="{$relative-path}">{
                            (: workaround until https://github.com/eXist-db/exist/issues/2394 is resolved :)
                            util:declare-option(
                                "exist:serialize", 
                                "expand-xincludes=" 
                                || (if ($expand-xincludes) then "yes" else "no")
                                || " indent=" 
                                || (if ($indent) then "yes" else "no")
                                || " omit-xml-declaration=" 
                                || (if ($omit-xml-declaration) then "yes" else "no")
                            ),
                            doc($res)
                        }</entry>
            else
                ()
        })
    let $archive := compression:zip($entries, true())
    return (
        response:set-header("Content-Disposition", concat("attachment; filename=", $name)),
        response:stream-binary($archive, "application/zip", $name)
    )
};

... then this PR could be extended to download collections (like /db/test) by calling:

http://localhost:8080/exist/apps/eXide/modules/deployment.xq?download=true&collection=%2Fdb%2Ftest&indent=false&expand-xincludes=false&omit-xml-decl=true

The collection param should contain the full, URL-encoded path to the desired collection. The indent, expand-xincludes, and omit-xml-decl parameters should be read from preferences, as other similar commands do.

Do you think that's feasible to incorporate into this PR?

@marmoure
Copy link
Contributor Author

@joewiz can you please go ahead and give this one a test

@joewiz
Copy link
Member

joewiz commented Jun 27, 2022

@marmoure Works beautifully - even with mixed selections of resources AND collections. Thank you!

@joewiz joewiz merged commit 3012c28 into eXist-db:develop Jun 27, 2022
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

Successfully merging this pull request may close these issues.

Add download button to DB Manager view
2 participants