Modify

Opened 5 years ago

Last modified 5 years ago

#13554 new enhancement

Integration with TracJsGanttPlugin

Reported by: M. Awater <marco.awater@…> Owned by: Chris Nelson
Priority: normal Component: TeamCalendarPlugin
Severity: normal Keywords:
Cc: Trac Release: 1.2

Description

The TracJsGanttPlugin documentation mentions it can be used in combination with the TeamCalendar plugin. However, I found the required code didn't (yet) exist.

We've added the following code to the end of calender.py to integrate the two plugins with one another. See also #13553.

##########################################################
# TracJSGantt integration
#    TracJSGantt looks for any alternate IResourceCalendar
#    implementations via a Trac ExtensionPoint. 
#    Any such implementations automatically override 
#    the default (SimpleCalendar).
##########################################################

from trac.core import ExtensionPoint
from tracjsgantt.pmapi import IResourceCalendar


class AvailabilityCalendar(Component):
    implements(IResourceCalendar)

    def __init__(self):
        self.env.log.debug('Creating team availability calendar')
        # No further init code

    def hoursAvailable(self, date, resource=None):
        self.env.log.debug('Getting available hours for "%s" on "%s"', resource, date)

        # If there is no owner for a ticket, the resource passed is an empty string.
        # There is of course no availability info for an empty string, so skip the DB query.
        if len(resource) > 0:
            # Look up availability data for the resource
            utc_dt = to_utc_utimestamp(date)
            db_results = self.env.db_query("""
                             SELECT time, username, availability
                             FROM team_calendar
                             WHERE time = {} and username = '{}'
                             """.format(utc_dt, resource) )
        else:
            # No resource specified
            db_results = []

        # Check availability of the resource
        if len(db_results) > 0:
            self.env.log.debug('Availability data for "%s" on "%s": "%s"', resource, date, db_results[0][2])
            if db_results[0][2]:
                hours = 8.0  # Person is available
            else:
                hours = 0    # Person is not available
        
        else:
            self.env.log.debug('No availability data for "%s" on  "%s"', resource, date)
            self.env.log.debug('Using default: available for 8 hours on all weekdays')

            # No hours on weekends
            if date.weekday() > 4:
                hours = 0
            # 8 hours on week days
            else:
                hours = 8.0

        return hours

It provides an alternative IResourceCalendar implementation (AvailabilityCalendar) which takes into account the availability information entered from the TeamCalendar plugin. The TracJSGantt plugin automatically uses it instead of the default implementation (SimpleCalendar).

If desired, this could be added as an enhancement to the TeamCalendar plugin.

Attachments (0)

Change History (0)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as new The owner will remain Chris Nelson.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.