Commit e0e926eb authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

rangement

parent 4ae11036
Loading
Loading
Loading
Loading

Empty file added.

+1 −1
Changes for plugins-available/default/ead_toc/ead_toc.xq: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -7,4 +7,4 @@ declare variable $project external;
declare variable $doc external;
declare variable $id external;

max.ead_toc:buildEADDocumentTOC($project, $doc)
 No newline at end of file
max.ead_toc:buildEADDocumentTOC($project, $doc, $id)
 No newline at end of file
+121
Changes for rxq/ead/ead_basket.xqm: 121 added lines, 0 removed lines.
Original line number Diff line number Diff line
module namespace max.ead_basket = "pddn/max/ead/ead_basket.xqm";

declare namespace CirceClient = "fr.unicaen.certic.circe.CirceClient";
declare namespace Helpers = "fr.unicaen.certic.circe.Helpers";

import module namespace max.config = 'pddn/max/config' at '../../rxq/config.xqm';
import module namespace max.util = 'pddn/max/util' at '../../rxq/util.xqm';
import module namespace rest = "http://exquery.org/ns/restxq";
import module namespace max.html = 'pddn/max/html' at '../../rxq/html.xqm';

declare variable $max.ead_basket:PLUGIN_ID := "ead";
declare variable $max.ead_basket:CIRCE_ENDPOINT_PARAMETER := "CIRCE_ENDPOINT";
declare variable $max.ead_basket:CIRCE_SECRET_PARAMETER := "CIRCE_SECRET";
declare variable $max.ead_basket:CIRCE_APP_UUID_PARAMETER := "CIRCE_APP_UUID";

declare function max.ead_basket:getResourceFilePath($projectId, $path){
    let $edition_path := max.util:maxHome() || "editions/" || $projectId || "/" || $path
    return
        if(file:exists($edition_path))
        then $edition_path
        else max.util:maxHome() || $path
};


declare function max.ead_basket:circeclient($projectId){
    let $plugin := max.config:getPluginByName($projectId, $max.ead_basket:PLUGIN_ID)
    let $endpoint := string($plugin//parameter[@key = $max.ead_basket:CIRCE_ENDPOINT_PARAMETER]/@value)
    let $appuuid := string($plugin//parameter[@key = $max.ead_basket:CIRCE_APP_UUID_PARAMETER]/@value)
    let $secret := string($plugin//parameter[@key = $max.ead_basket:CIRCE_SECRET_PARAMETER]/@value)
    return CirceClient:new($endpoint, $secret, $appuuid)
};


declare function max.ead_basket:basketItemsForPDF($projectId, $items){
    let $dbPath := max.config:getProjectDBPath($projectId)
    let $items_list := fn:tokenize($items, ",")
    for $item in $items_list
    let $xmlDocName := fn:substring-before($item, "|")
    let $nodeId := fn:substring-after($item, "|")
    let $target := doc(concat($dbPath, '/', $xmlDocName))//*[@xml:id = $nodeId or @id = $nodeId]
    (: todo: make xslt transfo here :)
    return <h1>{$nodeId}</h1>
};

declare
%rest:GET
%rest:query-param("items", "{$items}")
%rest:path("/{$projectId}/ead/basket.pdf")
function max.ead_basket:basketpdf($projectId, $items){
    let $client := max.ead_basket:circeclient($projectId)
    let $helper := Helpers:new($client)
    let $content := <html>
        <head><title>Contenu du porte-documents</title></head>
        <body>{max.ead_basket:basketItemsForPDF($projectId, $items)}</body></html>

    return
        (<rest:response>
            <http:response status="200">
                <http:header name="content-type" value="application/pdf"/>
            </http:response>
        </rest:response>,
        convert:integers-to-base64(Helpers:html2pdf($helper, fn:serialize($content))))
};

declare
%rest:GET
%output:method("html")
%rest:path("/{$projectId}/ead/accueil.html")
function max.ead_basket:accueil($projectId){
    let $documents :=
        <ul>
            {
                for $doc in collection($projectId)
                return
                    <li>
                        <a href="/{$projectId}/ead/{tokenize(base-uri($doc), '/')[last()]}/parcourir/accueil.html">
                            {$doc/*:ead/*:eadheader/*:filedesc/*:titlestmt/*:titleproper//text()}
                            –
                            {$doc/*:ead/*:eadheader/*:filedesc/*:titlestmt/*:author//text()}
                        </a>
                    </li>
            }
        </ul>
    return max.html:renderTemplate(doc(max.ead_basket:getResourceFilePath($projectId, "/plugins/ead/accueil.html")), map {"projectId" : $projectId, "documentsList" : $documents})
};


declare
%rest:GET
%output:method("html")
%rest:path("/{$projectId}/ead/porte-documents.html")
function max.ead_basket:basket($projectId){
    max.html:renderTemplate(doc(max.ead_basket:getResourceFilePath($projectId, "/plugins/ead/porte-documents.html")),
            map {
            "projectId" : $projectId
            })
};


declare function max.ead_basket:itemPorteDocuments($projectId, $item){
    let $dbPath := max.config:getProjectDBPath($projectId)
    let $xmlDocName := fn:substring-before($item, "|")
    let $nodeId := fn:substring-after($item, "|")
    let $target := doc(concat($dbPath, '/', $xmlDocName))//*[@xml:id = $nodeId or @id = $nodeId]
    let $xsl := max.ead_basket:getResourceFilePath($projectId, "/plugins/ead/item_porte-documents.xsl")
    return xslt:transform($target[1],
            $xsl,
            map {
            "project" : $projectId,
            "docName" : $xmlDocName,
            "nodeId" : $nodeId})/*[1]
};

declare
%rest:path("/{$projectId}/ead/fetch_basket_data.html")
%output:method("html")
%rest:POST("{$itemsList}")
function max.ead_basket:basketData($projectId, $itemsList){
    for $item in $itemsList/json/_
    return max.ead_basket:itemPorteDocuments($projectId, $item)
};
+4 −1
Changes for rxq/ead/ead_toc.xqm: 4 added lines, 1 removed line.
Original line number Diff line number Diff line
module namespace max.ead_toc = "pddn/max/ead/ead_toc.xqm";
import module namespace max.config = 'pddn/max/config' at '../config.xqm';

declare function max.ead_toc:buildEADDocumentTOC($projectId, $docPath){
    max.ead_toc:buildEADDocumentTOC($projectId, $docPath, "")
};
declare function max.ead_toc:buildEADDocumentTOC($projectId, $docPath, $nodeId){
    let $dbPath := concat(max.config:getProjectDBPath($projectId), "/", $docPath)
    let $target := doc($dbPath)

@@ -20,6 +22,7 @@ declare function max.ead_toc:buildEADDocumentTOC($projectId, $docPath){
                    {max.ead_toc:getComponentChildren($c, $projectId, $docPath)}
                </details>
            }
            <input type="hidden" name="currentEADItem" value="{$projectId}/{$docPath}/{$nodeId}"></input>
        </nav>
};

+1 −1
Changes for rxq/html.xqm: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -168,7 +168,7 @@ as element(script)*
            src="{$publicjs}"></script>

    let $envJS := if (max.config:getXMLFormat($projectId) = $max.cons:EAD)
    then <script type="text/javascript" src="{max.config:getBaseURI() || $projectId || '/core/ui/js/dist/ead_treeview.min.js'}"/>
    then ()  (: TODO include Sortable.js and ead.js :)
    else ()

    return ($envJS, $projectJS, $pluginsJS)
Loading