From 5c7aaa4d1eed86e0a3e687ab4a2263b00a68d611 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Tue, 4 Apr 2017 17:07:13 +0000 Subject: [PATCH] Makes Attachments column available on the issue list (#25515). git-svn-id: http://svn.redmine.org/redmine/trunk@16473 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/helpers/queries_helper.rb | 31 +++++++++++++-------- app/models/issue_query.rb | 3 +- lib/redmine/export/pdf/issues_pdf_helper.rb | 5 +++- public/stylesheets/application.css | 3 +- test/functional/issues_controller_test.rb | 20 +++++++++++++ 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/app/helpers/queries_helper.rb b/app/helpers/queries_helper.rb index b4a0a0b75..061da8dec 100644 --- a/app/helpers/queries_helper.rb +++ b/app/helpers/queries_helper.rb @@ -228,6 +228,8 @@ module QueriesHelper link_to_if(value > 0, format_hours(value), project_time_entries_path(item.project, :issue_id => "#{item.id}")) when :total_spent_hours link_to_if(value > 0, format_hours(value), project_time_entries_path(item.project, :issue_id => "~#{item.id}")) + when :attachments + value.to_a.map {|a| format_object(a)}.join(" ").html_safe else format_object(value) end @@ -243,20 +245,25 @@ module QueriesHelper end def csv_value(column, object, value) - format_object(value, false) do |value| - case value.class.name - when 'Float' - sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) - when 'IssueRelation' - value.to_s(object) - when 'Issue' - if object.is_a?(TimeEntry) - "#{value.tracker} ##{value.id}: #{value.subject}" + case column.name + when :attachments + value.to_a.map {|a| a.filename}.join("\n") + else + format_object(value, false) do |value| + case value.class.name + when 'Float' + sprintf("%.2f", value).gsub('.', l(:general_csv_decimal_separator)) + when 'IssueRelation' + value.to_s(object) + when 'Issue' + if object.is_a?(TimeEntry) + "#{value.tracker} ##{value.id}: #{value.subject}" + else + value.id + end else - value.id + value end - else - value end end end diff --git a/app/models/issue_query.rb b/app/models/issue_query.rb index 5ca76a5bc..94a47e3fe 100644 --- a/app/models/issue_query.rb +++ b/app/models/issue_query.rb @@ -45,6 +45,7 @@ class IssueQuery < Query QueryColumn.new(:closed_on, :sortable => "#{Issue.table_name}.closed_on", :default_order => 'desc'), QueryColumn.new(:last_updated_by, :sortable => lambda {User.fields_for_order_statement("last_journal_user")}), QueryColumn.new(:relations, :caption => :label_related_issues), + QueryColumn.new(:attachments, :caption => :label_attachment_plural), QueryColumn.new(:description, :inline => false), QueryColumn.new(:last_notes, :caption => :label_last_notes, :inline => false) ] @@ -278,7 +279,7 @@ class IssueQuery < Query limit(options[:limit]). offset(options[:offset]) - scope = scope.preload([:tracker, :author, :assigned_to, :fixed_version, :category] & columns.map(&:name)) + scope = scope.preload([:tracker, :author, :assigned_to, :fixed_version, :category, :attachments] & columns.map(&:name)) if has_custom_field_column? scope = scope.preload(:custom_values) end diff --git a/lib/redmine/export/pdf/issues_pdf_helper.rb b/lib/redmine/export/pdf/issues_pdf_helper.rb index c72ff6657..1130670ea 100644 --- a/lib/redmine/export/pdf/issues_pdf_helper.rb +++ b/lib/redmine/export/pdf/issues_pdf_helper.rb @@ -374,8 +374,11 @@ module Redmine show_value(cv, false) else value = issue.send(column.name) - if column.name == :subject + case column.name + when :subject value = " " * level + value + when :attachments + value = value.to_a.map {|a| a.filename}.join("\n") end if value.is_a?(Date) format_date(value) diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index 03545c6c5..a250ba36b 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -223,7 +223,8 @@ table.list, .table-list { border: 1px solid #e4e4e4; border-collapse: collapse; table.list th, .table-list-header { background-color:#EEEEEE; padding: 4px; white-space:nowrap; font-weight:bold; } table.list td {text-align:center; vertical-align:middle; padding-right:10px;} table.list td.id { width: 2%; text-align: center;} -table.list td.name, table.list td.description, table.list td.subject, table.list td.comments, table.list td.roles {text-align: left;} +table.list td.name, table.list td.description, table.list td.subject, table.list td.comments, table.list td.roles, table.list td.attachments {text-align: left;} +table.list td.attachments a {display:block;} table.list td.tick {width:15%} table.list td.checkbox { width: 15px; padding: 2px 0 0 0; } table.list td.checkbox input {padding:0px;} diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index a6f7cd13a..6c025123d 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -1023,6 +1023,26 @@ class IssuesControllerTest < Redmine::ControllerTest assert_equal ["John Smith", "John Smith", ""], css_select('td.last_updated_by').map(&:text) end + def test_index_with_attachments_column + get :index, :c => %w(subject attachments), :set_filter => '1', :sort => 'id' + assert_response :success + + assert_select 'td.attachments' + assert_select 'tr#issue-2' do + assert_select 'td.attachments' do + assert_select 'a', :text => 'source.rb' + assert_select 'a', :text => 'picture.jpg' + end + end + end + + def test_index_with_attachments_column_as_csv + get :index, :c => %w(subject attachments), :set_filter => '1', :sort => 'id', :format => 'csv' + assert_response :success + + assert_include "\"source.rb\npicture.jpg\"", response.body + end + def test_index_with_estimated_hours_total Issue.delete_all Issue.generate!(:estimated_hours => 5.5) -- 2.39.5