changeset 607:cb5a9c4f5e3a

CLOSED - # 268: display of subdocuments https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/268
author casties
date Fri, 14 Dec 2012 17:28:31 -0500
parents 37ad612edf5a
children 0c6056271654
files css/docuviewer.css documentViewer.py version.txt zpt/viewer/common_template.zpt zpt/viewer/toc_thumbs.zpt zpt/viewer/viewer_thumbs.zpt
diffstat 6 files changed, 71 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/css/docuviewer.css	Tue Dec 11 16:33:12 2012 -0500
+++ b/css/docuviewer.css	Fri Dec 14 17:28:31 2012 -0500
@@ -172,6 +172,9 @@
 div.tocbody table.thumbs .thumbcap {
     color: black;
 }
+div.tocbody table.thumbs a.outside {
+    font-weight: normal;
+}
 
 div.tocbody table.concordance {
 	border-collapse: collapse;
--- a/documentViewer.py	Tue Dec 11 16:33:12 2012 -0500
+++ b/documentViewer.py	Fri Dec 14 17:28:31 2012 -0500
@@ -160,7 +160,7 @@
             templateFolder['zogilib'] = zogilib
             #templateFolder._setObject('zogilib',zogilib)
         except Exception, e:
-            logging.error("Unable to create zogiLib for zogilib: "+str(e))
+            logging.error("Unable to create zogiLib for 'zogilib': "+str(e))
             
         try:
             # assume MetaDataFolder instance is called metadata 
@@ -637,6 +637,10 @@
             if docinfo.get('numTextPages', 0) > 0:
                 # replace with numTextPages (text-only?)
                 docinfo['numPages'] = docinfo['numTextPages']
+                
+        # min and max page no
+        docinfo['minPageNo'] = docinfo.get('minPageNo', 1)
+        docinfo['maxPageNo'] = docinfo.get('maxPageNo', docinfo['numPages'])
 
         # normalize path
         if 'imagePath' in docinfo and not docinfo['imagePath'].startswith('/'):
@@ -683,10 +687,26 @@
         # image dir
         imageDir = getMDText(texttool.get('image', None))
         docPath = getMDText(docinfo.get('documentPath', None))
-        if imageDir and docPath:
-            imageDir = os.path.join(docPath, imageDir)
-            imageDir = imageDir.replace('/mpiwg/online', '', 1)
-            docinfo['imagePath'] = imageDir
+        if imageDir:
+            if imageDir.startswith('/'):
+                # absolute path
+                imageDir = imageDir.replace('/mpiwg/online', '', 1)
+                docinfo['imagePath'] = imageDir
+                
+            elif docPath:
+                # relative path
+                imageDir = os.path.join(docPath, imageDir)
+                imageDir = imageDir.replace('/mpiwg/online', '', 1)
+                docinfo['imagePath'] = imageDir
+                
+        # start and end page (for subdocuments of other documents)
+        imgStartNo = getMDText(texttool.get('image-start-no', None))            
+        minPageNo = getInt(imgStartNo, 1)
+        docinfo['minPageNo'] = minPageNo
+
+        imgEndNo = getMDText(texttool.get('image-end-no', None))
+        if imgEndNo:
+            docinfo['maxPageNo'] = getInt(imgEndNo)
         
         # old style text URL
         textUrl = getMDText(texttool.get('text', None))
@@ -724,7 +744,7 @@
         docinfo['oddPage'] = getMDText(texttool.get('odd-scan-position', 'left'))
             
         # number of title page (default 1)
-        docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', 1))
+        docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', minPageNo))
             
         # old presentation stuff
         presentation = getMDText(texttool.get('presentation', None))
@@ -864,6 +884,8 @@
         pageinfo['viewLayer'] = viewLayer
         pageinfo['tocMode'] = tocMode
 
+        minPageNo = docinfo.get('minPageNo', 1)
+
         # pf takes precedence over pn
         if pf:
             pageinfo['pf'] = pf
@@ -872,7 +894,7 @@
             self.REQUEST.form.pop('pf', None)
             self.REQUEST.form['pn'] = pn
         else:
-            pn = getInt(pn, 1)
+            pn = getInt(pn, minPageNo)
             pf = getPfForPn(docinfo, pn)
             pageinfo['pf'] = pf
             
@@ -883,17 +905,22 @@
         pageinfo['cols'] = cols
         grpsize = cols * rows
         pageinfo['groupsize'] = grpsize
-        # is start is empty use one around pn
-        start = getInt(start, default=(math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1)))
-        # int(current / grpsize) * grpsize +1))
+        # if start is empty use one around pn
+        grouppn = math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1)
+        # but not smaller than minPageNo
+        start = getInt(start, max(grouppn, minPageNo))
         pageinfo['start'] = start
         # get number of pages
