diff --git a/app/controllers/dmsf_upload_controller.rb b/app/controllers/dmsf_upload_controller.rb index 4e3706a9..d85e8557 100644 --- a/app/controllers/dmsf_upload_controller.rb +++ b/app/controllers/dmsf_upload_controller.rb @@ -86,7 +86,7 @@ class DmsfUploadController < ApplicationController files = [] failed_uploads = [] commited_files.each_value do |commited_file| - name = commited_file["name"]; + name = commited_file['name']; new_revision = DmsfFileRevision.new file = DmsfFile.visible.find_file_by_name(@project, @folder, name) @@ -95,7 +95,7 @@ class DmsfUploadController < ApplicationController file.project = @project file.name = name file.folder = @folder - file.notification = !Setting.plugin_redmine_dmsf["dmsf_default_notifications"].blank? + file.notification = !Setting.plugin_redmine_dmsf['dmsf_default_notifications'].blank? new_revision.minor_version = 0 new_revision.major_version = 0 @@ -107,26 +107,25 @@ class DmsfUploadController < ApplicationController 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 - #new_revision.workflow = last_revision.workflow + new_revision.minor_version = last_revision.minor_version end - commited_disk_filepath = "#{DmsfHelper.temp_dir}/#{commited_file["disk_filename"].gsub(/[\/\\]/,'')}" + commited_disk_filepath = "#{DmsfHelper.temp_dir}/#{commited_file['disk_filename'].gsub(/[\/\\]/,'')}" new_revision.project = @project new_revision.folder = @folder new_revision.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"] - new_revision.increase_version(commited_file["version"].to_i, true) + new_revision.title = commited_file['title'] + new_revision.description = commited_file['description'] + new_revision.comment = commited_file['comment'] + new_revision.increase_version(commited_file['version'].to_i, true) new_revision.mime_type = Redmine::MimeType.of(new_revision.name) new_revision.size = File.size(commited_disk_filepath) - file_upload = File.new(commited_disk_filepath, "rb") - if file_upload.nil? + file_upload = File.new(commited_disk_filepath, 'rb') + unless file_upload failed_uploads.push(commited_file) flash[:error] = l(:error_file_commit_require_uploaded_file) next @@ -161,11 +160,13 @@ class DmsfUploadController < ApplicationController files.push(file) - unless commited_file["dmsf_file_revision"].blank? - commited_file["dmsf_file_revision"]["custom_field_values"].each do |v| - cv = CustomValue.find(:first, :conditions => ["customized_id = " + new_revision.id.to_s + " AND custom_field_id = " + v[0]]) - cv.value = v[1] - cv.save + if commited_file['dmsf_file_revision'].present? + commited_file['dmsf_file_revision']['custom_field_values'].each do |v| + cv = CustomValue.where(:customized_id => new_revision.id, :custom_field_id => v[0]).first + if cv + cv.value = v[1] + cv.save + end end end else @@ -173,18 +174,18 @@ class DmsfUploadController < ApplicationController end end unless files.empty? - files.each {|file| log_activity(file, "uploaded") unless file.nil?} + files.each { |file| log_activity(file, 'uploaded') if file } begin DmsfMailer.files_updated(User.current, files).deliver rescue ActionView::MissingTemplate => e - Rails.logger.error "Could not send email notifications: " + e.to_s + Rails.logger.error "Could not send email notifications: #{e.message}" end end unless failed_uploads.empty? - flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u["name"]}.join(", ")) + flash[:warning] = l(:warning_some_files_were_not_commited, :files => failed_uploads.map{|u| u['name']}.join(', ')) end end - redirect_to :controller => "dmsf", :action => "show", :id => @project, :folder_id => @folder + redirect_to :controller => 'dmsf', :action => 'show', :id => @project, :folder_id => @folder end private @@ -198,14 +199,14 @@ class DmsfUploadController < ApplicationController end def find_folder - @folder = DmsfFolder.visible.find(params[:folder_id]) if params.keys.include?("folder_id") + @folder = DmsfFolder.visible.find(params[:folder_id]) if params.keys.include?('folder_id') check_project(@folder) rescue DmsfAccessError render_403 end def check_project(entry) - if !entry.nil? && entry.project != @project + if entry && entry.project != @project raise DmsfAccessError, l(:error_entry_project_does_not_match_current_project) end end diff --git a/app/models/dmsf_file.rb b/app/models/dmsf_file.rb index 08861423..ab04b03f 100644 --- a/app/models/dmsf_file.rb +++ b/app/models/dmsf_file.rb @@ -20,7 +20,7 @@ begin require 'xapian' $xapian_bindings_available = true rescue LoadError - Rails.logger.info "REDMAIN_XAPIAN ERROR: No Ruby bindings for Xapian installed !!. PLEASE install Xapian search engine interface for Ruby." + Rails.logger.info 'REDMAIN_XAPIAN ERROR: No Ruby bindings for Xapian installed !!. PLEASE install Xapian search engine interface for Ruby.' $xapian_bindings_available = false end @@ -30,15 +30,15 @@ class DmsfFile < ActiveRecord::Base include RedmineDmsf::Lockable belongs_to :project - belongs_to :folder, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id" - has_many :revisions, :class_name => "DmsfFileRevision", :foreign_key => "dmsf_file_id", + belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id' + has_many :revisions, :class_name => 'DmsfFileRevision', :foreign_key => 'dmsf_file_id', :order => "#{DmsfFileRevision.table_name}.major_version DESC, #{DmsfFileRevision.table_name}.minor_version DESC, #{DmsfFileRevision.table_name}.updated_at DESC", :dependent => :destroy - has_many :locks, :class_name => "DmsfLock", :foreign_key => "entity_id", + has_many :locks, :class_name => 'DmsfLock', :foreign_key => 'entity_id', :order => "#{DmsfLock.table_name}.updated_at DESC", :conditions => {:entity_type => 0}, :dependent => :destroy - belongs_to :deleted_by_user, :class_name => "User", :foreign_key => "deleted_by_user_id" + belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id' scope :visible, lambda {|*args| where(DmsfFile.visible_condition(args.shift || User.current, *args)).readonly(false)} @@ -55,18 +55,18 @@ class DmsfFile < ActiveRecord::Base def validates_name_uniqueness existing_file = DmsfFile.visible.find_file_by_name(self.project, self.folder, self.name) - errors.add(:name, l("activerecord.errors.messages.taken")) unless + 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.title} - #{o.name}"}, :description => Proc.new {|o| o.description }, - :url => Proc.new {|o| {:controller => "dmsf_files", :action => "show", :id => o, :download => ""}}, + :url => Proc.new {|o| {:controller => 'dmsf_files', :action => 'show', :id => o, :download => ''}}, :datetime => Proc.new {|o| o.updated_at }, :author => Proc.new {|o| o.last_revision.user } - @@storage_path = Setting.plugin_redmine_dmsf["dmsf_storage_directory"].strip + @@storage_path = Setting.plugin_redmine_dmsf['dmsf_storage_directory'].strip def self.storage_path if !File.exists?(@@storage_path) @@ -82,20 +82,14 @@ class DmsfFile < ActiveRecord::Base end def self.project_root_files(project) - visible.find(:all, :conditions => - ["dmsf_folder_id is NULL and project_id = :project_id", - {:project_id => project.id}], :order => "#{self.table_name}.name ASC") + visible.where(:dmsf_folder_id => nil, :project_id => project.if).order('name ASC') end def self.find_file_by_name(project, folder, name) - if folder.nil? - visible.find(:first, :conditions => - ["dmsf_folder_id is NULL and project_id = :project_id and name = :name", - {:project_id => project.id, :name => name}]) + if folder + visible.where(:project_id => project, :dmsf_folder_id => folder.id, :name => name).first else - visible.find(:first, :conditions => - ["dmsf_folder_id = :folder_id and project_id = :project_id and name = :name", - {:project_id => project.id, :folder_id => folder.id, :name => name}]) + visible.where(:project_id => project, :dmsf_folder_id => nil, :name => name).first end end @@ -109,14 +103,14 @@ class DmsfFile < ActiveRecord::Base errors[:base] << l(:error_file_is_locked) return false end - if Setting.plugin_redmine_dmsf["dmsf_really_delete_files"] - CustomValue.find(:all, :conditions => "customized_id = " + self.id.to_s).each do |v| + if Setting.plugin_redmine_dmsf['dmsf_really_delete_files'] + CustomValue.where(:customized_id => self.id).all.each do |v| v.destroy end self.revisions.visible.each {|r| r.delete(true)} self.destroy else - #Revisions of a deleted file SHOULD be deleted too + # Revisions of a deleted file SHOULD be deleted too self.revisions.visible.each {|r| r.delete } self.deleted = true self.deleted_by_user = User.current @@ -171,13 +165,8 @@ class DmsfFile < ActiveRecord::Base self.save! end - def display_name - #if self.name.length > 33 - # extension = File.extname(self.name) - # return self.name[0, self.name.length - extension.length][0, 25] + "..." + extension - #else - return self.name - #end + def display_name + return self.name end # Returns an array of projects that current user can copy file to @@ -193,17 +182,7 @@ class DmsfFile < ActiveRecord::Base # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields def available_custom_fields - search_project = nil - if self.project.present? - search_project = self.project - elsif self.project_id.present? - search_project = Project.find(self.project_id) - end - if search_project - search_project.all_dmsf_custom_fields - else - DmsfFileRevisionCustomField.all - end + DmsfFileRevisionCustomField.all end def move_to(project, folder) @@ -219,14 +198,14 @@ class DmsfFile < ActiveRecord::Base new_revision.comment = l(:comment_moved_from, :source => "#{self.project.identifier}:#{self.dmsf_path_str}") new_revision.custom_values = [] - temp_custom_values = self.last_revision.custom_values.select{|cv| new_revision.project.all_dmsf_custom_fields.include?(cv.custom_field)}.map(&:clone) + temp_custom_values = self.last_revision.custom_values.select{|cv| new_revision.available_custom_fields.include?(cv.custom_field)}.map(&:clone) new_revision.custom_values = temp_custom_values - #add default value for CFs not existing + # Add default value for CFs not existing present_custom_fields = new_revision.custom_values.collect(&:custom_field).uniq - Project.find(new_revision.project_id).all_dmsf_custom_fields.each do |cf| + new_revision.available_custom_fields.each do |cf| unless present_custom_fields.include?(cf) - new_revision.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) + new_revision.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) if cf.default_value end end @@ -257,16 +236,14 @@ class DmsfFile < ActiveRecord::Base new_revision.folder = folder new_revision.project = folder ? folder.project : project new_revision.comment = l(:comment_copied_from, :source => "#{self.project.identifier}: #{self.dmsf_path_str}") + + new_revision.custom_values = Array.new(self.last_revision.custom_values) - new_revision.custom_values = [] - temp_custom_values = self.last_revision.custom_values.select{|cv| new_revision.project.all_dmsf_custom_fields.include?(cv.custom_field)}.map(&:clone) - new_revision.custom_values = temp_custom_values - - #add default value for CFs not existing + # Add default value for CFs not existing present_custom_fields = new_revision.custom_values.collect(&:custom_field).uniq - new_revision.project.all_dmsf_custom_fields.each do |cf| + new_revision.available_custom_fields.each do |cf| unless present_custom_fields.include?(cf) - new_revision.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) + new_revision.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) if cf.default_value end end @@ -324,9 +301,9 @@ class DmsfFile < ActiveRecord::Base if !options[:titles_only] && $xapian_bindings_available database = nil begin - database = Xapian::Database.new(Setting.plugin_redmine_dmsf["dmsf_index_database"].strip) + database = Xapian::Database.new(Setting.plugin_redmine_dmsf['dmsf_index_database'].strip) rescue - Rails.logger.warn "REDMAIN_XAPIAN ERROR: Xapian database is not properly set or initiated or is corrupted." + Rails.logger.warn 'REDMAIN_XAPIAN ERROR: Xapian database is not properly set or initiated or is corrupted.' end unless database.nil? @@ -339,9 +316,12 @@ class DmsfFile < ActiveRecord::Base qp.database = database case Setting.plugin_redmine_dmsf['dmsf_stemming_strategy'].strip - when "STEM_NONE" then qp.stemming_strategy = Xapian::QueryParser::STEM_NONE - when "STEM_SOME" then qp.stemming_strategy = Xapian::QueryParser::STEM_SOME - when "STEM_ALL" then qp.stemming_strategy = Xapian::QueryParser::STEM_ALL + when 'STEM_NONE' + qp.stemming_strategy = Xapian::QueryParser::STEM_NONE + when 'STEM_SOME' + qp.stemming_strategy = Xapian::QueryParser::STEM_SOME + when 'STEM_ALL' + qp.stemming_strategy = Xapian::QueryParser::STEM_ALL end if options[:all_words] @@ -355,12 +335,12 @@ class DmsfFile < ActiveRecord::Base enquire.query = query matchset = enquire.mset(0, 1000) - unless matchset.nil? + if matchset matchset.matches.each {|m| docdata = m.document.data{url} dochash = Hash[*docdata.scan(/(url|sample|modtime|type|size)=\/?([^\n\]]+)/).flatten] - filename = dochash["url"] - if !filename.nil? + filename = dochash['url'] + if filename dmsf_attrs = filename.scan(/^([^\/]+\/[^_]+)_([\d]+)_(.*)$/) id_attribute = 0 id_attribute = dmsf_attrs[0][1] if dmsf_attrs.length > 0 @@ -369,7 +349,7 @@ class DmsfFile < ActiveRecord::Base dmsf_file = DmsfFile.where(limit_options[:conditions]).where(:id => id_attribute, :deleted => false).first - if !dmsf_file.nil? + if dmsf_file if options[:offset] if options[:before] next if dmsf_file.updated_at < options[:offset] @@ -380,7 +360,7 @@ class DmsfFile < ActiveRecord::Base allowed = User.current.allowed_to?(:view_dmsf_files, dmsf_file.project) project_included = false - project_included = true if projects.nil? + project_included = true unless projects unless project_included projects.each do |x| if x.is_a?(ActiveRecord::Relation) diff --git a/app/models/dmsf_file_revision.rb b/app/models/dmsf_file_revision.rb index 2ca4fa49..f6c8ebd2 100644 --- a/app/models/dmsf_file_revision.rb +++ b/app/models/dmsf_file_revision.rb @@ -18,16 +18,16 @@ class DmsfFileRevision < ActiveRecord::Base unloadable - belongs_to :file, :class_name => "DmsfFile", :foreign_key => "dmsf_file_id" - belongs_to :source_revision, :class_name => "DmsfFileRevision", :foreign_key => "source_dmsf_file_revision_id" + belongs_to :file, :class_name => 'DmsfFile', :foreign_key => 'dmsf_file_id' + belongs_to :source_revision, :class_name => 'DmsfFileRevision', :foreign_key => 'source_dmsf_file_revision_id' belongs_to :user - belongs_to :folder, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id" - belongs_to :deleted_by_user, :class_name => "User", :foreign_key => "deleted_by_user_id" + belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id' + belongs_to :deleted_by_user, :class_name => 'User', :foreign_key => 'deleted_by_user_id' belongs_to :project - has_many :access, :class_name => "DmsfFileRevisionAccess", :foreign_key => "dmsf_file_revision_id", :dependent => :destroy + has_many :access, :class_name => 'DmsfFileRevisionAccess', :foreign_key => 'dmsf_file_revision_id', :dependent => :destroy has_many :dmsf_workflow_step_assignment, :dependent => :destroy - #Returns a list of revisions that are not deleted here, or deleted at parent level either + # Returns a list of revisions that are not deleted here, or deleted at parent level either scope :visible, lambda {|*args| joins(:file).where(DmsfFile.visible_condition(args.shift || User.current, *args)).where("#{self.table_name}.deleted = :false", :false => false ).readonly(false) } acts_as_customizable @@ -38,7 +38,7 @@ class DmsfFileRevision < ActiveRecord::Base :description => Proc.new {|o| o.comment }, :author => Proc.new {|o| o.user } - acts_as_activity_provider :type => "dmsf_files", + acts_as_activity_provider :type => 'dmsf_files', :timestamp => "#{DmsfFileRevision.table_name}.updated_at", :author_key => "#{DmsfFileRevision.table_name}.user_id", :permission => :view_dmsf_files, @@ -57,9 +57,9 @@ class DmsfFileRevision < ActiveRecord::Base filename[0, (filename.length - File.extname(filename).length)] end - #TODO: check if better to move to dmsf_upload class + # TODO: check if better to move to dmsf_upload class def self.filename_to_title(filename) - remove_extension(filename).gsub(/_+/, " "); + remove_extension(filename).gsub(/_+/, ' '); end def delete(delete_all = false) @@ -71,19 +71,18 @@ class DmsfFileRevision < ActiveRecord::Base errors[:base] << l(:error_at_least_one_revision_must_be_present) return false end - dependent = DmsfFileRevision.find(:all, :conditions => - ["source_dmsf_file_revision_id = :id and deleted = :deleted", - {:id => self.id, :deleted => false}]) + dependent = DmsfFileRevision.find(:source_dmsf_file_revision_id => self.id, :deleted => false).all dependent.each do |d| d.source_revision = self.source_revision d.save! end - if Setting.plugin_redmine_dmsf["dmsf_really_delete_files"] - dependent = DmsfFileRevision.find(:all, :conditions => - ["disk_filename = :filename", {:filename => self.disk_filename}]) + if Setting.plugin_redmine_dmsf['dmsf_really_delete_files'] + dependent = DmsfFileRevision..where(:disk_filename => self.disk_filename).all File.delete(self.disk_file) if dependent.length <= 1 && File.exist?(self.disk_file) - DmsfFileRevisionAccess.find(:all, :conditions => ["dmsf_file_revision_id = ?", self.id]).each {|a| a.destroy} - CustomValue.find(:all, :conditions => "customized_id = " + self.id.to_s).each do |v| + DmsfFileRevisionAccess.where(:dmsf_file_revision_id => self.id).all.each do |a| + a.destroy + end + CustomValue.find(:customized_id => self.id).all.each do |v| v.destroy end self.destroy @@ -106,7 +105,7 @@ class DmsfFileRevision < ActiveRecord::Base # custom SQL into a temporary object # def access_grouped - access.select("user_id, count(*) as count, min(created_at) as first_at, max(created_at) as last_at").group("user_id") + access.select('user_id, COUNT(*) AS count, MIN(created_at) AS first_at, MAX(created_at) AS last_at').group('user_id') end def version @@ -126,11 +125,11 @@ class DmsfFileRevision < ActiveRecord::Base def detect_content_type content_type = self.mime_type content_type = Redmine::MimeType.of(self.disk_filename) if content_type.blank? - content_type = "application/octet-stream" if content_type.blank? + content_type = 'application/octet-stream' if content_type.blank? content_type.to_s end - #TODO: use standard clone method + # TODO: use standard clone method def clone new_revision = DmsfFileRevision.new new_revision.file = self.file @@ -213,16 +212,12 @@ class DmsfFileRevision < ActiveRecord::Base end end - def display_title - #if self.title.length > 35 - # return self.title[0, 30] + "..." - #else - return self.title - #end + def display_title + return self.title end def new_storage_filename - raise DmsfAccessError, "File id is not set" unless self.file.id + raise DmsfAccessError, 'File id is not set' unless self.file.id filename = DmsfHelper.sanitize_filename(self.name) timestamp = DateTime.now.strftime("%y%m%d%H%M%S") while File.exist?(File.join(DmsfFile.storage_path, "#{timestamp}_#{self.file.id}_#{filename}")) @@ -232,7 +227,7 @@ class DmsfFileRevision < ActiveRecord::Base end def copy_file_content(open_file) - File.open(self.disk_file, "wb") do |f| + File.open(self.disk_file, 'wb') do |f| while (buffer = open_file.read(8192)) f.write(buffer) end @@ -241,17 +236,7 @@ class DmsfFileRevision < ActiveRecord::Base # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields def available_custom_fields - search_project = nil - if self.project.present? - search_project = self.project - elsif self.project_id.present? - search_project = Project.find(self.project_id) - end - if search_project - search_project.all_dmsf_custom_fields - else - DmsfFileRevisionCustomField.all - end + DmsfFileRevisionCustomField.all end end diff --git a/app/models/dmsf_file_revision_custom_field.rb b/app/models/dmsf_file_revision_custom_field.rb index 30d28ec3..4b084387 100644 --- a/app/models/dmsf_file_revision_custom_field.rb +++ b/app/models/dmsf_file_revision_custom_field.rb @@ -1,13 +1,23 @@ -class DmsfFileRevisionCustomField < CustomField - unloadable - has_and_belongs_to_many :projects, :join_table => "#{table_name_prefix}custom_fields_projects#{table_name_suffix}", :foreign_key => "custom_field_id" - - def initialize(attributes = nil) - super - self.searchable = true - end +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2013 Karel Picman +# +# 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. +class DmsfFileRevisionCustomField < CustomField def type_name - :DMSF_custom_field + :menu_dmsf end end \ No newline at end of file diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index d7a24702..1f00e165 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -25,19 +25,19 @@ class DmsfFolder < ActiveRecord::Base @@invalid_characters = /\A[^\/\\\?":<>]*\z/ belongs_to :project - belongs_to :folder, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id" - has_many :subfolders, :class_name => "DmsfFolder", :foreign_key => "dmsf_folder_id", :order => "#{DmsfFolder.table_name}.title ASC", + belongs_to :folder, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id' + has_many :subfolders, :class_name => 'DmsfFolder', :foreign_key => 'dmsf_folder_id', :order => "#{DmsfFolder.table_name}.title ASC", :dependent => :destroy - has_many :files, :class_name => "DmsfFile", :foreign_key => "dmsf_folder_id", + has_many :files, :class_name => 'DmsfFile', :foreign_key => 'dmsf_folder_id', :dependent => :destroy belongs_to :user - has_many :locks, :class_name => "DmsfLock", :foreign_key => "entity_id", + has_many :locks, :class_name => 'DmsfLock', :foreign_key => 'entity_id', :order => "#{DmsfLock.table_name}.updated_at DESC", :conditions => {:entity_type => 1}, :dependent => :destroy - scope :visible, lambda {|*args| {:conditions => "" }} #For future use, however best to be referenced now + scope :visible, lambda {|*args| {:conditions => '' }} #For future use, however best to be referenced now acts_as_customizable @@ -51,7 +51,7 @@ class DmsfFolder < ActiveRecord::Base acts_as_event :title => Proc.new {|o| o.title}, :description => Proc.new {|o| o.description }, - :url => Proc.new {|o| {:controller => "dmsf", :action => "show", :id => o.project, :folder_id => o}}, + :url => Proc.new {|o| {:controller => 'dmsf', :action => 'show', :id => o.project, :folder_id => o}}, :datetime => Proc.new {|o| o.updated_at }, :author => Proc.new {|o| o.user } @@ -69,20 +69,15 @@ class DmsfFolder < ActiveRecord::Base end def self.project_root_folders(project) - find(:all, :conditions => - ["#{DmsfFolder.table_name}.dmsf_folder_id is NULL and #{DmsfFolder.table_name}.project_id = :project_id", {:project_id => project.id}], :order => "#{DmsfFolder.table_name}.title ASC") + visible.where(:project_id => project.id, :dmsf_folder_id => nil, ).order('title ASC').all end - def self.find_by_title(project, folder, title) - if folder.nil? - visible.find(:first, :conditions => - ["#{DmsfFolder.table_name}.dmsf_folder_id is NULL and #{DmsfFolder.table_name}.project_id = :project_id and #{DmsfFolder.table_name}.title = :title", - {:project_id => project.id, :title => title}]) + def self.find_by_title(project, folder, title) + if folder + visible.where(:project_id => project.id, :dmsf_folder_id => nil, :title => title).first else - visible.find(:first, :conditions => - ["#{DmsfFolder.table_name}.dmsf_folder_id = :folder_id and #{DmsfFolder.table_name}.title = :title", - {:project_id => project.id, :folder_id => folder.id, :title => title}]) - end + visible.where(:project_id => project.id, :dmsf_folder_id => folder.id, :title => title).first + end end def delete @@ -99,7 +94,7 @@ class DmsfFolder < ActiveRecord::Base def dmsf_path folder = self path = [] - while !folder.nil? + while folder path.unshift(folder) folder = folder.folder end @@ -109,7 +104,7 @@ class DmsfFolder < ActiveRecord::Base def dmsf_path_str path = self.dmsf_path string_path = path.map { |element| element.title } - string_path.join("/") + string_path.join('/') end def notify? @@ -195,18 +190,15 @@ class DmsfFolder < ActiveRecord::Base new_folder.project = folder ? folder.project : project new_folder.title = self.title new_folder.description = self.description - new_folder.user = User.current - - #copy only cfs present in destination project - temp_custom_values = self.custom_values.select{|cv| new_folder.project.all_dmsf_custom_fields.include?(cv.custom_field)}.map(&:clone) + new_folder.user = User.current - new_folder.custom_values = temp_custom_values + new_folder.custom_values = Array.new(self.custom_values) - #add default value for CFs not existing + # Add default value for CFs not existing present_custom_fields = new_folder.custom_values.collect(&:custom_field).uniq - new_folder.project.all_dmsf_custom_fields.each do |cf| + new_folder.available_custom_fields.each do |cf| unless present_custom_fields.include?(cf) - new_folder.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) + new_folder.custom_values << CustomValue.new({:custom_field => cf, :value => cf.default_value}) if cf.default_value end end @@ -225,17 +217,7 @@ class DmsfFolder < ActiveRecord::Base # Overrides Redmine::Acts::Customizable::InstanceMethods#available_custom_fields def available_custom_fields - search_project = nil - if self.project.present? - search_project = self.project - elsif self.project_id.present? - search_project = Project.find(self.project_id) - end - if search_project - search_project.all_dmsf_custom_fields - else - DmsfFileRevisionCustomField.all - end + DmsfFileRevisionCustomField.all end # To fullfill searchable module expectations @@ -244,12 +226,12 @@ class DmsfFolder < ActiveRecord::Base projects = [] << projects unless projects.nil? || projects.is_a?(Array) find_options = {:include => [:project]} - find_options[:order] = "dmsf_folders.updated_at " + (options[:before] ? 'DESC' : 'ASC') + find_options[:order] = 'dmsf_folders.updated_at ' + (options[:before] ? 'DESC' : 'ASC') limit_options = {} limit_options[:limit] = options[:limit] if options[:limit] if options[:offset] - limit_options[:conditions] = "(dmsf_folders.updated_at " + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')" + limit_options[:conditions] = '(dmsf_folders.updated_at ' + (options[:before] ? '<' : '>') + "'#{connection.quoted_date(options[:offset])}')" end columns = options[:titles_only] ? ["dmsf_folders.title"] : ["dmsf_folders.title", "dmsf_folders.description"] diff --git a/app/views/dmsf/_custom_fields.html.erb b/app/views/dmsf/_custom_fields.html.erb index 1fa7de3d..007f7729 100644 --- a/app/views/dmsf/_custom_fields.html.erb +++ b/app/views/dmsf/_custom_fields.html.erb @@ -1,9 +1,9 @@ -<% unless object.nil? %> -
- <% object.show_custom_field_values.each do |custom_value| %> -
- <%= label_tag("", h(custom_value.custom_field.name) + ":") %> <%= show_value(custom_value) %> -
- <% end %> -
+<% if object %> +
+ <% object.show_custom_field_values.each do |custom_value| %> +
+ <%= label_tag('', "#{h(custom_value.custom_field.name)}:") %> <%= show_value(custom_value) %> +
+ <% end %> +
<% end %> \ No newline at end of file diff --git a/app/views/dmsf/show.html.erb b/app/views/dmsf/show.html.erb index dcd9472a..88ef38b2 100644 --- a/app/views/dmsf/show.html.erb +++ b/app/views/dmsf/show.html.erb @@ -54,10 +54,10 @@
-
- <%= textilizable(@folder.nil? ? @project.dmsf_description : @folder.description) %> -
- <%= render "custom_fields", :object => @folder %> +
+ <%= textilizable(@folder ? @folder.description : @project.dmsf_description) %> +
+ <%#= render 'custom_fields', :object => @folder %>
<%= error_messages_for('dmsf_workflow') %> @@ -98,7 +98,7 @@ {:action => "show", :id => @project, :folder_id => subfolder}, :class => "icon icon-folder") %>
[<%= subfolder.deep_file_count %>]
- <%= render 'custom_fields', :object => subfolder %> + <%#= render 'custom_fields', :object => subfolder %> <%= number_to_human_size(subfolder.deep_size) %> <%= format_time(subfolder.updated_at) %> @@ -178,7 +178,7 @@ :title => l(:title_title_version_version_download, :title => h(file.title), :version => file.version), "data-downloadurl" => "#{file.last_revision.detect_content_type}:#{h(file.name)}:#{file_download_url}") %>
<%= h(file.display_name) %>
- <%= render 'custom_fields', :object => file.last_revision %> + <%#= render 'custom_fields', :object => file.last_revision %> <%= number_to_human_size(file.last_revision.size) %> diff --git a/app/views/dmsf_files/_file_new_revision.html.erb b/app/views/dmsf_files/_file_new_revision.html.erb index e09f73f7..3999e585 100644 --- a/app/views/dmsf_files/_file_new_revision.html.erb +++ b/app/views/dmsf_files/_file_new_revision.html.erb @@ -1,81 +1,100 @@ +<%# +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2013 Karel Picman +# +# 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. +%> +
- <%= l(:heading_new_revision) %> [-] -
- <% if @file.locked_for_user? %> -

