allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [39/50] [abbrv] allura git commit: [#7919] clean up existingTools validation variables
Date Thu, 17 Dec 2015 19:22:26 GMT
[#7919] clean up existingTools validation variables


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

Branch: refs/heads/db/8034
Commit: 1ad421edb20bc552f8a21ef9519eb6be5a21d692
Parents: 68f31e1
Author: Dave Brondsema <dave@brondsema.net>
Authored: Thu Dec 10 16:26:58 2015 -0500
Committer: Heith Seewald <heiths@gmail.com>
Committed: Wed Dec 16 13:55:40 2015 -0600

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py           | 29 ++++++-----
 .../admin/templates/project_install_tool.html   |  4 +-
 Allura/allura/model/project.py                  | 10 ++++
 Allura/allura/public/nf/js/navbar.es6.js        | 51 --------------------
 .../allura/templates/jinja_master/top_nav.html  |  9 ++--
 5 files changed, 30 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/1ad421ed/Allura/allura/ext/admin/admin_main.py
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/admin_main.py b/Allura/allura/ext/admin/admin_main.py
index f0bc151..eb7175a 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -336,21 +336,21 @@ class ProjectAdminController(BaseController):
     @expose('jinja:allura.ext.admin:templates/project_install_tool.html')
     def install_tool(self, tool_name=None, **kw):
         if tool_name == 'subproject':
-            return dict(
-                    tool_name=tool_name,
-                    tool={
-                        'tool_label': 'Sub Project',
-                        'default_mount_label': 'SubProject',
-                        'default_mount_point': 'subproject'
-                    },
-                    options=[],
-            )
-
-        tool = g.entry_points['tool'][tool_name]
+            tool = {
+                'tool_label': 'Sub Project',
+                'default_mount_label': 'SubProject',
+                'default_mount_point': 'subproject'
+            },
+            options = []
+        else:
+            tool = g.entry_points['tool'][tool_name]
+            options = tool.options_on_install()
+
         return dict(
-                tool_name=tool_name,
-                tool=tool,
-                options=tool.options_on_install(),
+            tool_name=tool_name,
+            tool=tool,
+            options=options,
+            existing_mount_points=c.project.mount_points()
         )
 
     @expose()
@@ -360,7 +360,6 @@ class ProjectAdminController(BaseController):
             raise exc.HTTPNotFound, name
         return app.admin, remainder
 
-
     @without_trailing_slash
     @expose('jinja:allura.ext.admin:templates/project_permissions.html')
     def groups(self, **kw):

http://git-wip-us.apache.org/repos/asf/allura/blob/1ad421ed/Allura/allura/ext/admin/templates/project_install_tool.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/project_install_tool.html b/Allura/allura/ext/admin/templates/project_install_tool.html
index 82f6f65..39fb9db 100644
--- a/Allura/allura/ext/admin/templates/project_install_tool.html
+++ b/Allura/allura/ext/admin/templates/project_install_tool.html
@@ -61,6 +61,8 @@
 
 
 <script>
+    var _existingMountPoints = {{ h.escape_json(existing_mount_points)|safe }};
+
     $('#admin_modal_title').hide();
     var mount_point = $('#id_url_input');
     var _re = mount_point.data('regex');
@@ -77,7 +79,7 @@
     function validateNewToolForm() {
         var mp = document.getElementById('id_url_input');
         var v = $(mp).val();
-        var mp_exists = _.contains(document._existingTools, $(mp).val());
+        var mp_exists = _.contains(_existingMountPoints, $(mp).val());
 
         if(v.length > 61){
             submit_button.attr('disabled', true);

http://git-wip-us.apache.org/repos/asf/allura/blob/1ad421ed/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index 6a2007d..eadd4d7 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -784,6 +784,16 @@ class Project(SearchIndexable, MappedClass, ActivityNode, ActivityObject):
             ordinal = last_menu_item['sub'].ordinal
         return ordinal
 
+    def mount_points_generator(self):
+        for item in self.ordered_mounts(include_hidden=True):
+            if 'ac' in item:
+                yield item['ac'].options.mount_point
+            else:
+                yield item['sub'].shortname
+
+    def mount_points(self):
+        return list(self.mount_points_generator())
+
     def install_app(self, ep_name, mount_point=None, mount_label=None, ordinal=None, **override_options):
         '''
         Install an app

http://git-wip-us.apache.org/repos/asf/allura/blob/1ad421ed/Allura/allura/public/nf/js/navbar.es6.js
----------------------------------------------------------------------
diff --git a/Allura/allura/public/nf/js/navbar.es6.js b/Allura/allura/public/nf/js/navbar.es6.js
index a4cfeb3..28f87c7 100644
--- a/Allura/allura/public/nf/js/navbar.es6.js
+++ b/Allura/allura/public/nf/js/navbar.es6.js
@@ -42,55 +42,6 @@ function _getProjectUrl(rest = true) {
     return (rest ? '/rest/' : '/') + nbhd_proj;
 }
 
-/**
- * Get a mount point from a NavBarItem node.
-
- * @constructor
- * @param {NavBarItem} node
- * @returns {string}
- */
-function getMountPoint(node) {
-    if(node.hasOwnProperty('mount_point') && node['mount_point'] !== null){
-        return node['mount_point'];
-    }
-    return node.props.children[0].props.mount_point;
-}
-
-/**
- * Get a url from a NavBarItem node.
-
- * @constructor
- * @param {NavBarItem} node
- * @returns {string}
- */
-function getUrlByNode(node) {
-    if(node.hasOwnProperty('url') && node['url'] !== null){
-        return node['url'];
-    }
-    return node.props.children[0].props.url;
-}
-
-/**
- * Returns all existing mount points for a given project.
-
- * @constructor
- * @param {array} items
- * @returns {array}
- */
-function getMountPoints(items) {
-    var existingTools = [];
-    for (let item of items) {
-        if (item.hasOwnProperty('mount_point') && item.mount_point !== null) {
-            existingTools.push(item.mount_point);
-        } else if (item.hasOwnProperty('children')) {
-            for (let child of item.children) {
-                existingTools.push(child.mount_point)
-            }
-        }
-    }
-    return existingTools;
-}
-
 const ToolsPropType = React.PropTypes.shape({
     mount_point: React.PropTypes.string,
     name: React.PropTypes.string.isRequired,
@@ -304,7 +255,6 @@ var NormalNavBar = React.createClass({
 
     render: function() {
         var listItems = this.props.items.map(this.buildMenu);
-        var existingTools = getMountPoints(this.props.items);
         return (
             <ul
                 id="normal-nav-bar"
@@ -313,7 +263,6 @@ var NormalNavBar = React.createClass({
                 <li id="add-tool-container">
                     <ToggleAddNewTool
                         {...this.props}
-                        mountPointValidation={existingTools}
                         onOptionClick={this.onOptionClick} />
                 </li>
             </ul>

http://git-wip-us.apache.org/repos/asf/allura/blob/1ad421ed/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 53ffc6b..32047be 100644
--- a/Allura/allura/templates/jinja_master/top_nav.html
+++ b/Allura/allura/templates/jinja_master/top_nav.html
@@ -50,11 +50,9 @@
     {% do g.register_forge_js('js/react-reorderable.min.js') %}
     {% do g.register_forge_js('js/build/transpiled.js') %} {# if we do more es6, we'll need
to register this in other places, or maybe even global #}
     <script>
-    'use strict';
-    var _data = {{ h.escape_json(c.project.nav_data(admin_options=True))|safe  }};
+        'use strict';
+        var _data = {{ h.escape_json(c.project.nav_data(admin_options=True))|safe }};
         $(document).ready(function () {
-            var _existingTools = getMountPoints(_data['menu']);
-            document._existingTools = getMountPoints(_data['menu'])
             $('#toggle-admin-btn').click(function () {
                 ReactDOM.render(React.createElement(Main, {
                     initialData: _data
@@ -62,8 +60,7 @@
             });
 
             ReactDOM.render(React.createElement(ToggleAddNewTool, {
-                        installableTools: _data['installable_tools'],
-                        mountPointValidation:_existingTools
+                        installableTools: _data['installable_tools']
                     }), document.getElementById('add-tool-container'));
 
             $("#toggle-admin-btn").tooltipster({


Mime
View raw message