You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by gj...@apache.org on 2012/04/01 03:16:16 UTC
svn commit: r1307976 - in /incubator/bloodhound/trunk/bloodhound_dashboard:
bhdashboard/util.py bhdashboard/web_ui.py bhdashboard/widgets/query.py
setup.py
Author: gjm
Date: Sun Apr 1 01:16:16 2012
New Revision: 1307976
URL: http://svn.apache.org/viewvc?rev=1307976&view=rev
Log:
Dashboard code import: BH_Dashboard: Added TicketQueryWidget
Added:
incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.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/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=1307976&r1=1307975&r2=1307976&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/util.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/util.py Sun Apr 1 01:16:16 2012
@@ -28,6 +28,7 @@ from functools import update_wrapper
import inspect
from pkg_resources import get_distribution
from urlparse import urlparse
+from wsgiref.util import setup_testing_defaults
from trac.core import Component, implements
from trac.web.api import Request
@@ -37,11 +38,13 @@ from trac.web.main import RequestDispatc
from bhdashboard.api import DashboardSystem, IWidgetProvider, InvalidIdentifier
def dummy_request(env, uname=None):
- environ = {
- 'trac.base_url' : str(env._abs_href()),
+ environ = {}
+ setup_testing_defaults(environ)
+ environ.update({
'REQUEST_METHOD' : 'GET',
- 'SCRIPT_NAME' : urlparse(str(env._abs_href())).path
- }
+ 'SCRIPT_NAME' : urlparse(str(env._abs_href())).path,
+ 'trac.base_url' : str(env._abs_href()),
+ })
req = Request(environ, lambda *args, **kwds: None)
# Intercept redirection
req.redirect = lambda *args, **kwds: None
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=1307976&r1=1307975&r2=1307976&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:16:16 2012
@@ -103,14 +103,22 @@ class DashboardModule(Component):
chance to customize this at all.
"""
# TODO: Implement dynamic dashboard specification
+ from bhdashboard.widgets.query import TicketQueryWidget
from bhdashboard.widgets.report import TicketReportWidget
from bhdashboard.widgets.timeline import TimelineWidget
ctx = Context.from_request(req)
+ dashboard_query = 'status=accepted&status=assigned&status=new' \
+ '&status=reopened&group=time&col=id&col=summary&col=owner' \
+ '&col=status&col=priority&order=priority&groupdesc=1&desc=1'
widgets_spec = [
{
- 'c' : TicketReportWidget(self.env),
- 'args' : ['TicketReport', ctx, {'args' : {'id' : 3}}]
+ 'c' : TicketQueryWidget(self.env),
+ 'args' : ['TicketQuery', ctx,
+ {'args' : {'max' : 10,
+ 'query' : dashboard_query,
+ 'title' : 'Dashboard'}
+ }]
},
{
'c' : TimelineWidget(self.env),
Added: 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=1307976&view=auto
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.py (added)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.py Sun Apr 1 01:16:16 2012
@@ -0,0 +1,133 @@
+#!/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 report data.
+"""
+
+from cgi import parse_qs
+from datetime import datetime, date, time
+from itertools import count, imap, islice
+
+from genshi.builder import tag
+from trac.core import implements, TracError
+from trac.mimeview.api import Context
+from trac.resource import Resource, ResourceNotFound
+from trac.ticket.query import QueryModule
+from trac.util.translation import _
+from trac.web.api import RequestDone
+
+from bhdashboard.util import WidgetBase, InvalidIdentifier, \
+ check_widget_name, dummy_request, \
+ pretty_wrapper, trac_version, trac_tags
+
+class TicketQueryWidget(WidgetBase):
+ """Display tickets matching a TracQuery using a grid
+ """
+ def get_widget_params(self, name):
+ """Return a dictionary containing arguments specification for
+ the widget with specified name.
+ """
+ return {
+ 'query' : {
+ 'desc' : """Query string""",
+ 'required' : True,
+ },
+ 'max' : {
+ 'default' : 0,
+ 'desc' : """Limit the number of results displayed""",
+ 'type' : int,
+ },
+ 'page' : {
+ 'desc' : """Page number""",
+ 'type' : int,
+ },
+ 'title' : {
+ 'desc' : """Widget title""",
+ },
+ }
+ 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
+ """
+ data = None
+ req = context.req
+ try:
+ params = ('query', 'max', 'page', 'title')
+ qstr, maxrows, page, title = self.bind_params(name, options, *params)
+
+ fakereq = dummy_request(self.env, req.authname)
+ fakereq.args = args = parse_qs(qstr)
+ for k,v in args.items():
+ try:
+ if len(v) == 1:
+ args[k] = v[0]
+ except TypeError:
+ pass
+ args.update({'page' : page, 'max': maxrows})
+
+ qrymdl = self.env[QueryModule]
+ if qrymdl is None :
+ raise TracError('Query module not available (disabled?)')
+ data = qrymdl.process_request(fakereq)[1]
+ except TracError, exc:
+ if data is not None:
+ exc.title = data.get('title', 'TracQuery')
+ raise
+ else:
+ qryctx = Context.from_request(fakereq)
+ query = data['query']
+ idxs = count()
+ headers = [dict(title=h['label'], col=h['name'], hidden=False,
+ asc=h['name'] == query.order and not query.desc) \
+ for h in data['headers']]
+ data.update(
+ dict(header_groups=[headers],
+ numrows=len(data['tickets']),
+ row_groups=[(group_value,
+ [{
+ '__color__' : t['priority_value'],
+ '__idx__' : idxs.next(),
+ 'cell_groups' : [[
+ {
+ 'header' : h,
+ 'index' : hidx,
+ 'value' : t[h['col']]
+ } \
+ for hidx, h in enumerate(headers)]],
+ 'id' : t['id'],
+ 'resource' : Resource('ticket', t['id'])
+ } for t in tickets]) \
+ for group_value, tickets in data['groups'] ]))
+ return 'widget_grid.html', \
+ {
+ 'title' : title or _('Custom Query'),
+ 'data' : data,
+ 'ctxtnav' : [
+ tag.a(_('More'),
+ href=req.abs_href.query() + "?" + qstr)]
+ }, \
+ qryctx
+
+ render_widget = pretty_wrapper(render_widget, check_widget_name)
+
Propchange: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/widgets/query.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=1307976&r1=1307975&r2=1307976&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/setup.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/setup.py Sun Apr 1 01:16:16 2012
@@ -105,7 +105,9 @@ ENTRY_POINTS = r"""
[trac.plugins]
bhdashboard.api = bhdashboard.api
bhdashboard.web_ui = bhdashboard.web_ui
+ bhdashboard.widgets.query = bhdashboard.widgets.query
bhdashboard.widgets.report = bhdashboard.widgets.report
+ bhdashboard.widgets.timeline = bhdashboard.widgets.timeline
"""
setup(