Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Redmine 2.2 and Ruby 1.8.7 compatibility #1

Open
wants to merge 4 commits into
base: redmine2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions app/controllers/importer_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ def match
i = 0
@samples = []

CSV.parse(iip.csv_data.force_encoding("UTF-8"), {:headers=>true,
csv_data = iip.csv_data
csv_data.force_encoding("UTF-8") if csv_data.respond_to?(:force_encoding)
CSV.parse(csv_data, {:headers=>true,
:quote_char=>iip.quote_char, :col_sep=>iip.col_sep}).each do |row|
@samples[i] = row

Expand Down Expand Up @@ -208,6 +210,10 @@ def result

# attrs_map is fields_map's invert
attrs_map = fields_map.invert
attrs_map = Marshal.load(Marshal.dump(fields_map.invert))
attrs_map.values.each do |v|
v.force_encoding('utf-8') if v.respond_to?(:force_encoding)
end

# check params
unique_error = nil
Expand All @@ -228,7 +234,9 @@ def result
return
end

CSV.parse(iip.csv_data.force_encoding("UTF-8"), {:headers=>true,
csv_data = iip.csv_data
csv_data.force_encoding("UTF-8") if csv_data.respond_to?(:force_encoding)
CSV.parse(csv_data, {:headers=>true,
:quote_char=>iip.quote_char, :col_sep=>iip.col_sep}).each do |row|

project = Project.find_by_name(row[attrs_map["project"]])
Expand All @@ -249,7 +257,7 @@ def result
end
assigned_to = row[attrs_map["assigned_to"]] != nil ? user_for_login!(row[attrs_map["assigned_to"]]) : nil
fixed_version_name = row[attrs_map["fixed_version"]]
fixed_version_id = !fixed_version_name.empty? ? version_id_for_name!(project,fixed_version_name,add_versions) : nil
fixed_version_id = !fixed_version_name.blank? ? version_id_for_name!(project,fixed_version_name,add_versions) : nil
watchers = row[attrs_map["watchers"]]
# new issue or find exists one
issue = Issue.new
Expand Down
25 changes: 17 additions & 8 deletions app/views/importer/match.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
<% content_for :header_tags do %>
<%= stylesheet_link_tag 'importer', :plugin => 'redmine_importer' %>
<script type="text/javascript">
//<![CDATA[
$(document).ready(function() {
$("#update_issue").bind("change", function() {
is_disabled = ($(this).attr("checked") != "checked");

$("#journal_field").attr("disabled", is_disabled);
$("#update_other_project").attr("disabled", is_disabled);
$("#ignore_non_exist").attr("disabled", is_disabled);
});
});
//]]>
</script>
<% end %>

<h2><%= l('redmine_importer.label_match_columns') %></h2>
Expand Down Expand Up @@ -37,13 +50,6 @@
<label><%= check_box_tag "add_versions", true, false %> <%= l('redmine_importer.label_importer_add_versions') %> </label><br/>
<label><%= check_box_tag "update_issue", true, false %> <%= l('redmine_importer.label_update_issue') %>
</label><br/>
<%= observe_field("update_issue", :function => <<END_OF_STRING
document.getElementById("journal_field").disabled = !element.checked;
document.getElementById("update_other_project").disabled = !element.checked;
document.getElementById("ignore_non_exist").disabled = !element.checked;
END_OF_STRING
)
%>

&nbsp;&nbsp;&nbsp;&nbsp;<label><%= l('redmine_importer.label_journal_field') %>
<%= select_tag "journal_field", "<option value=\"\">#{l('redmine_importer.option_ignore')}</option>" + options_for_select(@headers), {:disabled => true} %></label><br/>
Expand Down Expand Up @@ -74,7 +80,10 @@ END_OF_STRING
<tbody>
<% @samples.each do |issue| -%>
<tr class="<%= cycle("odd", "even") %>">
<% issue.each do |column| %><%= content_tag 'td', column[1].force_encoding("UTF-8") unless column[1].nil? %><% end %>
<% issue.each do |column| %>
<% v = column[1] ; v = v.force_encoding("UTF-8") if v.respond_to?(:force_encoding) %>
<%= content_tag 'td', v %>
<% end %>
</tr>
<% end %>
<tr class="<%= cycle("odd", "even") %>">
Expand Down
5 changes: 4 additions & 1 deletion app/views/importer/result.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
<% @failed_issues.each do |id, issue| -%>
<tr class="<%= cycle("odd", "even") %>">
<td><%= id %></td>
<% issue.each do |column| %><%= content_tag 'td', column[1].force_encoding('UTF-8') unless column[1].nil? %><% end %>
<% issue.each do |column| %>
<% v = column[1] ; v = v.force_encoding("UTF-8") if v.respond_to?(:force_encoding) %>
<%= content_tag 'td', v %>
<% end %>
</tr>
<% end %>
</tbody>
Expand Down
2 changes: 2 additions & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
end
menu :project_menu, :importer, { :controller => 'importer', :action => 'index' }, :caption => :"redmine_importer.label_import", :before => :settings, :param => :project_id
end

CSV = FCSV if RUBY_VERSION < '1.9'