Feature #26279 » select_encoding2.patch
| app/helpers/application_helper.rb | ||
|---|---|---|
| 1495 | 1495 |
encoding = l(:general_csv_encoding) |
| 1496 | 1496 |
end |
| 1497 | 1497 | |
| 1498 |
def export_csv_encoding_select_tag |
|
| 1499 |
return if l(:general_csv_encoding).casecmp('UTF-8') == 0
|
|
| 1500 |
options = [l(:general_csv_encoding), 'UTF-8'] |
|
| 1501 |
content_tag(:p) do |
|
| 1502 |
concat( |
|
| 1503 |
content_tag(:label) do |
|
| 1504 |
concat l(:label_encoding) |
|
| 1505 |
concat select_tag('encoding', options_for_select(options, l(:general_csv_encoding)))
|
|
| 1506 |
end |
|
| 1507 |
) |
|
| 1508 |
end |
|
| 1509 |
end |
|
| 1510 | ||
| 1498 | 1511 |
private |
| 1499 | 1512 | |
| 1500 | 1513 |
def wiki_helper |
| app/helpers/queries_helper.rb | ||
|---|---|---|
| 271 | 271 |
def query_to_csv(items, query, options={})
|
| 272 | 272 |
columns = query.columns |
| 273 | 273 | |
| 274 |
Redmine::Export::CSV.generate do |csv| |
|
| 274 |
Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
|
|
| 275 | 275 |
# csv header fields |
| 276 | 276 |
csv << columns.map {|c| c.caption.to_s}
|
| 277 | 277 |
# csv lines |
| ... | ... | |
| 366 | 366 | |
| 367 | 367 |
tags |
| 368 | 368 |
end |
| 369 |
|
|
| 369 | ||
| 370 | 370 |
def query_hidden_sort_tag(query) |
| 371 | 371 |
hidden_field_tag("sort", query.sort_criteria.to_param, :id => nil)
|
| 372 | 372 |
end |
| app/helpers/timelog_helper.rb | ||
|---|---|---|
| 76 | 76 |
end |
| 77 | 77 | |
| 78 | 78 |
def report_to_csv(report) |
| 79 |
Redmine::Export::CSV.generate do |csv| |
|
| 79 |
Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
|
|
| 80 | 80 |
# Column headers |
| 81 | 81 |
headers = report.criteria.collect {|criteria| l(report.available_criteria[criteria][:label]) }
|
| 82 | 82 |
headers += report.periods |
| app/views/issues/index.html.erb | ||
|---|---|---|
| 39 | 39 |
<label><%= check_box_tag 'c[]', 'description', @query.has_column?(:description) %> <%= l(:field_description) %></label> |
| 40 | 40 |
<label><%= check_box_tag 'c[]', 'last_notes', @query.has_column?(:last_notes) %> <%= l(:label_last_notes) %></label> |
| 41 | 41 |
</p> |
| 42 |
<%= export_csv_encoding_select_tag %> |
|
| 42 | 43 |
<% if @issue_count > Setting.issues_export_limit.to_i %> |
| 43 | 44 |
<p class="icon icon-warning"> |
| 44 | 45 |
<%= l(:setting_issues_export_limit) %>: <%= Setting.issues_export_limit.to_i %> |
| app/views/timelog/index.html.erb | ||
|---|---|---|
| 1 | 1 |
<div class="contextual"> |
| 2 |
<%= link_to l(:button_log_time),
|
|
| 2 |
<%= link_to l(:button_log_time), |
|
| 3 | 3 |
_new_time_entry_path(@project, @issue), |
| 4 | 4 |
:class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %> |
| 5 | 5 |
</div> |
| ... | ... | |
| 31 | 31 |
<label><%= radio_button_tag 'c[]', '', true %> <%= l(:description_selected_columns) %></label><br /> |
| 32 | 32 |
<label><%= radio_button_tag 'c[]', 'all_inline' %> <%= l(:description_all_columns) %></label> |
| 33 | 33 |
</p> |
| 34 |
<%= export_csv_encoding_select_tag %> |
|
| 34 | 35 |
<p class="buttons"> |
| 35 | 36 |
<%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %> |
| 36 | 37 |
<%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %> |
| app/views/timelog/report.html.erb | ||
|---|---|---|
| 1 | 1 |
<div class="contextual"> |
| 2 |
<%= link_to l(:button_log_time),
|
|
| 2 |
<%= link_to l(:button_log_time), |
|
| 3 | 3 |
_new_time_entry_path(@project, @issue), |
| 4 | 4 |
:class => 'icon icon-time-add' if User.current.allowed_to?(:log_time, @project, :global => true) %> |
| 5 | 5 |
</div> |
| ... | ... | |
| 24 | 24 |
:disabled => (@report.criteria.length >= 3), |
| 25 | 25 |
:id => "criterias") %> |
| 26 | 26 |
<%= link_to l(:button_clear), {:params => request.query_parameters.merge(:criteria => nil)}, :class => 'icon icon-reload' %></p>
|
| 27 |
<%= hidden_field_tag 'encoding', l(:general_csv_encoding) unless l(:general_csv_encoding).casecmp('UTF-8') == 0 %>
|
|
| 27 | 28 |
<% end %> |
| 28 | 29 | |
| 29 | 30 |
<% if @query.valid? %> |
| ... | ... | |
| 62 | 63 |
</div> |
| 63 | 64 | |
| 64 | 65 |
<% other_formats_links do |f| %> |
| 65 |
<%= f.link_to_with_query_parameters 'CSV' %> |
|
| 66 |
<%= f.link_to_with_query_parameters 'CSV', {}, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
|
|
| 66 | 67 |
<% end %> |
| 67 | 68 |
<% end %> |
| 69 |
<div id="csv-export-options" style="display: none;"> |
|
| 70 |
<h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3> |
|
| 71 |
<%= export_csv_encoding_select_tag %> |
|
| 72 |
<p class="buttons"> |
|
| 73 |
<%= submit_tag l(:button_export), :name => nil, :id => 'csv-export-button' %> |
|
| 74 |
<%= submit_tag l(:button_cancel), :name => nil, :onclick => 'hideModal(this);', :type => 'button' %> |
|
| 75 |
</p> |
|
| 76 |
</div> |
|
| 68 | 77 |
<% end %> |
| 69 | 78 |
<% end %> |
| 70 | 79 | |
| ... | ... | |
| 74 | 83 | |
| 75 | 84 |
<% html_title(@query.new_record? ? l(:label_spent_time) : @query.name, l(:label_report)) %> |
| 76 | 85 | |
| 86 | ||
| 87 |
<%= javascript_tag do %> |
|
| 88 |
$(document).ready(function(){
|
|
| 89 |
$('input#csv-export-button').click(function(){
|
|
| 90 |
$('form input#encoding').val($('select#encoding option:selected').val());
|
|
| 91 |
$('form#query_form').attr('action', '<%= report_time_entries_path(:format => 'csv') %>').submit();
|
|
| 92 |
$('form#query_form').attr('action', '<%= report_time_entries_path %>');
|
|
| 93 |
hideModal(this); |
|
| 94 |
}); |
|
| 95 |
}); |
|
| 96 |
<% end %> |
|
| lib/redmine/export/csv.rb | ||
|---|---|---|
| 31 | 31 | |
| 32 | 32 |
class << self |
| 33 | 33 | |
| 34 |
def generate(&block) |
|
| 34 |
def generate(options = {}, &block)
|
|
| 35 | 35 |
col_sep = l(:general_csv_separator) |
| 36 |
encoding = l(:general_csv_encoding) |
|
| 36 |
encoding = options[:encoding].presence || l(:general_csv_encoding)
|
|
| 37 | 37 | |
| 38 | 38 |
str = ''.force_encoding(encoding) |
| 39 | 39 |
if encoding == 'UTF-8' |
| test/unit/helpers/application_helper_test.rb | ||
|---|---|---|
| 1597 | 1597 |
assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">:45</span>', html_hours('0:45')
|
| 1598 | 1598 |
assert_equal '<span class="hours hours-int">0</span><span class="hours hours-dec">.75</span>', html_hours('0.75')
|
| 1599 | 1599 |
end |
| 1600 | ||
| 1601 |
def test_export_csv_encoding_select_tag_should_return_nil_when_general_csv_encoding_is_UTF8 |
|
| 1602 |
with_locale 'az' do |
|
| 1603 |
assert_equal l(:general_csv_encoding), 'UTF-8' |
|
| 1604 |
assert_nil export_csv_encoding_select_tag |
|
| 1605 |
end |
|
| 1606 |
end |
|
| 1607 | ||
| 1608 |
def test_export_csv_encoding_select_tag_should_have_two_option_when_general_csv_encoding_is_not_UTF8 |
|
| 1609 |
with_locale 'en' do |
|
| 1610 |
assert_not_equal l(:general_csv_encoding), 'UTF-8' |
|
| 1611 |
result = export_csv_encoding_select_tag |
|
| 1612 |
assert_select_in result, "option[selected='selected'][value=#{l(:general_csv_encoding)}]", :text => l(:general_csv_encoding)
|
|
| 1613 |
assert_select_in result, "option[value='UTF-8']", :text => 'UTF-8' |
|
| 1614 |
end |
|
| 1615 |
end |
|
| 1600 | 1616 |
end |