Commit 06adb03c authored by Jérôme Chauveau's avatar Jérôme Chauveau
Browse files

migration des fonctionnalités 'panier ead' sous forme de plugin (ead_basket)

parent 486e8dc2
Loading
Loading
Loading
Loading
+22 −22
Changes for plugins-available/default/ead_basket/ead_basket.xqm: 22 added lines, 22 removed lines.
Original line number Diff line number Diff line
module namespace max.ead_basket = "pddn/max/ead/ead_basket.xqm";
module namespace max.plugin.ead_basket = "pddn/max/plugin/ead_basket";

declare namespace CirceClient = "fr.unicaen.certic.circe.CirceClient";
declare namespace Helpers = "fr.unicaen.certic.circe.Helpers";
@@ -8,12 +8,12 @@ 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 variable $max.plugin.ead_basket:PLUGIN_ID := "ead_basket";
declare variable $max.plugin.ead_basket:CIRCE_ENDPOINT_PARAMETER := "CIRCE_ENDPOINT";
declare variable $max.plugin.ead_basket:CIRCE_SECRET_PARAMETER := "CIRCE_SECRET";
declare variable $max.plugin.ead_basket:CIRCE_APP_UUID_PARAMETER := "CIRCE_APP_UUID";

declare function max.ead_basket:getResourceFilePath($projectId, $path){
declare function max.plugin.ead_basket:getResourceFilePath($projectId, $path){
    let $edition_path := max.util:maxHome() || "editions/" || $projectId || "/" || $path
    return
        if(file:exists($edition_path))
@@ -21,15 +21,15 @@ declare function max.ead_basket:getResourceFilePath($projectId, $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)
declare function max.plugin.ead_basket:circeclient($projectId){
    let $plugin := max.config:getPluginByName($projectId, $max.plugin.ead_basket:PLUGIN_ID)
    let $endpoint := string($plugin//parameter[@key = $max.plugin.ead_basket:CIRCE_ENDPOINT_PARAMETER]/@value)
    let $appuuid := string($plugin//parameter[@key = $max.plugin.ead_basket:CIRCE_APP_UUID_PARAMETER]/@value)
    let $secret := string($plugin//parameter[@key = $max.plugin.ead_basket:CIRCE_SECRET_PARAMETER]/@value)
    return CirceClient:new($endpoint, $secret, $appuuid)
};

declare function max.ead_basket:basketItemsForPDF($projectId, $items){
declare function max.plugin.ead_basket:basketItemsForPDF($projectId, $items){
    let $dbPath := max.config:getProjectDBPath($projectId)
    let $items_list := fn:tokenize($items, ",")
    for $item in $items_list
@@ -44,12 +44,12 @@ 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)
function max.plugin.ead_basket:basketpdf($projectId, $items){
    let $client := max.plugin.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>
        <body>{max.plugin.ead_basket:basketItemsForPDF($projectId, $items)}</body></html>

    return
        (<rest:response>
@@ -64,7 +64,7 @@ declare
%rest:GET
%output:method("html")
%rest:path("/{$projectId}/ead/accueil.html")
function max.ead_basket:accueil($projectId){
function max.plugin.ead_basket:accueil($projectId){
    let $documents :=
        <ul>
            {
@@ -79,14 +79,14 @@ function max.ead_basket:accueil($projectId){
                    </li>
            }
        </ul>
    return max.html:renderTemplate(doc(max.ead_basket:getResourceFilePath($projectId, "/plugins/ead/accueil.html")), map {"projectId" : $projectId, "documentsList" : $documents})
    return max.html:renderTemplate(doc(max.plugin.ead_basket:getResourceFilePath($projectId, "/plugins/ead/accueil.html")), map {"projectId" : $projectId, "documentsList" : $documents})
};

declare
%rest:GET
%output:method("html")
%rest:path("/{$projectId}/porte-documents.html")
function max.ead_basket:basket($projectId){
function max.plugin.ead_basket:basket($projectId){
    max.html:render($projectId, "porte document", <section class="porte-documents">
        <h2>Porte-documents</h2>
        <p>
@@ -105,12 +105,12 @@ function max.ead_basket:basket($projectId){
    )
};

declare function max.ead_basket:itemPorteDocuments($projectId, $item){
declare function max.plugin.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, "ui/xsl/item_porte-documents.xsl")
    let $xsl := max.plugin.ead_basket:getResourceFilePath($projectId, "ui/xsl/item_porte-documents.xsl")
    return xslt:transform($target[1],
            $xsl,
            map {
@@ -123,7 +123,7 @@ declare
%rest:path("/{$projectId}/ead/fetch_basket_data.html")
%output:method("html")
%rest:POST("{$itemsList}")
function max.ead_basket:basketData($projectId, $itemsList){
function max.plugin.ead_basket:basketData($projectId, $itemsList){
    for $item in $itemsList/json/_
    return max.ead_basket:itemPorteDocuments($projectId, $item)
    return max.plugin.ead_basket:itemPorteDocuments($projectId, $item)
};
+1 −1
Changes for ui/templates/ead.html: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@
  </head>
  <body>
    <header>
      <h1><a href="{$baseURI}{$projectId}/">{$prettyName}</a></h1>
      <h1><a href="{$baseURI}{$projectId}/accueil.html">{$prettyName}</a></h1>
    </header>
    <section class="browse">
    {$content}