incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1307979 - in /incubator/bloodhound/trunk/bloodhound_dashboard: bhdashboard/util.py bhdashboard/web_ui.py bhdashboard/widgets/query.py bhdashboard/widgets/templates/widget_cloud.html bhdashboard/widgets/ticket.py setup.py
Date Sun, 01 Apr 2012 01:20:08 GMT
Author: gjm
Date: Sun Apr  1 01:20:08 2012
New Revision: 1307979

URL: http://svn.apache.org/viewvc?rev=1307979&view=rev
Log:
Dashboard code import: BH_Dashboard: Introducing TicketFieldCloudWidget

Added:
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/templates/widget_cloud.html
  (with props)
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/ticket.py   (with
props)
Modified:
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/util.py
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.py
    incubator/bloodhound/trunk/bloodhound_dashboard/setup.py

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/util.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/util.py?rev=1307979&r1=1307978&r2=1307979&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/util.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/util.py Sun Apr  1 01:20:08
2012
@@ -37,6 +37,10 @@ from trac.web.main import RequestDispatc
 
 from bhdashboard.api import DashboardSystem, IWidgetProvider, InvalidIdentifier
 
+#------------------------------------------------------
+#    Request handling
+#------------------------------------------------------
+
 def dummy_request(env, uname=None):
     environ = {}
     setup_testing_defaults(environ)
@@ -77,6 +81,10 @@ def merge_links(srcreq, dstreq, exclude=
                 for link in links:
                     add_link(dstreq, rel, **link)
 
+#------------------------------------------------------
+#    Widget helpers
+#------------------------------------------------------
+
 class WidgetBase(Component):
     """Abstract base class for widgets"""
 
@@ -122,6 +130,10 @@ def check_widget_name(f):
         return f(self, name, *args, **kwargs)
     return widget_name_checker
 
+#------------------------------------------------------
+#    Function decorators and wrappers
+#------------------------------------------------------
+
 def pretty_wrapper(wrapped, *decorators):
     """Apply multiple decorators to a given function and make the result 
     look like wrapped function.
@@ -145,3 +157,25 @@ trac_tags = (
         (0, 13), # TODO: Find the exact version ( Trac=0.12 ? )
     )
 
+#------------------------------------------------------
+#    Miscellaneous
+#------------------------------------------------------
+
+def minmax(seq, accessor=lambda x: x):
+    """Retrieve lower and upper bounds in a squence
+    """
+    minval = maxval = None
+    seq = iter(seq)
+    try:
+        minval = maxval = accessor(seq.next())
+    except StopIteration:
+        pass
+    for x in seq:
+        value = accessor(x)
+        if value > maxval:
+            maxval = value
+        if value < minval:
+            minval = value
+    return dict(min=minval, max=maxval)
+
+

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py?rev=1307979&r1=1307978&r2=1307979&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py Sun Apr  1 01:20:08
2012
@@ -110,7 +110,7 @@ class DashboardModule(Component):
         """
         # TODO: Implement dynamic dashboard specification
         from bhdashboard.widgets.query import TicketQueryWidget
-        from bhdashboard.widgets.report import TicketReportWidget
+        from bhdashboard.widgets.ticket import TicketFieldCloudWidget
         from bhdashboard.widgets.timeline import TimelineWidget
 
         ctx = Context.from_request(req)
@@ -130,6 +130,13 @@ class DashboardModule(Component):
                     'c' : TimelineWidget(self.env),
                     'args' : ['Timeline', ctx, {'args' : {}}]
                 },
+                {
+                    'c' : TicketFieldCloudWidget(self.env),
+                    'args' : ['TicketFieldCloud', ctx, 
+                            {'args' : {'field' : 'component',
+                                    'verbose' : True}
+                            }]
+                },
             ]
         chrome = Chrome(self.env)
         render = chrome.render_template

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.py?rev=1307979&r1=1307978&r2=1307979&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.py Sun Apr 
1 01:20:08 2012
@@ -69,7 +69,7 @@ class TicketQueryWidget(WidgetBase):
     get_widget_params = pretty_wrapper(get_widget_params, check_widget_name)
 
     def render_widget(self, name, context, options):