<%= l(:info_file_locked) %>

- <% else %> -<%= form_for(@revision, :url => {:action => "create_revision", :id => @file}, - :html => {:method=>:post, :multipart => true, :id => "new_revision_form"}) do |f| %> -
-
-

- <%= label_tag("dmsf_file_revision_title", l(:label_title) + ":") %> - <%= f.text_field(:title, :size => "32") %> -

-
-
-

- <%= label_tag("", l(:label_file) + ":") %> - <%= f.select(:dmsf_folder_id, - options_for_select(DmsfFolder.directory_tree(@project), - :selected => (@revision.folder.id unless @revision.folder.nil?))) %> / - <%= f.text_field(:name, :size => "22") %> -

-
-
-

- <%= label_tag("dmsf_file_revision_description", l(:label_description) + ":") %> -

-
- <%= f.text_area(:description, :rows=> "6", :class => "wiki-edit") %> -
-
-

- <%= label_tag("fileMinorVersionRadio", l(:label_version) + ":") %> -

-
- <%= radio_button_tag("version", 0, @revision.version == @file.last_revision.version, :id => "fileSameVersionRadio") %> - <%= @file.last_revision.major_version %>.<%= @file.last_revision.minor_version %> <%= l(:option_version_same) %>
- <%= radio_button_tag("version", 1, - @revision.major_version == @file.last_revision.major_version && @revision.minor_version != @file.last_revision.minor_version, - :id => "fileMinorVersionRadio") %> - <%= @file.last_revision.major_version %>.<%= @file.last_revision.minor_version + 1 %> <%= l(:option_version_minor) %>
- <%= radio_button_tag("version", 2, @revision.major_version != @file.last_revision.major_version) %> - <%= @file.last_revision.major_version + 1 %>.0 <%= l(:option_version_major) %>
-
-
-
-

