Class: TaskJuggler::TableReport

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

Overview

This is base class for all types of tabular reports. All tabular reports are converted to an abstract (output independent) intermediate form first, before the are turned into the requested output format.

Direct Known Subclasses

AccountListRE, ResourceListRE, TaskListRE

Constant Summary collapse

@@propertiesById =
{
  # ID                   Header                   Indent  Align   Scen Spec.
  'activetasks'       => [ 'Active Tasks',         true,   :right, true ],
  'annualleave'       => [ 'Annual Leave',         true,   :right, true ],
  'annualleavebalance'=> [ 'Annual Leave Balance', false,  :right, true ],
  'annualleavelist'   => [ 'Annual Leave List',    false,  :left,  true ],
  'alert'             => [ 'Alert',                true,   :left,  false ],
  'alertmessages'     => [ 'Alert Messages',       false,  :left,  false ],
  'alertsummaries'    => [ 'Alert Summaries',      false,  :left,  false ],
  'alerttrend'        => [ 'Alert Trend',          false,  :left,  false ],
  'balance'           => [ 'Balance',              true,   :right, true ],
  'bsi'               => [ 'BSI',                  false,  :left,  false ],
  'children'          => [ 'Children'    ,         false,  :left,  false ],
  'closedtasks'       => [ 'Closed Tasks',         true,   :right, true ],
  'competitorcount'   => [ 'Competitor count',     true,   :right, true ],
  'competitors'       => [ 'Competitors',          true,   :left,  true ],
  'complete'          => [ 'Completion',           false,  :right, true ],
  'cost'              => [ 'Cost',                 true,   :right, true ],
  'duration'          => [ 'Duration',             true,   :right, true ],
  'effort'            => [ 'Effort',               true,   :right, true ],
  'effortdone'        => [ 'Effort Done',          true,   :right, true ],
  'effortleft'        => [ 'Effort Left',          true,   :right, true ],
  'freetime'          => [ 'Free Time',            true,   :right, true ],
  'freework'          => [ 'Free Work',            true,   :right, true ],
  'followers'         => [ 'Followers',            false,  :left,  true ],
  'fte'               => [ 'FTE',                  true,   :right, true ],
  'headcount'         => [ 'Headcount',            true,   :right, true ],
  'id'                => [ 'Id',                   false,  :left,  false ],
  'inputs'            => [ 'Inputs',               false,  :left,  true ],
  'journal'           => [ 'Journal',              false,  :left,  false ],
  'journal_sub'       => [ 'Journal',              false,  :left,  false ],
  'journalmessages'   => [ 'Journal Messages',     false,  :left,  false ],
  'journalsummaries'  => [ 'Journal Summaries',    false,  :left,  false ],
  'line'              => [ 'Line No.',             false,  :right, false ],
  'name'              => [ 'Name',                 true,   :left,  false ],
  'no'                => [ 'No.',                  false,  :right, false ],
  'opentasks'         => [ 'Open Tasks',           true,   :right, true ],
  'precursors'        => [ 'Precursors',           false,  :left,  true ],
  'rate'              => [ 'Rate',                 true,   :right, true ],
  'resources'         => [ 'Resources',            false,  :left,  true ],
  'responsible'       => [ 'Responsible',          false,  :left,  true ],
  'revenue'           => [ 'Revenue',              true,   :right, true ],
  'scenario'          => [ 'Scenario',             false,  :left,  true ],
  'scheduling'        => [ 'Scheduling Mode',      true,   :left,  true ],
  'sickleave'         => [ 'Sick Leave',           true,   :right, true ],
  'specialleave'      => [ 'Special Leave',        true,   :right, true ],
  'status'            => [ 'Status',               false,  :left,  true ],
  'targets'           => [ 'Targets',              false,  :left,  true ],
  'unpaidleave'       => [ 'Unpaid Leave',         true,   :right, true ]
}
@@propertiesByType =
{
  # Type                     Indent  Align
  DateAttribute         => [ false,  :left ],
  IntegerAttribute       => [ false,  :right ],
  FloatAttribute        => [ false,  :right ],
  ResourceListAttribute => [ false, :left ],
  RichTextAttribute     => [ false,  :left ],
  StringAttribute       => [ false,  :left ]
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ReportBase

#a, #filterAccountList, #filterResourceList, #filterTaskList

Constructor Details

#initialize(report) ⇒ TableReport

Generate a new TableReport object.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/taskjuggler/reports/TableReport.rb', line 91

def initialize(report)
  super
  @report.content = self

  # Reference to the intermediate representation.
  @table = nil
  # The table is generated row after row. We need to hold some computed
  # values that are specific to certain columns. For that we use a Hash of
  # ReportTableColumn objects.
  @columns = { }

  @legend = ReportTableLegend.new

end

Instance Attribute Details

#legendObject (readonly)

Returns the value of attribute legend.



29
30
31
# File 'lib/taskjuggler/reports/TableReport.rb', line 29

def legend
  @legend
end

Class Method Details

.alignment(colId, attributeType) ⇒ Object

Return the alignment of the column based on the colId or the attributeType.



180
181
182
183
184
185
186
187
188
# File 'lib/taskjuggler/reports/TableReport.rb', line 180

def TableReport::alignment(colId, attributeType)
  if @@propertiesById.has_key?(colId)
    return @@propertiesById[colId][2]
  elsif @@propertiesByType.has_key?(attributeType)
    return @@propertiesByType[attributeType][1]
  else
    :center
  end
end

.calculated?(colId) ⇒ Boolean

This function returns true if the values for the colId column need to be calculated.

Returns:

  • (Boolean)


192
193
194
# File 'lib/taskjuggler/reports/TableReport.rb', line 192

def TableReport::calculated?(colId)
  return @@propertiesById.has_key?(colId)
end

.defaultColumnTitle(id) ⇒ Object

Returns the default column title for the columns id.



156
157
158
159
160
161
162
163
164
# File 'lib/taskjuggler/reports/TableReport.rb', line 156

def TableReport::defaultColumnTitle(id)
  # Return an empty string for some special columns that don't have a fixed
  # title.
  specials = %w( chart hourly daily weekly monthly quarterly yearly)
  return '' if specials.include?(id)

  # Return the title for build-in hardwired columns.
  @@propertiesById.include?(id) ? @@propertiesById[id][0] : nil
end

.indent(colId, propertyType) ⇒ Object

Return if the column values should be indented based on the colId or the propertyType.



168
169
170
171
172
173
174
175
176
# File 'lib/taskjuggler/reports/TableReport.rb', line 168

def TableReport::indent(colId, propertyType)
  if @@propertiesById.has_key?(colId)
    return @@propertiesById[colId][1]
  elsif @@propertiesByType.has_key?(propertyType)
    return @@propertiesByType[propertyType][0]
  else
    false
  end
end

.scenarioSpecific?(colId) ⇒ Boolean

This functions returns true if the values for the col_id column are scenario specific.

Returns:

  • (Boolean)


198
199
200
201
202
203
# File 'lib/taskjuggler/reports/TableReport.rb', line 198

def TableReport::scenarioSpecific?(colId)
  if @@propertiesById.has_key?(colId)
    return @@propertiesById[colId][3]
  end
  return false
end

Instance Method Details

#generateIntermediateFormatObject



106
107
108
# File 'lib/taskjuggler/reports/TableReport.rb', line 106

def generateIntermediateFormat
  super
end

#to_csvObject

Convert the table into an Array of Arrays. It has one Array for each line. The nested Arrays have one String for each column.



151
152
153
# File 'lib/taskjuggler/reports/TableReport.rb', line 151

def to_csv
  @table.to_csv
end

#to_htmlObject

Turn the TableReport into an equivalent HTML element tree.



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/taskjuggler/reports/TableReport.rb', line 111

def to_html
  html = []

  html << XMLComment.new("Dynamic Report ID: " +
                         "#{@report.project.reportContexts.last.
                            dynamicReportId}")
  html << rt_to_html('header')
  html << (tableFrame = generateHtmlTableFrame)

  # Now generate the actual table with the data.
  tableFrame << generateHtmlTableRow do
    td = XMLElement.new('td')
    td << @table.to_html
    td
  end

  # Embedd the caption as RichText into the table footer.
  if a('caption')
    tableFrame << generateHtmlTableRow do
      td = XMLElement.new('td')
      td << (div = XMLElement.new('div', 'class' => 'tj_table_caption'))
      a('caption').sectionNumbers = false
      div << a('caption').to_html
      td
    end
  end

  # The legend.
  tableFrame << generateHtmlTableRow do
    td = XMLElement.new('td')
    td << @legend.to_html
    td
  end

  html << rt_to_html('footer')
  html
end