Project

General

Profile

RE: Issue Closed Date » экспорт_в_csv.patch

Alexander Kulemin, 2011-07-14 04:51

View differences:

app/controllers/issues_controller.rb (working copy)
84 84
        format.xml  { render :layout => false }
85 85
        format.json { render :text => @issues.to_json, :layout => false }
86 86
        format.atom { render_feed(@issues, :title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}") }
87
        format.csv  { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
87
#        format.csv  { send_data(issues_to_csv(@issues, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
88
        format.csv  { send_data(issues_to_csv_query(@issues, @query, @project), :type => 'text/csv; header=present', :filename => 'export.csv') }
88 89
        format.pdf  { send_data(issues_to_pdf(@issues, @project, @query), :type => 'application/pdf', :filename => 'export.pdf') }
89 90
      end
90 91
    else
app/helpers/issues_helper.rb (working copy)
175 175
      return record.name if record
176 176
    end
177 177
  end
178
  
178

  
179
#??????? ? csv ? ?????? ?????????? ???????
180
 def issues_to_csv_query(issues, query, project = nil)
181
    ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')    
182
    decimal_separator = l(:general_csv_decimal_separator)
183
    export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
184
      # csv header fields
185
	headers = [ "#"]
186
	query.columns.each do |column|
187
		headers << column.caption.to_s	
188
	end
189
      csv << headers.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
190
      # csv lines
191
      issues.each do |issue|
192
	fields = [issue.id.to_s]
193
	query.columns.each do |column|
194
		fields << txt_column_content(column, issue)
195
	end
196
        csv << fields.collect {|c| begin; ic.iconv(c.to_s); rescue; c.to_s; end }
197
      end
198
    end
199
    export
200
  end
201

  
202
#"??????????" ??????? ???????? ? CSV
179 203
  def issues_to_csv(issues, project = nil)
180 204
    ic = Iconv.new(l(:general_csv_encoding), 'UTF-8')    
181 205
    decimal_separator = l(:general_csv_decimal_separator)
app/helpers/queries_helper.rb (working copy)
26 26
                                                        :default_order => column.default_order) : 
27 27
                      content_tag('th', column.caption)
28 28
  end
29

  
30
#?????????? ???????? ?? ???????? ???? ???????. ??? HTML.
31
  def txt_column_content(column, issue)
32
    value = column.value(issue)
33
    
34
    case value.class.name
35
    when 'String'  
36
	value
37
    when 'Time'
38
      format_time(value)
39
    when 'Date'
40
      format_date(value)
41
    when 'Fixnum', 'Float'
42
        value.to_s
43
    when 'User'
44
       value
45
    when 'Project'
46
      value
47
    when 'Version'
48
      value
49
    when 'TrueClass'
50
      l(:general_text_Yes)
51
    when 'FalseClass'
52
      l(:general_text_No)
53
    when 'Issue'
54
      value
55
    else
56
      value
57
    end
58
  end
59

  
29 60
  
30 61
  def column_content(column, issue)
31 62
    value = column.value(issue)
    (1-1/1)