- <%= label_tag("file_upload", l(:label_new_content) + ":") %> -

- <%= file_field_tag("file_upload", :size => 30) %> -
- - (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) - -
-

-
-
-
- <% @revision.custom_field_values.each do |value| %> -

<%= custom_field_tag_with_label(:dmsf_file_revision, value) %>

- <% end %> -
-
-

- <%= label_tag("dmsf_file_revision_comment", l(:label_comment) + ":") %> -

- <%= f.text_area(:comment, :rows=> "2", :style => "width: 99%;") %> -
-

-
-
- <%= submit_tag(l(:submit_create)) %> - -<% end %> - <% end %> -
+ <%= l(:heading_new_revision) %> [-] +
+ <% if @file.locked_for_user? %> +

<%= l(:info_file_locked) %>

+ <% else %> + <%= form_for(@revision, :url => {:action => 'create_revision', :id => @file}, + :html => {:method=>:post, :multipart => true, :id => 'new_revision_form'}) do |f| %> +
+
+

+ <%= label_tag('dmsf_file_revision_title', "#{l(:label_title)}:") %> + <%= f.text_field(:title, :size => '32') %> +

+
+
+

+ <%= label_tag('', "#{l(:label_file)}:") %> + <%= f.select(:dmsf_folder_id, + options_for_select(DmsfFolder.directory_tree(@project), + :selected => (@revision.folder.id if @revision.folder))) %> / + <%= f.text_field(:name, :size => '22') %> +

