allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [03/38] git commit: [#4019] ticket:481 choices_for_filters
Date Wed, 30 Apr 2014 18:15:35 GMT
[#4019] ticket:481 choices_for_filters


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

Branch: refs/heads/master
Commit: c1bc04beaf7911147f57224f83d98d21325c4b17
Parents: 930c845
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Tue Dec 10 15:34:52 2013 +0200
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Wed Apr 30 15:55:08 2014 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/search.py             | 45 ++++++++++++++++++++
 .../tracker_widgets/ticket_search_results.html  |  2 +-
 .../forgetracker/widgets/ticket_search.py       | 13 +++---
 3 files changed, 52 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/c1bc04be/ForgeTracker/forgetracker/search.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/search.py b/ForgeTracker/forgetracker/search.py
new file mode 100644
index 0000000..3bb5bfd
--- /dev/null
+++ b/ForgeTracker/forgetracker/search.py
@@ -0,0 +1,45 @@
+#       Licensed to the Apache Software Foundation (ASF) under one
+#       or more contributor license agreements.  See the NOTICE file
+#       distributed with this work for additional information
+#       regarding copyright ownership.  The ASF licenses this file
+#       to you under the Apache License, Version 2.0 (the
+#       "License"); you may not use this file except in compliance
+#       with the License.  You may obtain a copy of the License at
+#
+#         http://www.apache.org/licenses/LICENSE-2.0
+#
+#       Unless required by applicable law or agreed to in writing,
+#       software distributed under the License is distributed on an
+#       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#       KIND, either express or implied.  See the License for the
+#       specific language governing permissions and limitations
+#       under the License.
+
+from pylons import tmpl_context as c
+
+from allura.lib.search import search
+
+
+def choices_for_filter():
+    params = {
+        'short_timeout': True,
+        'fq': [
+            'project_id_s:%s' % c.project._id,
+            'mount_point_s:%s' % c.app.config.options.mount_point
+            ],
+        'rows': 0,
+        'facet': 'true',
+        'facet.field': ['milestone_s', 'status_s', 'assigned_to_s', 'reported_by_s'],
+        'facet.limit': -1,
+        'facet.sort': 'index',
+        'facet.mincount': 1,
+    }
+    result = search(None, **params)
+    def reformat(field):
+        name, val = field
+        name = name[:-2] if name != 'milestone_s' else '_milestone'
+        new_val = []
+        for i in range(0, len(val), 2):
+            new_val.append((val[i], val[i+1]))
+        return name, new_val
+    return dict(map(reformat, result.facets['facet_fields'].iteritems()))

http://git-wip-us.apache.org/repos/asf/allura/blob/c1bc04be/ForgeTracker/forgetracker/templates/tracker_widgets/ticket_search_results.html
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/templates/tracker_widgets/ticket_search_results.html
b/ForgeTracker/forgetracker/templates/tracker_widgets/ticket_search_results.html
index 60b33bc..41e4bfd 100644
--- a/ForgeTracker/forgetracker/templates/tracker_widgets/ticket_search_results.html
+++ b/ForgeTracker/forgetracker/templates/tracker_widgets/ticket_search_results.html
@@ -42,8 +42,8 @@
           <tr class="ticket-filter" data-column="{{col['name']}}">
             <th colspan="{{columns|length + 1}}">
               <p><a data-sort="{{col['sort_name']}}" title="{{col['label']}}">Toggle
sort by {{col['label']}}</a></p>
-              <p>Filter by {{col['label']}}</p>
               {% if col['name'] in widget.filters.keys() %}
+                <p>Filter by {{col['label']}}</p>
                 <p>
                   <select name="filter-{{col['name']}}" data-label="{{col['label']}}"
multiple="multiple">
                     {% for o in widget.filters[col['name']] %}

http://git-wip-us.apache.org/repos/asf/allura/blob/c1bc04be/ForgeTracker/forgetracker/widgets/ticket_search.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/widgets/ticket_search.py b/ForgeTracker/forgetracker/widgets/ticket_search.py
index 80cc990..5c9c787 100644
--- a/ForgeTracker/forgetracker/widgets/ticket_search.py
+++ b/ForgeTracker/forgetracker/widgets/ticket_search.py
@@ -20,6 +20,8 @@ import ew.jinja2_ew as ew
 
 from allura.lib.widgets import form_fields as ffw
 from allura.lib.widgets import forms
+from forgetracker.search import choices_for_filter
+
 
 
 class TicketSearchResults(ew_core.SimpleForm):
@@ -43,13 +45,10 @@ class TicketSearchResults(ew_core.SimpleForm):
 
     @property
     def filters(self):
-        return {
-            '_milestone': [{'value': 'm1', 'label': 'M1', 'selected': False},
-                           {'value': 'm1', 'label': 'M1', 'selected': True}],
-            'status': [{'value': 'm1', 'label': 'M1', 'selected': False}],
-            'assigned_to': [{'value': 'm1', 'label': 'M1', 'selected': False}],
-            'reported_by': [{'value': 'm1', 'label': 'M1', 'selected': False}],
-        }
+        return {name: [{'value': val,
+                        'label': '%s (%s)' % (val, count),
+                        'selected': False} for val, count in field]
+                for name, field in choices_for_filter().iteritems()}
 
     def resources(self):
         yield ew.JSLink('tracker_js/jquery.multiselect.min.js')


Mime
View raw message