mirror of
https://github.com/meineerde/redmine.git
synced 2025-12-19 15:01:14 +00:00
Moves blocks definition to Redmine::MyPage.
git-svn-id: http://svn.redmine.org/redmine/trunk@15930 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
6ef3ecc030
commit
8b86d5158e
@ -27,19 +27,6 @@ class MyController < ApplicationController
|
|||||||
helper :users
|
helper :users
|
||||||
helper :custom_fields
|
helper :custom_fields
|
||||||
|
|
||||||
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
|
||||||
'issuesreportedbyme' => :label_reported_issues,
|
|
||||||
'issueswatched' => :label_watched_issues,
|
|
||||||
'news' => :label_news_latest,
|
|
||||||
'calendar' => :label_calendar,
|
|
||||||
'documents' => :label_document_plural,
|
|
||||||
'timelog' => :label_spent_time
|
|
||||||
}.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
|
|
||||||
|
|
||||||
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
|
|
||||||
'right' => ['issuesreportedbyme']
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
def index
|
def index
|
||||||
page
|
page
|
||||||
render :action => 'page'
|
render :action => 'page'
|
||||||
@ -48,7 +35,7 @@ class MyController < ApplicationController
|
|||||||
# Show user's page
|
# Show user's page
|
||||||
def page
|
def page
|
||||||
@user = User.current
|
@user = User.current
|
||||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
|
@blocks = @user.pref.my_page_layout
|
||||||
end
|
end
|
||||||
|
|
||||||
# Edit user's account
|
# Edit user's account
|
||||||
@ -146,13 +133,7 @@ class MyController < ApplicationController
|
|||||||
# User's page layout configuration
|
# User's page layout configuration
|
||||||
def page_layout
|
def page_layout
|
||||||
@user = User.current
|
@user = User.current
|
||||||
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
@blocks = @user.pref.my_page_layout
|
||||||
@block_options = []
|
|
||||||
BLOCKS.each do |k, v|
|
|
||||||
unless @blocks.values.flatten.include?(k)
|
|
||||||
@block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a block to user's page
|
# Add a block to user's page
|
||||||
@ -160,14 +141,14 @@ class MyController < ApplicationController
|
|||||||
# params[:block] : id of the block to add
|
# params[:block] : id of the block to add
|
||||||
def add_block
|
def add_block
|
||||||
block = params[:block].to_s.underscore
|
block = params[:block].to_s.underscore
|
||||||
if block.present? && BLOCKS.key?(block)
|
if block.present? && Redmine::MyPage.blocks.key?(block)
|
||||||
@user = User.current
|
@user = User.current
|
||||||
layout = @user.pref[:my_page_layout] || {}
|
layout = @user.pref.my_page_layout
|
||||||
# remove if already present in a group
|
# remove if already present in a group
|
||||||
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||||
# add it on top
|
# add it on top
|
||||||
layout['top'].unshift block
|
layout['top'].unshift block
|
||||||
@user.pref[:my_page_layout] = layout
|
@user.pref.my_page_layout = layout
|
||||||
@user.pref.save
|
@user.pref.save
|
||||||
end
|
end
|
||||||
redirect_to my_page_layout_path
|
redirect_to my_page_layout_path
|
||||||
@ -179,9 +160,9 @@ class MyController < ApplicationController
|
|||||||
block = params[:block].to_s.underscore
|
block = params[:block].to_s.underscore
|
||||||
@user = User.current
|
@user = User.current
|
||||||
# remove block in all groups
|
# remove block in all groups
|
||||||
layout = @user.pref[:my_page_layout] || {}
|
layout = @user.pref.my_page_layout
|
||||||
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
%w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||||||
@user.pref[:my_page_layout] = layout
|
@user.pref.my_page_layout = layout
|
||||||
@user.pref.save
|
@user.pref.save
|
||||||
redirect_to my_page_layout_path
|
redirect_to my_page_layout_path
|
||||||
end
|
end
|
||||||
@ -196,13 +177,13 @@ class MyController < ApplicationController
|
|||||||
group_items = (params["blocks"] || []).collect(&:underscore)
|
group_items = (params["blocks"] || []).collect(&:underscore)
|
||||||
group_items.each {|s| s.sub!(/^block_/, '')}
|
group_items.each {|s| s.sub!(/^block_/, '')}
|
||||||
if group_items and group_items.is_a? Array
|
if group_items and group_items.is_a? Array
|
||||||
layout = @user.pref[:my_page_layout] || {}
|
layout = @user.pref.my_page_layout
|
||||||
# remove group blocks if they are presents in other groups
|
# remove group blocks if they are presents in other groups
|
||||||
%w(top left right).each {|f|
|
%w(top left right).each {|f|
|
||||||
layout[f] = (layout[f] || []) - group_items
|
layout[f] = (layout[f] || []) - group_items
|
||||||
}
|
}
|
||||||
layout[group] = group_items
|
layout[group] = group_items
|
||||||
@user.pref[:my_page_layout] = layout
|
@user.pref.my_page_layout = layout
|
||||||
@user.pref.save
|
@user.pref.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -40,7 +40,7 @@ module MyHelper
|
|||||||
|
|
||||||
# Renders a single block content
|
# Renders a single block content
|
||||||
def render_block_content(block, user)
|
def render_block_content(block, user)
|
||||||
unless MyController::BLOCKS.keys.include?(block)
|
unless Redmine::MyPage.blocks.key?(block)
|
||||||
Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences")
|
Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -53,6 +53,15 @@ module MyHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def block_select_tag(user)
|
||||||
|
disabled = user.pref.my_page_layout.values.flatten
|
||||||
|
options = content_tag('option')
|
||||||
|
Redmine::MyPage.block_options.each do |label, block|
|
||||||
|
options << content_tag('option', label, :value => block, :disabled => disabled.include?(block))
|
||||||
|
end
|
||||||
|
content_tag('select', options, :id => "block-select")
|
||||||
|
end
|
||||||
|
|
||||||
def calendar_items(startdt, enddt)
|
def calendar_items(startdt, enddt)
|
||||||
Issue.visible.
|
Issue.visible.
|
||||||
where(:project_id => User.current.projects.map(&:id)).
|
where(:project_id => User.current.projects.map(&:id)).
|
||||||
|
|||||||
@ -82,4 +82,12 @@ class UserPreference < ActiveRecord::Base
|
|||||||
|
|
||||||
def textarea_font; self[:textarea_font] end
|
def textarea_font; self[:textarea_font] end
|
||||||
def textarea_font=(value); self[:textarea_font]=value; end
|
def textarea_font=(value); self[:textarea_font]=value; end
|
||||||
|
|
||||||
|
def my_page_layout
|
||||||
|
self[:my_page_layout] ||= Redmine::MyPage.default_layout.deep_dup
|
||||||
|
end
|
||||||
|
|
||||||
|
def my_page_layout=(arg)
|
||||||
|
self[:my_page_layout] = arg
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
<div class="contextual">
|
<div class="contextual">
|
||||||
<% if @block_options.present? %>
|
|
||||||
<%= form_tag({:action => "add_block"}, :id => "block-form") do %>
|
<%= form_tag({:action => "add_block"}, :id => "block-form") do %>
|
||||||
<%= label_tag('block-select', l(:label_my_page_block)) %>:
|
<%= label_tag('block-select', l(:label_my_page_block)) %>:
|
||||||
<%= select_tag 'block',
|
<%= block_select_tag(@user) %>
|
||||||
content_tag('option') + options_for_select(@block_options),
|
|
||||||
:id => "block-select" %>
|
|
||||||
<%= link_to l(:button_add), '#', :onclick => '$("#block-form").submit()', :class => 'icon icon-add' %>
|
<%= link_to l(:button_add), '#', :onclick => '$("#block-form").submit()', :class => 'icon icon-add' %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
|
||||||
<%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %>
|
<%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
62
lib/redmine/my_page.rb
Normal file
62
lib/redmine/my_page.rb
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
# Redmine - project management software
|
||||||
|
# Copyright (C) 2006-2016 Jean-Philippe Lang
|
||||||
|
#
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
module Redmine
|
||||||
|
module MyPage
|
||||||
|
include Redmine::I18n
|
||||||
|
|
||||||
|
CORE_BLOCKS = {
|
||||||
|
'issuesassignedtome' => :label_assigned_to_me_issues,
|
||||||
|
'issuesreportedbyme' => :label_reported_issues,
|
||||||
|
'issueswatched' => :label_watched_issues,
|
||||||
|
'news' => :label_news_latest,
|
||||||
|
'calendar' => :label_calendar,
|
||||||
|
'documents' => :label_document_plural,
|
||||||
|
'timelog' => :label_spent_time
|
||||||
|
}
|
||||||
|
|
||||||
|
# Returns the available blocks
|
||||||
|
def self.blocks
|
||||||
|
CORE_BLOCKS.merge(additional_blocks).freeze
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.block_options
|
||||||
|
options = []
|
||||||
|
blocks.each do |k, v|
|
||||||
|
options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
|
||||||
|
end
|
||||||
|
options
|
||||||
|
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|
|
||||||
|
name = File.basename(file).split('.').first.gsub(/^_/, '')
|
||||||
|
h[name] = name.to_sym
|
||||||
|
h
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
# Returns the default layout for My Page
|
||||||
|
def self.default_layout
|
||||||
|
{
|
||||||
|
'left' => ['issuesassignedtome'],
|
||||||
|
'right' => ['issuesreportedbyme']
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,32 +0,0 @@
|
|||||||
# Redmine - project management software
|
|
||||||
# Copyright (C) 2006-2016 Jean-Philippe Lang
|
|
||||||
#
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
module Redmine
|
|
||||||
module Views
|
|
||||||
module MyPage
|
|
||||||
module Block
|
|
||||||
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] = name.to_sym
|
|
||||||
h
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -52,7 +52,7 @@ class MyControllerTest < Redmine::ControllerTest
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_page_with_all_blocks
|
def test_page_with_all_blocks
|
||||||
blocks = MyController::BLOCKS.keys
|
blocks = Redmine::MyPage.blocks.keys
|
||||||
preferences = User.find(2).pref
|
preferences = User.find(2).pref
|
||||||
preferences[:my_page_layout] = {'top' => blocks}
|
preferences[:my_page_layout] = {'top' => blocks}
|
||||||
preferences.save!
|
preferences.save!
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user