+
+
+

+ <%= label_tag('dmsf_file_revision_description', "#{l(:label_description)}:") %> +

+
+ <%= f.text_area(:description, :rows=> '6', :class => 'wiki-edit') %> +
+
+

+ <%= label_tag('fileMinorVersionRadio', "#{l(:label_version)}:") %> +

+
+ <%= radio_button_tag('version', 0, @revision.version == @file.last_revision.version, :id => 'fileSameVersionRadio') %> + <%= @file.last_revision.major_version %>.<%= @file.last_revision.minor_version %> <%= l(:option_version_same) %>
+ <%= radio_button_tag('version', 1, + @revision.major_version == @file.last_revision.major_version && @revision.minor_version != @file.last_revision.minor_version, + :id => 'fileMinorVersionRadio') %> + <%= @file.last_revision.major_version %>.<%= @file.last_revision.minor_version + 1 %> <%= l(:option_version_minor) %>
+ <%= radio_button_tag('version', 2, @revision.major_version != @file.last_revision.major_version) %> + <%= @file.last_revision.major_version + 1 %>.0 <%= l(:option_version_major) %>
+
+
+
+

+ <%= label_tag('file_upload', "#{l(:label_new_content)}:") %> +

+ <%= file_field_tag('file_upload', :size => 30) %> +
+ + (<%= l(:label_max_size) %>: <%= number_to_human_size(Setting.attachment_max_size.to_i.kilobytes) %>) + +
+

