Class: TaskJuggler::ICalReport

Inherits:
ReportBase show all
Defined in:
lib/taskjuggler/reports/ICalReport.rb

Overview

This Report derivative generates iCalendar files.

Instance Method Summary collapse

Methods inherited from ReportBase

#a, #filterAccountList, #filterResourceList, #filterTaskList

Constructor Details

#initialize(report) ⇒ ICalReport

Create a new ICalReport with report as description.



23
24
25
# File 'lib/taskjuggler/reports/ICalReport.rb', line 23

def initialize(report)
  super
end

Instance Method Details

#generateIntermediateFormatObject

Generate an intermediate version of the report data.



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/taskjuggler/reports/ICalReport.rb', line 28

def generateIntermediateFormat
  super
  # Prepare the task list.
  @taskList = PropertyList.new(@project.tasks)
  @taskList.setSorting(a('sortTasks'))
  @taskList = filterTaskList(@taskList, nil, a('hideTask'), a('rollupTask'),
                             a('openNodes'))
  @taskList.sort!

  # Prepare the resource list. This is not yet used.
  @resourceList = PropertyList.new(@project.resources)
  @resourceList.setSorting(a('sortResources'))
  @resourceList = filterResourceList(@resourceList, nil, a('hideResource'),
                                     a('rollupResource'), a('openNodes'))
  @resourceList.sort!

  @query = @report.project.reportContexts.last.query.dup

  @ical = ICalendar.new("#{AppConfig.packageName}-#{@project['projectid']}")
  # Use the project start date of the current date (whichever is earlier)
  # for the calendar creation date.
  @ical.creationDate = [ @report.project['start'], TjTime.new ].min
  # Use the project 'now' date a last modification date.
  @ical.lastModified = @report.project['now']

  # We only care about the first requested scenario.
  scenarioIdx = a('scenarios').first
  uidMap = {}
  @taskList.each do |task|
    todo = ICalendar::Todo.new(
      @ical, "#{task['projectid', scenarioIdx]}-#{task.fullId}",
      task.name, task['start', scenarioIdx], task['end', scenarioIdx])
    # Save the ical UID of this TODO.
    uidMap[task] = todo.uid
    @query.property = task
    @query.attributeId = 'complete'
    @query.scenarioIdx = scenarioIdx
    @query.process
    todo.percentComplete = @query.to_num.to_i
    # We must convert the TJ priority range (1 - 1000) to iCalendar range
    # (0 - 9).
    todo.priority = (task['priority', scenarioIdx] - 1) / 100
    # If there is a parent task and it's known already, we set the
    # relation in the TODO component.
    if task.parent && uidMap[task.parent]
      todo.relatedTo = uidMap[task.parent]
    end
    # If we have a task note, use this for the DESCRIPTION property.
    if (note = task.get('note'))
      note = note.to_s
      todo.description = note
    end
    # Check if we have a responsible resource with an email address. Since
    # ICalendar only knows one organizer we ignore all but the first.
    organizer = nil
    if !(responsible = task['responsible', scenarioIdx]).empty? &&
       @resourceList.include?(organizer = responsible[0]) &&
       organizer.get('email')
      todo.setOrganizer(organizer.name, organizer.get('email'))
    end
    # Set the assigned resources as attendees.
    attendees = []
    task['assignedresources', scenarioIdx].each do |resource|
      next unless @resourceList.include?(resource) &&
                  resource.get('email')
      attendees << resource
      todo.addAttendee(resource.name, resource.get('email'))
    end

    # Generate an additional VEVENT entry for all leaf tasks that aren't
    # milestones.
    if task.leaf? && !task['milestone', scenarioIdx] && @report.get('novevents') == [false]
      event = ICalendar::Event.new(
        @ical, "#{task['projectid', scenarioIdx]}-#{task.fullId}",
        task.name, task['start', scenarioIdx], task['end', scenarioIdx])
      event.description = note if note
      if organizer
        event.setOrganizer(organizer.name, organizer.get('email'))
      end

      attendees.each do |attendee|
        event.addAttendee(attendee.name, attendee.get('email'))
      end
    end

    # Generate VJOURNAL entries for all the journal entries of this task.
    @report.project['journal'].
      entriesByTask(task, a('start'), a('end'),
                    a('hideJournalEntry')).each do |entry|
      journal = ICalendar::Journal.new(
        @ical, "#{task['projectid', scenarioIdx]}-#{task.fullId}",
        entry.headline, entry.date)
      journal.relatedTo = uidMap[task]
      journal.description = entry.summary.to_s + entry.details.to_s
      # Set the author of the journal entry as organizer.
      if (author = entry.author) && @resourceList.include?(author) &&
         author.get('email')
        journal.setOrganizer(author.name, author.get('email'))
      end
    end
  end
end

#to_iCalObject

Convert the intermediate format into a DOS formated String.



132
133
134
# File 'lib/taskjuggler/reports/ICalReport.rb', line 132

def to_iCal
  @ical.to_s
end