Feature #34040 » draft.patch
| app/controllers/issues_controller.rb | ||
|---|---|---|
|
:title => "#{@project || Setting.app_title}: #{l(:label_issue_plural)}")
|
||
|
end
|
||
|
format.csv do
|
||
|
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i)
|
||
|
@issues = @query.issues(:limit => Setting.issues_export_limit.to_i, :with_notes => (params[:with_notes] == '1'))
|
||
|
send_data(query_to_csv(@issues, @query, params[:csv]),
|
||
|
:type => 'text/csv; header=present', :filename => 'issues.csv')
|
||
|
end
|
||
| app/helpers/queries_helper.rb | ||
|---|---|---|
|
columns = query.columns
|
||
|
Redmine::Export::CSV.generate(:encoding => params[:encoding]) do |csv|
|
||
|
journal_columns = IssueQuery.journal_columns if params[:with_notes] == '1'
|
||
|
# csv header fields
|
||
|
csv << columns.map {|c| c.caption.to_s}
|
||
|
csv << columns.map {|c| c.caption.to_s} + (journal_columns || []).map{|c| c.caption.to_s}
|
||
|
# csv lines
|
||
|
items.each do |item|
|
||
|
csv << columns.map {|c| csv_content(c, item)}
|
||
|
if journal_columns
|
||
|
item.journals_with_notes.each_with_index do |journal, index|
|
||
|
if index == 0
|
||
|
csv << columns.map {|c| csv_content(c, item)} + journal_columns.map {|c| csv_content(c, journal)}
|
||
|
else
|
||
|
csv << columns.map {|c| csv_content(c, item) if c.name == :id } + journal_columns.map {|c| csv_content(c, journal)}
|
||
|
end
|
||
|
end
|
||
|
else
|
||
|
csv << columns.map {|c| csv_content(c, item)}
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
end
|
||
| app/models/issue.rb | ||
|---|---|---|
|
@total_estimated_hours = nil
|
||
|
@last_updated_by = nil
|
||
|
@last_notes = nil
|
||
|
@journals_with_notes = nil
|
||
|
base_reload(*args)
|
||
|
end
|
||
| ... | ... | |
|
def last_notes
|
||
|
if @last_notes
|
||
|
@last_notes
|
||
|
elsif @journals_with_notes.first.notes
|
||
|
@journals_with_notes.first.notes
|
||
|
else
|
||
|
journals.where.not(notes: '').reorder(:id => :desc).first.try(:notes)
|
||
|
end
|
||
|
end
|
||
|
def journals_with_notes
|
||
|
if @journals_with_notes
|
||
|
@journals_with_notes
|
||
|
else
|
||
|
journals.where.not(notes: '').reorder(:id => :asc)
|
||
|
end
|
||
|
end
|
||
|
# Preloads relations for a collection of issues
|
||
|
def self.load_relations(issues)
|
||
|
if issues.any?
|
||
| ... | ... | |
|
end
|
||
|
# Preloads visible last notes for a collection of issues
|
||
|
def self.load_visible_last_notes(issues, user=User.current)
|
||
|
def self.load_visible_last_notes(issues, user=User.current, has_notes=false)
|
||
|
if issues.any?
|
||
|
if has_notes
|
||
|
issues.each do |issue|
|
||
|
issue.instance_variable_set("@last_notes", issue.journals_with_notes.last.notes)
|
||
|
end
|
||
|
return
|
||
|
end
|
||
|
issue_ids = issues.map(&:id)
|
||
|
journal_ids = Journal.joins(issue: :project).
|
||
|
where(:journalized_type => 'Issue', :journalized_id => issue_ids).
|
||
| ... | ... | |
|
end
|
||
|
end
|
||
|
# Preloads visible journals_with_notes for a collection of issues
|
||
|
def self.load_visible_journals_with_notes(issues, user=User.current)
|
||
|
if issues.any?
|
||
|
issue_ids = issues.map(&:id)
|
||
|
journals = Journal.joins(issue: :project).
|
||
|
where(:journalized_type => 'Issue', :journalized_id => issue_ids).
|
||
|
where(Journal.visible_notes_condition(user, :skip_pre_condition => true)).
|
||
|
where.not(notes: '').
|
||
|
reorder(id: :asc)
|
||
|
issues.each do |issue|
|
||
|
issue.instance_variable_set("@journals_with_notes", journals.where(journalized_id: issue.id))
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Finds an issue relation given its id.
|
||
|
def find_relation(relation_id)
|
||
|
IssueRelation.where("issue_to_id = ? OR issue_from_id = ?", id, id).find(relation_id)
|
||
| app/models/issue_query.rb | ||
|---|---|---|
|
@available_columns
|
||
|
end
|
||
|
def self.journal_columns
|
||
|
columns =
|
||
|
[
|
||
|
QueryColumn.new(:id, :caption => :label_notes_id, :inline => false),
|
||
|
QueryColumn.new(:notes, :caption => :field_notes, :inline => false),
|
||
|
QueryColumn.new(:user, :caption => :label_notes_author, :inline => false),
|
||
|
QueryColumn.new(:created_on, :caption => :label_notes_created_on, :inline => false)
|
||
|
]
|
||
|
if User.current.allowed_to?(:set_notes_private, nil, :global => true)
|
||
|
columns << QueryColumn.new(:private_notes, :caption => :field_private_notes, :inline => false)
|
||
|
end
|
||
|
end
|
||
|
def default_columns_names
|
||
|
@default_columns_names ||= begin
|
||
|
default_columns = Setting.issue_list_default_columns.map(&:to_sym)
|
||
| ... | ... | |
|
if has_column?(:relations)
|
||
|
Issue.load_visible_relations(issues)
|
||
|
end
|
||
|
if options[:with_notes]
|
||
|
Issue.load_visible_journals_with_notes(issues)
|
||
|
end
|
||
|
if has_column?(:last_notes)
|
||
|
Issue.load_visible_last_notes(issues)
|
||
|
Issue.load_visible_last_notes(issues, User.current, options[:with_notes])
|
||
|
end
|
||
|
issues
|
||
|
rescue ::ActiveRecord::StatementInvalid => e
|
||
| app/views/issues/index.html.erb | ||
|---|---|---|
|
<% @query.available_block_columns.each do |column| %>
|
||
|
<label><%= check_box_tag 'c[]', column.name, @query.has_column?(column), :id => nil %> <%= column.caption %></label>
|
||
|
<% end %>
|
||
|
<label><%= check_box_tag 'with_notes', '1', false, id: nil %> <%= l(:label_all_notes) %></label>
|
||
|
</fieldset>
|
||
|
<% end %>
|
||
|
<%= export_csv_encoding_select_tag %>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
label_display_type_board: Board
|
||
|
label_my_bookmarks: My bookmarks
|
||
|
label_assign_to_me: Assign to me
|
||
|
label_all_notes: All notes
|
||
|
label_notes_id: Notes-#
|
||
|
label_notes_author: Notes author
|
||
|
label_notes_created_on: Notes created
|
||
|
button_login: Login
|
||
|
button_submit: Submit
|
||