You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by br...@apache.org on 2015/10/30 21:55:54 UTC

[35/50] [abbrv] allura git commit: [#7919] first step in better injecting of the react nav bar

[#7919] first step in better injecting of the react nav bar

* remove unneeded child_count
* move JS to run only on top nav template
* still render regular HTML menu for admins, then replace it when ready
  this avoids any flash
* use h.escape_json instead of just 'safe', to ensure no subtle security issues


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/dd606cca
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/dd606cca
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/dd606cca

Branch: refs/heads/db/7919
Commit: dd606ccad491a2bbdae222120da6be91bc673b60
Parents: 43b08ce
Author: Dave Brondsema <da...@brondsema.net>
Authored: Fri Oct 16 17:53:11 2015 -0400
Committer: Heith Seewald <hs...@hsmb.local>
Committed: Thu Oct 29 20:21:41 2015 -0400

----------------------------------------------------------------------
 Allura/allura/controllers/project.py            |   2 +-
 Allura/allura/model/project.py                  |   9 +-
 Allura/allura/public/nf/css/navbar.css          | 187 ++-----------------
 .../allura/templates/jinja_master/master.html   |  11 --
 .../allura/templates/jinja_master/top_nav.html  |  16 +-
 5 files changed, 37 insertions(+), 188 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/dd606cca/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index 185fc58..75b1aaf 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -381,7 +381,7 @@ class ProjectController(FeedController):
 
     @expose('json:')
     def _nav(self):
-        return c.project.json_nav()
+        return c.project.nav_data()
 
     @expose()
     def _lookup(self, name, *remainder):

http://git-wip-us.apache.org/repos/asf/allura/blob/dd606cca/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index e40f1a5..1609057 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -602,7 +602,7 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                 i += 1
         return new_tools
 
-    def json_nav(self):
+    def nav_data(self):
         grouping_threshold = self.get_tool_data('allura', 'grouping_threshold', 1)
         anchored_tools = self.neighborhood.get_anchored_tools()
         children = []
@@ -619,7 +619,6 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                          ordinal=i)
             i += 1
             if s.children:
-                entry['child_count'] = len(s.children)
                 entry['children'] = [dict(name=child.label,
                                           url=child.url,
                                           icon=child.ui_icon or 'tool-admin',
@@ -631,9 +630,9 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
                 i += len(s.children)
             children.append(entry)
 
-        return json.dumps(dict(grouping_threshold=grouping_threshold,
-                               menu=children,
-                               child_count=i))
+        return dict(grouping_threshold=grouping_threshold,
+                    menu=children,
+                    )
 
     def grouped_navbar_entries(self):
         """Return a :class:`~allura.app.SitemapEntry` list suitable for rendering

http://git-wip-us.apache.org/repos/asf/allura/blob/dd606cca/Allura/allura/public/nf/css/navbar.css
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/css/navbar.css b/Allura/allura/public/nf/css/navbar.css
index 6b947d1..d27b727 100644
--- a/Allura/allura/public/nf/css/navbar.css
+++ b/Allura/allura/public/nf/css/navbar.css
@@ -4,9 +4,9 @@
     display: none;
 }
 
-.hidden {
-    display: none;
-}
+/*.hidden {*/
+/*display: none;*/
+/*}*/
 
 .submenu ul {
     list-style: none;
@@ -85,7 +85,7 @@ nav {
     -ms-border-radius: 4px;
     -khtml-border-radius: 4px;
     border-radius: 4px;
-    width: 918px;  /* 940px - 32px for toggle-admin-btn */
+    width: 918px; /* 940px - 32px for toggle-admin-btn */
 }
 
 #top_nav_admin .edit-mode .fa {
@@ -196,174 +196,29 @@ ul.dropdown .hover, ul.dropdown li:hover {
     color: gray;
 }
 
-.nav_admin{
+.nav_admin {
     height: auto;
 }
 
-.nav_admin > div > ul > li{
+.nav_admin > div > ul > li {
     height: 1.2rem;
     font-weight: inherit;
 }
 
 .tool-partition {
     height: 0;
-    /*padding-top: 5px;*/
     border-top: 3px solid #777;
 }
 
 .installable-tool-box {
-    /* position: relative; */
     display: flex;
     background-color: white;
-    background-image: 
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(0%, #ffffff), color-stop(100%, rgba(204, 204, 204, 0.6)));
-    background-image: 
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    
-    -moz-linear-gradient(top, #ffffff 0%, #cccccc 100%);
+    background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, color-stop(0%, #ffffff), color-stop(100%, rgba(204, 204, 204, 0.6)));
+    background-image: -moz-linear-gradient(top, #ffffff 0%, #cccccc 100%);
     background-image: linear-gradient(top, #ffffff 0%, #cccccc 100%);
     flex-wrap: wrap;
-    /*justify-content: flex-start;*/
     justify-content: space-around;
-    /*margin-left: 0;*/
     flex-direction: row;
-    /* padding-bottom: 5px; */
-    /* padding-top: 4px; */
-    /*display: -webkit-flex;*/
-    /*display: flex;*/
-    /*-webkit-flex-direction: row;*/
-    /*flex-direction: row;*/
-    /*margin-bottom: 8px;*/
 }
 
 .installable-tool-box div {
@@ -389,7 +244,6 @@ ul.dropdown .hover, ul.dropdown li:hover {
     user-select: none;
 }
 
-
 /*.installable-tool-box > div{
     color:blue;
     background: rgba(255, 255, 255, 0.8);
@@ -397,8 +251,7 @@ ul.dropdown .hover, ul.dropdown li:hover {
     border: 1px dashed orange;
 }*/
 
-
-.selected-tool{
+.selected-tool {
     background: #09C !important;
     color: white !important;
     height: 21px;
@@ -521,14 +374,14 @@ ul.dropdown .hover, ul.dropdown li:hover {
     height: auto;
 }
 
-#add-tool-form > label{
+#add-tool-form > label {
     padding: 0;
     font-size: 13pt;
     position: absolute;
     margin-left: 18px;
 }
 
-#add-tool-form > p{
+#add-tool-form > p {
     font-size: large;
 
 }
@@ -540,24 +393,24 @@ ul.dropdown .hover, ul.dropdown li:hover {
     margin: 23px 60px 11px 19px;
 }
 
-#add-tool-form{
+#add-tool-form {
     padding-top: 20px;
     padding-left: 25px;
     padding-right: 25px;
 }
 
-.tool-form-fields{
+.tool-form-fields {
     clear: both;
     position: relative;
     display: flex;
     flex-direction: row;
 }
 
-#mount_point :invalid{
+#mount_point :invalid {
     background: #333;
 }
 
-.add-tool-toggle{
+.add-tool-toggle {
     background: rgba(255, 255, 255, 0.32);
     /*clear: both;*/
     color: #8b8b8b;
@@ -584,21 +437,21 @@ ul.dropdown .hover, ul.dropdown li:hover {
     -o-user-select: none;
     user-select: none;
 }
-.add-tool-toggle:hover{
+
+.add-tool-toggle:hover {
     background: #F4F4F4;
     color: #777;
 }
 
-.active-nav-link{
+.active-nav-link {
     font-weight: bolder;
 }
 
-.add-tool-field{
+.add-tool-field {
     width: 50%;
 }
 
-
-.error-box{
+.error-box {
     background: rgba(255, 114, 114, 0.65);
     color: white;
     padding: 4px;

http://git-wip-us.apache.org/repos/asf/allura/blob/dd606cca/Allura/allura/templates/jinja_master/master.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/master.html b/Allura/allura/templates/jinja_master/master.html
index be6515e..3017c51 100644
--- a/Allura/allura/templates/jinja_master/master.html
+++ b/Allura/allura/templates/jinja_master/master.html
@@ -188,16 +188,5 @@
         });
     })
 </script>
-{% if is_admin %}
-    <script>
-        'use strict';
-        $(document).ready(function () {
-            React.render(React.createElement(Main, {
-                initialData: {{ c.project.json_nav()|safe }}
-            }), document.getElementById("top_nav_admin"));
-        });
-    </script>
-{% endif %}
-{% do g.register_forge_js('/') %}
 </body>
 </html>

http://git-wip-us.apache.org/repos/asf/allura/blob/dd606cca/Allura/allura/templates/jinja_master/top_nav.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/jinja_master/top_nav.html b/Allura/allura/templates/jinja_master/top_nav.html
index c433991..88d7904 100644
--- a/Allura/allura/templates/jinja_master/top_nav.html
+++ b/Allura/allura/templates/jinja_master/top_nav.html
@@ -17,10 +17,7 @@
        under the License.
 -#}
 {% if c.project %}
-{% if h.has_access(c.project, 'admin')() %}
-    <div id="top_nav_admin"></div>
-    {#        {{ c.app.admin_modal.display() }}  <-- Currently Does not work on non-admin urls #}
-{% else %}
+<div id="top_nav_admin">
 <ul class="dropdown">
   {% for s in c.project.grouped_navbar_entries() %}
     <li class="{% if s.matches_url(request) %}selected{% endif %}">
@@ -38,5 +35,16 @@
     </li>
 	{% endfor %}
 </ul>
+</div>
+{% if h.has_access(c.project, 'admin')() %}
+    {#        {{ c.app.admin_modal.display() }}  <-- Currently Does not work on non-admin urls #}
+    <script>
+        'use strict';
+        $(document).ready(function () {
+            React.render(React.createElement(Main, {
+                initialData: {{ h.escape_json(c.project.nav_data())|safe }}
+            }), document.getElementById("top_nav_admin"));
+        });
+    </script>
 {% endif %}
 {% endif %}