incubator-allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject git commit: [#5479] Allow user control of automatic tool grouping threshold
Date Mon, 07 Jan 2013 21:01:04 GMT
Updated Branches:
  refs/heads/cj/5479 1afd53b6a -> fb38ef6fb (forced update)


[#5479] Allow user control of automatic tool grouping threshold

Signed-off-by: Cory Johns <johnsca@geek.net>


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

Branch: refs/heads/cj/5479
Commit: fb38ef6fb4e8af102696daa1e282079b5b5f4912
Parents: 0ee6907
Author: Cory Johns <johnsca@geek.net>
Authored: Mon Jan 7 20:57:35 2013 +0000
Committer: Cory Johns <johnsca@geek.net>
Committed: Mon Jan 7 21:00:42 2013 +0000

----------------------------------------------------------------------
 Allura/allura/ext/admin/admin_main.py              |   11 ++++++
 .../allura/ext/admin/templates/project_tools.html  |   15 +++++++++
 Allura/allura/model/project.py                     |   19 +++++------
 Allura/allura/tests/functional/test_admin.py       |   13 ++++++++
 Allura/allura/tests/unit/test_project.py           |   25 +++++++++++++++
 5 files changed, 73 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fb38ef6f/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 2ba4a56..b2d965c 100644
--- a/Allura/allura/ext/admin/admin_main.py
+++ b/Allura/allura/ext/admin/admin_main.py
@@ -195,6 +195,7 @@ class ProjectAdminController(BaseController):
         c.admin_modal = W.admin_modal
         c.install_modal = W.install_modal
         mounts = c.project.ordered_mounts()
+        c.project.tool_data.setdefault('allura', {'grouping_threshold': 1})
         return dict(
             mounts=mounts,
             installable_tools=AdminApp.installable_tools_for(c.project),
@@ -203,6 +204,16 @@ class ProjectAdminController(BaseController):
 
     @expose()
     @require_post()
+    def configure_tool_grouping(self, grouping_threshold='1', **kw):
+        try:
+            c.project.tool_data.setdefault('allura', {'grouping_threshold': 1})
+            c.project.tool_data.allura.grouping_threshold = int(grouping_threshold)
+        except ValueError as e:
+            flash('Invalid threshold', 'error')
+        redirect('tools')
+
+    @expose()
+    @require_post()
     def update_labels(self, labels=None, **kw):
         require_access(c.project, 'admin')
         c.project.labels = labels.split(',')

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fb38ef6f/Allura/allura/ext/admin/templates/project_tools.html
----------------------------------------------------------------------
diff --git a/Allura/allura/ext/admin/templates/project_tools.html b/Allura/allura/ext/admin/templates/project_tools.html
index 30f72b6..8d996b6 100644
--- a/Allura/allura/ext/admin/templates/project_tools.html
+++ b/Allura/allura/ext/admin/templates/project_tools.html
@@ -115,6 +115,14 @@
 {{c.admin_modal.display(content='<h1 id="popup_title"></h1><div id="popup_contents"></div>')}}
 {{c.mount_delete.display(content='<h1>Confirm Delete</h1>')}}
 <div><!--dummy-->
+
+<h3 style="clear:left">Grouping</h3>
+<form method="POST" action="configure_tool_grouping" id="configure_grouping_form">
+    <label>Threshold for grouping tools by type:
+        <input name="grouping_threshold" value="{{c.project.tool_data.allura.grouping_threshold}}"/>
+    </label>
+    <br/><input type="submit" value="Change"/>
+</form>
 {% endblock %}
 
 {% block extra_js %}
@@ -132,5 +140,12 @@
 .pad .fourcol .fleft {
   min-height: 200px;
 }
+
+#configure_grouping_form {
+    padding-left: 10px;
+}
+#configure_grouping_form input[name=grouping_threshold] {
+    width: 1.5em;
+}
 </style>
 {% endblock %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fb38ef6f/Allura/allura/model/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/project.py b/Allura/allura/model/project.py
index e8263e7..130e10d 100644
--- a/Allura/allura/model/project.py
+++ b/Allura/allura/model/project.py
@@ -443,26 +443,25 @@ class Project(MappedClass, ActivityNode, ActivityObject):
         grouped_nav = OrderedDict()
         # count how many tools of each type we have
         counts = Counter([e.tool_name.lower() for e in sitemap if e.tool_name])
+        grouping_threshold = self.tool_data.get('allura', {}).get('grouping_threshold', 1)
         for e in sitemap:
             # if it's not a tool, add to navbar and continue
             if not e.tool_name:
                 grouped_nav[id(e)] = e
                 continue
             tool_name = e.tool_name.lower()
-            # tool of a type we don't have in the navbar yet
-            if tool_name not in grouped_nav:
-                # there's more than one tool of this type
-                if counts.get(tool_name, 1) > 1:
+            if counts.get(tool_name, 1) <= grouping_threshold:
+                # don't need grouping, so just add it by label
+                grouped_nav[e.label] = e
+            else:
+                # tool of a type we don't have in the navbar yet
+                if tool_name not in grouped_nav:
                     # change label to be the tool name (type)
                     e.label = tool_name.capitalize()
-                    # add tool url to list of urls that will match this nav entry
-                    e.matching_urls.append(e.url)
                     # change url to point to tool list page
                     e.url = self.url() + '_list/' + tool_name
-                grouped_nav[tool_name] = e
-            else:
-                # already have a tool of this type in the nav; add this tool's
-                # url to the list of urls that match this nav entry
+                    grouped_nav[tool_name] = e
+                # add tool url to list of urls that will match this nav entry
                 grouped_nav[tool_name].matching_urls.append(e.url)
         return grouped_nav.values()
 

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fb38ef6f/Allura/allura/tests/functional/test_admin.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_admin.py b/Allura/allura/tests/functional/test_admin.py
index 9c0be46..ad933ab 100644
--- a/Allura/allura/tests/functional/test_admin.py
+++ b/Allura/allura/tests/functional/test_admin.py
@@ -175,6 +175,19 @@ class TestProjectAdmin(TestController):
         # that we don't know about
         assert len(set(expected_tools) - set(tool_strings)) == 0, tool_strings
 
+    def test_grouping_threshold(self):
+        r = self.app.get('/admin/tools')
+        grouping_threshold = r.html.find('input',{'name':'grouping_threshold'})
+        assert_equals(grouping_threshold['value'], '1')
+        r = self.app.post('/admin/configure_tool_grouping', params={
+                'grouping_threshold': '2',
+            }).follow()
+        grouping_threshold = r.html.find('input',{'name':'grouping_threshold'})
+        assert_equals(grouping_threshold['value'], '2')
+        r = self.app.get('/admin/tools')
+        grouping_threshold = r.html.find('input',{'name':'grouping_threshold'})
+        assert_equals(grouping_threshold['value'], '2')
+
     def test_project_icon(self):
         file_name = 'neo-icon-set-454545-256x350.png'
         file_path = os.path.join(allura.__path__[0],'nf','allura','images',file_name)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/fb38ef6f/Allura/allura/tests/unit/test_project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/unit/test_project.py b/Allura/allura/tests/unit/test_project.py
index b59d04f..f33c592 100644
--- a/Allura/allura/tests/unit/test_project.py
+++ b/Allura/allura/tests/unit/test_project.py
@@ -28,3 +28,28 @@ class TestProject(unittest.TestCase):
         actual = [(e.label, e.url, len(e.matching_urls))
                 for e in p.grouped_navbar_entries()]
         self.assertEqual(expected, actual)
+
+    def test_grouped_navbar_threshold(self):
+        p = M.Project()
+        sitemap_entries = [
+            SitemapEntry('bugs', url='bugs url', tool_name='Tickets'),
+            SitemapEntry('wiki', url='wiki url', tool_name='Wiki'),
+            SitemapEntry('discuss', url='discuss url', tool_name='Discussion'),
+            SitemapEntry('subproject', url='subproject url'),
+            SitemapEntry('features', url='features url', tool_name='Tickets'),
+            SitemapEntry('help', url='help url', tool_name='Discussion'),
+            SitemapEntry('support reqs', url='support url', tool_name='Tickets'),
+        ]
+        p.url = Mock(return_value='proj_url/')
+        p.sitemap = Mock(return_value=sitemap_entries)
+        p.tool_data['allura'] = {'grouping_threshold': 2}
+        expected = [
+            ('Tickets', 'proj_url/_list/tickets', 3),
+            ('wiki', 'wiki url', 0),
+            ('discuss', 'discuss url', 0),
+            ('subproject', 'subproject url', 0),
+            ('help', 'help url', 0),
+        ]
+        actual = [(e.label, e.url, len(e.matching_urls))
+                for e in p.grouped_navbar_entries()]
+        self.assertEqual(expected, actual)


Mime
View raw message