+
+
+
+ <% @revision.custom_field_values.each do |value| %> +

<%= custom_field_tag_with_label(:dmsf_file_revision, value) %>

+ <% end %> +
+
+

+ <%= label_tag('dmsf_file_revision_comment', "#{l(:label_comment)}:") %> +

+ <%= f.text_area(:comment, :rows=> '2', :style => 'width: 99%;') %> +
+

+
+
+ <%= submit_tag(l(:submit_create)) %> + <% end %> + <% end %> +
-<%= wikitoolbar_for "dmsf_file_revision_description" %> +<%= wikitoolbar_for 'dmsf_file_revision_description' %> diff --git a/app/views/dmsf_files/_revision_access.html.erb b/app/views/dmsf_files/_revision_access.html.erb index f5a97fc9..b7629009 100644 --- a/app/views/dmsf_files/_revision_access.html.erb +++ b/app/views/dmsf_files/_revision_access.html.erb @@ -1,22 +1,43 @@ +<%#= +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2011 Vít Jonáš +# Copyright (C) 2012 Daniel Munn +# Copyright (C) 2013 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. +%>

- - - - - - - - - - -<% revision.access_grouped.each do |access| %> - - - - - - -<% end %> - -
<%=l(:field_user)%><%=l(:heading_access_downloads_emails)%><%=l(:heading_access_first)%><%=l(:heading_access_last)%>
<%=link_to_user(access.user)%><%=access["count"]%><%=format_time(DmsfHelper::to_time(access.first_at))%><%=format_time(DmsfHelper::to_time(access.last_at))%>
+ + + + + + + + + + + <% revision.access_grouped.each do |access| %> + + + + + + + <% end %> + +
<%= l(:field_user) %><%= l(:heading_access_downloads_emails) %><%= l(:heading_access_first) %><%= l(:heading_access_last) %>
<%= link_to_user(access.user) %><%= access['count'] %><%= format_time(DmsfHelper::to_time(access.first_at)) %><%= format_time(DmsfHelper::to_time(access.last_at)) %>

