Add beadcrumbs and login component in header
authorJuliette Belin <juliette.belin@logilab.fr>
Wed, 01 Feb 2017 10:41:26 +0100
changeset 52 d64b898667ad
parent 51 954fb42ee5fb
child 53 b389b4efa60c
Add beadcrumbs and login component in header
data/cubes.sherpa.css
views/templates.py
views/templates/maintemplate.jinja2
--- a/data/cubes.sherpa.css	Wed Feb 01 10:38:16 2017 +0100
+++ b/data/cubes.sherpa.css	Wed Feb 01 10:41:26 2017 +0100
@@ -76,10 +76,8 @@
 
 /*breadcrumbs */
 
-#breadcrumbs_wrapper {
-  background-color: #0b6ba8;
-}
-#breadcrumbs{
+
+#breadcrumbs {
   background-color: #0b6ba8;
   color: #fff;
   padding: 0;
@@ -90,6 +88,15 @@
   margin-bottom: 0;
 }
 
+#breadcrumbs a {
+  color: #fff;
+
+}
+
+.breadcrumbs_wrapper {
+  background-color: #0b6ba8;
+}
+
 /* aside */
 #aside-main-left {
   margin-top : 3em;
--- a/views/templates.py	Wed Feb 01 10:38:16 2017 +0100
+++ b/views/templates.py	Wed Feb 01 10:41:26 2017 +0100
@@ -83,19 +83,43 @@
         left_boxes = list(self._cw.vreg['ctxcomponents'].poss_visible_objects(
             req, rset=self.cw_rset, view=view, context='left'))
 
+        #left boxes
         stream = UStringIO()
         for box in left_boxes:
             box.render(w=stream.write, view=view)
         left_boxes_html = stream.getvalue()
 
+        #header
+        stream = UStringIO()
+        w=stream.write
+        components = self.get_components(view, context='header-right')
+        if components:
+            w(u'<ul class="nav navbar-nav navbar-right">')
+            for component in components:
+                w(u'<li>')
+                component.render(w=w)
+                w(u'</li>')
+            w(u'</ul>')
+        right_header_component = stream.getvalue()
+
+        #breadcrumbs
+        stream = UStringIO()
+        w=stream.write
+        components = self.get_components(view, context='header-center')
+        if components:
+            for component in components:
+                component.render(w=w)
+        breadcrumbs = stream.getvalue()
+
         ctx = {
-            'header_row': None,
             'title': view.page_title(),
+            'breadcrumbs': breadcrumbs,
             'base_url': self._cw.build_url(''),
             'data_url': self._cw.datadir_url,
             'cssfiles': self._cw.uiprops['STYLESHEETS'],
             'jsfiles': self._cw.uiprops['JAVASCRIPTS'],
             'page_id': 'contentmain',
+            'right_header_component': right_header_component,
             '_': self._cw._,
             'side_box': {
                 'resources': [
@@ -128,22 +152,6 @@
             'current_url': req.relative_path(),
         }
 
-        breadcrumbs = []
-        if self.cw_rset and len(self.cw_rset) == 1:
-            entity = self.cw_rset.one()
-            ibc = entity.cw_adapt_to('IBreadCrumbs')
-            if ibc is not None:
-                for bc_element in ibc.breadcrumbs():
-                    if isinstance(bc_element, (list, tuple)):
-                        breadcrumbs.append(bc_element)
-                    elif isinstance(bc_element, string_types):
-                        breadcrumbs.append((None, bc_element))
-                    else:
-                        breadcrumbs.append((bc_element.absolute_url(),
-                                            bc_element.dc_title()))
-                ctx['breadcrumbs'] = breadcrumbs
-
-        print ctx['left_boxes']
         return ctx
 
 def registration_callback(vreg):
--- a/views/templates/maintemplate.jinja2	Wed Feb 01 10:38:16 2017 +0100
+++ b/views/templates/maintemplate.jinja2	Wed Feb 01 10:41:26 2017 +0100
@@ -36,40 +36,19 @@
           </div>
           <div class="col-md-2 col-md-offset-1 col-xs-4">
 
-            {{ login_html }}
-            {% block login %}
+              {{ right_header_component }}
 
-              <span class="login">
-                {{ user }}<i class="icon-user"></i>
-                <a href="{{ base_url }}{{ "login" if isanon else "logout" }}?postlogin_path={{ current_url }}">
-                  <i class="fa fa-{{ "sign-in" if isanon else "sign-out" }}"></i>
-                </a>
-              </span>
-
-            {% endblock %}
-
-            {% block adminpanel %}
-              {% if not isanon %}
-                <div id="admin-panel"></div>
-              {% endif %}
-            {% endblock %}
 
           </div>
       </div>
     </nav>
 
     {% if breadcrumbs %}
-    <div id="breadcrumbs_wrapper">
-      <ul id="breadcrumbs" class="breadcrumb col-md-offset-2">
-        {% for url, label in breadcrumbs %}
-          {% if url and not loop.last %}
-            <li><a href="{{ url }}">{{ label }}</a></li>
-          {% else %}
-            <li>{{ label }}</li>
-          {% endif %}
-        {% endfor %}
-      </ul>
-    </div>
+    <nav role="navigation" class="breadcrumbs_wrapper">
+      <div class="col-md-offset-3">
+            {{ breadcrumbs }}
+      </div>
+    </nav>
     {% endif %}
 
     <div id="{{page_id}}" class="container-fluid" role="main">
@@ -105,7 +84,7 @@
         {{ left_boxes }}
       </aside>
 
-      <div class="col-md-10">
+      <div class="col-md-9 col-md-offset-1">
         <div class="row">
           {{ page_content }}
         </div>