Edgewall Software

Changes between Initial Version and Version 1 of TracDev/PluginDevelopment/ExtensionPoints/trac.timeline.ITimelineEventProvider


Ignore:
Timestamp:
Nov 9, 2014, 1:04:40 PM (9 years ago)
Author:
Peter Suter
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PluginDevelopment/ExtensionPoints/trac.timeline.ITimelineEventProvider

    v1 v1  
     1== Extension Point : ''ITimelineEventProvider'' ==
     2
     3||'''Interface'''||''ITimelineEventProvider''||'''Since'''||0.9||
     4||'''Module'''||''trac.timeline.api''||'''Source'''||[source:trunk/trac/timeline/api.py#/ITimelineEventProvider api.py]||
     5
     6The ''ITimelineEventProvider'' allows components to provide events listed in the TracTimeline.
     7
     8== Purpose ==
     9The timeline provides a historic view of the project in a single report. It lists all Trac events that have occurred in chronological order, a brief description of each event and if applicable, the person responsible for the change. Plugins can hook into the timeline system to extend the set of events that can be viewed.
     10
     11The main purpose for this interface is to allow plugins to query any source (e.g. new DB tables) for such new event types (e.g. for changes of new resources).
     12
     13== Usage ==
     14
     15Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment].
     16
     17Trac automatically calls the `get_timeline_filters` method to retrieve a list of filters displayed in the option panel.
     18
     19Trac then calls `get_timeline_events` to query the set of events of a given filter in the selected time frame.
     20
     21Finally `render_timeline_event` is called for each event field separately.
     22
     23== Examples ==
     24
     25The following example uses the pypi:feedparser library to parse the RSS feed of the ''Trac-Announce'' MailingList.
     26
     27{{{#!python
     28import feedparser
     29
     30from genshi.builder import tag
     31
     32from trac.core import Component, implements
     33from trac.timeline.api import ITimelineEventProvider
     34from trac.util.datefmt import parse_date
     35
     36
     37class TracAnnounceFeedTimelineProvider(Component):
     38    implements(ITimelineEventProvider)
     39
     40    url = 'https://groups.google.com/forum/feed/trac-announce/msgs/rss_v2_0.xml?num=50'
     41
     42    def get_timeline_filters(self, req):
     43        yield 'trac-announce-feed', "Trac announcements"
     44
     45    def get_timeline_events(self, req, start, stop, filters):
     46        if 'trac-announce-feed' in filters:
     47            feed = feedparser.parse(self.url)
     48            for post in feed.entries:
     49                date = parse_date(post.published)
     50                if start <= date and date <= stop:
     51                    yield 'feed-event', date, post.author, post
     52
     53    def render_timeline_event(self, context, field, event):
     54        post = event[3]
     55        if field == 'url':
     56            return post.links[0]['href']
     57        elif field == 'title':
     58            return tag.em(post.title)
     59        elif field == 'description':
     60            return post.summary
     61}}}
     62
     63== Available Implementations ==
     64
     65* `trac.ticket.roadmap.MilestoneModule`: Provides ''milestone completed'' and ''milestone attachment'' events.
     66* `trac.ticket.web_ui.TicketModule`: Provides ''ticket opened'' and ''closed'', ''ticket updated'' and ''ticket attachment'' events.
     67* `trac.versioncontrol.web_ui.changeset.ChangesetModule`: Provides ''changeset'' events.
     68* `trac.wiki.web_ui.WikiModule`: Provides ''wiki page changed'' and ''wiki page attachment'' events.
     69
     70* th:FullBlogPlugin: Provides ''new blog post'', ''blog comment'' and ''blog attachment'' events.
     71* th:DiscussionPlugin: Provides ''new forum'', ''new discussion'' and ''new reply'' events.
     72* th:DownloadsPlugin: Provides ''new download'' events.
     73* th:ScreenshotsPlugin: Provides ''new screenshot'' events.
     74* th:PeerReviewPlugin: Provides ''new code review'' events.
     75* th:ExoWebCodeReviewPlugin: Provides ''code review created'', ''edited'' and ''completed'' events.
     76* th:TracPastePlugin: Provides ''pastebin change'' events.
     77* th:SensitiveTicketsPlugin: Provides ''sensitive ticket'' events (only to users with relevant permissions).
     78* th:WorkLogPlugin: Provides ''work started'' and ''ended'' events.
     79* th:BambooTracPlugin: Provides ''Bamboo build successful'' and ''failed'' events.
     80* th:TeamcityPluginIntegration: Provides ''Teamcity build successful'' and ''failed'' events.
     81* th:LuntbuildTracIntegration: Provides ''Luntbuild build successful'' and ''failed'' events.
     82
     83== Additional Information and References ==
     84
     85 * [apiref:trac.timeline.api.ITimelineEventProvider-class epydoc]
     86 * [apidoc:api/trac_timeline_api#trac.timeline.api.ITimelineEventProvider API Reference]
     87
     88=== API History
     89 * 0.9 introduced the interface
     90 * [wiki:TracDev/ApiChanges/0.11#ITimelineEventProvider 0.11] changed the interface considerably
     91    * Moved to the `trac.timeline` (all lowercase) package.
     92    * Changed `start` and `stop` arguments to `datetime` objects.
     93    * Changed return value to tuple with `data` dictionary.
     94    * Introduced `render_timeline_event()` method.