-        np = int(docinfo.get('numPages', 0))
-        if np == 0:
+        numPages = int(docinfo.get('numPages', 0))
+        if numPages == 0:
             # try numTextPages
-            np = docinfo.get('numTextPages', 0)
-            if np != 0:
-                docinfo['numPages'] = np
+            numPages = docinfo.get('numTextPages', 0)
+            if numPages != 0:
+                docinfo['numPages'] = numPages
+
+        maxPageNo = docinfo.get('maxPageNo', numPages)
+        logging.debug("minPageNo=%s maxPageNo=%s start=%s numPages=%s"%(minPageNo,maxPageNo,start,numPages))
+        np = maxPageNo
 
         # cache table of contents
         pageinfo['tocPageSize'] = getInt(self.REQUEST.get('tocPageSize', 30))
@@ -906,7 +933,7 @@
         # add zeroth page for two columns
         pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft))
         pageinfo['pageZero'] = pageZero
-        pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
+        pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=minPageNo, maxIdx=np)
         # more page parameters
         pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
         if docinfo.get('pageNumbers'):
@@ -938,18 +965,20 @@
 
     def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
         """returns dict with array of page information for one screenfull of thumbnails"""
+        logging.debug("getPageBatch start=%s minIdx=%s maxIdx=%s"%(start,minIdx,maxIdx))
         batch = {}
         grpsize = rows * cols
         if maxIdx == 0:
             maxIdx = start + grpsize
 
-        nb = int(math.ceil(maxIdx / float(grpsize)))
+        np = maxIdx - minIdx + 1
+        nb = int(math.ceil(np / float(grpsize)))
         # list of all batch start and end points
         batches = []
         if pageZero:
-            ofs = 0
+            ofs = minIdx - 1
         else:
-            ofs = 1
+            ofs = minIdx
             
         for i in range(nb):
             s = i * grpsize + ofs
@@ -959,9 +988,9 @@
         batch['batches'] = batches
 
         pages = []
-        if pageZero and start == 1:
+        if pageZero and start == minIdx:
             # correct beginning
-            idx = 0
+            idx = minIdx - 1
         else:
             idx = start
             
@@ -981,8 +1010,8 @@
                 
             pages.append(row)
             
-        if start > 1:
-            batch['prevStart'] = max(start - grpsize, 1)
+        if start > minIdx:
+            batch['prevStart'] = max(start - grpsize, minIdx)
         else:
             batch['prevStart'] = None
             
--- a/version.txt	Tue Dec 11 16:33:12 2012 -0500
+++ b/version.txt	Fri Dec 14 17:28:31 2012 -0500
@@ -1,1 +1,1 @@
-DocumentViewer 2.2.9
\ No newline at end of file
+DocumentViewer 2.2.10
\ No newline at end of file
--- a/zpt/viewer/common_template.zpt	Tue Dec 11 16:33:12 2012 -0500
+++ b/zpt/viewer/common_template.zpt	Fri Dec 14 17:28:31 2012 -0500
@@ -44,9 +44,9 @@
 
   <!-- page ruler with previous/next page buttons -->
   <metal:block metal:define-macro="page_ruler"
-    tal:define="
-              prev python:test(pn>1,pn-1,None); next python:test(pn<numPages,pn+1,None);
-              first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None);
+    tal:define="minPageNo docinfo/minPageNo; maxPageNo docinfo/maxPageNo;
+              prev python:test(pn>minPageNo,pn-1,None); next python:test(pn<maxPageNo,pn+1,None);
+              first python:test(pn>minPageNo,minPageNo,None); last python:test(pn<maxPageNo,maxPageNo,None);
               left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev);
               leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first);">
     <form class="autosubmit" tal:attributes="action viewerUrl">
@@ -89,16 +89,16 @@
   <metal:block metal:define-macro="toc_ruler_thumbs">
     <form class="autosubmit" tal:attributes="action viewerUrl">
       <input type="hidden" tal:define="params python:here.getParams('start',None)" tal:repeat="param params"
