diff options
author | Go MAEDA <maeda@farend.jp> | 2018-07-08 00:27:58 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2018-07-08 00:27:58 +0000 |
commit | cb5fce04426df4803726c874e0e9e9285cdd7837 (patch) | |
tree | 066885a639a5437c288a8b537cf48011881c0a54 /app | |
parent | d1c84dbdf98258c0c08ca6af2afaaae4b74991e3 (diff) | |
download | redmine-cb5fce04426df4803726c874e0e9e9285cdd7837.tar.gz redmine-cb5fce04426df4803726c874e0e9e9285cdd7837.zip |
Adds link to container to attachment view (#29190).
Patch by Gregor Schmidt.
git-svn-id: http://svn.redmine.org/redmine/trunk@17435 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/helpers/application_helper.rb | 34 | ||||
-rw-r--r-- | app/views/layouts/_file.html.erb | 4 |
2 files changed, 37 insertions, 1 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? %> |