-        """Execute stored report and render data using a grid
+        """Execute custom query and render data using a grid
         """
         data = None
         req = context.req

Added: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/templates/widget_cloud.html
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/templates/widget_cloud.html?rev=1307979&view=auto
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/templates/widget_cloud.html
(added)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/templates/widget_cloud.html
Sun Apr  1 01:20:08 2012
@@ -0,0 +1,18 @@
+
+<div id="content" class="well"
+  xmlns="http://www.w3.org/1999/xhtml"
+  xmlns:py="http://genshi.edgewall.org/"
+  xmlns:xi="http://www.w3.org/2001/XInclude">
+
+  <h3 style="display: inline;">$heading</h3>
+  <p style="font-size: medium; line-height: 150%;">
+    <py:for each="item in items"
+        py:with="_max = bounds.max ; _min = bounds.min" >
+      <a href="${item_link(item)}" 
+          style="font-size: ${int(28 - (13 / (_max - _min)) * (_max - item[1]) )}px">
+        ${item[0]} <py:if test="verbose">(${item[1]})</py:if>
+      </a>
+      &nbsp;&nbsp;
+    </py:for>
+  </p>
+</div>

Propchange: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/templates/widget_cloud.html
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/templates/widget_cloud.html
------------------------------------------------------------------------------
    svn:mime-type = text/html

Added: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/ticket.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/ticket.py?rev=1307979&view=auto
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/ticket.py (added)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/ticket.py Sun Apr
 1 01:20:08 2012
@@ -0,0 +1,118 @@
+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+#  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.
+
+
+r"""Project dashboard for Apache(TM) Bloodhound
+
+Widgets displaying timeline data.
+"""
+
+from itertools import imap, islice
+
+from genshi.builder import tag
+from trac.core import implements, TracError
+from trac.ticket.api import TicketSystem
+from trac.util.translation import _
+
+from bhdashboard.api import DateField, EnumField, InvalidWidgetArgument, \
+                            ListField
+from bhdashboard.util import WidgetBase, check_widget_name, \
+                              dummy_request, merge_links, minmax, \
+                              pretty_wrapper, trac_version, trac_tags
+
+class TicketFieldCloudWidget(WidgetBase):
+    """Display a tag cloud representing frequency of values assigned to 
+    ticket fields.
+    """
+    def get_widget_params(self, name):
+        """Return a dictionary containing arguments specification for
+        the widget with specified name.
+        """
+        return {
+                'field' : {
+                        'desc' : """Target ticket field""",
+                        'required' : True,
+                    },
+                'title' : {
+                        'desc' : """Widget title""",
+                    },
+                'verbose' : {
+                        'desc' : """Show frequency next to each value""",
+                        'default' : False,
+                        'type' : bool, 
+                    },
+                'threshold' : {
+                        'desc' : """Filter items having smaller frequency""",
+                        'type' : int,
+                    },
+                'max' : {
+                        'default' : 0,
+                        'desc' : """Limit the number of items displayed""",
+                        'type' : int
+                    },
+            }
+    get_widget_params = pretty_wrapper(get_widget_params, check_widget_name)
+
+    def render_widget(self, name, context, options):
+        """Count ocurrences of values assigned to given ticket field.
+        """
+        req = context.req
+        params = ('field', 'verbose', 'threshold', 'max', 'title')
+        fieldnm, verbose, threshold, maxitems, title = \
+                self.bind_params(name, options, *params)
+        tsys = self.env[TicketSystem]
+        if tsys is None:
+            raise TracError('Error loading ticket system (disabled?)')
+        for field in tsys.get_ticket_fields():
+            if field['name'] == fieldnm:
+                break
+        else:
+            raise InvalidWidgetArgument('Unknown ticket field %s' % (fieldnm,))
+        if field.get('custom'):
+            sql = "SELECT value, count(value) FROM ticket_custom " \
+                    "WHERE name='%(name)s' GROUP BY value"
+        else:
+            sql = "SELECT %(name)s, count(%(name)s) FROM ticket " \
+                    "GROUP BY %(name)s"
+        sql = sql % field
+        # TODO : Implement threshold and max
+        db = self.env.get_db_cnx()
+        cursor = db.cursor()
+        cursor.execute(sql)
+        items = cursor.fetchall()
+
+        QUERY_COLS = ['id', 'summary', 'owner', 'type', 'status', 'priority']
+        item_link= lambda item: req.href.query(col=QUERY_COLS + [fieldnm], 
+                                                **{fieldnm:item[0]})
+        return 'widget_cloud.html', \
+                {
+                    'title' : title,
+                    'data' : dict(
+                            bounds=minmax(items, lambda x: x[1]),
+                            item_link= item_link,
+                            heading=_(fieldnm.capitalize()),
+                            items=items,
+                            verbose=verbose
+                        ), 
+                }, \
+                context
+
+    render_widget = pretty_wrapper(render_widget, check_widget_name)
+

Propchange: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/ticket.py
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/setup.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/setup.py?rev=1307979&r1=1307978&r2=1307979&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/setup.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/setup.py Sun Apr  1 01:20:08 2012
@@ -107,6 +107,7 @@ ENTRY_POINTS = r"""
                bhdashboard.web_ui = bhdashboard.web_ui
                bhdashboard.widgets.query = bhdashboard.widgets.query
                bhdashboard.widgets.report = bhdashboard.widgets.report
+               bhdashboard.widgets.ticket = bhdashboard.widgets.ticket
                bhdashboard.widgets.timeline = bhdashboard.widgets.timeline
                """
 



Mime
View raw message