| 1 | {{{#!box info |
| 2 | Status: Proposed in #12156 |
| 3 | }}} |
| 4 | |
| 5 | == Extension Point : ''ITicketQueryRenderer'' == |
| 6 | |
| 7 | ||'''Interface'''||''ITicketQueryRenderer''||'''Since'''||[wiki:TracDev/ApiChanges/1.2#ITicketQueryRenderer 1.2]|| |
| 8 | ||'''Module'''||''trac.ticket''||'''Source'''||[source:trunk/trac/ticket/api.py#/ITicketQueryRenderer api.py]|| |
| 9 | |
| 10 | |
| 11 | The ''ITicketQueryRenderer'' visualizes [TracQuery query] results in various ways. |
| 12 | |
| 13 | == Purpose == |
| 14 | |
| 15 | Trac provides an extensive TracQuery system with an interactive UI, a special [TracQuery#QueryLanguage query language], a [TicketQuery wiki macro] and more. Typically the results of a query would be displayed as a table of tickets in the interactive UI. The wiki macro already supported various hardcoded formats including a similar table view, a simple ticket list or count and roadmap-style progress bars. |
| 16 | |
| 17 | With this interface plugins can extend the list of available visualization formats to for example display the queried tickets in pie diagrams, burndown charts, Kanban boards etc. |
| 18 | |
| 19 | These renderers could be available wherever ticket queries are visualized, like in the interactive query UI or the roadmap view. |
| 20 | |
| 21 | == Usage == |
| 22 | |
| 23 | Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment]. |
| 24 | |
| 25 | A simple `get_ticket_query_formats()` method lists the internal and display names of the supported formats. The `render_ticket_query()` is called to render a given ticket query to HTML. |
| 26 | |
| 27 | == Examples == |
| 28 | |
| 29 | The following minimal example renders a warning sign if a query finds any tickets: |
| 30 | {{{#!python |
| 31 | from genshi import tag |
| 32 | from trac.core import implements, Component |
| 33 | from trac.ticket.api import ITicketQueryRenderer |
| 34 | |
| 35 | class WarningTicketQueryRenderer(Component): |
| 36 | |
| 37 | implements(ITicketQueryRenderer) |
| 38 | |
| 39 | def get_ticket_query_formats(self): |
| 40 | yield ('warning', _("Warning Sign")) |
| 41 | |
| 42 | def render_ticket_query(self, context, query, query_string, tickets, format): |
| 43 | if tickets: |
| 44 | return tag.span(u"\u26A0") # Warning sign |
| 45 | else: |
| 46 | return tag.span(u"\u2713") # Check mark |
| 47 | }}} |
| 48 | |
| 49 | == Available Implementations == |
| 50 | |
| 51 | * [source:trunk/trac/ticket/query.py#/QueryModule trac.ticket.query.QueryModule] implements the table format. |
| 52 | * [source:trunk/trac/ticket/roadmap.py#/RoadmapModule trac.ticket.roadmap.RoadmapModule] implements the progress format. |
| 53 | |
| 54 | == Additional Information and References == |
| 55 | |
| 56 | * [apiref:trac.ticket.api.ITicketQueryRenderer-class epydoc] |
| 57 | * [apidoc:api/trac_ticket#trac.ticket.api.ITicketQueryRenderer API Reference] |
| 58 | |
| 59 | * Related to the [[wiki:TracDev/PluginDevelopment/ExtensionPoints/trac.ticket.roadmap.ITicketGroupStatsProvider]] interface. |
| 60 | |
| 61 | === History |
| 62 | * [wiki:TracDev/ApiChanges/1.2#ITicketQueryRenderer 1.2]: Introduced (#12156) |