-        tal:attributes="name param; value python:params[param]" /><span class="ruler-main"><a tal:condition="left"
-        tal:attributes="href python:here.getLink('start',left)">&lt;</a> <span tal:condition="not:left">&lt;</span> <select
+        tal:attributes="name param; value python:params[param]" /><span class="ruler-main"><a tal:omit-tag="not:left"
+        tal:attributes="href python:here.getLink('start',left)">&lt;</a> <select
         class="autosubmit" name="start" tal:define="ofs python:test(pageinfo['pageZero'],0,1)">
           <tal:block>
             <option tal:repeat="grp pageBatch/batches" tal:attributes="selected python:(start>=grp['start'] and start<=grp['end']); value grp/start;"
               tal:content="string:${grp/start} - ${grp/end}" />
             <option tal:condition="python:start>pageBatch['last']" selected="selected" value="1">[out of range]</option>
           </tal:block>
-      </select> <input type="submit" value="Go" /> <a tal:condition="right" tal:attributes="href python:here.getLink('start',right)">&gt;</a>
-        <span tal:condition="not:right">&gt;</span></span>
+      </select> <input type="submit" value="Go" /> <a tal:omit-tag="not:right" tal:attributes="href python:here.getLink('start',right)">&gt;</a>
+      </span>
     </form>
   </metal:block>
 
--- a/zpt/viewer/toc_thumbs.zpt	Tue Dec 11 16:33:12 2012 -0500
+++ b/zpt/viewer/toc_thumbs.zpt	Fri Dec 14 17:28:31 2012 -0500
@@ -10,6 +10,8 @@
     <!-- block used for main content area -->
     <div class="tocbody thumbs"
       tal:define="start pageinfo/start;
+                minPageNo docinfo/minPageNo;
+                maxPageNo docinfo/maxPageNo;
                 grpsize pageinfo/groupsize;
                 numgroups pageinfo/numgroups;
                 pageBatch pageinfo/pageBatch; pageZero pageinfo/pageZero;
@@ -25,7 +27,9 @@
         <table class="thumbs">
           <tr tal:repeat="row pageBatch/pages">
             <td tal:repeat="thumb row" tal:attributes="class python:here.getStyle(thumb['idx'],pn,'thumb')"><a
-              tal:define="idx thumb/idx" tal:condition="idx" tal:attributes="href python:here.getLink('pn',idx)"> <img
+              tal:define="idx thumb/idx" tal:condition="idx"
+              tal:attributes="href python:here.getLink('pn',idx); class python:test(idx<minPageNo or idx>maxPageNo, 'outside')"><img
+                tal:condition="python:docinfo.get('imageURL',None) or exists('template/text.png')"
                 tal:attributes="src python:test(docinfo.get('imageURL',None),here.getScalerUrl(pn=idx,dw=100,dh=100,docinfo=docinfo),'template/text.png');
                                 alt idx;" /><br />
                 <span tal:attributes="title string:Scan number $idx" tal:content="idx" /> <span
--- a/zpt/viewer/viewer_thumbs.zpt	Tue Dec 11 16:33:12 2012 -0500
+++ b/zpt/viewer/viewer_thumbs.zpt	Fri Dec 14 17:28:31 2012 -0500
@@ -26,11 +26,13 @@
   <tal:block
     tal:define="pn pageinfo/pn;
                 start pageinfo/start;
+                minPageNo docinfo/minPageNo;
+                maxPageNo docinfo/maxPageNo;
                 thumbRows python:int(request.get('thumbRows', 10));
                 thumbCols python:int(request.get('thumbCols', 12));
                 thumbSize python:int(request.get('thumbSize', 100));
                 flowLtr python:docinfo.get('pageFlow','ltr')!='rtl';
-                pageBatch python:here.getPageBatch(start=start, rows=thumbRows, cols=thumbCols, pageFlowLtr=flowLtr, maxIdx=numPages);
+                pageBatch python:here.getPageBatch(start=start, rows=thumbRows, cols=thumbCols, pageFlowLtr=flowLtr, minIdx=minPageNo, maxIdx=maxPageNo);
                 pageNumbers docinfo/pageNumbers | nothing;
                 left python:test(flowLtr,pageBatch['prevStart'],pageBatch['nextStart']);
                 right python:test(flowLtr,pageBatch['nextStart'],pageBatch['prevStart']);">