summaryrefslogtreecommitdiffstats
path: root/lib/redmine/my_page.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2017-03-16 18:02:43 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2017-03-16 18:02:43 +0000
commit4cfd5133733a08ebf5ba89aa3994e4a86679c809 (patch)
tree562cc4d5d11453a058134de4aa95c2c9f121ebf5 /lib/redmine/my_page.rb
parent1a180a67be5c205653e5d006fd027c0cafb3b597 (diff)
downloadredmine-4cfd5133733a08ebf5ba89aa3994e4a86679c809.tar.gz
redmine-4cfd5133733a08ebf5ba89aa3994e4a86679c809.zip
Allow multiple instances of custom queries on My page (#1565).
git-svn-id: http://svn.redmine.org/redmine/trunk@16413 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/my_page.rb')
-rw-r--r--lib/redmine/my_page.rb33
1 files changed, 27 insertions, 6 deletions
diff --git a/lib/redmine/my_page.rb b/lib/redmine/my_page.rb
index dc9c6928f..34195bbcd 100644
--- a/lib/redmine/my_page.rb
+++ b/lib/redmine/my_page.rb
@@ -20,10 +20,10 @@ module Redmine
include Redmine::I18n
CORE_BLOCKS = {
- 'issuesassignedtome' => {:label => :label_assigned_to_me_issues, :partial => 'my/blocks/issues'},
- 'issuesreportedbyme' => {:label => :label_reported_issues, :partial => 'my/blocks/issues'},
- 'issueswatched' => {:label => :label_watched_issues, :partial => 'my/blocks/issues'},
- 'issuequery' => {:label => :label_issue_plural, :partial => 'my/blocks/issues'},
+ 'issuesassignedtome' => {:label => :label_assigned_to_me_issues},
+ 'issuesreportedbyme' => {:label => :label_reported_issues},
+ 'issueswatched' => {:label => :label_watched_issues},
+ 'issuequery' => {:label => :label_issue_plural, :max_occurs => 3},
'news' => {:label => :label_news_latest, :partial => 'my/blocks/news'},
'calendar' => {:label => :label_calendar, :partial => 'my/blocks/calendar'},
'documents' => {:label => :label_document_plural, :partial => 'my/blocks/documents'},
@@ -35,15 +35,36 @@ module Redmine
CORE_BLOCKS.merge(additional_blocks).freeze
end
- def self.block_options
+ def self.block_options(blocks_in_use=[])
options = []
blocks.each do |block, block_options|
+ indexes = blocks_in_use.map {|n|
+ if n =~ /\A#{block}(__(\d+))?\z/
+ $2.to_i
+ end
+ }.compact
+
+ occurs = indexes.size
+ block_id = indexes.any? ? "#{block}__#{indexes.max + 1}" : block
+ disabled = (occurs >= (Redmine::MyPage.blocks[block][:max_occurs] || 1))
+ block_id = nil if disabled
+
label = block_options[:label]
- options << [l("my.blocks.#{label}", :default => [label, label.to_s.humanize]), block.dasherize]
+ options << [l("my.blocks.#{label}", :default => [label, label.to_s.humanize]), block_id]
end
options
end
+ def self.valid_block?(block, blocks_in_use=[])
+ block.present? && block_options(blocks_in_use).map(&:last).include?(block)
+ end
+
+ def self.find_block(block)
+ block.to_s =~ /\A(.*?)(__\d+)?\z/
+ name = $1
+ blocks.has_key?(name) ? blocks[name].merge(:name => name) : nil
+ end
+
# Returns the additional blocks that are defined by plugin partials
def self.additional_blocks
@@additional_blocks ||= Dir.glob("#{Redmine::Plugin.directory}/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file|