From 65820f97f3beaf31258b99da15a9e88f54d7c87b Mon Sep 17 00:00:00 2001 From: Karel Picman Date: Thu, 26 Jan 2017 10:20:39 +0100 Subject: [PATCH] Linking Issues and DMSF Documents #48 --- app/controllers/dmsf_controller.rb | 2 +- app/controllers/dmsf_upload_controller.rb | 130 +------ app/helpers/dmsf_upload_helper.rb | 146 ++++++++ app/models/dmsf_file.rb | 55 ++- app/models/dmsf_file_revision.rb | 4 +- app/models/dmsf_file_revision_access.rb | 6 +- app/models/dmsf_upload.rb | 3 +- app/models/dmsf_workflow.rb | 5 +- app/views/dmsf/show.html.erb | 2 +- app/views/dmsf_files/_links.html.erb | 44 +++ app/views/dmsf_files/_upload_form.html.erb | 36 -- app/views/dmsf_upload/_form.html.erb | 49 +++ app/views/dmsf_upload/_multi_upload.html.erb | 12 +- app/views/dmsf_upload/upload.js.erb | 36 ++ assets/javascripts/attachments_dmsf.js | 331 +++++++++--------- assets/stylesheets/redmine_dmsf.css | 22 +- config/routes.rb | 1 + .../20170118142001_dmsf_file_container.rb | 36 ++ lib/redmine_dmsf.rb | 7 +- .../controllers/issues_controller_hooks.rb | 52 +++ .../hooks/views/base_view_hooks.rb | 5 +- .../hooks/views/issue_view_hooks.rb | 51 +++ lib/redmine_dmsf/patches/issue_patch.rb | 44 +++ lib/redmine_dmsf/patches/project_patch.rb | 4 +- lib/redmine_dmsf/webdav/dmsf_resource.rb | 1 + lib/tasks/dmsf_convert_documents.rake | 1 + 26 files changed, 720 insertions(+), 365 deletions(-) create mode 100644 app/helpers/dmsf_upload_helper.rb create mode 100644 app/views/dmsf_files/_links.html.erb delete mode 100644 app/views/dmsf_files/_upload_form.html.erb create mode 100644 app/views/dmsf_upload/_form.html.erb create mode 100644 app/views/dmsf_upload/upload.js.erb create mode 100644 db/migrate/20170118142001_dmsf_file_container.rb create mode 100644 lib/redmine_dmsf/hooks/controllers/issues_controller_hooks.rb create mode 100644 lib/redmine_dmsf/hooks/views/issue_view_hooks.rb create mode 100644 lib/redmine_dmsf/patches/issue_patch.rb diff --git a/app/controllers/dmsf_controller.rb b/app/controllers/dmsf_controller.rb index 175b32f8..b0e7add0 100644 --- a/app/controllers/dmsf_controller.rb +++ b/app/controllers/dmsf_controller.rb @@ -66,7 +66,7 @@ class DmsfController < ApplicationController @file_manipulation_allowed = User.current.allowed_to? :file_manipulation, @project @file_delete_allowed = User.current.allowed_to? :file_delete, @project @subfolders = DmsfFolder.deleted.where(:project_id => @project.id) - @files = DmsfFile.deleted.where(:project_id => @project.id) + @files = DmsfFile.deleted.where(:container_id => @project.id, :container_type => 'Project') @dir_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFolder.model_name.to_s) @file_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => DmsfFile.model_name.to_s) @url_links = DmsfLink.deleted.where(:project_id => @project.id, :target_type => 'DmsfUrl') diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index 628b38d1..1361ff94 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -3,7 +3,7 @@ # Redmine plugin for Document Management System "Features" # # Copyright (C) 2011 Vít Jonáš -# Copyright (C) 2011-16 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 @@ -24,8 +24,9 @@ class DmsfUploadController < ApplicationController menu_item :dmsf - before_filter :find_project - before_filter :authorize + before_filter :find_project, :except => [:upload] + before_filter :authorize, :except => [:upload] + before_filter :authorize_global, :only => [:upload] before_filter :find_folder, :except => [:upload_file, :upload, :commit] helper :all @@ -34,7 +35,7 @@ class DmsfUploadController < ApplicationController accept_api_auth :upload, :commit def upload_files - uploaded_files = params[:attachments] + uploaded_files = params[:dmsf_attachments] @uploads = [] if uploaded_files && uploaded_files.is_a?(Hash) # standard file input uploads @@ -134,129 +135,12 @@ class DmsfUploadController < ApplicationController private def commit_files_internal(commited_files) - if commited_files && commited_files.is_a?(Hash) - @files = [] - failed_uploads = [] - commited_files.each_value do |commited_file| - name = commited_file[:name] - - new_revision = DmsfFileRevision.new - file = DmsfFile.visible.find_file_by_name(@project, @folder, name) - unless file - link = DmsfLink.find_link_by_file_name(@project, @folder, name) - file = link.target_file if link - end - - unless file - file = DmsfFile.new - file.project = @project - file.name = name - file.dmsf_folder = @folder - file.notification = Setting.plugin_redmine_dmsf[:dmsf_default_notifications].present? - new_revision.minor_version = 0 - new_revision.major_version = 0 - else - if file.last_revision - last_revision = file.last_revision - new_revision.source_revision = last_revision - new_revision.major_version = last_revision.major_version - new_revision.minor_version = last_revision.minor_version - else - new_revision.minor_version = 0 - new_revision.major_version = 0 - end - end - - if file.locked_for_user? - failed_uploads.push(commited_file) - next - end - - commited_disk_filepath = "#{DmsfHelper.temp_dir}/#{commited_file[:disk_filename].gsub(/[\/\\]/,'')}" - - new_revision.dmsf_file = file - new_revision.user = User.current - new_revision.name = name - new_revision.title = commited_file[:title] - new_revision.description = commited_file[:description] - new_revision.comment = commited_file[:comment] - version = commited_file[:version].to_i - if version == 3 - new_revision.major_version = commited_file[:custom_version_major].to_i - new_revision.minor_version = commited_file[:custom_version_minor].to_i - else - new_revision.increase_version(version) - end - new_revision.mime_type = Redmine::MimeType.of(new_revision.name) - new_revision.size = File.size(commited_disk_filepath) - new_revision.digest = DmsfFileRevision.create_digest commited_disk_filepath - - # Need to save file first to generate id for it in case of creation. - # File id is needed to properly generate revision disk filename - if commited_file[:dmsf_file_revision].present? - commited_file[:dmsf_file_revision][:custom_field_values].each_with_index do |v, i| - new_revision.custom_field_values[i].value = v[1] - end - end - - if new_revision.valid? && file.save - new_revision.disk_filename = new_revision.new_storage_filename - else - failed_uploads.push(commited_file) - next - end - - if new_revision.save - new_revision.assign_workflow(commited_file[:dmsf_workflow_id]) - begin - FileUtils.mv(commited_disk_filepath, new_revision.disk_file) - file.set_last_revision new_revision - @files.push(file) - rescue Exception => e - Rails.logger.error e.message - flash[:error] = e.message - failed_uploads.push(file) - end - else - failed_uploads.push(commited_file) - end - end - unless @files.empty? - @files.each { |file| log_activity(file, 'uploaded') if file } - if (@folder && @folder.notification?) || (!@folder && @project.dmsf_notification?) - begin - recipients = DmsfMailer.get_notify_users(@project, @files) - recipients.each do |u| - DmsfMailer.files_updated(u, @project, @files).deliver - end - if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' - unless recipients.empty? - to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ') - to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.') - flash[:warning] = l(:warning_email_notifications, :to => to) - end - end - rescue Exception => e - Rails.logger.error "Could not send email notifications: #{e.message}" - end - end - end - unless failed_uploads.empty? - flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', ')) - end - end + DmsfUploadHelper.commit_files_internal(commited_files, @project, @folder) respond_to do |format| format.js - format.api { - render_validation_errors(failed_uploads) unless failed_uploads.empty? - } + format.api { render_validation_errors(failed_uploads) unless failed_uploads.empty? } format.html { redirect_to dmsf_folder_path(:id => @project, :folder_id => @folder) } end - - end - - def log_activity(file, action) - Rails.logger.info "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}@#{request.remote_ip}/#{request.env['HTTP_X_FORWARDED_FOR']}: #{action} dmsf://#{file.project.identifier}/#{file.id}/#{file.last_revision.id}" end def find_folder diff --git a/app/helpers/dmsf_upload_helper.rb b/app/helpers/dmsf_upload_helper.rb new file mode 100644 index 00000000..52c62f07 --- /dev/null +++ b/app/helpers/dmsf_upload_helper.rb @@ -0,0 +1,146 @@ +# 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. + +module DmsfUploadHelper + + def self.commit_files_internal(commited_files, container, folder = nil) + if container.is_a?(Project) + project = container + else + project = container.project + end + if commited_files && commited_files.is_a?(Hash) + files = [] + failed_uploads = [] + commited_files.each_value do |commited_file| + name = commited_file[:name] + new_revision = DmsfFileRevision.new + file = DmsfFile.visible.find_file_by_name(container, folder, name) + unless file + link = DmsfLink.find_link_by_file_name(project, folder, name) + file = link.target_file if link + end + + unless file + file = DmsfFile.new + file.container_type = container.class.name.demodulize + file.container_id = container.id + #file.project = project if container_type == 'Project' + file.name = name + file.dmsf_folder = folder + file.notification = Setting.plugin_redmine_dmsf[:dmsf_default_notifications].present? + new_revision.minor_version = 0 + new_revision.major_version = 0 + else + if file.last_revision + last_revision = file.last_revision + new_revision.source_revision = last_revision + new_revision.major_version = last_revision.major_version + new_revision.minor_version = last_revision.minor_version + else + new_revision.minor_version = 0 + new_revision.major_version = 0 + end + end + + if file.locked_for_user? + failed_uploads.push(commited_file) + next + end + + commited_disk_filepath = "#{DmsfHelper.temp_dir}/#{commited_file[:disk_filename].gsub(/[\/\\]/,'')}" + + new_revision.dmsf_file = file + new_revision.user = User.current + new_revision.name = name + new_revision.title = commited_file[:title] + new_revision.description = commited_file[:description] + new_revision.comment = commited_file[:comment] + version = commited_file[:version].to_i + if version == 3 + new_revision.major_version = commited_file[:custom_version_major].to_i + new_revision.minor_version = commited_file[:custom_version_minor].to_i + else + new_revision.increase_version(version) + end + new_revision.mime_type = Redmine::MimeType.of(new_revision.name) + new_revision.size = File.size(commited_disk_filepath) + new_revision.digest = DmsfFileRevision.create_digest commited_disk_filepath + + # Need to save file first to generate id for it in case of creation. + # File id is needed to properly generate revision disk filename + if commited_file[:dmsf_file_revision].present? + commited_file[:dmsf_file_revision][:custom_field_values].each_with_index do |v, i| + new_revision.custom_field_values[i].value = v[1] + end + end + + if new_revision.valid? && file.save + new_revision.disk_filename = new_revision.new_storage_filename + else + Rails.logger.error (new_revision.errors + file.errors).full_messages.to_sentence + failed_uploads.push(commited_file) + next + end + + if new_revision.save + new_revision.assign_workflow(commited_file[:dmsf_workflow_id]) + begin + FileUtils.mv(commited_disk_filepath, new_revision.disk_file) + file.set_last_revision new_revision + files.push(file) + rescue Exception => e + Rails.logger.error e.message + #flash[:error] = e.message + failed_uploads.push(file) + end + else + failed_uploads.push(commited_file) + end + end + #unless files.empty? + #files.each do |file| + #Rails.logger.info "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')} #{User.current.login}: uploaded dmsf://#{file.project.identifier}/#{file.id}/#{file.last_revision.id}" + #end + #end + if container.is_a?(Project) && ((folder && folder.notification?) || (!folder && project.dmsf_notification?)) + begin + recipients = DmsfMailer.get_notify_users(project, files) + recipients.each do |u| + DmsfMailer.files_updated(u, project, files).deliver + end + if Setting.plugin_redmine_dmsf[:dmsf_display_notified_recipients] == '1' + unless recipients.empty? + to = recipients.collect{ |r| r.name }.first(DMSF_MAX_NOTIFICATION_RECEIVERS_INFO).join(', ') + to << ((recipients.count > DMSF_MAX_NOTIFICATION_RECEIVERS_INFO) ? ',...' : '.') + #flash[:warning] = l(:warning_email_notifications, :to => to) + end + end + rescue Exception => e + Rails.logger.error "Could not send email notifications: #{e.message}" + end + end + end + unless failed_uploads.empty? + #flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', ')) + end + end + +end diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 75f7cb23..3228ab80 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -3,7 +3,7 @@ # Redmine plugin for Document Management System "Features" # # Copyright (C) 2011 Vít Jonáš -# Copyright (C) 2011-16 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 @@ -32,7 +32,6 @@ class DmsfFile < ActiveRecord::Base include RedmineDmsf::Lockable - belongs_to :project belongs_to :dmsf_folder belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id' @@ -56,10 +55,11 @@ class DmsfFile < ActiveRecord::Base validate :validates_name_uniqueness + attr_accessible :project, :project_id + def validates_name_uniqueness - existing_file = DmsfFile.visible.find_file_by_name(self.project, self.dmsf_folder, self.name) - errors.add(:name, l('activerecord.errors.messages.taken')) unless - existing_file.nil? || existing_file.id == self.id + existing_file = DmsfFile.visible.findn_file_by_name(self.container_id, self.container_type, self.dmsf_folder, self.name) + errors.add(:name, l('activerecord.errors.messages.taken')) unless (existing_file.nil? || existing_file.id == self.id) end acts_as_event :title => Proc.new { |o| o.name }, @@ -115,9 +115,14 @@ class DmsfFile < ActiveRecord::Base @@storage_path = path end - def self.find_file_by_name(project, folder, name) + def self.find_file_by_name(container, folder, name) + self.findn_file_by_name(container.id, container.class.name.demodulize, folder, name) + end + + def self.findn_file_by_name(container_id, container_type, folder, name) where( - :project_id => project, + :container_id => container_id, + :container_type => container_type, :dmsf_folder_id => folder ? folder.id : nil, :name => name).visible.first end @@ -273,6 +278,7 @@ class DmsfFile < ActiveRecord::Base file = DmsfFile.new file.dmsf_folder = folder + file.container_type = 'Project' file.project = project file.name = self.name file.notification = Setting.plugin_redmine_dmsf['dmsf_default_notifications'].present? @@ -533,4 +539,39 @@ class DmsfFile < ActiveRecord::Base csv end + def project + unless @project + case self.container_type + when 'Project' + @project = Project.find_by_id(self.container_id) + when 'Issue' + issue = Issue.find_by_id(self.container_id) + @project = issue.project if issue + end + end + @project + end + + def project=(project) + case self.container_type + when 'Project' + self.container_id = project.id + else + raise Exception.new('The container type is not project!') + end + end + + def project_id + self.project.id if self.project + end + + def project_id=(project_id) + case self.container_type + when 'Project' + self.container_id = project_id + else + raise Exception.new('The container type is not project!') + end + end + end diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb index 84a002b3..170f9d37 100644 --- a/app/models/dmsf_file_revision.rb +++ b/app/models/dmsf_file_revision.rb @@ -51,8 +51,8 @@ class DmsfFileRevision < ActiveRecord::Base :scope => select("#{DmsfFileRevision.table_name}.*"). joins( "INNER JOIN #{DmsfFile.table_name} ON #{DmsfFileRevision.table_name}.dmsf_file_id = #{DmsfFile.table_name}.id " + - "INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.project_id = #{Project.table_name}.id"). - where("#{DmsfFile.table_name}.deleted = ?", STATUS_ACTIVE) + "INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.container_id = #{Project.table_name}.id"). + where("#{DmsfFile.table_name}.deleted = ? AND #{DmsfFile.table_name}.container_type = ?", STATUS_ACTIVE, 'Project') validates :title, :presence => true validates_format_of :name, :with => DmsfFolder::INVALID_CHARACTERS, diff --git a/app/models/dmsf_file_revision_access.rb b/app/models/dmsf_file_revision_access.rb index 61d8a87f..ddfb195d 100644 --- a/app/models/dmsf_file_revision_access.rb +++ b/app/models/dmsf_file_revision_access.rb @@ -3,7 +3,7 @@ # Redmine plugin for Document Management System "Features" # # Copyright (C) 2011 Vít Jonáš -# Copyright (C) 2011-16 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 @@ -44,6 +44,6 @@ class DmsfFileRevisionAccess < ActiveRecord::Base joins( "INNER JOIN #{DmsfFileRevision.table_name} ON #{DmsfFileRevisionAccess.table_name}.dmsf_file_revision_id = #{DmsfFileRevision.table_name}.id " + "INNER JOIN #{DmsfFile.table_name} ON #{DmsfFileRevision.table_name}.dmsf_file_id = #{DmsfFile.table_name}.id " + - "INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.project_id = #{Project.table_name}.id"). - where("#{DmsfFile.table_name}.deleted = ?", DmsfFile::STATUS_ACTIVE) + "INNER JOIN #{Project.table_name} ON #{DmsfFile.table_name}.container_id = #{Project.table_name}.id"). + where("#{DmsfFile.table_name}.deleted = ? AND #{DmsfFile.table_name}.container_type = ?", DmsfFile::STATUS_ACTIVE, 'Project') end diff --git a/app/models/dmsf_upload.rb b/app/models/dmsf_upload.rb index ff1efd06..16271a5f 100644 --- a/app/models/dmsf_upload.rb +++ b/app/models/dmsf_upload.rb @@ -76,7 +76,8 @@ class DmsfUpload @minor_version = 0 @workflow = nil file = DmsfFile.new - file.project = @project + file.container_type = 'Project' + file.project = project revision = DmsfFileRevision.new revision.dmsf_file = file @custom_values = revision.custom_field_values diff --git a/app/models/dmsf_workflow.rb b/app/models/dmsf_workflow.rb index dd3aec4c..4e04d59b 100644 --- a/app/models/dmsf_workflow.rb +++ b/app/models/dmsf_workflow.rb @@ -106,9 +106,8 @@ class DmsfWorkflow < ActiveRecord::Base def delegates(q, dmsf_workflow_step_assignment_id, dmsf_file_revision_id) if dmsf_workflow_step_assignment_id && dmsf_file_revision_id sql = [ - 'id NOT IN (SELECT a.user_id FROM dmsf_workflow_step_assignments a WHERE id = ?) AND id IN (SELECT m.user_id FROM members m JOIN dmsf_files f ON f.project_id = m.project_id JOIN dmsf_file_revisions r ON r.dmsf_file_id = f.id WHERE r.id = ?)', - dmsf_workflow_step_assignment_id, - dmsf_file_revision_id] + 'id NOT IN (SELECT a.user_id FROM dmsf_workflow_step_assignments a WHERE id = ?) AND id IN (SELECT m.user_id FROM members m JOIN dmsf_files f ON f.container_id = m.project_id JOIN dmsf_file_revisions r ON r.dmsf_file_id = f.id WHERE r.id = ? AND container_type = ?)', + dmsf_workflow_step_assignment_id, dmsf_file_revision_id, 'Project'] elsif project sql = ['id IN (SELECT user_id FROM members WHERE project_id = ?)', project.id] else diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index 2d4e3c3b..48ad4a51 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -178,7 +178,7 @@ <% if @folder %> return "<%= "#{l(:label_number_of_folders)}: #{@folder.deep_folder_count} #{l(:label_number_of_documents)}: #{@folder.deep_file_count}" %>"; <% else %> - return "<%= "#{l(:label_number_of_folders)}: #{DmsfFolder.visible.where(:project_id => @project.id).count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfFolder').count}, #{l(:label_number_of_documents)}: #{DmsfFile.visible.where(:project_id => @project.id).count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfFile').count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfUrl').count}" %>"; + return "<%= "#{l(:label_number_of_folders)}: #{DmsfFolder.visible.where(:project_id => @project.id).count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfFolder').count}, #{l(:label_number_of_documents)}: #{DmsfFile.visible.where(:container_id => @project.id, :container_type => 'Project').count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfFile').count + DmsfLink.visible.where(:project_id => @project.id, :target_type => 'DmsfUrl').count}" %>"; <% end %> <% else %> return "<%= "#{l(:label_number_of_folders)}: #{@subfolders.count + @dir_links.count}, #{l(:label_number_of_documents)}: #{@files.count + @file_links.count + @url_links.count}" %>"; diff --git a/app/views/dmsf_files/_links.html.erb b/app/views/dmsf_files/_links.html.erb new file mode 100644 index 00000000..4c9dff35 --- /dev/null +++ b/app/views/dmsf_files/_links.html.erb @@ -0,0 +1,44 @@ +<% + # 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. +%> + +
+
+<% for dmsf_file in dmsf_files %> +

