Class: TaskJuggler::Navigator
- Defined in:
- lib/taskjuggler/reports/Navigator.rb
Overview
A Navigator is an automatically generated menu to navigate a list of reports. The hierarchical structure of the reports will be reused to group them. The actual structure of the Navigator depends on the output format.
Instance Attribute Summary collapse
-
#hideReport ⇒ Object
Returns the value of attribute hideReport.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
-
#generate(allReports, currentReports, reportDef, parentElement) ⇒ Object
Generate an output format independant version of the navigator.
-
#initialize(id, project) ⇒ Navigator
constructor
A new instance of Navigator.
- #to_html ⇒ Object
Constructor Details
#initialize(id, project) ⇒ Navigator
Returns a new instance of Navigator.
105 106 107 108 109 110 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 105 def initialize(id, project) @id = id @project = project @hideReport = LogicalExpression.new(LogicalOperation.new(0)) @elements = [] end |
Instance Attribute Details
#hideReport ⇒ Object
Returns the value of attribute hideReport.
103 104 105 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 103 def hideReport @hideReport end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
102 103 104 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 102 def id @id end |
Instance Method Details
#generate(allReports, currentReports, reportDef, parentElement) ⇒ Object
Generate an output format independant version of the navigator. This is a tree of NavigatorElement objects.
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 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 114 def generate(allReports, currentReports, reportDef, parentElement) element = nextParentElement = nextParentReport = nil currentReports.each do |report| hasURL = report.get('formats').include?(:html) # Only generate menu entries for container reports or leaf reports # have a HTML output format. next if (report.leaf? && !hasURL) || !allReports.include?(report) # What label should be used for the menu entry? It's either the name # of the report or the user specified title. label = report.get('title') || report.name url = findReportURL(report, allReports, reportDef) # Now we have all data so we can create the actual menu entry. parentElement.elements << (element = NavigatorElement.new(parentElement, label, url)) # Check if 'report' matches the 'reportDef' report or is a child of # it. if reportDef == report || reportDef.isChildOf?(report) nextParentReport = report nextParentElement = element element.current = true end end if nextParentReport && nextParentReport.container? generate(allReports, nextParentReport.kids, reportDef, nextParentElement) end end |
#to_html ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/taskjuggler/reports/Navigator.rb', line 147 def to_html # The the Report object that contains this Navigator. reportDef ||= @project.reportContexts.last.report raise "Report context missing" unless reportDef # Compile a list of all reports that the user wants to include in the # menu. reports = filterReports return nil if reports.empty? # Make sure the report is actually in the filtered list. unless reports.include?(reportDef) @project.warning('nav_in_hidden_rep', "Navigator requested for a report that is not " + "included in the navigator list.", reportDef.sourceFileInfo) return nil end # Find the list of reports that become the top-level menu entries. topLevelReports = [ reportDef ] report = reportDef while report.parent report = report.parent topLevelReports = report.kids end generate(reports, topLevelReports, reportDef, content = NavigatorElement.new(nil)) content.to_html end |