diff --git a/app/views/dmsf_files/show.html.erb b/app/views/dmsf_files/show.html.erb index a328a78c..ffbb7a57 100644 --- a/app/views/dmsf_files/show.html.erb +++ b/app/views/dmsf_files/show.html.erb @@ -1,43 +1,43 @@ <% html_title(l(:dmsf)) %>
- <% if User.current.allowed_to?(:file_manipulation, @project) %> - <% unless @file.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> - <% if @file.locked? %> - <% unless @file.unlockable? %> - <%= image_tag("locked.png", :plugin => :redmine_dmsf, :title => l(:title_file_parent_locked, :name => @file.lock.reverse[0].folder.title)) %> - <% else %> - <%= link_to_function(image_tag("unlock.png", :plugin => "redmine_dmsf"), - "manipulation_link('#{url_for(:action => 'unlock', :id => @file, :current => request.url)}')", - :title => l(:title_unlock_file)) %> - <% end %> - <% else %> - <%= link_to_function(image_tag("lock.png", :plugin => "redmine_dmsf"), - "manipulation_link('#{url_for(:action => 'lock', :id => @file, :current => request.url)}')", - :title => l(:title_lock_file)) %> - <% end %> - <% end %> - <% if User.current.allowed_to?(:file_manipulation, @project) && !@file.locked_for_user? %> -   - <%= link_to_function(image_tag("delete.png", :plugin => "redmine_dmsf"), - "confirmation_link('#{url_for(:action => 'delete', :id => @file)}', '#{l(:question_do_you_really_want_to_delete_this_entry)}')", - :title => l(:title_delete)) %> - <% end %> - <% if User.current.allowed_to?(:file_approval, @project) %> -   - <% if @file.notification %> - <%= link_to_function(image_tag("notify.png", :plugin => "redmine_dmsf"), - "manipulation_link('#{url_for(:action => 'notify_deactivate', :id => @file, :current => request.url)}')", - :title => l(:title_notifications_active_deactivate)) %> - <% else %> - <%= link_to_function(image_tag("notifynot.png", :plugin => "redmine_dmsf"), - "manipulation_link('#{url_for(:action => 'notify_activate', :id => @file, :current => request.url)}')", - :title => l(:title_notifications_not_active_activate)) %> - <% end %> - <% end %> - <% end %> -   - <%= link_to(image_tag("copy.png"), {:controller => :dmsf_files_copy, :action => "new", :id => @file }, :title => l(:title_copy_or_move)) %> + <% if User.current.allowed_to?(:file_manipulation, @project) %> + <% unless @file.locked_for_user? && !User.current.allowed_to?(:force_file_unlock, @project)%> + <% if @file.locked? %> + <% unless @file.unlockable? %> + <%= image_tag('locked.png', :plugin => :redmine_dmsf, :title => l(:title_file_parent_locked, :name => @file.lock.reverse[0].folder.title)) %> + <% else %> + <%= link_to_function(image_tag('unlock.png', :plugin => 'redmine_dmsf'), + "manipulation_link('#{url_for(:action => 'unlock', :id => @file, :current => request.url)}')", + :title => l(:title_unlock_file)) %> + <% end %> + <% else %> + <%= link_to_function(image_tag('lock.png', :plugin => 'redmine_dmsf'), + "manipulation_link('#{url_for(:action => 'lock', :id => @file, :current => request.url)}')", + :title => l(:title_lock_file)) %> + <% end %> + <% end %> + <% if User.current.allowed_to?(:file_manipulation, @project) && !@file.locked_for_user? %> +   + <%= link_to_function(image_tag('delete.png', :plugin => 'redmine_dmsf'), + "confirmation_link('#{url_for(:action => 'delete', :id => @file)}', '#{l(:question_do_you_really_want_to_delete_this_entry)}')", + :title => l(:title_delete)) %> + <% end %> + <% if User.current.allowed_to?(:file_approval, @project) %> +   + <% if @file.notification %> + <%= link_to_function(image_tag('notify.png', :plugin => 'redmine_dmsf'), + "manipulation_link('#{url_for(:action => 'notify_deactivate', :id => @file, :current => request.url)}')", + :title => l(:title_notifications_active_deactivate)) %> + <% else %> + <%= link_to_function(image_tag('notifynot.png', :plugin => 'redmine_dmsf'), + "manipulation_link('#{url_for(:action => 'notify_activate', :id => @file, :current => request.url)}')", + :title => l(:title_notifications_not_active_activate)) %> + <% end %> + <% end %> + <% end %> +   + <%= link_to(image_tag('copy.png'), {:controller => :dmsf_files_copy, :action => "new", :id => @file }, :title => l(:title_copy_or_move)) %>

@@ -52,12 +52,12 @@ <%= image_tag('notify.png', :plugin => 'redmine_dmsf', :title => l(:title_notifications_active)) if @file.notification %>

-<%= error_messages_for("file") %> -<%= error_messages_for("revision") %> +<%= error_messages_for('file') %> +<%= error_messages_for('revision') %> -<%= render(:partial => "file_new_revision") if User.current.allowed_to?(:file_manipulation, @file.project) %> +<%= render(:partial => 'file_new_revision') if User.current.allowed_to?(:file_manipulation, @file.project) %> -<%= form_tag("", :id => "manipulation_form") %> +<%= form_tag('', :id => 'manipulation_form') %>

<%= l(:heading_revisions) %>

