Commit cba0b142 authored by dje's avatar dje
Browse files

fixes #2

parent 8691ab2a
Loading
Loading
Loading
Loading
+31 −16
Original line number Diff line number Diff line
(: For conditions of distribution and use, see the accompanying legal.txt file. :)
(:
For conditions of distribution and use, see the accompanying legal.txt file.
:)

module namespace max.plugin.pager = 'pddn/max/plugin/pager';

@@ -15,12 +17,12 @@ declare
%rest:GET
%output:method("html")
%output:indent("no")
%rest:path("/editions/{$project}/{$route=.*\.xml}/page/{$n=[0-9]+}")
%rest:path("/editions/{$project}/{$route=.*\.xml}/page/{$n}")
function max.plugin.pager:paginate($project as xs:string, $route as xs:string, $n as xs:integer){
   let $routeDoc := if(starts-with($route,'doc/'))
                    then tokenize($route, 'doc/')[last()]
                    else $route
   let $dbName:=max.util:dbNameFromCollection(max.config:getProjectDBPath($project))                               
   let $dbName:=max.config:getProjectDBPath($project)                              
   let $xmlAndNavlinks :=
          max.plugin.pager:paginateNodes($project, $routeDoc, $n, $dbName)
   let $xml :=  $xmlAndNavlinks[1]
@@ -49,7 +51,8 @@ function max.plugin.pager:paginateWithTarget($project as xs:string, $route as xs
  let $html := max.plugin.pager:paginate($project, $route, $n)
  return copy $c := $html
    modify (
      replace value of node $c/descendant-or-self::*[@*:id=$id]/@*:id with "scrollfocus"
      replace value of node $c/descendant-or-self::*[@*:id=$id]/@*:id with "scrollfocus",
      for $a in  $c//*:div[@*:id='pagerNav']//*:a return replace value of node $a/@*:href with '../'||$a/@*:href
    )
    return $c
};
@@ -68,8 +71,9 @@ declare function max.plugin.pager:paginateNodes(

  (:computes start and end page links:)
  let $beforeRange:= ceiling($nbLinks div 2)
  let $targetDoc:= $context || '/' || $project || '/' || $routeDoc
  let $count := xquery:eval("count(doc('" ||$targetDoc|| "')"||$itemsPath||")",map{'' : db:open($context)})
  let $targetDoc:= $context  || '/' || $routeDoc
  let $dbname := max.util:dbNameFromCollection($context)
  let $count := xquery:eval("count(doc('" ||$targetDoc|| "')"||$itemsPath||")",map{'' : db:open($dbname)})
  let $nbPages := ceiling($count div $nbPerPage)
  let $startPage := if(($currentPage - $beforeRange) < 0)
                      then 1
@@ -80,35 +84,46 @@ declare function max.plugin.pager:paginateNodes(
  let $endPage :=  if(($currentPage + $afterRange) > $nbPages)
                      then $nbPages
                      else ($currentPage + $afterRange)
  
  let $hrefPrefixPath := ''(: if($withTarget)
                           then '../'
                           else '' :) 
  let $navLinks := <div id="pagerNav">
                    {if($startPage = 1) (:adds first page link if needed:)
                      then ()
                      else <a id="firstPage" href="1">&lt;&lt;</a>
                      else <a id="firstPage" href="{$hrefPrefixPath || '1'}">&lt;&lt;</a>
                    }
                    {for $i in (xs:integer($startPage) to xs:integer($endPage))
                     return <a 
                            href="{$i}"
                            href="{$hrefPrefixPath || $i}"
                            class="{if($i=$currentPage) then 'curPageLink' else 'pageLink'}">{$i}</a>}
                    { if($endPage = $nbPages) (:adds last page link if needed:)
                       then ()       
                       else <a id="lastPage" href="{$nbPages}">&gt;&gt;</a>
                       else <a id="lastPage" href="{$hrefPrefixPath || $nbPages}">&gt;&gt;</a>
                    }        
                   </div>
  (:queries current page's blocks:)
  let $startPosition := (($currentPage - 1) * $nbPerPage) +1
  let $endPosition :=  $startPosition + $nbPerPage -1 
  let $docPathAsString := "doc('" || $targetDoc || "')"
  (:On calcule la position de la balise qui se trouve juste après l'item précédent, sauf pour le premier item :)
	let $realStart := if($startPosition = 1)
		then 1
		else (xquery:eval("count(doc('" ||$targetDoc|| "')//*:list/*:item[" ||$startPosition|| " -1]/preceding-sibling::*) +2",map{'' : db:open($dbname)}))

  let $endPosition := xquery:eval("count(doc('" ||$targetDoc|| "')//*:list/*:item[(" ||$startPosition|| " + " ||$nbPerPage|| ")-1]/preceding-sibling::*) +1",map{'' : db:open($dbname)})
  (:=pour la dernière page, on calcule la position de la dernière balise :)
  let $realEndPosition:= xquery:eval("count(doc('" ||$targetDoc|| "')//*:list/*)",map{'' : db:open($dbname)})
  let $realEnd := if($endPosition = 1)
		then $realEndPosition
		else ($endPosition)

  let $blocks := xquery:eval(
                    $docPathAsString || $itemsPath||'[position()>='|| $startPosition||' and position()<='||$endPosition ||']',
                    map{'' : db:open($context)})
                    "doc('" ||$targetDoc|| "')//*:list/*[fn:position()=("|| $realStart||" to "||$realEnd ||")]", map{'' : db:open($dbname)})
         
  (:then add blocks to a new element with the same qname of their parent one:)                 let $parent:=$blocks[1]/..
   (: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)
  return (element{QName($ns,$parent/name())}{$blocks}, $navLinks, <div>{$startPosition}</div>)
};

(:
+1 −17
Original line number Diff line number Diff line
@@ -116,22 +116,6 @@ mark {
#target {
  background-color: rgba(200, 200, 200, 0.4);
}

#scrollfocus {
  background-color: rgba(200, 250, 200, 0.4);
}

footer{
  text-align:center;
}
.footer-logos {

}
#biblissima {
  width: 110px;
  margin-right:25px;
}
#invav {
  width: 70px;
  width: 100px;
}
+1 −1
Original line number Diff line number Diff line
function runSearch(e,s,t,i,r){var s=s.join(" ");$.post(MAX.getBaseURL()+"/"+MAX.getProjectID()+"/search",{search:e,docs:s,transform:t},function(e){i.html(e),$("head").append('<script type="text/javascript" src="'+MAX.getBaseURL()+'/ui/js/lib/jQuery.dotdotdot/src/js/jquery.dotdotdot.min.js"></script>'),afficherMasquer(),updateHitsInfo(s,r)})}function runSearchFromForm(){var e=$("#searchInput").val();if(""===e.trim())return void alert("Recherche vide ou incorrecte.");$("#searchLoading").show(),doc=new Array,$(".inputDoc").each(function(){$(this).is(":checked")&&doc.push($(this).attr("value"))});var s=$("#searchTransform").prop("checked")?"yes":"no";runSearch(e,doc,s,$("#searchResults"),!0)}function afficherMasquer(){$(".blocResults").each(function(e){var s=$(this).find(".hit");if(s.length>0){numero="im"+(e+1);var t="deplierRes('"+numero+"')";if($(this).children("h3").prepend('<span class="flSearch fl'+numero+'" onclick="'+t+'">▼</span>'),1==s.length)var i="résultat";else var i="résultats";$(this).children("h3").append('<span class="numRes">['+s.length+" "+i+"]</span>"),$(this).children(".hit").addClass(numero)}else $(this).remove()})}function updateHitsInfo(e,s){$(".hit").each(function(){$(this).prepend("<span class='hit_range'>"+($(this).prevAll(".hit").size()+1)+" |&#160;</span>")}),$("#searchResults").prepend("<div class='n-search-result'>"+$(".hit").length+" résultat(s)</div>"),s&&$(".hit").dotdotdot({ellipsis:" ... ",wrap:"word"}),$("#hits").css("visibility","visible"),$("#searchLoading").hide()}function allChecked(e){$("."+e).each(function(){$("input[class='inputAll']").is(":checked")?$(this).prop("checked",!0):$(this).prop("checked",!1)})}function deplierRes(e){$("."+e).is(":visible")?($("."+e).hide(),$(".fl"+e).html("&#9654;")):($("."+e).show(),$(".fl"+e).html("&#9660;"))}$("#searchInput").keyup(function(e){13==e.keyCode&&$("#sendButton").click()});
 No newline at end of file
function runSearch(e,t,s,r,i){$.post(MAX.getBaseURL()+"/"+MAX.getProjectID()+"/search",{search:e,docs:t,transform:s},function(e){r.html(e),$("head").append('<script type="text/javascript" src="'+MAX.getBaseURL()+'/ui/js/lib/jQuery.dotdotdot/src/js/jquery.dotdotdot.min.js"></script>'),updateHitsInfo(t,i)})}function runSearchFromForm(){var e=$("#searchInput").val();if(""===e.trim())return void alert("Recherche vide ou incorrecte.");$("#searchLoading").show();var t=$("#searchSelect").val(),s=$("#searchTransform").prop("checked")?"yes":"no";runSearch(e,t,s,$("#searchResults"),!0)}function updateHitsInfo(e,t){$(".hit").each(function(){$(this).prepend("<span class='hit_range'>["+($(this).prevAll(".hit").size()+1)+"]</span>")}),$("#searchResults").prepend("<div class='n-search-result'>"+$(".hit").length+" résultat(s)</div>"),t&&$(".hit").dotdotdot({ellipsis:" ... ",wrap:"word"}),$("#hits").css("visibility","visible"),$("#searchLoading").hide()}
 No newline at end of file