Changeset 607:cb5a9c4f5e3a in documentViewer


Ignore:
Timestamp:
Dec 14, 2012, 10:28:31 PM (12 years ago)
Author:
casties
Branch:
default
Message:

CLOSED - # 268: display of subdocuments
https://it-dev.mpiwg-berlin.mpg.de/tracs/mpdl-project-software/ticket/268

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • css/docuviewer.css

    r597 r607  
    173173    color: black;
    174174}
     175div.tocbody table.thumbs a.outside {
     176    font-weight: normal;
     177}
    175178
    176179div.tocbody table.concordance {
  • documentViewer.py

    r602 r607  
    161161            #templateFolder._setObject('zogilib',zogilib)
    162162        except Exception, e:
    163             logging.error("Unable to create zogiLib for zogilib: "+str(e))
     163            logging.error("Unable to create zogiLib for 'zogilib': "+str(e))
    164164           
    165165        try:
     
    638638                # replace with numTextPages (text-only?)
    639639                docinfo['numPages'] = docinfo['numTextPages']
     640               
     641        # min and max page no
     642        docinfo['minPageNo'] = docinfo.get('minPageNo', 1)
     643        docinfo['maxPageNo'] = docinfo.get('maxPageNo', docinfo['numPages'])
    640644
    641645        # normalize path
     
    684688        imageDir = getMDText(texttool.get('image', None))
    685689        docPath = getMDText(docinfo.get('documentPath', None))
    686         if imageDir and docPath:
    687             imageDir = os.path.join(docPath, imageDir)
    688             imageDir = imageDir.replace('/mpiwg/online', '', 1)
    689             docinfo['imagePath'] = imageDir
     690        if imageDir:
     691            if imageDir.startswith('/'):
     692                # absolute path
     693                imageDir = imageDir.replace('/mpiwg/online', '', 1)
     694                docinfo['imagePath'] = imageDir
     695               
     696            elif docPath:
     697                # relative path
     698                imageDir = os.path.join(docPath, imageDir)
     699                imageDir = imageDir.replace('/mpiwg/online', '', 1)
     700                docinfo['imagePath'] = imageDir
     701               
     702        # start and end page (for subdocuments of other documents)
     703        imgStartNo = getMDText(texttool.get('image-start-no', None))           
     704        minPageNo = getInt(imgStartNo, 1)
     705        docinfo['minPageNo'] = minPageNo
     706
     707        imgEndNo = getMDText(texttool.get('image-end-no', None))
     708        if imgEndNo:
     709            docinfo['maxPageNo'] = getInt(imgEndNo)
    690710       
    691711        # old style text URL
     
    725745           
    726746        # number of title page (default 1)
    727         docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', 1))
     747        docinfo['titlePage'] = getMDText(texttool.get('title-scan-no', minPageNo))
    728748           
    729749        # old presentation stuff
     
    865885        pageinfo['tocMode'] = tocMode
    866886
     887        minPageNo = docinfo.get('minPageNo', 1)
     888
    867889        # pf takes precedence over pn
    868890        if pf:
     
    873895            self.REQUEST.form['pn'] = pn
    874896        else:
    875             pn = getInt(pn, 1)
     897            pn = getInt(pn, minPageNo)
    876898            pf = getPfForPn(docinfo, pn)
    877899            pageinfo['pf'] = pf
     
    884906        grpsize = cols * rows
    885907        pageinfo['groupsize'] = grpsize
    886         # is start is empty use one around pn
    887         start = getInt(start, default=(math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1)))
    888         # int(current / grpsize) * grpsize +1))
     908        # if start is empty use one around pn
     909        grouppn = math.ceil(float(pn)/float(grpsize))*grpsize-(grpsize-1)
     910        # but not smaller than minPageNo
     911        start = getInt(start, max(grouppn, minPageNo))
    889912        pageinfo['start'] = start
    890913        # get number of pages
    891         np = int(docinfo.get('numPages', 0))
    892         if np == 0:
     914        numPages = int(docinfo.get('numPages', 0))
     915        if numPages == 0:
    893916            # try numTextPages
    894             np = docinfo.get('numTextPages', 0)
    895             if np != 0:
    896                 docinfo['numPages'] = np
     917            numPages = docinfo.get('numTextPages', 0)
     918            if numPages != 0:
     919                docinfo['numPages'] = numPages
     920
     921        maxPageNo = docinfo.get('maxPageNo', numPages)
     922        logging.debug("minPageNo=%s maxPageNo=%s start=%s numPages=%s"%(minPageNo,maxPageNo,start,numPages))
     923        np = maxPageNo
    897924
    898925        # cache table of contents
     
    907934        pageZero = (cols == 2 and (pageFlowLtr != oddScanLeft))
    908935        pageinfo['pageZero'] = pageZero
    909         pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=1, maxIdx=np)
     936        pageinfo['pageBatch'] = self.getPageBatch(start=start, rows=rows, cols=cols, pageFlowLtr=pageFlowLtr, pageZero=pageZero, minIdx=minPageNo, maxIdx=np)
    910937        # more page parameters
    911938        pageinfo['characterNormalization'] = self.REQUEST.get('characterNormalization','reg')
     
    939966    def getPageBatch(self, start=1, rows=10, cols=2, pageFlowLtr=True, pageZero=False, minIdx=1, maxIdx=0):
    940967        """returns dict with array of page information for one screenfull of thumbnails"""
     968        logging.debug("getPageBatch start=%s minIdx=%s maxIdx=%s"%(start,minIdx,maxIdx))
    941969        batch = {}
    942970        grpsize = rows * cols
     
    944972            maxIdx = start + grpsize
    945973
    946         nb = int(math.ceil(maxIdx / float(grpsize)))
     974        np = maxIdx - minIdx + 1
     975        nb = int(math.ceil(np / float(grpsize)))
    947976        # list of all batch start and end points
    948977        batches = []
    949978        if pageZero:
    950             ofs = 0
    951         else:
    952             ofs = 1
     979            ofs = minIdx - 1
     980        else:
     981            ofs = minIdx
    953982           
    954983        for i in range(nb):
     
    960989
    961990        pages = []
    962         if pageZero and start == 1:
     991        if pageZero and start == minIdx:
    963992            # correct beginning
    964             idx = 0
     993            idx = minIdx - 1
    965994        else:
    966995            idx = start
     
    9821011            pages.append(row)
    9831012           
    984         if start > 1:
    985             batch['prevStart'] = max(start - grpsize, 1)
     1013        if start > minIdx:
     1014            batch['prevStart'] = max(start - grpsize, minIdx)
    9861015        else:
    9871016            batch['prevStart'] = None
  • version.txt

    r591 r607  
    1 DocumentViewer 2.2.9
     1DocumentViewer 2.2.10
  • zpt/viewer/common_template.zpt

    r594 r607  
    4545  <!-- page ruler with previous/next page buttons -->
    4646  <metal:block metal:define-macro="page_ruler"
    47     tal:define="
    48               prev python:test(pn>1,pn-1,None); next python:test(pn<numPages,pn+1,None);
    49               first python:test(pn>1,1,None); last python:test(pn<numPages,numPages,None);
     47    tal:define="minPageNo docinfo/minPageNo; maxPageNo docinfo/maxPageNo;
     48              prev python:test(pn>minPageNo,pn-1,None); next python:test(pn<maxPageNo,pn+1,None);
     49              first python:test(pn>minPageNo,minPageNo,None); last python:test(pn<maxPageNo,maxPageNo,None);
    5050              left python:test(flowLtr,prev,next); right python:test(flowLtr,next,prev);
    5151              leftest python:test(flowLtr,first,last); rightest python:test(flowLtr,last,first);">
     
    9090    <form class="autosubmit" tal:attributes="action viewerUrl">
    9191      <input type="hidden" tal:define="params python:here.getParams('start',None)" tal:repeat="param params"
    92         tal:attributes="name param; value python:params[param]" /><span class="ruler-main"><a tal:condition="left"
    93         tal:attributes="href python:here.getLink('start',left)">&lt;</a> <span tal:condition="not:left">&lt;</span> <select
     92        tal:attributes="name param; value python:params[param]" /><span class="ruler-main"><a tal:omit-tag="not:left"
     93        tal:attributes="href python:here.getLink('start',left)">&lt;</a> <select
    9494        class="autosubmit" name="start" tal:define="ofs python:test(pageinfo['pageZero'],0,1)">
    9595          <tal:block>
     
    9898            <option tal:condition="python:start>pageBatch['last']" selected="selected" value="1">[out of range]</option>
    9999          </tal:block>
    100       </select> <input type="submit" value="Go" /> <a tal:condition="right" tal:attributes="href python:here.getLink('start',right)">&gt;</a>
    101         <span tal:condition="not:right">&gt;</span></span>
     100      </select> <input type="submit" value="Go" /> <a tal:omit-tag="not:right" tal:attributes="href python:here.getLink('start',right)">&gt;</a>
     101      </span>
    102102    </form>
    103103  </metal:block>
  • zpt/viewer/toc_thumbs.zpt

    r594 r607  
    1111    <div class="tocbody thumbs"
    1212      tal:define="start pageinfo/start;
     13                minPageNo docinfo/minPageNo;
     14                maxPageNo docinfo/maxPageNo;
    1315                grpsize pageinfo/groupsize;
    1416                numgroups pageinfo/numgroups;
     
    2628          <tr tal:repeat="row pageBatch/pages">
    2729            <td tal:repeat="thumb row" tal:attributes="class python:here.getStyle(thumb['idx'],pn,'thumb')"><a
    28               tal:define="idx thumb/idx" tal:condition="idx" tal:attributes="href python:here.getLink('pn',idx)"> <img
     30              tal:define="idx thumb/idx" tal:condition="idx"
     31              tal:attributes="href python:here.getLink('pn',idx); class python:test(idx<minPageNo or idx>maxPageNo, 'outside')"><img
     32                tal:condition="python:docinfo.get('imageURL',None) or exists('template/text.png')"
    2933                tal:attributes="src python:test(docinfo.get('imageURL',None),here.getScalerUrl(pn=idx,dw=100,dh=100,docinfo=docinfo),'template/text.png');
    3034                                alt idx;" /><br />
  • zpt/viewer/viewer_thumbs.zpt

    r594 r607  
    2727    tal:define="pn pageinfo/pn;
    2828                start pageinfo/start;
     29                minPageNo docinfo/minPageNo;
     30                maxPageNo docinfo/maxPageNo;
    2931                thumbRows python:int(request.get('thumbRows', 10));
    3032                thumbCols python:int(request.get('thumbCols', 12));
    3133                thumbSize python:int(request.get('thumbSize', 100));
    3234                flowLtr python:docinfo.get('pageFlow','ltr')!='rtl';
    33                 pageBatch python:here.getPageBatch(start=start, rows=thumbRows, cols=thumbCols, pageFlowLtr=flowLtr, maxIdx=numPages);
     35                pageBatch python:here.getPageBatch(start=start, rows=thumbRows, cols=thumbCols, pageFlowLtr=flowLtr, minIdx=minPageNo, maxIdx=maxPageNo);
    3436                pageNumbers docinfo/pageNumbers | nothing;
    3537                left python:test(flowLtr,pageBatch['prevStart'],pageBatch['nextStart']);
Note: See TracChangeset for help on using the changeset viewer.