[PATCH 8 of 9 saem_ref] [eac] Simplify timeline/graph generation

Sylvain Thenault sylvain.thenault at logilab.fr
Thu Mar 16 17:38:23 CET 2017


# HG changeset patch
# User Sylvain Thénault <sylvain.thenault at logilab.fr>
# Date 1489675073 -3600
#      Thu Mar 16 15:37:53 2017 +0100
# Node ID 35b37b8be87d1696e4917a92fd606291ed4e0d53
# Parent  45ef4ef9f186e7bab3f93c7494dea1eef6277053
[eac] Simplify timeline/graph generation

now that relations are also displayed as 'standard' list which offers dates,
description and edition links, we don't have to bother adding such information
in timeline nor hierarchical graph.

Add some CSS rules regarding hierarchical graph to enhance display after this
diet.

Related to #14591642

diff --git a/cubicweb_saem_ref/data/cubes.saem_ref.css b/cubicweb_saem_ref/data/cubes.saem_ref.css
--- a/cubicweb_saem_ref/data/cubes.saem_ref.css
+++ b/cubicweb_saem_ref/data/cubes.saem_ref.css
@@ -194,5 +194,12 @@ div.facet div.facetTitle {
 
 .highlight {
   background-color: #F6A048;
 }
 
+.jOrgChart {
+  margin-top: 3em;
+}
+
+.jOrgChart .node {
+  height: auto !important;
+}
\ No newline at end of file
diff --git a/cubicweb_saem_ref/views/authorityrecord.py b/cubicweb_saem_ref/views/authorityrecord.py
--- a/cubicweb_saem_ref/views/authorityrecord.py
+++ b/cubicweb_saem_ref/views/authorityrecord.py
@@ -720,106 +720,45 @@ class AuthorityRecordTimelineJsonView(En
     }
 
     def entity_call(self, entity):
         data = dict(self.headers)
         data['date'] = [
-            self.entity_as_date(entity, tag=self._cw._('subject'),
-                                text=entity.dc_description()),
+            self.entity_as_date(entity, tag=self._cw._('subject')),
         ]
         for successor_relation in entity.reverse_chronological_successor:
             predecessor = successor_relation.chronological_predecessor[0]
             data['date'].append(self.entity_as_date(
-                predecessor,
-                text=successor_relation.view(
-                    'saem.timeline-item',
-                    __redirectpath=entity.rest_path()),
-                tag=self._cw._('chronological_predecessor'))
-            )
+                predecessor, tag=self._cw._('chronological_predecessor')))
         for predecessor_relation in entity.reverse_chronological_predecessor:
             successor = predecessor_relation.chronological_successor[0]
             data['date'].append(self.entity_as_date(
-                successor,
-                text=predecessor_relation.view(
-                    'saem.timeline-item',
-                    __redirectpath=entity.rest_path()),
-                tag=self._cw._('chronological_successor'))
-            )
+                successor, tag=self._cw._('chronological_successor')))
         self.w(json_dumps({'timeline': data}))
 
     @staticmethod
-    def entity_as_date(entity, **kwargs):
+    def entity_as_date(entity, tag):
         """Return a dict suitable for insertion within the `date` entry of
         TimelineJS JSON structure.
         """
-        date = {}
+        date = {'tag': tag}
         calendarable = entity.cw_adapt_to('ICalendarable')
         if calendarable and (calendarable.start or calendarable.stop):
-            date.update(
-                {'headline': entity.view('incontext'),
-                 'text': entity.view('vtimeline-itemdescr')}
-            )
+            date['headline'] = entity.view('incontext')
             if calendarable.start:
                 date['startDate'] = ustrftime(calendarable.start, '%Y,%m,%d')
             if calendarable.stop:
                 date['endDate'] = ustrftime(calendarable.stop, '%Y,%m,%d')
-        date.update(kwargs)
         return date
 
 
