summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/timelog_controller.rb3
-rw-r--r--app/helpers/timelog_helper.rb40
-rw-r--r--app/views/timelog/index.html.erb16
3 files changed, 23 insertions, 36 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index a6f160fa0..e90442c68 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -39,6 +39,7 @@ class TimelogController < ApplicationController
helper :custom_fields
include CustomFieldsHelper
helper :queries
+ include QueriesHelper
def index
@query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_')
@@ -86,7 +87,7 @@ class TimelogController < ApplicationController
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
:order => sort_clause
)
- send_data(entries_to_csv(@entries), :type => 'text/csv; header=present', :filename => 'timelog.csv')
+ send_data(entries_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv')
}
end
end
diff --git a/app/helpers/timelog_helper.rb b/app/helpers/timelog_helper.rb
index cc4fbff47..380c4721c 100644
--- a/app/helpers/timelog_helper.rb
+++ b/app/helpers/timelog_helper.rb
@@ -86,44 +86,16 @@ module TimelogHelper
value)
end
- def entries_to_csv(entries)
- decimal_separator = l(:general_csv_decimal_separator)
- custom_fields = TimeEntryCustomField.all
+ def entries_to_csv(entries, query, options={})
+ encoding = l(:general_csv_encoding)
+ columns = (options[:columns] == 'all' ? query.available_inline_columns : query.inline_columns)
+
export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
# csv header fields
- headers = [l(:field_spent_on),
- l(:field_user),
- l(:field_activity),
- l(:field_project),
- l(:field_issue),
- l(:field_tracker),
- l(:field_subject),
- l(:field_hours),
- l(:field_comments)
- ]
- # Export custom fields
- headers += custom_fields.collect(&:name)
-
- csv << headers.collect {|c| Redmine::CodesetUtil.from_utf8(
- c.to_s,
- l(:general_csv_encoding) ) }
+ csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(c.caption.to_s, encoding) }
# csv lines
entries.each do |entry|
- fields = [format_date(entry.spent_on),
- entry.user,
- entry.activity,
- entry.project,
- (entry.issue ? entry.issue.id : nil),
- (entry.issue ? entry.issue.tracker : nil),
- (entry.issue ? entry.issue.subject : nil),
- entry.hours.to_s.gsub('.', decimal_separator),
- entry.comments
- ]
- fields += custom_fields.collect {|f| show_value(entry.custom_field_values.detect {|v| v.custom_field_id == f.id}) }
-
- csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8(
- c.to_s,
- l(:general_csv_encoding) ) }
+ csv << columns.collect {|c| Redmine::CodesetUtil.from_utf8(csv_content(c, entry), encoding) }
end
end
export
diff --git a/app/views/timelog/index.html.erb b/app/views/timelog/index.html.erb
index 52c9118e7..e1fa5b26e 100644
--- a/app/views/timelog/index.html.erb
+++ b/app/views/timelog/index.html.erb
@@ -22,8 +22,22 @@
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => params.merge({:issue_id => @issue, :key => User.current.rss_key}) %>
- <%= f.link_to 'CSV', :url => params %>
+ <%= f.link_to 'CSV', :url => params, :onclick => "showModal('csv-export-options', '330px'); return false;" %>
<% end %>
+
+<div id="csv-export-options" style="display:none;">
+ <h3 class="title"><%= l(:label_export_options, :export_format => 'CSV') %></h3>
+ <%= form_tag(params.merge({:format => 'csv',:page=>nil}), :method => :get, :id => 'csv-export-form') do %>
+ <p>
+ <label><%= radio_button_tag 'columns', '', true %> <%= l(:description_selected_columns) %></label><br />
+ <label><%= radio_button_tag 'columns', 'all' %> <%= l(:description_all_columns) %></label>
+ </p>
+ <p class="buttons">
+ <%= submit_tag l(:button_export), :name => nil, :onclick => "hideModal(this);" %>
+ <%= submit_tag l(:button_cancel), :name => nil, :onclick => "hideModal(this);", :type => 'button' %>
+ </p>
+ <% end %>
+</div>
<% end %>
<% html_title l(:label_spent_time), l(:label_details) %>