allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [3/4] git commit: [#4790] ticket:234 add option to show/hide default fields on search
Date Tue, 18 Dec 2012 23:12:15 GMT
[#4790] ticket:234 add option to show/hide default fields on search


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

Branch: refs/heads/master
Commit: 750e966f478cda94130c98e2dfea8e26e8463b2c
Parents: ad9554e
Author: Yuriy Arhipov <yuriyarhipovua@yandex.ru>
Authored: Mon Dec 17 07:46:06 2012 +0400
Committer: Dave Brondsema <dbrondsema@geek.net>
Committed: Tue Dec 18 23:11:27 2012 +0000

----------------------------------------------------------------------
 ForgeTracker/forgetracker/model/ticket.py          |    8 ++
 .../templates/tracker/admin_fields.html            |   17 +++
 .../tracker_widgets/ticket_search_results.html     |    7 +
 .../forgetracker/tests/functional/test_root.py     |   36 +++++-
 ForgeTracker/forgetracker/tracker_main.py          |   94 +++++++++++++--
 5 files changed, 149 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/750e966f/ForgeTracker/forgetracker/model/ticket.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/model/ticket.py b/ForgeTracker/forgetracker/model/ticket.py
index cd23784..a86a44a 100644
--- a/ForgeTracker/forgetracker/model/ticket.py
+++ b/ForgeTracker/forgetracker/model/ticket.py
@@ -56,6 +56,14 @@ class Globals(MappedClass):
     _bin_counts_expire = FieldProperty(datetime)
     _milestone_counts = FieldProperty([dict(name=str,hits=int,closed=int)])
     _milestone_counts_expire = FieldProperty(datetime)
+    show_in_search = FieldProperty({str: bool}, if_missing={'ticket_num': True,
+                                                            'summary': True,
+                                                            '_milestone': True,
+                                                            'status': True,
+                                                            'assigned_to': True,
+                                                            'reported_by': True,
+                                                            'created_date': True,
+                                                            'mod_date': True})
 
     @classmethod
     def next_ticket_num(cls):

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/750e966f/ForgeTracker/forgetracker/templates/tracker/admin_fields.html
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/templates/tracker/admin_fields.html b/ForgeTracker/forgetracker/templates/tracker/admin_fields.html
index a3ab1e6..7336c08 100644
--- a/ForgeTracker/forgetracker/templates/tracker/admin_fields.html
+++ b/ForgeTracker/forgetracker/templates/tracker/admin_fields.html
@@ -10,6 +10,23 @@
 
 {% block content %}
   {{c.form.display(value=globals, action='set_custom_fields')}}
+<h1>Default fields</h1>
+<form name="show_fields_in_search" method="POST" action="allow_default_field">
+    <table>
+        <thead>
+        <tr>
+            <th>Filed name</th>
+            <th>Show in search</th>
+        </tr>
+        </thead>
+        {%for column in columns.keys()%}
+        <tr>
+            <td>{{columns[column]}}</td> <td><input type="checkbox"
name="{{column}}" {%if globals.show_in_search[column]%}checked {%endif%}></td>
+        </tr>
+        {%endfor%}
+        <tr><td><input type="submit" value="Save"></td><td></td></tr>
+    </table>
+</form>
 {% endblock %}
 
 {% block extra_css %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/750e966f/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 3420108..1d88558 100644
--- a/ForgeTracker/forgetracker/templates/tracker_widgets/ticket_search_results.html
+++ b/ForgeTracker/forgetracker/templates/tracker_widgets/ticket_search_results.html
@@ -1,3 +1,4 @@
+{% from 'allura:templates/jinja_master/lib.html' import abbr_date with context %}
 <div id="ticket_search_results_holder" style="clear:both">
   {% if solr_error %}<p>{{solr_error}}</p>{% endif %}
   {{widget.fields['page_size'].display(page=page, count=count, limit=limit)}}
@@ -31,6 +32,12 @@
                 <td class="{{t.open_or_closed}}">{{t.status}}</td>
               {% elif col['name'] == 'assigned_to' %}
                 <td>{% if t.assigned_to_id %}{{t.assigned_to.display_name}}{% endif
%}</td>
+              {% elif col['name'] == 'reported_by' %}
+              <td>{% if t.reported_by %}{{t.reported_by.display_name}}{% endif %}</td>
+              {% elif col['name'] == 'created_date' %}
+              <td>{% if t.created_date %}{{abbr_date(t.created_date)}}{% endif %}</td>
+              {% elif col['name'] == 'mod_date' %}
+              <td>{% if t.mod_date %}{{abbr_date(t.mod_date)}}{% endif %}</td>
               {% elif col['name'] == 'votes' %}
                 <td>{{ t.votes }}</td>
               {% else %}

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/750e966f/ForgeTracker/forgetracker/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tests/functional/test_root.py b/ForgeTracker/forgetracker/tests/functional/test_root.py
index 72d91fe..defa5c4 100644
--- a/ForgeTracker/forgetracker/tests/functional/test_root.py
+++ b/ForgeTracker/forgetracker/tests/functional/test_root.py
@@ -1281,8 +1281,8 @@ class TestCustomUserField(TrackerTestController):
         kw = {'custom_fields._code_review': 'test-admin'}
         self.new_ticket(summary='test custom fields', **kw)
         r = self.app.get('/bugs/')
-        assert r.html.find('table', 'ticket-list').findAll('th')[5].text == 'Code Review'
-        assert r.html.find('table', 'ticket-list').tbody.tr.findAll('td')[5].text == 'Test
Admin'
+        assert r.html.find('table', 'ticket-list').findAll('th')[8].text == 'Code Review'
+        assert r.html.find('table', 'ticket-list').tbody.tr.findAll('td')[8].text == 'Test
Admin'
 
 class TestHelpTextOptions(TrackerTestController):
     def _set_options(self, new_txt='', search_txt=''):
@@ -1315,6 +1315,38 @@ class TestHelpTextOptions(TrackerTestController):
         r = self.app.get('/bugs/new/')
         assert len(r.html.findAll(attrs=dict(id='new-ticket-help-msg'))) == 0
 
+class test_show_default_fields(TrackerTestController):
+    def test_show_default_fields(self):
+        r = self.app.get('/admin/bugs/fields')
+        assert '<td>Ticket Number</td> <td><input type="checkbox" name="ticket_num"
checked ></td>' in r
+        assert '<td>Summary</td> <td><input type="checkbox" name="summary"
checked ></td>' in r
+        assert '<td>Milestone</td> <td><input type="checkbox" name="_milestone"
checked ></td>' in r
+        assert '<td>Status</td> <td><input type="checkbox" name="status"
checked ></td>' in r
+        assert '<td>Owner</td> <td><input type="checkbox" name="assigned_to"
checked ></td>' in r
+        assert '<td>Creator</td> <td><input type="checkbox" name="reported_by"
checked ></td>' in r
+        assert '<td>Created</td> <td><input type="checkbox" name="created_date"
checked ></td>' in r
+        assert '<td>Updated</td> <td><input type="checkbox" name="mod_date"
checked ></td>' in r
+        self.new_ticket(summary='test')
+        M.MonQTask.run_ready()
+        r = self.app.get('/bugs/search', params=dict(q='test'))
+        assert '<td><a href="/p/test/bugs/1/">1</a></td>' in r
+        p = M.Project.query.get(shortname='test')
+        app = p.app_instance('bugs')
+        app.globals.show_in_search['ticket_num'] = False
+        r = self.app.get('/bugs/search', params=dict(q='test'))
+        assert '<td><a href="/p/test/bugs/1/">1</a></td>' not in
r
+        self.app.post('/admin/bugs/allow_default_field', params={'status': 'on'})
+        r = self.app.get('/admin/bugs/fields')
+        assert '<td>Ticket Number</td> <td><input type="checkbox" name="ticket_num"
></td>' in r
+        assert '<td>Summary</td> <td><input type="checkbox" name="summary"
></td>' in r
+        assert '<td>Milestone</td> <td><input type="checkbox" name="_milestone"
></td>' in r
+        assert '<td>Status</td> <td><input type="checkbox" name="status"
checked ></td>' in r
+        assert '<td>Owner</td> <td><input type="checkbox" name="assigned_to"
></td>' in r
+        assert '<td>Creator</td> <td><input type="checkbox" name="reported_by"
></td>' in r
+        assert '<td>Created</td> <td><input type="checkbox" name="created_date"
></td>' in r
+        assert '<td>Updated</td> <td><input type="checkbox" name="mod_date"
></td>' in r
+
+
 def sidebar_contains(response, text):
     sidebar_menu = response.html.find('div', attrs={'id': 'sidebar'})
     return text in str(sidebar_menu)

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/750e966f/ForgeTracker/forgetracker/tracker_main.py
----------------------------------------------------------------------
diff --git a/ForgeTracker/forgetracker/tracker_main.py b/ForgeTracker/forgetracker/tracker_main.py
index 83c2a0b..bad0ba5 100644
--- a/ForgeTracker/forgetracker/tracker_main.py
+++ b/ForgeTracker/forgetracker/tracker_main.py
@@ -79,6 +79,12 @@ def _mongo_col_to_solr_col(name):
         return 'assigned_to_s'
     elif name == 'custom_fields._milestone':
         return '_milestone_s'
+    elif name == 'reported_by':
+        return 'reported_by_s'
+    elif name == 'created_date':
+        return 'created_date_dt'
+    elif name == 'mod_date':
+        return 'mod_date_dt'
     else:
         for field in c.app.globals.sortable_custom_fields_shown_in_search():
             if name == field['name']:
@@ -329,11 +335,38 @@ class ForgeTrackerApp(Application):
 ### Controllers ###
 
 def mongo_columns():
-    columns = [dict(name='ticket_num', sort_name='ticket_num', label='Ticket Number', active=True),
-               dict(name='summary', sort_name='summary', label='Summary', active=True),
-               dict(name='_milestone', sort_name='custom_fields._milestone', label='Milestone',
active=True),
-               dict(name='status', sort_name='status', label='Status', active=True),
-               dict(name='assigned_to', sort_name='assigned_to_username', label='Owner',
active=True)]
+    columns = [dict(name='ticket_num',
+                    sort_name='ticket_num',
+                    label='Ticket Number',
+                    active=c.app.globals.show_in_search['ticket_num']),
+               dict(name='summary',
+                    sort_name='summary',
+                    label='Summary',
+                    active=c.app.globals.show_in_search['summary']),
+               dict(name='_milestone',
+                    sort_name='custom_fields._milestone',
+                    label='Milestone',
+                    active=c.app.globals.show_in_search['_milestone']),
+               dict(name='status',
+                    sort_name='status',
+                    label='Status',
+                    active=c.app.globals.show_in_search['status']),
+               dict(name='assigned_to',
+                    sort_name='assigned_to_username',
+                    label='Owner',
+                    active=c.app.globals.show_in_search['assigned_to']),
+               dict(name='reported_by',
+                    sort_name='reported_by',
+                    label='Creator',
+                    active=c.app.globals.show_in_search['reported_by']),
+               dict(name='created_date',
+                    sort_name='created_date',
+                    label='Created',
+                    active=c.app.globals.show_in_search['created_date']),
+               dict(name='mod_date',
+                    sort_name='mod_date',
+                    label='Updated',
+                    active=c.app.globals.show_in_search['mod_date'])]
     for field in c.app.globals.sortable_custom_fields_shown_in_search():
         columns.append(
             dict(name=field['name'], sort_name=field['name'], label=field['label'], active=True))
@@ -342,11 +375,38 @@ def mongo_columns():
     return columns
 
 def solr_columns():
-    columns = [dict(name='ticket_num', sort_name='ticket_num_i', label='Ticket Number', active=True),
-               dict(name='summary', sort_name='snippet_s', label='Summary', active=True),
-               dict(name='_milestone', sort_name='_milestone_s', label='Milestone', active=True),
-               dict(name='status', sort_name='status_s', label='Status', active=True),
-               dict(name='assigned_to', sort_name='assigned_to_s', label='Owner', active=True)]
+    columns = [dict(name='ticket_num',
+                    sort_name='ticket_num_i',
+                    label='Ticket Number',
+                    active=c.app.globals.show_in_search['ticket_num']),
+               dict(name='summary',
+                    sort_name='snippet_s',
+                    label='Summary',
+                    active=c.app.globals.show_in_search['summary']),
+               dict(name='_milestone',
+                    sort_name='_milestone_s',
+                    label='Milestone',
+                    active=c.app.globals.show_in_search['_milestone']),
+               dict(name='status',
+                    sort_name='status_s',
+                    label='Status',
+                    active=c.app.globals.show_in_search['status']),
+               dict(name='assigned_to',
+                    sort_name='assigned_to_s',
+                    label='Owner',
+                    active=c.app.globals.show_in_search['assigned_to']),
+               dict(name='reported_by',
+                    sort_name='reported_by_s',
+                    label='Creator',
+                    active=c.app.globals.show_in_search['reported_by']),
+               dict(name='created_date',
+                    sort_name='created_date_dt',
+                    label='Created',
+                    active=c.app.globals.show_in_search['created_date']),
+               dict(name='mod_date',
+                    sort_name='mod_date_dt',
+                    label='Updated',
+                    active=c.app.globals.show_in_search['mod_date'])]
     for field in c.app.globals.sortable_custom_fields_shown_in_search():
         columns.append(dict(name=field['name'], sort_name=field['sortable_name'], label=field['label'],
active=True))
     if c.app.config.options.get('EnableVoting'):
@@ -1222,7 +1282,9 @@ class TrackerAdminController(DefaultAdminController):
     @expose('jinja:forgetracker:templates/tracker/admin_fields.html')
     def fields(self, **kw):
         c.form = W.field_admin
-        return dict(app=self.app, globals=self.app.globals)
+        c.app = self.app
+        columns = dict((column, get_label(column)) for column in self.app.globals['show_in_search'].keys())
+        return dict(app=self.app, globals=self.app.globals, columns=columns)
 
     @expose('jinja:forgetracker:templates/tracker/admin_options.html')
     def options(self, **kw):
@@ -1246,6 +1308,16 @@ class TrackerAdminController(DefaultAdminController):
         redirect(c.project.url() + 'admin/tools')
 
     @expose()
+    @require_post()
+    def allow_default_field(self, **post_data):
+        for column in self.app.globals['show_in_search'].keys():
+            if post_data.has_key(column) and post_data[column] == 'on':
+                self.app.globals['show_in_search'][column] = True
+            else:
+                self.app.globals['show_in_search'][column] = False
+        redirect(request.referer)
+
+    @expose()
     def update_tickets(self, **post_data):
         pass
 


Mime
View raw message