<% @file.revisions.visible[@revision_pages.current.offset,@revision_pages.items_per_page].each do |revision| %> @@ -84,44 +84,44 @@
- <%= label_tag("", l(:label_title) + ":") %> + <%= label_tag('', "#{l(:label_title)}:") %> <%= h(revision.title) %>
- <%= label_tag("", l(:label_file) + ":") %> - <%= (h(revision.folder.dmsf_path_str) + "/") unless revision.folder.nil? %><%= h(revision.name) %> + <%= label_tag('', "#{l(:label_file)}:") %> + <%= ("#{h(revision.folder.dmsf_path_str)}/") if revision.folder %><%= h(revision.name) %>

- <%= label_tag("", l(:label_description) + ":") %> + <%= label_tag('', "#{l(:label_description)}:") %>

<%= textilizable(revision.description) %>
- <%= label_tag("", l(:label_version) + ":") %> + <%= label_tag('', "#{l(:label_version)}:") %> <%= revision.major_version %>.<%= revision.minor_version %>
- <%= label_tag('', l(:label_workflow) + ':') %> + <%= label_tag('', "#{l(:label_workflow)}:") %> <%= revision.workflow_str true %>
- <%= label_tag("", l(:label_mime) + ":") %> + <%= label_tag('', "#{l(:label_mime)}:") %> <%= h(revision.mime_type) %>  -
- <%= label_tag("", l(:label_size) + ":") %> +
+ <%= label_tag('', "#{l(:label_size)}:") %> <%= number_to_human_size(revision.size) %>
- <%= render "dmsf/custom_fields", :object => revision %> + <%= render 'dmsf/custom_fields', :object => revision %>
- <%= label_tag("", l(:label_comment) + ":") %> + <%= label_tag('', "#{l(:label_comment)}:") %> <%= h(revision.comment) %>

" style="display:none"> - <%= render(:partial => "revision_access", :locals => {:revision => revision}) if User.current.allowed_to?(:file_approval, @file.project) %> + <%= render(:partial => 'revision_access', :locals => {:revision => revision}) if User.current.allowed_to?(:file_approval, @file.project) %>
@@ -132,67 +132,71 @@

<%= pagination_links_full @revision_pages, @file.revisions.visible.count %>

<% -sUrl = "jquery.dataTables/en.json" -sUrl = "jquery.dataTables/#{I18n.locale.to_s.downcase}.json" if I18n.locale && !I18n.locale.to_s.match(/^en.*/) + sUrl = 'jquery.dataTables/en.json' + sUrl = "jquery.dataTables/#{I18n.locale.to_s.downcase}.json" if I18n.locale && !I18n.locale.to_s.match(/^en.*/) %> <% if @revision.valid? && @file.valid? %> - + <% end %> <% content_for :header_tags do %> - <%= stylesheet_link_tag "jquery-ui/jquery-ui-1.9.2.css", :plugin => "redmine_dmsf" %> - <%= stylesheet_link_tag "jquery.dataTables/jquery-ui.dataTables.css", :plugin => "redmine_dmsf" %> - <%= stylesheet_link_tag "dmsf", :plugin => "redmine_dmsf" %> - <%= javascript_include_tag "jquery-1.6.1.min.js", :plugin => "redmine_dmsf" %> - <%= javascript_include_tag "jquery-ui-1.8.13.min.js", :plugin => "redmine_dmsf" %> - <%= javascript_include_tag "jquery.dataTables/jquery.dataTables.min.js", :plugin => "redmine_dmsf" %> - -<% end %> + <%= stylesheet_link_tag 'jquery-ui/jquery-ui-1.9.2.css', :plugin => 'redmine_dmsf' %> + <%= stylesheet_link_tag 'jquery.dataTables/jquery-ui.dataTables.css', :plugin => 'redmine_dmsf' %> + <%= stylesheet_link_tag 'dmsf', :plugin => 'redmine_dmsf' %> + <%= javascript_include_tag 'jquery-1.6.1.min.js', :plugin => 'redmine_dmsf' %> + <%= javascript_include_tag 'jquery-ui-1.8.13.min.js', :plugin => 'redmine_dmsf' %> + <%= javascript_include_tag 'jquery.dataTables/jquery.dataTables.min.js', :plugin => 'redmine_dmsf' %> + +<% end %> \ No newline at end of file diff --git a/app/views/dmsf_state/_user_pref.html.erb b/app/views/dmsf_state/_user_pref.html.erb index d10394f8..de3ac4fc 100644 --- a/app/views/dmsf_state/_user_pref.html.erb +++ b/app/views/dmsf_state/_user_pref.html.erb @@ -1,39 +1,40 @@ +<%# +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2013 Karel Picman +# +# 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. +%> +

<%=l(:link_user_preferences)%>

- <%= form_tag({:controller => "dmsf_state", :action => "user_pref_save", :id => @project}, - :method=>:post) do %> -
- <% - member = @project.members.find(:first, :conditions => {:user_id => User.current.id}) - mail_notification = member ? member.dmsf_mail_notification : nil - %> - <%= l(:label_notifications) %>: - <%= select_tag("email_notify", - options_for_select([[l(:select_option_default), nil], - [l(:select_option_activated), true], [l(:select_option_deactivated), false]], - :selected => mail_notification)) %> - <%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %> -
- <% end %> - - <% custom_fields = DmsfFileRevisionCustomField.find(:all) %> - <% unless custom_fields.empty? %> - <%= form_for @project, :url => project_path(@project), :html => {:method=>:post} do %> -
<%=l(:label_custom_field_plural)%> - <% custom_fields.each do |custom_field| %> - - <% end %> - <%= hidden_field_tag 'project[dmsf_file_revision_custom_field_ids][]', '' %> - <%= hidden_field_tag '_method', 'put' %> -
- <%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %> - <% end %> - <% end %> + <%= form_tag({:controller => 'dmsf_state', :action => 'user_pref_save', :id => @project}, :method => :post) do %> +
+ <% member = @project.members.find(:first, :conditions => {:user_id => User.current.id}) %> + <% mail_notification = member ? member.dmsf_mail_notification : nil %> + <%= l(:label_notifications) %>: + <%= select_tag( + 'email_notify', + options_for_select([[l(:select_option_default), nil], + [l(:select_option_activated), true], [l(:select_option_deactivated), false]], + :selected => mail_notification)) %> + <%= submit_tag(l(:submit_save), :title => l(:title_save_preferences)) %> +
+ <% end %>
<% content_for :header_tags do %> - <%= stylesheet_link_tag "dmsf", :plugin => "redmine_dmsf" %> -<% end %> + <%= stylesheet_link_tag 'dmsf', :plugin => 'redmine_dmsf' %> +<% end %> \ No newline at end of file diff --git a/app/views/dmsf_upload/_upload_file.html.erb b/app/views/dmsf_upload/_upload_file.html.erb index 0f88f88b..1224ba1d 100644 --- a/app/views/dmsf_upload/_upload_file.html.erb +++ b/app/views/dmsf_upload/_upload_file.html.erb @@ -1,60 +1,77 @@ - +<%# +# Redmine plugin for Document Management System "Features" +# +# Copyright (C) 2013 Karel Picman +# +# 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. +%>
- <%= hidden_field_tag("commited_files[#{i}][disk_filename]", upload.disk_filename) %> -
-
-

