diff options
-rw-r--r-- | app/helpers/application_helper.rb | 34 | ||||
-rw-r--r-- | app/views/layouts/_file.html.erb | 4 | ||||
-rw-r--r-- | test/helpers/application_helper_test.rb | 46 | ||||
-rw-r--r-- | test/integration/lib/redmine/field_format/attachment_format_test.rb | 2 |
4 files changed, 83 insertions, 3 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index dd152f32c..576b99647 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -170,6 +170,40 @@ module ApplicationHelper link_to_if version.visible?, format_version_name(version), version_path(version), options end + RECORD_LINK = { + 'CustomValue' => -> (custom_value) { link_to_record(custom_value.customized) }, + 'Document' => -> (document) { link_to(document.title, document_path(document)) }, + 'Group' => -> (group) { link_to(group.name, group_path(group)) }, + 'Issue' => -> (issue) { link_to_issue(issue, :subject => false) }, + 'Message' => -> (message) { link_to_message(message) }, + 'News' => -> (news) { link_to(news.title, news_path(news)) }, + 'Project' => -> (project) { link_to_project(project) }, + 'User' => -> (user) { link_to_user(user) }, + 'Version' => -> (version) { link_to_version(version) }, + 'WikiPage' => -> (wiki_page) { link_to(wiki_page.pretty_title, project_wiki_page_path(wiki_page.project, wiki_page.title)) } + } + + def link_to_record(record) + if link = RECORD_LINK[record.class.name] + self.instance_exec(record, &link) + end + end + + ATTACHMENT_CONTAINER_LINK = { + # Custom list, since project/version attachments are listed in the files + # view and not in the project/milestone view + 'Project' => -> (project) { link_to(l(:project_module_files), project_files_path(project)) }, + 'Version' => -> (version) { link_to(l(:project_module_files), project_files_path(version.project)) }, + } + + def link_to_attachment_container(attachment_container) + if link = ATTACHMENT_CONTAINER_LINK[attachment_container.class.name] || + RECORD_LINK[attachment_container.class.name] + self.instance_exec(attachment_container, &link) + end + end + + # Helper that formats object for html or text rendering def format_object(object, html=true, &block) if block_given? diff --git a/app/views/layouts/_file.html.erb b/app/views/layouts/_file.html.erb index eb11f9931..3b225508b 100644 --- a/app/views/layouts/_file.html.erb +++ b/app/views/layouts/_file.html.erb @@ -2,7 +2,9 @@ <%= link_to_attachment @attachment, :text => "#{l(:button_download)} (#{number_to_human_size(@attachment.filesize)})", :download => true, :class => 'icon icon-download' -%> </div> -<h2><%=h @attachment.filename %></h2> +<h2> + <%= safe_join([link_to_attachment_container(@attachment.container), @attachment.filename].compact, ' » ') %> +</h2> <div class="attachments"> <p><%= "#{@attachment.description} - " unless @attachment.description.blank? %> diff --git a/test/helpers/application_helper_test.rb b/test/helpers/application_helper_test.rb index 34e4fe119..e28a56797 100644 --- a/test/helpers/application_helper_test.rb +++ b/test/helpers/application_helper_test.rb @@ -31,7 +31,8 @@ class ApplicationHelperTest < Redmine::HelperTest :trackers, :issue_statuses, :issues, :versions, :documents, :wikis, :wiki_pages, :wiki_contents, :boards, :messages, :news, - :attachments, :enumerations + :attachments, :enumerations, + :custom_values, :custom_fields, :custom_fields_projects def setup super @@ -1490,6 +1491,49 @@ RAW link_to_project(Project.find(1)) end + def test_link_to_record + [ + [custom_values(:custom_values_007), '<a href="/projects/ecookbook">eCookbook</a>'], + [documents(:documents_001), '<a href="/documents/1">Test document</a>'], + [Group.find(10), '<a href="/groups/10">A Team</a>'], + [issues(:issues_001), link_to_issue(issues(:issues_001), :subject => false)], + [messages(:messages_001), '<a href="/boards/1/topics/1">First post</a>'], + [news(:news_001), '<a href="/news/1">eCookbook first release !</a>'], + [projects(:projects_001), '<a href="/projects/ecookbook">eCookbook</a>'], + [users(:users_001), '<a class="user active" href="/users/1">Redmine Admin</a>'], + [versions(:versions_001), '<a title="07/01/2006" href="/versions/1">eCookbook - 0.1</a>'], + [wiki_pages(:wiki_pages_001), '<a href="/projects/ecookbook/wiki/CookBook_documentation">CookBook documentation</a>'] + ].each do |record, link| + assert_equal link, link_to_record(record) + end + end + + def test_link_to_attachment_container + field = ProjectCustomField.generate!(:name => "File", :field_format => 'attachment') + project = projects(:projects_001) + project_custom_value_attachment = new_record(Attachment) do + project.custom_field_values = {field.id => {:file => mock_file}} + project.save + end + + news_attachment = attachments(:attachments_004) + news_attachment.container = news(:news_001) + news_attachment.save! + + [ + [project_custom_value_attachment, '<a href="/projects/ecookbook">eCookbook</a>'], + [attachments(:attachments_002), '<a href="/documents/1">Test document</a>'], + [attachments(:attachments_001), link_to_issue(issues(:issues_003), :subject => false)], + [attachments(:attachments_013), '<a href="/boards/1/topics/1">First post</a>'], + [news_attachment, '<a href="/news/1">eCookbook first release !</a>'], + [attachments(:attachments_008), '<a href="/projects/ecookbook/files">Files</a>'], + [attachments(:attachments_009), '<a href="/projects/ecookbook/files">Files</a>'], + [attachments(:attachments_003), '<a href="/projects/ecookbook/wiki/Page_with_an_inline_image">Page with an inline image</a>'], + ].each do |attachment, link| + assert_equal link, link_to_attachment_container(attachment.container) + end + end + def test_principals_options_for_select_with_users User.current = nil users = [User.find(2), User.find(4)] diff --git a/test/integration/lib/redmine/field_format/attachment_format_test.rb b/test/integration/lib/redmine/field_format/attachment_format_test.rb index 759a73b17..958b25769 100644 --- a/test/integration/lib/redmine/field_format/attachment_format_test.rb +++ b/test/integration/lib/redmine/field_format/attachment_format_test.rb @@ -85,7 +85,7 @@ class AttachmentFieldFormatTest < Redmine::IntegrationTest # preview the attachment get link.attr('href') assert_response :success - assert_select 'h2', :text => 'testfile.txt' + assert_select 'h2', :text => "#{issue.tracker} ##{issue.id} » testfile.txt" end def test_create_without_attachment |