-class ChronologicalRelationTimelineItemView(EntityView):
-    """View for 'text' part of date event in timeline view"""
-    __regid__ = 'saem.timeline-item'
-    __select__ = is_instance('ChronologicalRelation')
-
-    def entity_call(self, entity, **urlparams):
-        self.w(entity.printable_value('description'))
-        vreg = self._cw.vreg
-        eschema = vreg.schema.eschema(entity.cw_etype)
-        if eschema.has_perm(self._cw, 'update'):
-            self.w(tags.a(title=self._cw._('edit'), klass='icon-pencil',
-                          href=entity.absolute_url('edition', **urlparams)))
-
-
-def _node(entity, rel=None):
-    req = entity._cw
-    if rel is not None:
-        url = entity.absolute_url()
-        descr = rel.printable_value('description', format='text/plain')
-        if descr:
-            descr_url_desc = descr
-            descr = cut(descr, 100)
-        else:
-            descr = req._('<no description specified>')
-            descr_url_desc = req._('view this relation')
-        descr_url = rel.absolute_url()
-        dates = []
-        if rel.start_date:
-            dates.append(rel.printable_value('start_date'))
-        if rel.end_date:
-            dates.append(rel.printable_value('end_date'))
-    else:
-        url = descr = descr_url = descr_url_desc = dates = u''
-    title = entity.dc_title()
+def _node(entity):
     return {
         'id': text_type(entity.eid),
-        'title': cut(title, 30),
-        'title_url': url,
-        'title_url_desc': title,
-        'descr': descr,
-        'descr_url': descr_url,
-        'descr_url_desc': descr_url_desc,
-        'dates': u' - '.join(dates),
+        'title': cut(entity.dc_title(), 30),
     }
 
 
-def _add_html_node_content(properties):
-    return (u'<p>%(title)s</p><p>%(descr)s</p><p class="dates">%(dates)s</p>' %
-            {'title': tags.a(properties['title'], href=properties['title_url'], klass=u'title'),
-             'descr': tags.a(properties['descr'], href=properties['descr_url']),
-             'dates': properties['dates']})
-
-
 class AuthorityRecordGraphView(EntityView):
     __select__ = EntityView.__select__ & (
         has_related_entities('hierarchical_parent', role='object') |
         has_related_entities('hierarchical_child', role='object'))
 
@@ -831,26 +770,25 @@ class AuthorityRecordGraphView(EntityVie
 
         self._cw.add_js(('jquery.js', 'jquery.jOrgChart.js'))
         self._cw.add_css('jquery.jOrgChart.css')
         hiera_list = u'<ul id="hierarchical_relations" style="display:none">'
         tags_closure = u'</ul>'
-        rset_parents = self._cw.execute('Any P, PR WHERE PR hierarchical_child X, '
+        rset_parents = self._cw.execute('Any P WHERE PR hierarchical_child X, '
                                         'PR hierarchical_parent P, X eid %(eid)s',
                                         {'eid': entity.eid})
         if rset_parents:
             parent = rset_parents.get_entity(0, 0)
-            parent_rel = rset_parents.get_entity(0, 1)
-            nprops = _node(parent, parent_rel)
-            hiera_list += u'<li>' + _add_html_node_content(nprops) + u'<ul>'
+            nprops = _node(parent)
+            hiera_list += u'<li>{}<ul>'.format(nprops['title'])
             tags_closure = u'</ul></li>' + tags_closure
         nprops = _node(entity)
-        hiera_list += u'<li class="main">' + _add_html_node_content(nprops) + u'<ul>'
+        hiera_list += u'<li class="main">{}<ul>'.format(nprops['title'])
         tags_closure = u'</ul></li>' + tags_closure
         for child_rel in entity.reverse_hierarchical_parent:
             for child in child_rel.hierarchical_child:
-                nprops = _node(child, child_rel)
-                hiera_list += u'<li>' + _add_html_node_content(nprops) + u'</li>'
+                nprops = _node(child)
+                hiera_list += u'<li></li>'.format(nprops['title'])
         hiera_list += tags_closure
         self.w(hiera_list)
         domid = make_uid()
         self._cw.add_onload(js.cw.jqNode('hierarchical_relations').jOrgChart(
             JSString('{chartElement: %s}' % js.cw.jqNode(domid))))


More information about the saem-devel mailing list