Loading max.xq +8 −2 Original line number Diff line number Diff line Loading @@ -191,11 +191,17 @@ declare %output:indent("no") %rest:path("/editions/{$project}/{$routeDoc=.*\.xml}/{$id}/target/{$targetId}/{$search}") function max:htmlFragmentAndTargetSearchWithNavigationBar($project, $routeDoc, $id, $targetId, $search){ copy $c := max:htmlFragmentWithNavigationBar($project, $routeDoc, $id) modify ( replace value of node $c//*[@*:id=$targetId]/@*:id with "target" replace value of node $c/descendant-or-self::*[@*:id=$targetId]/@*:id with "target" ) return ft:mark($c[.//*[@id='text']//text() contains text {$search}]) return $c (: return for $hit in ft:mark($d[.//text() contains text {$search}]) return $hit :) }; Loading plugins/pager/pager.xqm +47 −16 Original line number Diff line number Diff line Loading @@ -95,16 +95,25 @@ function max.plugin.pager:paginate($project as xs:string, $route as xs:string, $ let $routeDoc := if(starts-with($route,'doc/')) then tokenize($route, 'doc/')[last()] else $route let $xml := max.plugin.pager:paginateNodes($project, $routeDoc, $n, max.config:getProjectDBPath($project)) let $dbName:=max.util:dbNameFromCollection(max.config:getProjectDBPath($project)) let $xmlAndNavlinks := max.plugin.pager:paginateNodes($project, $routeDoc, $n, $dbName) let $xml := $xmlAndNavlinks[1] let $navLinks := $xmlAndNavlinks[2] let $xsltDoc := max.util:buildXSLTDoc( max.config:getDefaultTextXSL($project), max.config:getXSLTAddons($project, $route)) let $xsltParams := max.config:getXSLTParams($project, $route) let $html := xslt:transform($xml, $xsltDoc, $xsltParams) (:return max.config:getXSLTAddons($project, $route):) let $res := <div id='pagerBlocks'> <h4>{$navLinks}</h4> {$html} </div> return max.html:wrapInHTML($project, $route, $res) return max.html:wrapInHTML($project, $route, <div>{$html}</div>) }; declare function max.plugin.pager:paginateNodes( Loading @@ -121,15 +130,17 @@ declare function max.plugin.pager:paginateNodes( (:computes start and end page links:) let $beforeRange:= ceiling($nbLinks div 2) let $count := xquery:eval("count(doc('" || $project ||"/" || $routeDoc || "')"||$itemsPath||")",map{'' : db:open($context)}) let $targetDoc:= $context || '/' || $project || '/' || $routeDoc let $count := xquery:eval("count(doc('" ||$targetDoc|| "')"||$itemsPath||")",map{'' : db:open($context)}) let $nbPages := ceiling($count div $nbPerPage) let $startPage := if(($currentPage - $beforeRange) < 0) then 1 else ($currentPage - $beforeRange) + 1 let $afterRange := if(($currentPage - $beforeRange) < 0) then $beforeRange + abs($currentPage - $beforeRange) else $beforeRange let $endPage := if(($currentPage + $afterRange) > $count) then $count let $endPage := if(($currentPage + $afterRange) > $nbPages) then $nbPages else ($currentPage + $afterRange) let $navLinks := <div id="pagerNav"> Loading @@ -141,20 +152,40 @@ declare function max.plugin.pager:paginateNodes( return <a href="{$i}" class="{if($i=$currentPage) then 'curPageLink' else 'pageLink'}">{$i}</a>} { if($endPage = $count) (:adds last page link if needed:) { if($endPage = $nbPages) (:adds last page link if needed:) then () else <a id="lastPage" href="{$count}">>></a> else <a id="lastPage" href="{$nbPages}">>></a> } </div> (:queries current page's blocks:) let $blocks := <div id='pagerBlocks'> <h4>{$navLinks}</h4> {xquery:eval( $itemsPath||'[position()>='|| $startPage||' and position()<='||$endPage ||']', map{'' : db:open($context)})} </div> return $blocks let $startPosition := (($currentPage - 1) * $nbPerPage) +1 let $endPosition := $startPosition + $nbPerPage -1 let $docPathAsString := "doc('" || $targetDoc || "')" let $blocks := xquery:eval( $docPathAsString || $itemsPath||'[position()>='|| $startPosition||' and position()<='||$endPosition ||']', map{'' : db:open($context)}) (:then add blocks to a new element with the same qname of their parent one:) let $parent:=$blocks[1]/.. let $ns:=namespace-uri($parent) (:returns a sequence of 2 elements: blocks + navLinks:) return (element{QName($ns,$parent/name())}{$blocks}, $navLinks) }; (: declare function max.plugin.pager:getPageForID($project, $id){ let $plugin := max.config:getPluginByName($project, $max.plugin.pager:PLUGIN_ID) let $nbPerPage := $plugin//parameter[@key=$max.plugin.pager:NB_BLOCKS]/@value let $nbLinks := $plugin//parameter[@key=$max.plugin.pager:NB_LINKS]/@value let $itemsPath := $plugin//parameter[@key=$max.plugin.pager:ITEMS_PATH]/@value let $dbPath := max.config:getProjectDBPath($project) let $nbElements := xquery:invoke("count(collection('" ||$dbPath || "')" || $itemsPath ||")") return $nbElements }; :) declare Loading plugins/search/search.xqm +15 −4 Original line number Diff line number Diff line Loading @@ -101,7 +101,11 @@ function max.plugin.search:searchPage($project){ <option value='{$max.plugin.search:ALL_TXT}'>Dans tous les textes</option>, for $route in $routeList return let $docName := tokenize($route,'/')[last()] let $docName := if(contains($route,'/page/'))(:dirty hack for pager href:) then tokenize(substring-before(string($route),'/page/'), $max.cons:ROUTE||'/')[last()] else tokenize($route,'/')[last()] return if(max.config:isIgnored($docName, $project)) then () Loading Loading @@ -142,7 +146,11 @@ function max.plugin.search:search($project, $search as xs:string, $docs as item( let $docTargets := if($docs = $max.plugin.search:ALL_TXT) then for $a in max.route:HTMLRouteList($project)//a/@href return let $docName := tokenize(string($a), $max.cons:ROUTE||'/')[last()] let $docName := if(contains($a,'/page/')) then tokenize(substring-before(string($a),'/page/'), $max.cons:ROUTE||'/')[last()] else tokenize(string($a), $max.cons:ROUTE||'/')[last()] return if(max.config:isIgnored($docName, $project)) then () Loading @@ -162,7 +170,9 @@ function max.plugin.search:search($project, $search as xs:string, $docs as item( return if(doc-available($dbPath || "/" || $doc)=true()) then let $hits := for $hit in ft:mark(doc($dbPath || "/" || $doc)//*[local-name(.)=$tag and .//text() contains text {$search}]) let $hits := for $hit in ft:mark( doc($dbPath || "/" || $doc)//*[local-name(.)=$tag and .//text() contains text {$search}]) (:Needs element in its context:) let $hitInContext := doc($dbPath || "/" || $doc)//*[@*:id = $hit/@*:id] let $b2tID := xquery:eval($b2t_xpath, map{'' : $hitInContext}) Loading @@ -185,7 +195,7 @@ function max.plugin.search:search($project, $search as xs:string, $docs as item( return <div><h2>{$doc} - {count($hits) || ' '} {max.i18n:getText($project, 'search.results')}</h2>{$response}</div> else<div>NADA {doc-available($dbPath || "/" || $doc)}-{$dbPath || "/" || $doc}</div> else<div>*{$docTargets}</div> } </div> } Loading Loading @@ -220,3 +230,4 @@ function max.plugin.search:check($project){ rxq/config.xqm +6 −3 Original line number Diff line number Diff line Loading @@ -169,8 +169,11 @@ declare function max.config:getPluginsBaseURI() as xs:string{ gets a project route list type from config file :) declare function max.config:getRouteListType($projectId){ try{ max.config:checkConfiguration($projectId), string(doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]/routeList/@type) } catch *{fn:error(xs:QName("err:config"), "Please check your MaX configuration file (duplicate inclusion, wrong inclusion path ...) ")} }; (: Loading @@ -184,7 +187,7 @@ declare function max.config:getRouteList($projectId){ Gets a project's route list query file (could not exist) :) declare function max.config:getRouteListQueryFile($projectId){ string("../" || doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]//routeList/@file) string(max.util:maxHome() || doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]//routeList/@file) }; declare function max.config:getNavigationQueryFile($project){ Loading Loading @@ -251,14 +254,14 @@ declare function max.config:getProjectLayoutTemplate($projectId) { declare function max.config:getRouteListXSL($project as xs:string){ let $xsl := string(doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/routeList/@xsl) return if($xsl) then "../" || $xsl then max.util:maxHome() || $xsl else () }; declare function max.config:getRouteEntriesXSL($project as xs:string, $routeDoc as xs:string){ let $xsl := string(doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/routeList/route[@document=$routeDoc]/@xsl) return if($xsl) then "../" || $xsl then max.util:maxHome() || $xsl else () }; Loading rxq/route.xqm +7 −3 Original line number Diff line number Diff line Loading @@ -118,6 +118,8 @@ declare function max.route:HTMLRouteList($project){ case $max.cons:XQUERY_ROUTE_TYPE return let $xqFile:= max.config:getRouteListQueryFile($project) return xquery:invoke($xqFile, map{ 'project':$project, Loading @@ -125,6 +127,7 @@ declare function max.route:HTMLRouteList($project){ 'dbPath':max.config:getProjectDBPath($project) }) (:route list collected from config file:) case $max.cons:CONFIG_LIST_ROUTE_TYPE return Loading @@ -140,7 +143,8 @@ declare function max.route:HTMLRouteList($project){ case $max.cons:HTML_FILE_ROUTE_TYPE return let $xqFile:= max.config:getRouteListQueryFile($project) return doc("../" || $xqFile) return max.util:maxHome() || $xqFile (:default: route list deduced from XML database:) default Loading @@ -157,7 +161,7 @@ declare function max.route:HTMLRouteList($project){ }; (: Returns route entries as an html list Returns route entries for a specific route as an html list :) declare function max.route:getRouteEntriesAsHTML($project, $routeDoc){ try{ Loading Loading
max.xq +8 −2 Original line number Diff line number Diff line Loading @@ -191,11 +191,17 @@ declare %output:indent("no") %rest:path("/editions/{$project}/{$routeDoc=.*\.xml}/{$id}/target/{$targetId}/{$search}") function max:htmlFragmentAndTargetSearchWithNavigationBar($project, $routeDoc, $id, $targetId, $search){ copy $c := max:htmlFragmentWithNavigationBar($project, $routeDoc, $id) modify ( replace value of node $c//*[@*:id=$targetId]/@*:id with "target" replace value of node $c/descendant-or-self::*[@*:id=$targetId]/@*:id with "target" ) return ft:mark($c[.//*[@id='text']//text() contains text {$search}]) return $c (: return for $hit in ft:mark($d[.//text() contains text {$search}]) return $hit :) }; Loading
plugins/pager/pager.xqm +47 −16 Original line number Diff line number Diff line Loading @@ -95,16 +95,25 @@ function max.plugin.pager:paginate($project as xs:string, $route as xs:string, $ let $routeDoc := if(starts-with($route,'doc/')) then tokenize($route, 'doc/')[last()] else $route let $xml := max.plugin.pager:paginateNodes($project, $routeDoc, $n, max.config:getProjectDBPath($project)) let $dbName:=max.util:dbNameFromCollection(max.config:getProjectDBPath($project)) let $xmlAndNavlinks := max.plugin.pager:paginateNodes($project, $routeDoc, $n, $dbName) let $xml := $xmlAndNavlinks[1] let $navLinks := $xmlAndNavlinks[2] let $xsltDoc := max.util:buildXSLTDoc( max.config:getDefaultTextXSL($project), max.config:getXSLTAddons($project, $route)) let $xsltParams := max.config:getXSLTParams($project, $route) let $html := xslt:transform($xml, $xsltDoc, $xsltParams) (:return max.config:getXSLTAddons($project, $route):) let $res := <div id='pagerBlocks'> <h4>{$navLinks}</h4> {$html} </div> return max.html:wrapInHTML($project, $route, $res) return max.html:wrapInHTML($project, $route, <div>{$html}</div>) }; declare function max.plugin.pager:paginateNodes( Loading @@ -121,15 +130,17 @@ declare function max.plugin.pager:paginateNodes( (:computes start and end page links:) let $beforeRange:= ceiling($nbLinks div 2) let $count := xquery:eval("count(doc('" || $project ||"/" || $routeDoc || "')"||$itemsPath||")",map{'' : db:open($context)}) let $targetDoc:= $context || '/' || $project || '/' || $routeDoc let $count := xquery:eval("count(doc('" ||$targetDoc|| "')"||$itemsPath||")",map{'' : db:open($context)}) let $nbPages := ceiling($count div $nbPerPage) let $startPage := if(($currentPage - $beforeRange) < 0) then 1 else ($currentPage - $beforeRange) + 1 let $afterRange := if(($currentPage - $beforeRange) < 0) then $beforeRange + abs($currentPage - $beforeRange) else $beforeRange let $endPage := if(($currentPage + $afterRange) > $count) then $count let $endPage := if(($currentPage + $afterRange) > $nbPages) then $nbPages else ($currentPage + $afterRange) let $navLinks := <div id="pagerNav"> Loading @@ -141,20 +152,40 @@ declare function max.plugin.pager:paginateNodes( return <a href="{$i}" class="{if($i=$currentPage) then 'curPageLink' else 'pageLink'}">{$i}</a>} { if($endPage = $count) (:adds last page link if needed:) { if($endPage = $nbPages) (:adds last page link if needed:) then () else <a id="lastPage" href="{$count}">>></a> else <a id="lastPage" href="{$nbPages}">>></a> } </div> (:queries current page's blocks:) let $blocks := <div id='pagerBlocks'> <h4>{$navLinks}</h4> {xquery:eval( $itemsPath||'[position()>='|| $startPage||' and position()<='||$endPage ||']', map{'' : db:open($context)})} </div> return $blocks let $startPosition := (($currentPage - 1) * $nbPerPage) +1 let $endPosition := $startPosition + $nbPerPage -1 let $docPathAsString := "doc('" || $targetDoc || "')" let $blocks := xquery:eval( $docPathAsString || $itemsPath||'[position()>='|| $startPosition||' and position()<='||$endPosition ||']', map{'' : db:open($context)}) (:then add blocks to a new element with the same qname of their parent one:) let $parent:=$blocks[1]/.. let $ns:=namespace-uri($parent) (:returns a sequence of 2 elements: blocks + navLinks:) return (element{QName($ns,$parent/name())}{$blocks}, $navLinks) }; (: declare function max.plugin.pager:getPageForID($project, $id){ let $plugin := max.config:getPluginByName($project, $max.plugin.pager:PLUGIN_ID) let $nbPerPage := $plugin//parameter[@key=$max.plugin.pager:NB_BLOCKS]/@value let $nbLinks := $plugin//parameter[@key=$max.plugin.pager:NB_LINKS]/@value let $itemsPath := $plugin//parameter[@key=$max.plugin.pager:ITEMS_PATH]/@value let $dbPath := max.config:getProjectDBPath($project) let $nbElements := xquery:invoke("count(collection('" ||$dbPath || "')" || $itemsPath ||")") return $nbElements }; :) declare Loading
plugins/search/search.xqm +15 −4 Original line number Diff line number Diff line Loading @@ -101,7 +101,11 @@ function max.plugin.search:searchPage($project){ <option value='{$max.plugin.search:ALL_TXT}'>Dans tous les textes</option>, for $route in $routeList return let $docName := tokenize($route,'/')[last()] let $docName := if(contains($route,'/page/'))(:dirty hack for pager href:) then tokenize(substring-before(string($route),'/page/'), $max.cons:ROUTE||'/')[last()] else tokenize($route,'/')[last()] return if(max.config:isIgnored($docName, $project)) then () Loading Loading @@ -142,7 +146,11 @@ function max.plugin.search:search($project, $search as xs:string, $docs as item( let $docTargets := if($docs = $max.plugin.search:ALL_TXT) then for $a in max.route:HTMLRouteList($project)//a/@href return let $docName := tokenize(string($a), $max.cons:ROUTE||'/')[last()] let $docName := if(contains($a,'/page/')) then tokenize(substring-before(string($a),'/page/'), $max.cons:ROUTE||'/')[last()] else tokenize(string($a), $max.cons:ROUTE||'/')[last()] return if(max.config:isIgnored($docName, $project)) then () Loading @@ -162,7 +170,9 @@ function max.plugin.search:search($project, $search as xs:string, $docs as item( return if(doc-available($dbPath || "/" || $doc)=true()) then let $hits := for $hit in ft:mark(doc($dbPath || "/" || $doc)//*[local-name(.)=$tag and .//text() contains text {$search}]) let $hits := for $hit in ft:mark( doc($dbPath || "/" || $doc)//*[local-name(.)=$tag and .//text() contains text {$search}]) (:Needs element in its context:) let $hitInContext := doc($dbPath || "/" || $doc)//*[@*:id = $hit/@*:id] let $b2tID := xquery:eval($b2t_xpath, map{'' : $hitInContext}) Loading @@ -185,7 +195,7 @@ function max.plugin.search:search($project, $search as xs:string, $docs as item( return <div><h2>{$doc} - {count($hits) || ' '} {max.i18n:getText($project, 'search.results')}</h2>{$response}</div> else<div>NADA {doc-available($dbPath || "/" || $doc)}-{$dbPath || "/" || $doc}</div> else<div>*{$docTargets}</div> } </div> } Loading Loading @@ -220,3 +230,4 @@ function max.plugin.search:check($project){
rxq/config.xqm +6 −3 Original line number Diff line number Diff line Loading @@ -169,8 +169,11 @@ declare function max.config:getPluginsBaseURI() as xs:string{ gets a project route list type from config file :) declare function max.config:getRouteListType($projectId){ try{ max.config:checkConfiguration($projectId), string(doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]/routeList/@type) } catch *{fn:error(xs:QName("err:config"), "Please check your MaX configuration file (duplicate inclusion, wrong inclusion path ...) ")} }; (: Loading @@ -184,7 +187,7 @@ declare function max.config:getRouteList($projectId){ Gets a project's route list query file (could not exist) :) declare function max.config:getRouteListQueryFile($projectId){ string("../" || doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]//routeList/@file) string(max.util:maxHome() || doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$projectId]//routeList/@file) }; declare function max.config:getNavigationQueryFile($project){ Loading Loading @@ -251,14 +254,14 @@ declare function max.config:getProjectLayoutTemplate($projectId) { declare function max.config:getRouteListXSL($project as xs:string){ let $xsl := string(doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/routeList/@xsl) return if($xsl) then "../" || $xsl then max.util:maxHome() || $xsl else () }; declare function max.config:getRouteEntriesXSL($project as xs:string, $routeDoc as xs:string){ let $xsl := string(doc($max.config:CONFIGURATION_FILE)//edition[@xml:id=$project]/routeList/route[@document=$routeDoc]/@xsl) return if($xsl) then "../" || $xsl then max.util:maxHome() || $xsl else () }; Loading
rxq/route.xqm +7 −3 Original line number Diff line number Diff line Loading @@ -118,6 +118,8 @@ declare function max.route:HTMLRouteList($project){ case $max.cons:XQUERY_ROUTE_TYPE return let $xqFile:= max.config:getRouteListQueryFile($project) return xquery:invoke($xqFile, map{ 'project':$project, Loading @@ -125,6 +127,7 @@ declare function max.route:HTMLRouteList($project){ 'dbPath':max.config:getProjectDBPath($project) }) (:route list collected from config file:) case $max.cons:CONFIG_LIST_ROUTE_TYPE return Loading @@ -140,7 +143,8 @@ declare function max.route:HTMLRouteList($project){ case $max.cons:HTML_FILE_ROUTE_TYPE return let $xqFile:= max.config:getRouteListQueryFile($project) return doc("../" || $xqFile) return max.util:maxHome() || $xqFile (:default: route list deduced from XML database:) default Loading @@ -157,7 +161,7 @@ declare function max.route:HTMLRouteList($project){ }; (: Returns route entries as an html list Returns route entries for a specific route as an html list :) declare function max.route:getRouteEntriesAsHTML($project, $routeDoc){ try{ Loading