diff --git a/app/views/dmsf_files/_links.html.erb b/app/views/dmsf_files/_links.html.erb index b9d0ccea..c9b193e4 100644 --- a/app/views/dmsf_files/_links.html.erb +++ b/app/views/dmsf_files/_links.html.erb @@ -28,20 +28,6 @@ <% links.each do |dmsf_file, link, create_at| %> <%= render :partial => 'dmsf_files/link', :locals => { :dmsf_file => dmsf_file, :link => link } %> <% end %> - <% # Thumbnails %> - <% if defined?(thumbnails) && thumbnails %> - <% images = links.map{ |x| x[0] }.select(&:image?) %> - <% if images.any? %> -
- <% images.each do |file| %> -
- <%= link_to image_tag(dmsf_thumbnail_path(file)), - url_for({:controller => :dmsf_files, :action => 'view', :id => file}), - :alt => file.title %> -
- <% end %> -
- <% end %> - <% end %> + <%= render :partial => 'dmsf_files/thumbnails', :locals => { :links => links, :thumbnails => thumbnails } %> <% end %> diff --git a/app/views/dmsf_files/_thumbnails.html.erb b/app/views/dmsf_files/_thumbnails.html.erb new file mode 100644 index 00000000..c576f14f --- /dev/null +++ b/app/views/dmsf_files/_thumbnails.html.erb @@ -0,0 +1,37 @@ +<% + # encoding: utf-8 + # + # Redmine plugin for Document Management System "Features" + # + # Copyright (C) 2011-17 Karel Pičman + # + # This program is free software; you can redistribute it and/or + # modify it under the terms of the GNU General Public License + # as published by the Free Software Foundation; either version 2 + # of the License, or (at your option) any later version. + # + # This program is distributed in the hope that it will be useful, + # but WITHOUT ANY WARRANTY; without even the implied warranty of + # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + # GNU General Public License for more details. + # + # You should have received a copy of the GNU General Public License + # along with this program; if not, write to the Free Software + # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +%> + +<% # Thumbnails %> +<% if defined?(thumbnails) && thumbnails %> + <% images = links.map{ |x| x[0] }.select(&:image?) %> + <% if images.any? %> +
+ <% images.each do |file| %> +
+ <%= link_to image_tag(dmsf_thumbnail_path(file)), + url_for({:controller => :dmsf_files, :action => 'view', :id => file}), + :alt => file.title %> +
+ <% end %> +
+ <% end %> +<% end %> diff --git a/lib/redmine_dmsf.rb b/lib/redmine_dmsf.rb index 6d5a9d7a..dc705511 100644 --- a/lib/redmine_dmsf.rb +++ b/lib/redmine_dmsf.rb @@ -37,6 +37,7 @@ require 'redmine_dmsf/patches/role_patch' if defined?(EasyExtensions) require 'redmine_dmsf/patches/easy_crm_case_patch' + require 'redmine_dmsf/patches/attachable_patch' end # Load up classes that make up our WebDAV solution ontop of DAV4Rack diff --git a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb index dce1df0f..ee82c119 100644 --- a/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb +++ b/lib/redmine_dmsf/hooks/views/issue_view_hooks.rb @@ -39,11 +39,48 @@ module RedmineDmsf end def view_issues_show_attachments_bottom(context={}) - show_attached_documents(context[:container], context[:controller]) + unless context[:options][:only_mails].present? + show_attached_documents(context[:container], context[:controller]) + end + end + + def view_issues_show_thumbnails(context={}) + unless context[:options][:only_mails].present? + show_thumbnails(context[:container], context[:controller]) + end end private + def get_links(container) + if User.current.allowed_to?(:view_dmsf_files, container.project) && + Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] && + (container.project.dmsf_act_as_attachable == Project::ATTACHABLE_DMS_AND_ATTACHMENTS) + links = [] + for dmsf_file in container.dmsf_files + if dmsf_file.last_revision + links << [dmsf_file, nil, dmsf_file.created_at] + end + end + for dmsf_link in container.dmsf_links + dmsf_file = dmsf_link.target_file + if dmsf_file && dmsf_file.last_revision + links << [dmsf_file, dmsf_link, dmsf_link.created_at] + end + end + # Sort by 'create_at' + links.sort{ |x, y| x[2] <=> y[2] } + end + end + + def show_thumbnails(container, controller) + links = get_links(container) + html = controller.send(:render_to_string, + { :partial => 'dmsf_files/thumbnails', + :locals => { :links => links, :thumbnails => Setting.thumbnails_enabled?} }) + html.html_safe + end + def attach_documents_form(context) if context.is_a?(Hash) && context[:issue] # Add Dmsf upload form @@ -65,23 +102,8 @@ module RedmineDmsf def show_attached_documents(container, controller) # Add list of attached documents - if User.current.allowed_to?(:view_dmsf_files, container.project) && - Setting.plugin_redmine_dmsf['dmsf_act_as_attachable'] && - (container.project.dmsf_act_as_attachable == Project::ATTACHABLE_DMS_AND_ATTACHMENTS) - links = [] - for dmsf_file in container.dmsf_files - if dmsf_file.last_revision - links << [dmsf_file, nil, dmsf_file.created_at] - end - end - for dmsf_link in container.dmsf_links - dmsf_file = dmsf_link.target_file - if dmsf_file && dmsf_file.last_revision - links << [dmsf_file, dmsf_link, dmsf_link.created_at] - end - end - # Sort by 'create_at' - links.sort!{ |x, y| x[2] <=> y[2] } + links = get_links(container) + if links.any? unless defined?(EasyExtensions) controller.send(:render_to_string, {:partial => 'dmsf_files/links', :locals => { :links => links, :thumbnails => Setting.thumbnails_enabled? }}) @@ -91,8 +113,6 @@ module RedmineDmsf end end - private - def attachment_rows(links, issue, controller) html = '' links.each do |dmsf_file, link, create_at| diff --git a/lib/redmine_dmsf/hooks/views/view_projects_form_hook.rb b/lib/redmine_dmsf/hooks/views/view_projects_form_hook.rb index a03e80c0..73f6fba2 100644 --- a/lib/redmine_dmsf/hooks/views/view_projects_form_hook.rb +++ b/lib/redmine_dmsf/hooks/views/view_projects_form_hook.rb @@ -1,6 +1,6 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2011-14 Karel Pičman +# Copyright (C) 2011-17 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License diff --git a/lib/redmine_dmsf/patches/acts_as_customizable.rb b/lib/redmine_dmsf/patches/acts_as_customizable.rb index 271ce6ba..9d5901cd 100644 --- a/lib/redmine_dmsf/patches/acts_as_customizable.rb +++ b/lib/redmine_dmsf/patches/acts_as_customizable.rb @@ -1,7 +1,7 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2011 Vít Jonáš -# Copyright (C) 2013 Karel Pičman +# Copyright (C) 2011 Vít Jonáš +# Copyright (C) 2011-17 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License diff --git a/lib/redmine_dmsf/patches/attachable_patch.rb b/lib/redmine_dmsf/patches/attachable_patch.rb new file mode 100644 index 00000000..44da87fd --- /dev/null +++ b/lib/redmine_dmsf/patches/attachable_patch.rb @@ -0,0 +1,47 @@ +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011-17 Karel Pičman +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module RedmineDmsf + module Patches + module AttachablePatch + + def self.included(base) + base.send(:include, InstanceMethods) + base.class_eval do + unloadable + alias_method_chain :has_attachments?, :has_attachments_dms + end + end + + module InstanceMethods + + def has_attachments_with_has_attachments_dms? + has_attachments_without_has_attachments_dms? || self.dmsf_files.any? + end + + end + end + end +end + + # Apply the patch + Rails.configuration.to_prepare do + unless Redmine::Acts::Attachable::InstanceMethods.included_modules.include?(RedmineDmsf::Patches::AttachablePatch) + Redmine::Acts::Attachable::InstanceMethods.send(:include, RedmineDmsf::Patches::AttachablePatch) + end + end diff --git a/lib/redmine_dmsf/patches/project_tabs_extended.rb b/lib/redmine_dmsf/patches/project_tabs_extended.rb index 87fb6da3..341a2078 100644 --- a/lib/redmine_dmsf/patches/project_tabs_extended.rb +++ b/lib/redmine_dmsf/patches/project_tabs_extended.rb @@ -1,8 +1,8 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2011 Vít Jonáš -# Copyright (C) 2012 Daniel Munn -# Copyright (C) 2013 Karel Pičman +# Copyright (C) 2011 Vít Jonáš +# Copyright (C) 2012 Daniel Munn +# Copyright (C) 2011-17 Karel Pičman # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License