+ <% file_view_url = url_for({:controller => :dmsf_files, :action => 'view', :id => dmsf_file}) %> + <%= link_to(h(dmsf_file.title), + file_view_url, + :target => '_blank', + :class => "icon icon-file #{DmsfHelper.filetype_css(dmsf_file.name)}", + :title => h(dmsf_file.last_revision.try(:tooltip)), + 'data-downloadurl' => "#{dmsf_file.last_revision.detect_content_type}:#{h(dmsf_file.name)}:#{file_view_url}") %> + <%= " - #{dmsf_file.description}" unless dmsf_file.description.blank? %> + (<%= number_to_human_size dmsf_file.last_revision.size %>) + <%= link_to(image_tag('delete.png'), + dmsf_file_path(:id => dmsf_file), + :data => {:confirm => l(:text_are_you_sure)}, + :method => :delete, + :title => l(:title_delete)) %> + <%= dmsf_file.last_revision.user %>, <%= format_time(dmsf_file.last_revision.updated_at) %> +

+<% end %> +
diff --git a/app/views/dmsf_files/_upload_form.html.erb b/app/views/dmsf_files/_upload_form.html.erb deleted file mode 100644 index df4d6954..00000000 --- a/app/views/dmsf_files/_upload_form.html.erb +++ /dev/null @@ -1,36 +0,0 @@ -<% hide = false %> - - -<% if defined?(container) && container && container.saved_attachments %> - <% container.saved_attachments.each_with_index do |attachment, i| %> - - <%= text_field_tag("attachments[p#{i}][filename]", attachment.filename, :class => 'filename') %> - <%= hidden_field_tag "attachments[p#{i}][token]", "#{attachment.token}" %> - <% hide = true %> - - <% end %> -<% end %> - - -<% unless hide %> - - <%= file_field_tag 'attachments[dummy][file]', - :id => nil, - :class => 'file_selector', - :multiple => false, - :onchange => 'addInputFile(this);', - :data => { - :max_file_size => Setting.attachment_max_size.to_i.kilobytes, - :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), - :max_file_count_message => l(:error_maximum_upload_filecount, :filecount => 1), - :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, - :upload_path => uploads_path(:format => 'js'), - :description_placeholder => l(:label_optional_description) - } %> - (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) - -<% end %> - -<% content_for :header_tags do %> - <%= javascript_include_tag 'attachments_dmsf', :plugin => 'redmine_dmsf' %> -<% end %> diff --git a/app/views/dmsf_upload/_form.html.erb b/app/views/dmsf_upload/_form.html.erb new file mode 100644 index 00000000..b9276423 --- /dev/null +++ b/app/views/dmsf_upload/_form.html.erb @@ -0,0 +1,49 @@ +<% + # 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. +%> + + +<% if defined?(container) && container && container.saved_attachments %> + <% container.saved_attachments.each_with_index do |attachment, i| %> + + <%= text_field_tag("dmsf_attachments[p#{i}][filename]", attachment.filename, :class => 'filename') + + text_field_tag("dmsf_attachments[p#{i}][description]", attachment.description, :maxlength => 255, :placeholder => l(:label_optional_description), :class => 'description') + + link_to(' '.html_safe, attachment_path(attachment, :attachment_id => "p#{i}", :format => 'js'), :method => 'delete', :remote => true, :class => 'remove-upload') %> + <%= hidden_field_tag "dmsf_attachments[p#{i}][token]", "#{attachment.token}" %> + + <% end %> +<% end %> + + +<%= file_field_tag 'dmsf_attachments[dummy][file]', + :id => nil, + :class => 'file_selector', + :multiple => true, + :onchange => 'dmsfAddInputFiles(this);', + :data => { + :max_file_size => Setting.attachment_max_size.to_i.kilobytes, + :max_file_size_message => l(:error_attachment_too_big, :max_size => number_to_human_size(Setting.attachment_max_size.to_i.kilobytes)), + :max_concurrent_uploads => Redmine::Configuration['max_concurrent_ajax_uploads'].to_i, + :upload_path => dmsf_uploads_path(:format => 'js'), + :description_placeholder => l(:label_optional_description) + } %> + (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) + diff --git a/app/views/dmsf_upload/_multi_upload.html.erb b/app/views/dmsf_upload/_multi_upload.html.erb index 20dc8dc3..172f9f81 100644 --- a/app/views/dmsf_upload/_multi_upload.html.erb +++ b/app/views/dmsf_upload/_multi_upload.html.erb @@ -36,11 +36,11 @@ <%= form_tag({:controller => 'dmsf_upload', :action => 'upload_files', :id => @project, :folder_id => @folder}, :id => 'uploadform', :method => :post, :multipart => true) do %> -
-
+
+

- - <%= render :partial => 'attachments/form' %> + + <%= render :partial => 'dmsf_upload/form' %>

<%= submit_tag l(:label_upload) %> @@ -49,14 +49,14 @@