Class: TaskJuggler::ReportContext

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/reports/ReportContext.rb

Overview

The ReportContext objects provide some settings that are used during the generation of a report. Reports can be nested, so multiple objects can exist at a time. But there is only one current ReportContext that is always accessable via Project.reportContexts.last().

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project, report) ⇒ ReportContext

Returns a new instance of ReportContext.



25
26
27
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
# File 'lib/taskjuggler/reports/ReportContext.rb', line 25

def initialize(project, report)
  @project = project
  @report = report
  @childReportCounter = 0
  @attributeBackup = nil
  queryAttrs = {
    'project' => @project,
    'loadUnit' => @report.get('loadUnit'),
    'numberFormat' => @report.get('numberFormat'),
    'timeFormat' => @report.get('timeFormat'),
    'currencyFormat' => @report.get('currencyFormat'),
    'start' => @report.get('start'), 'end' => @report.get('end'),
    'hideJournalEntry' => @report.get('hideJournalEntry'),
    'journalMode' => @report.get('journalMode'),
    'journalAttributes' => @report.get('journalAttributes'),
    'sortJournalEntries' => @report.get('sortJournalEntries'),
    'costAccount' => @report.get('costaccount'),
    'revenueAccount' => @report.get('revenueaccount')
  }
  @query = Query.new(queryAttrs)
  if (@parent = @project.reportContexts.last)
    # For interactive reports we need some ID that uniquely identifies the
    # report within the composed report. Since a project report can be
    # included multiple times in the same report, we need to generate
    # another ID for each instantiated report. We create this report by
    # using a counter for the number of child reports that each report
    # has. The unique ID is then the concatenated list of counters from
    # parent to leaf, separating each value by a '.'.
    @dynamicReportId = @parent.dynamicReportId +
                       ".#{@parent.childReportCounter}"
    @parent.childReportCounter += 1
    # If the new ReportContext is created from within an existing context,
    # this is used as parent context and the settings are copied as
    # default initial values.
    @tasks = @parent.tasks.dup
    @resources = @parent.resources.dup
  else
    # The ID of the root report is always "0". The first child will then
    # be "0.0", the seconds "0.1" and so on.
    @dynamicReportId = "0"
    # There is no existing ReportContext yet, so we create one based on
    # the settings of the report.
    @tasks = @project.tasks.dup
    @resources = @project.resources.dup
  end
end

Instance Attribute Details

#attributeBackupObject

Returns the value of attribute attributeBackup.



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

def attributeBackup
  @attributeBackup
end

#childReportCounterObject

Returns the value of attribute childReportCounter.



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

def childReportCounter
  @childReportCounter
end

#dynamicReportIdObject (readonly)

Returns the value of attribute dynamicReportId.



22
23
24
# File 'lib/taskjuggler/reports/ReportContext.rb', line 22

def dynamicReportId
  @dynamicReportId
end

#projectObject (readonly)

Returns the value of attribute project.



22
23
24
# File 'lib/taskjuggler/reports/ReportContext.rb', line 22

def project
  @project
end

#queryObject (readonly)

Returns the value of attribute query.



22
23
24
# File 'lib/taskjuggler/reports/ReportContext.rb', line 22

def query
  @query
end

#reportObject (readonly)

Returns the value of attribute report.



22
23
24
# File 'lib/taskjuggler/reports/ReportContext.rb', line 22

def report
  @report
end

#resourcesObject

Returns the value of attribute resources.



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

def resources
  @resources
end

#tasksObject

Returns the value of attribute tasks.



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

def tasks
  @tasks
end