- <%= label_tag("commited_files[#{i}][title]", l(:label_title) + ":") %> - <%= text_field_tag("commited_files[#{i}][title]", upload.title, :size => "32") %> -

-
-
-

- <%= label_tag("", l(:label_filename) + ":") %> - <%= h(upload.name) %> - <%= hidden_field_tag("commited_files[#{i}][name]", upload.name) %> -

-
-
-

- <%= label_tag("commited_files[#{i}][description]", l(:label_description) + ":") %> -

-
- <%= text_area_tag("commited_files[#{i}][description]", upload.description, :rows=> "6", :class => "wiki-edit") %> -
-
-

- <%= label_tag("commited_files[#{i}][version]_minor", l(:label_version) + ":") %> -

-
- <%= radio_button_tag("commited_files[#{i}][version]", 1, true) %> - <%= upload.major_version %>.<%= upload.minor_version + 1 %> <%= l(:option_version_minor) %>
- <%= radio_button_tag("commited_files[#{i}][version]", 2) %> - <%= upload.major_version + 1 %>.0 <%= l(:option_version_major) %>
-
-
-
-

- <%= label_tag("", l(:label_mime) + ":") %> - <%= h(upload.mime_type) %> -

-

- <%= label_tag("", l(:label_size) + ":") %> - <%= number_to_human_size(upload.size) %> -

-
-
- <% @folder ? folder_exists = true : folder_exists = false %> - <% values = folder_exists ? @folder.custom_field_values : DmsfFileRevision.new(:file => DmsfFile.new(:project => @project)).custom_field_values %> - <% values.each do |value| %> -

<%= custom_field_tag_with_label("commited_files[#{i}][dmsf_file_revision]", value) %>

- <% end %> -

- <%= label_tag("commited_files[#{i}][comment]", l(:label_comment) + ":") %> -

- <%= text_area_tag("commited_files[#{i}][comment]", upload.comment, :rows=> "2", :style => "width: 99%;") %> -
-

+ <%= hidden_field_tag("commited_files[#{i}][disk_filename]", upload.disk_filename) %> +
+
+

+ <%= label_tag("commited_files[#{i}][title]", "#{l(:label_title)}:") %> + <%= text_field_tag("commited_files[#{i}][title]", upload.title, :size => '32') %> +

+
+
+

+ <%= label_tag('', "#{l(:label_filename)}:") %> + <%= h(upload.name) %> + <%= hidden_field_tag("commited_files[#{i}][name]", upload.name) %> +

+
+
+

+ <%= label_tag("commited_files[#{i}][description]", "#{l(:label_description)}:") %> +

+
+ <%= text_area_tag("commited_files[#{i}][description]", upload.description, :rows=> '6', :class => 'wiki-edit') %> +
+
+

+ <%= label_tag("commited_files[#{i}][version]_minor", "#{l(:label_version)}:") %> +

+
+ <%= radio_button_tag("commited_files[#{i}][version]", 1, true) %> + <%= upload.major_version %>.<%= upload.minor_version + 1 %> <%= l(:option_version_minor) %>
+ <%= radio_button_tag("commited_files[#{i}][version]", 2) %> + <%= upload.major_version + 1 %>.0 <%= l(:option_version_major) %>
+
+
+
+

+ <%= label_tag('', "#{l(:label_mime)}:") %> + <%= h(upload.mime_type) %> +

+

+ <%= label_tag('', "#{l(:label_size)}:") %> + <%= number_to_human_size(upload.size) %> +

+
+
+ <% values = DmsfFileRevision.new(:file => DmsfFile.new(:project => @project)).custom_field_values %> + <% values.each do |value| %> +

<%= custom_field_tag_with_label("commited_files[#{i}][dmsf_file_revision]", value) %>

+ <% end %> +

+ <%= label_tag("commited_files[#{i}][comment]", "#{l(:label_comment)}:") %> +

+ <%= text_area_tag("commited_files[#{i}][comment]", upload.comment, :rows=> '2', :style => 'width: 99%;') %> +
+

<%= wikitoolbar_for "commited_files_#{i}_description" %> diff --git a/assets/stylesheets/dmsf.css b/assets/stylesheets/dmsf.css index 618bf64f..8b3f668a 100644 --- a/assets/stylesheets/dmsf.css +++ b/assets/stylesheets/dmsf.css @@ -225,7 +225,7 @@ table.access-table tbody td, table.access-table tbody tr:hover td { /* Custom field */ .dmsf-customfields { - margin: 5px 0 5px 25px; + margin: 5px 0px 5px 0px; } .dmsf-customfields .customfield { diff --git a/lib/redmine_dmsf/patches/acts_as_customizable.rb b/lib/redmine_dmsf/patches/acts_as_customizable.rb index 2e5887b7..81117efb 100644 --- a/lib/redmine_dmsf/patches/acts_as_customizable.rb +++ b/lib/redmine_dmsf/patches/acts_as_customizable.rb @@ -1,7 +1,8 @@ # Redmine plugin for Document Management System "Features" # -# Copyright (C) 2011 Vt Jon +# Copyright (C) 2011 Vít Jonáš # Copyright (C) 2012 Daniel Munn +# Copyright (C) 2013 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 @@ -21,13 +22,24 @@ module Redmine module Acts module Customizable module InstanceMethods - def available_custom_fields - cf_classname = self.class.name == 'DmsfFolder' ? 'DmsfFileRevision' : self.class.name - CustomField.find(:all, :conditions => "type = '#{cf_classname}CustomField'", :order => 'position') - end +# def available_custom_fields +# cf_classname = self.class.name == 'DmsfFolder' ? 'DmsfFileRevision' : self.class.name +# CustomField.find(:all, :conditions => "type = '#{cf_classname}CustomField'", :order => 'position') +# end def show_custom_field_values - custom_field_values.delete_if { |x| (!x.id && x.id.blank?) || x.value.blank? } +# a = custom_field_values +# c = a.count +# custom_field_values.each do |v| +# if v.id.blank? +# if v.value.blank? +# d = true +# end +# end +# end + #custom_field_values.delete_if { |x| (!x.id && x.id.blank?) || x.value.blank? } if d + custom_field_values.delete_if { |v| v.custom_field.blank? || v.value.blank? } +# b = a.count end end end diff --git a/lib/redmine_dmsf/patches/project_patch.rb b/lib/redmine_dmsf/patches/project_patch.rb index 010d49f5..b0afe88b 100644 --- a/lib/redmine_dmsf/patches/project_patch.rb +++ b/lib/redmine_dmsf/patches/project_patch.rb @@ -42,9 +42,9 @@ module RedmineDmsf end module InstanceMethods - def all_dmsf_custom_fields - @all_dmsf_custom_fields ||= (DmsfFileRevisionCustomField.for_all).uniq.sort # + dmsf_file_revision_custom_fields).uniq.sort - end + #def all_dmsf_custom_fields + # @all_dmsf_custom_fields ||= (DmsfFileRevisionCustomField.for_all).uniq.sort # + dmsf_file_revision_custom_fields).uniq.sort + #end def dmsf_count file_count = DmsfFile.visible.project_root_files(self).count