Class: TaskJuggler::ReportTableCell
- Defined in:
- lib/taskjuggler/reports/ReportTableCell.rb
Overview
This class models the output format independent version of a cell in a TableReport. It belongs to a certain ReportTableLine and ReportTableColumn. Normally a cell contains text on a colored background. By help of the @special variable it can alternatively contain any object the provides the necessary output methods such as to_html.
Instance Attribute Summary collapse
-
#alignment ⇒ Object
Returns the value of attribute alignment.
-
#bold ⇒ Object
Returns the value of attribute bold.
-
#category ⇒ Object
Returns the value of attribute category.
-
#cellColor ⇒ Object
Returns the value of attribute cellColor.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#data ⇒ Object
Returns the value of attribute data.
-
#fontColor ⇒ Object
Returns the value of attribute fontColor.
-
#fontSize ⇒ Object
Returns the value of attribute fontSize.
-
#force_string ⇒ Object
Returns the value of attribute force_string.
-
#hidden ⇒ Object
Returns the value of attribute hidden.
-
#icon ⇒ Object
Returns the value of attribute icon.
-
#iconTooltip ⇒ Object
Returns the value of attribute iconTooltip.
-
#indent ⇒ Object
Returns the value of attribute indent.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#padding ⇒ Object
Returns the value of attribute padding.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#showTooltipHint ⇒ Object
Returns the value of attribute showTooltipHint.
-
#special ⇒ Object
Returns the value of attribute special.
-
#text ⇒ Object
Returns the value of attribute text.
-
#tooltip ⇒ Object
Returns the value of attribute tooltip.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
-
#==(c) ⇒ Object
Return true if two cells are similar enough so that they can be merged in the report to a single, wider cell.
-
#initialize(line, query, text = nil, headerCell = false) ⇒ ReportTableCell
constructor
Create the ReportTableCell object and initialize the attributes to some default values.
-
#to_csv(csv, columnIdx, lineIdx) ⇒ Object
Add the text content of the cell to an Array of Arrays form of the table.
-
#to_html ⇒ Object
Turn the abstract cell representation into an HTML element tree.
Constructor Details
#initialize(line, query, text = nil, headerCell = false) ⇒ ReportTableCell
Create the ReportTableCell object and initialize the attributes to some default values. line is the ReportTableLine this cell belongs to. text is the text that should appear in the cell. headerCell is a flag that must be true only for table header cells.
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 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 36 def initialize(line, query, text = nil, headerCell = false) @line = line @line.addCell(self) if line # Specifies whether this is a header cell or not. @headerCell = headerCell # A copy of a Query object that is needed to access project data via the # query function. @query = query ? query.dup : nil # The cell textual content. This may be a String or a # RichTextIntermediate object. self.text = text || +'' # A custom text for the tooltip. @tooltip = nil # Determines if the tooltip is triggered by an special hinting icon or # the whole cell. @showTooltipHint = true # The original data of the cell content (optional, nil if not provided) @data = nil # Determines the background color of the cell. @category = nil # True of the cell is hidden (because other cells span multiple rows or # columns) @hidden = false # How to horizontally align the cell @alignment = :center # Horizontal padding between frame and cell content @padding = 3 # Don't convert Strings that look like numbers to String @force_string = false # Whether or not to indent the cell. If not nil, it is an Integer # indicating the indentation level. @indent = nil # The basename of the icon file @icon = nil # A custom tooltip for the cell icon @iconTooltip = nil # Font size of the cell text in pixels @fontSize = nil # The background color of the cell. Overwrite the @category color. @cellColor = nil # The color of the cell text font. @fontColor = nil # True of a bold font is to be used for the cell text. @bold = false # The width of the column in pixels @width = nil # The number of rows the cell spans @rows = 1 # The number of columns the cell spans @columns = 1 # Ignore everything and use this reference to generate the output. @special = nil end |
Instance Attribute Details
#alignment ⇒ Object
Returns the value of attribute alignment.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def alignment @alignment end |
#bold ⇒ Object
Returns the value of attribute bold.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def bold @bold end |
#category ⇒ Object
Returns the value of attribute category.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def category @category end |
#cellColor ⇒ Object
Returns the value of attribute cellColor.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def cellColor @cellColor end |
#columns ⇒ Object
Returns the value of attribute columns.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def columns @columns end |
#data ⇒ Object
Returns the value of attribute data.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def data @data end |
#fontColor ⇒ Object
Returns the value of attribute fontColor.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def fontColor @fontColor end |
#fontSize ⇒ Object
Returns the value of attribute fontSize.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def fontSize @fontSize end |
#force_string ⇒ Object
Returns the value of attribute force_string.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def force_string @force_string end |
#hidden ⇒ Object
Returns the value of attribute hidden.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def hidden @hidden end |
#icon ⇒ Object
Returns the value of attribute icon.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def icon @icon end |
#iconTooltip ⇒ Object
Returns the value of attribute iconTooltip.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def iconTooltip @iconTooltip end |
#indent ⇒ Object
Returns the value of attribute indent.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def indent @indent end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
24 25 26 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 24 def line @line end |
#padding ⇒ Object
Returns the value of attribute padding.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def padding @padding end |
#rows ⇒ Object
Returns the value of attribute rows.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def rows @rows end |
#showTooltipHint ⇒ Object
Returns the value of attribute showTooltipHint.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def showTooltipHint @showTooltipHint end |
#special ⇒ Object
Returns the value of attribute special.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def special @special end |
#text ⇒ Object
Returns the value of attribute text.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def text @text end |
#tooltip ⇒ Object
Returns the value of attribute tooltip.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def tooltip @tooltip end |
#width ⇒ Object
Returns the value of attribute width.
25 26 27 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 25 def width @width end |
Instance Method Details
#==(c) ⇒ Object
Return true if two cells are similar enough so that they can be merged in the report to a single, wider cell. c is the cell to compare this cell with.
94 95 96 97 98 99 100 101 102 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 94 def ==(c) @text == c.text && @tooltip == c.tooltip && @alignment == c.alignment && @padding == c.padding && @indent == c.indent && @cellColor == c.cellColor && @category == c.category end |
#to_csv(csv, columnIdx, lineIdx) ⇒ Object
Add the text content of the cell to an Array of Arrays form of the table.
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 158 def to_csv(csv, columnIdx, lineIdx) # We only support left indentation in CSV files as the spaces for right # indentation will be disregarded by most applications. indent = @indent && @alignment == :left ? ' ' * @indent : +'' columns = 1 if @special # This is for nested tables. They will be inserted as whole columns # in the existing table. csv[lineIdx][columnIdx] = nil columns = @special.to_csv(csv, columnIdx) else cell = if @data && @data.is_a?(String) @data elsif @text if @text.respond_to?('functionHandler') @text.setQuery(@query) end str = @text.to_s # Remove any trailing line breaks. These don't really make much # sense in CSV files. while str[-1] == ?\n str.chomp! end str end # Try to convert numbers and other types to their native Ruby type if # they are supported by CSVFile. native = @force_string ? cell : CSVFile.strToNative(cell) # Only for String objects, we add the indentation. csv[lineIdx][columnIdx] = (native.is_a?(String) && !@force_string ? indent + native : native) end return columns end |
#to_html ⇒ Object
Turn the abstract cell representation into an HTML element tree.
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 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/taskjuggler/reports/ReportTableCell.rb', line 105 def to_html return nil if @hidden return @special.to_html if @special # Determine cell attributes attribs = { } attribs['rowspan'] = "#{@rows}" if @rows > 1 attribs['colspan'] = "#{@columns}" if @columns > 1 attribs['class'] = @category ? @category : 'tabcell' style = +'' style += "background-color: #{@cellColor}; " if @cellColor attribs['style'] = style unless style.empty? cell = XMLElement.new('td', attribs) cell << (table = XMLElement.new('table', 'class' => @category ? 'tj_table_cell' : 'tj_table_header_cell', 'cellspacing' => '0', 'style' => cellStyle)) table << (row = XMLElement.new('tr')) calculateIndentation # Insert a padding cell for the left side indentation. if @leftIndent && @leftIndent > 0 row << XMLElement.new('td', 'style' => "width:#{@leftIndent}px; ") end row << cellIcon(cell) labelDiv, tooltip = cellLabel row << labelDiv # Overwrite the tooltip if the user has specified a custom tooltip. tooltip = @tooltip if @tooltip if tooltip && !tooltip.empty? && !selfcontained if @showTooltipHint row << (td = XMLElement.new('td')) td << XMLElement.new('img', 'src' => "#{auxDir}icons/details.png", 'class' => 'tj_table_cell_tooltip') addHtmlTooltip(tooltip, td, cell) else addHtmlTooltip(tooltip, cell) end end # Insert a padding cell for the right side indentation. if @rightIndent && @rightIndent > 0 row << XMLElement.new('td', 'style' => "width:#{@rightIndent}px; ") end cell end |