##// END OF EJS Templates
Use selected columns in the issues PDF export (#1190)....
Jean-Philippe Lang -
r2736:a49506ce5fa9
parent child
Show More
@@ -110,12 +110,20 module Redmine
110 # Returns a PDF string of a list of issues
110 # Returns a PDF string of a list of issues
111 def issues_to_pdf(issues, project, query)
111 def issues_to_pdf(issues, project, query)
112 pdf = IFPDF.new(current_language)
112 pdf = IFPDF.new(current_language)
113 title = project ? "#{project} - #{l(:label_issue_plural)}" : "#{l(:label_issue_plural)}"
113 title = query.new_record? ? l(:label_issue_plural) : query.name
114 title = "#{project} - #{title}" if project
114 pdf.SetTitle(title)
115 pdf.SetTitle(title)
115 pdf.AliasNbPages
116 pdf.AliasNbPages
116 pdf.footer_date = format_date(Date.today)
117 pdf.footer_date = format_date(Date.today)
117 pdf.AddPage("L")
118 pdf.AddPage("L")
118 row_height = 7
119
120 row_height = 6
121 col_width = []
122 unless query.columns.empty?
123 col_width = query.columns.collect {|column| column.name == :subject ? 4.0 : 1.0 }
124 ratio = 262.0 / col_width.inject(0) {|s,w| s += w}
125 col_width = col_width.collect {|w| w * ratio}
126 end
119
127
120 # title
128 # title
121 pdf.SetFontStyle('B',11)
129 pdf.SetFontStyle('B',11)
@@ -123,44 +131,47 module Redmine
123 pdf.Ln
131 pdf.Ln
124
132
125 # headers
133 # headers
126 pdf.SetFontStyle('B',10)
134 pdf.SetFontStyle('B',8)
127 pdf.SetFillColor(230, 230, 230)
135 pdf.SetFillColor(230, 230, 230)
128 pdf.Cell(15, row_height, "#", 0, 0, 'L', 1)
136 pdf.Cell(15, row_height, "#", 1, 0, 'L', 1)
129 pdf.Cell(30, row_height, l(:field_tracker), 0, 0, 'L', 1)
137 query.columns.each_with_index do |column, i|
130 pdf.Cell(30, row_height, l(:field_status), 0, 0, 'L', 1)
138 pdf.Cell(col_width[i], row_height, column.caption, 1, 0, 'L', 1)
131 pdf.Cell(30, row_height, l(:field_priority), 0, 0, 'L', 1)
139 end
132 pdf.Cell(40, row_height, l(:field_assigned_to), 0, 0, 'L', 1)
133 pdf.Cell(25, row_height, l(:field_updated_on), 0, 0, 'L', 1)
134 pdf.Cell(0, row_height, l(:field_subject), 0, 0, 'L', 1)
135 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
136 pdf.Ln
140 pdf.Ln
137 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
138 pdf.SetY(pdf.GetY() + 1)
139
141
140 # rows
142 # rows
141 pdf.SetFontStyle('',9)
143 pdf.SetFontStyle('',8)
142 pdf.SetFillColor(255, 255, 255)
144 pdf.SetFillColor(255, 255, 255)
143 group = false
145 group = false
144 issues.each do |issue|
146 issues.each do |issue|
145 if query.grouped? && issue.send(query.group_by) != group
147 if query.grouped? && issue.send(query.group_by) != group
146 group = issue.send(query.group_by)
148 group = issue.send(query.group_by)
147 pdf.SetFontStyle('B',10)
149 pdf.SetFontStyle('B',9)
148 pdf.Cell(0, row_height, "#{group.blank? ? 'None' : group.to_s}", 0, 1, 'L')
150 pdf.Cell(277, row_height, "#{group.blank? ? 'None' : group.to_s}", 1, 1, 'L')
149 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
151 pdf.SetFontStyle('',8)
150 pdf.SetY(pdf.GetY() + 0.5)
152 end
151 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
153 pdf.Cell(15, row_height, issue.id.to_s, 1, 0, 'L', 1)
152 pdf.SetY(pdf.GetY() + 1)
154 query.columns.each_with_index do |column, i|
153 pdf.SetFontStyle('',9)
155 s = if column.is_a?(QueryCustomFieldColumn)
156 cv = issue.custom_values.detect {|v| v.custom_field_id == column.custom_field.id}
157 show_value(cv)
158 else
159 value = issue.send(column.name)
160 if value.is_a?(Date)
161 format_date(value)
162 elsif value.is_a?(Time)
163 format_time(value)
164 else
165 value
166 end
154 end
167 end
155 pdf.Cell(15, row_height, issue.id.to_s, 0, 0, 'L', 1)
168 pdf.Cell(col_width[i], row_height, s.to_s, 1, 0, 'L', 1)
156 pdf.Cell(30, row_height, issue.tracker.name, 0, 0, 'L', 1)
169 end
157 pdf.Cell(30, row_height, issue.status.name, 0, 0, 'L', 1)
170 pdf.Ln
158 pdf.Cell(30, row_height, issue.priority.name, 0, 0, 'L', 1)
171 end
159 pdf.Cell(40, row_height, issue.assigned_to ? issue.assigned_to.to_s : '', 0, 0, 'L', 1)
172 if issues.size == Setting.issues_export_limit.to_i
160 pdf.Cell(25, row_height, format_date(issue.updated_on), 0, 0, 'L', 1)
173 pdf.SetFontStyle('B',10)
161 pdf.MultiCell(0, row_height, (project == issue.project ? issue.subject : "#{issue.project} - #{issue.subject}"))
174 pdf.Cell(0, row_height, '...')
162 pdf.Line(10, pdf.GetY, 287, pdf.GetY)
163 pdf.SetY(pdf.GetY() + 1)
164 end
175 end
165 pdf.Output
176 pdf.Output
166 end
177 end
General Comments 0
You need to be logged in to leave comments. Login now