diff --git a/app/models/dmsf_folder.rb b/app/models/dmsf_folder.rb index 7a08aa0d..9f016397 100644 --- a/app/models/dmsf_folder.rb +++ b/app/models/dmsf_folder.rb @@ -37,6 +37,12 @@ class DmsfFolder < ActiveRecord::Base validate :check_cycle + acts_as_event :title => Proc.new {|o| o.title}, + :description => Proc.new {|o| o.description }, + :url => Proc.new {|o| {:controller => "dmsf", :action => "show", :folder_id => o}}, + :datetime => Proc.new {|o| o.updated_at }, + :author => Proc.new {|o| o.user } + def check_cycle folders = [] self.subfolders.each {|f| folders.push(f)} @@ -116,6 +122,44 @@ class DmsfFolder < ActiveRecord::Base size end + # To fullfill searchable module expectations + def self.search(tokens, projects=nil, options={}) + tokens = [] << tokens unless tokens.is_a?(Array) + projects = [] << projects unless projects.nil? || projects.is_a?(Array) + + find_options = {:include => [:project]} + 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])}')" + end + + columns = options[:titles_only] ? ["dmsf_folders.title"] : ["dmsf_folders.title", "dmsf_folders.description"] + + token_clauses = columns.collect {|column| "(LOWER(#{column}) LIKE ?)"} + + sql = (['(' + token_clauses.join(' OR ') + ')'] * tokens.size).join(options[:all_words] ? ' AND ' : ' OR ') + find_options[:conditions] = [sql, * (tokens.collect {|w| "%#{w.downcase}%"} * token_clauses.size).sort] + + project_conditions = [] + project_conditions << (Project.allowed_to_condition(User.current, :view_dmsf_files)) + project_conditions << "project_id IN (#{projects.collect(&:id).join(',')})" unless projects.nil? + + results = [] + results_count = 0 + + with_scope(:find => {:conditions => [project_conditions.join(' AND ')]}) do + with_scope(:find => find_options) do + results_count = count(:all) + results = find(:all, limit_options) + end + end + + [results, results_count] + end + private def self.directory_subtree(tree, folder, level, current_folder) diff --git a/init.rb b/init.rb index 025ba703..3d392d40 100644 --- a/init.rb +++ b/init.rb @@ -52,7 +52,7 @@ Redmine::Plugin.register :redmine_dmsf do activity_provider :dmsf_files, :class_name => "DmsfFileRevision", :default => true project_module :dmsf do - permission :browse_documents, {:dmsf => [:show]} + permission :view_dmsf_folders, {:dmsf => [:show]} permission :user_preferences, {:dmsf_state => [:user_pref_save]} permission :view_dmsf_files, {:dmsf => [:entries_operation, :entries_email], :dmsf_files => [:show]} @@ -106,4 +106,5 @@ end Redmine::Search.map do |search| search.register :dmsf_files + search.register :dmsf_folders end