Module: Redmine::MyPage

Includes:
I18n
Defined in:
lib/redmine/my_page.rb

Overview

Since:

  • 3.4.0

Constant Summary collapse

CORE_GROUPS =
['top', 'left', 'right']
CORE_BLOCKS =
{
  '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},
  'calendar' => {:label => :label_calendar},
  'documents' => {:label => :label_document_plural},
  'timelog' => {:label => :label_spent_time},
  'activity' => {:label => :label_activity}
}

Class Method Summary collapse

Methods included from I18n

#current_language, #day_letter, #day_name, #find_language, #format_date, #format_hours, #format_time, #l, #l_hours, #l_hours_short, #l_or_humanize, #languages_options, #ll, #lu, #month_name, #set_language_if_valid, #valid_languages

Class Method Details

.additional_blocksObject

Returns the additional blocks that are defined by plugin partials



76
77
78
79
80
81
82
# File 'lib/redmine/my_page.rb', line 76

def self.additional_blocks
  @@additional_blocks ||= Dir.glob("#{Redmine::Plugin.directory}/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file|
    name = File.basename(file).split('.').first.gsub(/^_/, '')
    h[name] = {:label => name.to_sym, :partial => "my/blocks/#{name}"}
    h
  end
end

.block_options(blocks_in_use = []) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/redmine/my_page.rb', line 45

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_id]
  end
  options
end

.blocksObject

Returns the available blocks



41
42
43
# File 'lib/redmine/my_page.rb', line 41

def self.blocks
  CORE_BLOCKS.merge(additional_blocks).freeze
end

.default_layoutObject

Returns the default layout for My Page



85
86
87
88
89
90
# File 'lib/redmine/my_page.rb', line 85

def self.default_layout
  {
    'left' => ['issuesassignedtome'],
    'right' => ['issuesreportedbyme']
  }
end

.find_block(block) ⇒ Object



69
70
71
72
73
# File 'lib/redmine/my_page.rb', line 69

def self.find_block(block)
  block.to_s =~  /\A(.*?)(__\d+)?\z/
  name = $1
  blocks.has_key?(name) ? blocks[name].merge(:name => name) : nil
end

.groupsObject



36
37
38
# File 'lib/redmine/my_page.rb', line 36

def self.groups
  CORE_GROUPS.dup.freeze
end

.valid_block?(block, blocks_in_use = []) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/redmine/my_page.rb', line 65

def self.valid_block?(block, blocks_in_use=[])
  block.present? && block_options(blocks_in_use).map(&:last).include?(block)
end