Module: Redmine::MyPage

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

Constant Summary collapse

CORE_GROUPS =
['top', 'left', 'right']
CORE_BLOCKS =
{
  'issuesassignedtome' => {:label => :label_assigned_to_me_issues},
  'issuesreportedbyme' => {:label => :label_reported_issues},
  'issuesupdatedbyme' => {:label => :label_updated_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, included, #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



79
80
81
82
83
84
85
86
87
88
# File 'lib/redmine/my_page.rb', line 79

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



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

def self.block_options(blocks_in_use=[])
  options = []
  blocks.each do |block, block_options|
    indexes = blocks_in_use.map do |n|
      if n =~ /\A#{block}(__(\d+))?\z/
        $2.to_i
      end
    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



44
45
46
# File 'lib/redmine/my_page.rb', line 44

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

.default_layoutObject

Returns the default layout for My Page



91
92
93
94
95
96
# File 'lib/redmine/my_page.rb', line 91

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

.find_block(block) ⇒ Object



72
73
74
75
76
# File 'lib/redmine/my_page.rb', line 72

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



39
40
41
# File 'lib/redmine/my_page.rb', line 39

def self.groups
  CORE_GROUPS.dup.freeze
end

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

Returns:

  • (Boolean)


68
69
70
# File 'lib/redmine/my_page.rb', line 68

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