Anonymous avatar Anonymous committed 5ef6c2b

add list view template, and some extra display functions for links and dois

Comments (0)

Files changed (5)

     
     # UI template
     "template" : "solreyes.mako",
+    "result_view" : "table-view.mako",
     
     # Solreyes base URL
     "base_url" : "http://localhost:8080/",
     if len(capture) == 1:
         return capture[0]
     return value
+    
+def wrap(value, dict):
+    return dict['start'] + value + dict['end']
+    
+def doiify(value, dict):
+    # dois may start with:
+    # 10. - prefix http://dx.doi.org/
+    # doi: - strip doi: and replace with http://dx.doi.org/
+    # http://dx.doi.org/ already done, just linkify
+    resolver = dict.get("resolver", "http://dx.doi.org/")
+    link = None
+    if value.startswith("10."):
+        link = resolver + value
+    elif value.startswith("doi:"):
+        link = resolver + value[4:]
+    elif value.startswith("http://"):
+        link = value
+    
+    if link is not None:
+        return '<a href="' + link + '">' + value + '</a>'
+    else:
+        return value
+
+def _get_location_pairs(message, start_sub, finish_sub):
+    idx = 0
+    pairs = []
+    while message.find(start_sub, idx) > -1:
+        si = message.find(start_sub, idx)
+        sf = message.find(finish_sub, si)
+        pairs.append((si, sf))
+        idx = sf
+    return pairs
+
+def _create_url(url):
+    return "<a href=\"%(url)s\">%(url)s</a>" % {"url" : url}
+
+def linkify(nm, args):
+    parts = _get_location_pairs(nm, "http://", " ")
+    
+    # read into a sortable dictionary
+    dict = {}
+    for (s, f) in parts:
+        dict[s] = f
+    
+    # sort the starting points
+    keys = dict.keys()
+    keys.sort()
+    
+    # determine the splitting points
+    split_at = [0]
+    for s in keys:
+        f = dict.get(s)
+        split_at.append(s)
+        split_at.append(f)
+    
+    # turn the splitting points into pairs
+    pairs = []
+    for i in range(0, len(split_at)):
+        if split_at[i] == -1:
+            break
+        if i + 1 >= len(split_at):
+            end = len(nm)
+        elif split_at[i+1] == -1:
+            end = len(nm)
+        else:
+            end = split_at[i+1]
+        pair = (split_at[i], end)
+        pairs.append(pair)
+    
+    frags = []
+    for s, f in pairs:
+        frags.append(nm[s:f])
+    
+    for i in range(len(frags)):
+        if frags[i].startswith("http://"):
+            frags[i] = _create_url(frags[i])
+    
+    message = "".join(frags)
+    return message
 
 def years_different(lower, upper, dict):
     lyear = regex_map(lower, {"expression" : "([\\d]{4})-.*"})
     values = result.get(dict['count_field'])
     if values is None:
         return 0
-    return len(values)
+    return len(values)
+    

static/styless.css

     padding: 3px;
     background: #eeeeff;
     width: 300;
+}
+
+.list_view {
+
+}
+
+.list_result_odd {
+    
+}
+
+.list_result_even {
+
+}
+
+.list_result_field {
+
 }

templates/list-view.mako

+<% if c['results'].set_size() == 0:
+    return
+%>
+
+<div class="list_view">
+    % for i in range(len(c['results'].set())):
+        <div class="list_result_${'odd' if i % 2 == 0 else 'even'}">
+            % for field in c['config'].display_field_order:
+                % if c['results'].get_str(c['results'].set()[i], field) != "":
+                    <div class="list_result_field">${c['results'].get_str(c['results'].set()[i], field)}</div>
+                % endif
+            % endfor
+        </div>
+    % endfor
+</div>

templates/solreyes.mako

             <%include file="/paging.mako"/>
             <%include file="/resultsperpage.mako"/>
             <div class="result_view">
-                <%include file="/table-view.mako"/>
+                <%include file="/${c['config'].result_view}"/>
             </div>
         
         % endif
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.