﻿ticket,summary,type,release,owner,status,created,modified,_description,_reporter
9924,Display Team Calendar as a calendar,enhancement,0.11,Chris Nelson,new,2012-03-26T21:52:04+02:00,2012-03-26T21:52:11+02:00,"That is, one week per row with resources stacked in each day.",Chris Nelson
13554,Integration with TracJsGanttPlugin,enhancement,1.2,Chris Nelson,new,2019-04-30T11:14:20+02:00,2019-06-18T13:21:52+02:00,"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.

{{{#!python
##########################################################
# 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.",M. Awater <marco.awater@…>
