Changeset 526:3f375a048402 in documentViewer


Ignore:
Timestamp:
Apr 10, 2012, 5:41:44 PM (12 years ago)
Author:
casties
Branch:
default
Message:

moved search and dict into separate layers.
removed search_template.
added tocMode=concordance.
fixed bug with paging tocs.

Files:
3 added
1 deleted
11 edited

Legend:

Unmodified
Added
Removed
  • css/docuviewer.css

    r511 r526  
    1818
    1919div.toc-text .toc,
    20 div.toc-figures .toc {
     20div.toc-figures .toc,
     21div.toc-concordance .toc {
    2122    float:left;
    2223    clear:right;
    2324}
    2425div.toc-text .toc.float.right,
    25 div.toc-figures .toc.float.right  {
     26div.toc-figures .toc.float.right,
     27div.toc-concordance .toc.float.right {
    2628    float:right;
    2729}
  • documentViewer.py

    r525 r526  
    1717import re
    1818import string
     19import json
    1920
    2021from SrvTxtUtils import getInt, utf8ify, getText, getHttpData, refreshingImageFileIndexHtml
     
    124125    viewer_index = PageTemplateFile('zpt/viewer_index', globals())
    125126    # available layer types
    126     availableLayers = {'text': ['dict','search','gis','annotator'],
    127                        'xml': None, 'images': None, 'index': None}
     127    builtinLayers = {'text': ['dict','search','gis','annotator'],
     128                     'xml': None, 'images': None, 'index': None}
     129    availableLayers = builtinLayers;
    128130    # layer templates
     131    layer_text_dict = PageTemplateFile('zpt/layer_text_dict', globals())
     132    layer_text_search = PageTemplateFile('zpt/layer_text_search', globals())
    129133    layer_text_annotator = PageTemplateFile('zpt/layer_text_annotator', globals())
    130134    layer_text_gis = PageTemplateFile('zpt/layer_text_gis', globals())
     
    133137    toc_text = PageTemplateFile('zpt/toc_text', globals())
    134138    toc_figures = PageTemplateFile('zpt/toc_figures', globals())
     139    toc_concordance = PageTemplateFile('zpt/toc_concordance', globals())
    135140    toc_none = PageTemplateFile('zpt/toc_none', globals())
    136141    # other templates
    137142    common_template = PageTemplateFile('zpt/common_template', globals())
    138     search_template = PageTemplateFile('zpt/search_template', globals())
    139143    info_xml = PageTemplateFile('zpt/info_xml', globals())
    140144    docuviewer_css = ImageFile('css/docuviewer.css',globals())
     
    409413        return self.getLink(param=param, val=val, params=params, baseUrl=baseUrl, paramSep='&', duplicates=duplicates)
    410414   
     415
     416    def setAvailableLayers(self, newLayerString=None):
     417        """sets availableLayers to newLayerString or tries to autodetect available layers.
     418        assumes layer templates have the form layer_{m}_{l} for layer l in mode m.
     419        newLayerString is parsed as JSON."""
     420        if newLayerString is not None:
     421            try:
     422                layers = json.loads(newLayerString)
     423                if 'text' in layers and 'images' in layers:
     424                    self.availableLayers = layers
     425                    return
     426            except:
     427                pass
     428
     429            logging.error("invalid layers=%s! autodetecting..."%repr(newLayerString))
     430           
     431        # start with builtin layers
     432        self.availableLayers = self.builtinLayers.copy()
     433        # add layers from templates
     434        for t in self.template:
     435            if t.startswith('layer_'):
     436                try:
     437                    (x, m, l) = t.split('_', 3)
     438                    if m not in self.availableLayers:
     439                        # mode m doesn't exist -> new list
     440                        self.availableLayers[m] = [l]
     441                       
     442                    else:
     443                        # m exists -> append
     444                        if l not in self.availableLayers[m]:
     445                            self.availableLayers[m].append()
     446                           
     447                except:
     448                    pass
     449
     450    def getAvailableLayersJson(self):
     451        """returns available layers as JSON string."""
     452        return json.dumps(self.availableLayers)
     453   
    411454   
    412455    def getInfo_xml(self,url,mode):
     
    838881            batch['prevStart'] = None
    839882           
    840         if start + grpsize < maxIdx:
     883        if start + grpsize <= maxIdx:
    841884            batch['nextStart'] = start + grpsize
    842885        else:
     
    864907        this = []
    865908        j = 0
    866         for i in range(start, min(start+size, end)):
     909        for i in range(start, min(start+size, end+1)):
    867910            if data:
    868911                if fullData:
    869                     d = data[i]
     912                    d = data.get(i, None)
    870913                else:
    871                     d = data[j]
     914                    d = data.get(j, None)
    872915                    j += 1
    873916           
     
    888931            batch['nextStart'] = None
    889932       
     933        logging.debug("getBatch start=%s size=%s end=%s batch=%s"%(start,size,end,repr(batch)))
    890934        return batch
    891935       
     
    894938    changeDocumentViewerForm = PageTemplateFile('zpt/changeDocumentViewer', globals())
    895939   
    896     def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',RESPONSE=None):
     940    def changeDocumentViewer(self,title="",digilibBaseUrl=None,thumbrows=2,thumbcols=5,authgroups='mpiwg',availableLayers=None,RESPONSE=None):
    897941        """init document viewer"""
    898942        self.title=title
     
    906950        except Exception, e:
    907951            logging.error("Unable to find MetaDataFolder 'metadata': "+str(e))
     952           
     953        self.setAvailableLayers(availableLayers)
    908954
    909955        if RESPONSE is not None:
  • zpt/changeDocumentViewer.zpt

    r477 r526  
    1818        <p class="form-text">Access groups (separated by ',') that are considered local, i.e. when a ressource restricts access
    1919        to one of these groups, local access to the ressource is granted.</p>
     20        <p class="form-optional">Available Layers</p>
     21        <p class="form-element"><input size="80" tal:attributes="value here/getAvailableLayersJson | nothing" name="availableLayers"></p>
     22        <p class="form-text">List of available layers per view mode. JSON, one key per mode, null, or a list of layers per key.
     23          Leave empty for autoconfiguration.</p>
    2024        <p class="form-optional">Digilib base URL</p>
    2125        <p class="form-element"><input size="80" tal:attributes="value here/digilibBaseUrl | nothing" name="digilibBaseUrl"></p>
  • zpt/common_template.zpt

    r511 r526  
    6767  </metal:block>
    6868
     69  <!-- toc type switcher -->
     70  <metal:block metal:define-macro="toc_switcher">
     71    <ul class="switcher">
     72      <li tal:attributes="class python:test(tocMode=='thumbs', 'sel', None)"><a
     73        tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a>
     74      </li>
     75      <li tal:attributes="class python:test(tocMode=='text', 'sel', None)"
     76        tal:condition="python:docpath and docinfo.get('numTocEntries', None)">
     77        <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
     78      </li>
     79      <li tal:attributes="class python:test(tocMode=='figures', 'sel', None)"
     80        tal:condition="python:docpath and docinfo.get('numFigureEntries', None)">
     81        <a
     82        tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a>
     83      </li>
     84      <li tal:attributes="class python:test(tocMode=='concordance', 'sel', None)"
     85        tal:condition="python:docpath and docinfo.get('pageNumbers', None)">
     86        <a
     87        tal:attributes="href python:here.getLink('tocMode','concordance')">Concordance</a>
     88      </li>
     89      <li tal:attributes="class python:test(tocMode=='none', 'sel', None)"><a
     90        tal:attributes="href python:here.getLink('tocMode','none')">None</a>
     91      </li>
     92    </ul>
     93  </metal:block>
     94
    6995</body>
    7096</html>
  • zpt/layer_text_annotator.zpt

    r525 r526  
    33<html xmlns="http://www.w3.org/1999/xhtml">
    44<head>
    5 <metal:block metal:define-macro="html_head">
     5<metal:block metal:define-macro="html_head" tal:condition="python:'annotator' in viewLayers">
    66  <!--  annotator -->
    77  <link rel="stylesheet" type="text/css"
     
    8888  </div>
    8989
    90   <metal:block metal:define-macro="options_box">
     90  <metal:block metal:define-macro="options_box" tal:condition="python:'annotator' in viewLayers">
    9191    <!-- BEGIN ANNOTATIONS -->
    9292    <div class="options">
  • zpt/layer_text_gis.zpt

    r525 r526  
    2222  </div>
    2323
    24   <metal:block metal:define-macro="options_box">
     24  <metal:block metal:define-macro="options_box" tal:condition="python:'gis' in viewLayers">
    2525    <!--"BEGIN PLACES"-->
    26     <div class="options" tal:condition="python:'gis' in viewLayers">
     26    <div class="options">
    2727      <tal:block
    2828        tal:define="
  • zpt/toc_figures.zpt

    r518 r526  
    1010    tal:define="start pageinfo/start; tocsize docinfo/numFigureEntries; grpsize pageinfo/tocPageSize;
    1111                batch python:here.getBatch(start=start,size=grpsize,end=tocsize);">
    12     <ul class="switcher">
    13       <li><a
    14         tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a>
    15       </li>
    16       <li
    17         tal:condition="python:docpath and docinfo.get('numTocEntries', None)">
    18         <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
    19       </li>
    20       <li class="sel"
    21         tal:condition="python:docpath and docinfo.get('numFigureEntries', None)">
    22         <a
    23         tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a>
    24       </li>
    25       <li><a
    26         tal:attributes="href python:here.getLink('tocMode','none')">None</a>
    27       </li>
    28     </ul>
     12    <div metal:use-macro="here/template/common_template/macros/toc_switcher"/>
    2913    <div class="ruler">
    3014        <metal:block metal:use-macro="here/template/common_template/macros/toc_ruler"/>
     
    3317      tal:content="structure python:here.getTocPage(mode='figures',start=start,pageinfo=pageinfo,docinfo=docinfo)" />
    3418  </div>
    35   <!-- toc -->
     19  <!-- /toc -->
    3620</body>
    3721</html>
  • zpt/toc_none.zpt

    r491 r526  
    88  <!-- block used for main content area -->
    99  <div class="toc-none" metal:define-macro="main">
    10     <ul class="switcher">
    11       <li>
    12         <a tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a>
    13       </li>
    14       <li tal:condition="python:docpath and docinfo.get('numTocEntries', None)">
    15         <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
    16       </li>
    17       <li tal:condition="python:docpath and docinfo.get('numFigureEntries', None)">
    18         <a tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a>
    19       </li>
    20       <li class="sel">
    21         <a tal:attributes="href python:here.getLink('tocMode','none')">None</a>
    22       </li>
    23     </ul>
     10    <div metal:use-macro="here/template/common_template/macros/toc_switcher"/>
    2411    <div class="content"></div>
    2512  </div>
  • zpt/toc_text.zpt

    r518 r526  
    1010    tal:define="start pageinfo/start; tocsize docinfo/numTocEntries; grpsize pageinfo/tocPageSize;
    1111                batch python:here.getBatch(start=start,size=grpsize,end=tocsize);">
    12     <ul class="switcher">
    13       <li><a
    14         tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a>
    15       </li>
    16       <li class="sel"
    17         tal:condition="python:docpath and docinfo.get('numTocEntries', None)">
    18         <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
    19       </li>
    20       <li
    21         tal:condition="python:docpath and docinfo.get('numFigureEntries', None)">
    22         <a
    23         tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a>
    24       </li>
    25       <li><a
    26         tal:attributes="href python:here.getLink('tocMode','none')">None</a>
    27       </li>
    28     </ul>
     12    <div metal:use-macro="here/template/common_template/macros/toc_switcher"/>
    2913    <div class="ruler">
    3014        <metal:block metal:use-macro="here/template/common_template/macros/toc_ruler"/>
  • zpt/toc_thumbs.zpt

    r523 r526  
    1515                left python:test(flowLtr,pageBatch['prevStart'],pageBatch['nextStart']);
    1616                right python:test(flowLtr,pageBatch['nextStart'],pageBatch['prevStart']);">
    17     <ul class="toctype">
    18       <li class="sel">
    19         <a tal:attributes="href python:here.getLink('tocMode','thumbs')">Thumbnails</a>
    20       </li>
    21       <li tal:condition="python:docinfo.get('numTocEntries', None)">
    22         <a tal:attributes="href python:here.getLink('tocMode','text')">Content</a>
    23       </li>
    24       <li tal:condition="python:docinfo.get('numFigureEntries', None)">
    25         <a tal:attributes="href python:here.getLink('tocMode','figures')">Figures</a>
    26       </li>
    27       <li>
    28         <a tal:attributes="href python:here.getLink('tocMode','none')">None</a>
    29       </li>
    30     </ul>
     17    <div metal:use-macro="here/template/common_template/macros/toc_switcher"/>
    3118
    3219    <div class="content">
  • zpt/viewer_text.zpt

    r525 r526  
    2424// -->
    2525</script>
    26 <!--  layer headers -->
    27 <tal:block tal:repeat="layer viewLayers">
     26<!--  layer headers (rendered always) -->
     27<tal:block tal:repeat="layer availableLayers">
    2828  <tal:block tal:define="mpath string:here/template/layer_text_${layer}/macros/html_head"
    2929    tal:condition="python:exists(mpath)">
     
    3838                pn pageinfo/pn;
    3939                flowLtr python:docinfo.get('pageFlow','ltr')!='rtl';
    40                 query python:request.get('query', None);
    41                 queryType python:request.get('queryType','fulltextMorph');
    4240                textPage python:here.getTextPage(mode=viewLayer, pn=pn, docinfo=docinfo, pageinfo=pageinfo) or '[no text here]';">
    4341    <!-- header -->
     
    7169      <!-- end of col-main -->
    7270
    73       <!-- right-side search results -->
    74       <div class="col results" tal:condition="query">
    75         <!--"BEGIN SEARCH RESULTS"  -->
    76         <div class="options">
    77           <h4>Search results</h4>
    78           <div metal:use-macro="here/template/search_template/macros/results_div" />
    79         </div>
    80       </div>
     71      <!--  layer columns (rendered always) -->
     72      <tal:block tal:repeat="layer availableLayers">
     73        <tal:block tal:define="mpath string:here/template/layer_text_${layer}/macros/extra_column"
     74          tal:condition="python:exists(mpath)">
     75          <metal:block metal:use-macro="python:path(mpath)" />
     76        </tal:block>
     77      </tal:block>
    8178
    8279      <!-- right-side options -->
     
    9592                  tal:attributes="checked python:viewMode=='text'" /> Text
    9693                <ul>
    97                   <!-- text layers -->
    98                   <li>
    99                     <input type="checkbox" class="autosubmit" name="viewLayer"
    100                       value="dict" tal:attributes="checked python:'dict' in viewLayers" />
    101                     Dictionary
    102                   </li>
    103                   <li tal:condition="python:query">
    104                     <input type="checkbox" class="autosubmit" name="viewLayer"
    105                       value="search"
    106                       tal:attributes="checked python:'search' in viewLayers" /> Search
    107                     hits
    108                   </li>
    109                   <!-- auto-layer select buttons -->
     94                  <!-- text layer select buttons (rendered always) -->
    11095                  <tal:block tal:repeat="layer availableLayers">
    11196                    <tal:block
     
    127112        <!--"END TEXT DISPLAY"-->
    128113
    129         <!--"BEGIN SEARCH"-->
    130         <div class="options">
    131           <h4>Search</h4>
    132           <form tal:attributes="action viewerUrl">
    133             <input type="hidden"
    134               tal:define="params python:here.getParams(params={'query':None,'queryType':None,'viewLayer':None})"
    135               tal:repeat="param params"
    136               tal:attributes="name param; value python:params[param]" />
    137             <!-- make sure we have one viewLayer=search -->
    138             <tal:block tal:repeat="vl viewLayers">
    139               <input type="hidden" name="viewLayer" tal:attributes="value vl"
    140                 tal:condition="python:vl != 'search'" />
    141             </tal:block>
    142             <input type="hidden" name="viewLayer" value="search" />
    143             <!-- query text -->
    144             <input type="text" name="query" tal:attributes="value query" /> <input
    145               type="submit" value="Search" /> <a
    146               tal:attributes="href python:here.getLink('query',None)">Clear</a>
    147             <ul>
    148               <li>
    149                 <input type="radio" name="queryType" value="fulltext"
    150                   tal:attributes="checked python:queryType=='fulltext'" /> Exact
    151               </li>
    152               <li>
    153                 <input type="radio" name="queryType" value="fulltextMorph"
    154                   tal:attributes="checked python:queryType=='fulltextMorph'" /> All forms
    155               </li>
    156               <li>
    157                 <input type="radio" name="queryType" value="ftIndex"
    158                   tal:attributes="checked python:queryType=='ftIndex'" /> Fulltext index
    159               </li>
    160               <li>
    161                 <input type="radio" name="queryType" value="ftIndexMorph"
    162                   tal:attributes="checked python:queryType=='ftIndexMorph'" />
    163                 Morphological index
    164               </li>
    165             </ul>
    166           </form>
    167         </div>
    168         <!--"END SEARCH"-->
    169 
    170114        <!--"BEGIN TEXT SIZE"-->
    171115        <div class="options">
     
    184128        </div>
    185129        <!--"END TEXT SIZE"-->
    186 
    187         <!--"BEGIN DICTIONARY OVERVIEW"-->
    188         <div class="options" tal:condition="python:'dict' in viewLayers">
    189           <h4>Dictionary view</h4>
    190           <form name="f3" action="">
    191             <ul>
    192               <li>
    193                 <input type="radio" name="r3" /> Tab
    194               </li>
    195               <li>
    196                 <input type="radio" name="r3" /> Window
    197               </li>
    198             </ul>
    199           </form>
    200         </div>
    201         <!--"END DICTIONARY OVERVIEW"-->
    202130
    203131        <!--"BEGIN TEXT NORMALIZATION"-->
     
    230158        <!--"END TEXT NORMALIZATION"-->
    231159
    232         <!--  auto-layer option boxes -->
    233         <tal:block tal:repeat="layer viewLayers">
     160        <!--  layer option boxes (rendered if active) -->
     161        <tal:block tal:repeat="layer availableLayers">
    234162          <tal:block
    235163            tal:define="mpath string:here/template/layer_text_${layer}/macros/options_box"
Note: See TracChangeset for help on using the changeset viewer.