Feature #1565 » 2.6_stable_1565.diff
| app/controllers/my_controller.rb | ||
|---|---|---|
|
helper :issues
|
||
|
helper :users
|
||
|
helper :queries
|
||
|
helper :custom_fields
|
||
|
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
||
| ... | ... | |
|
# Show user's page
|
||
|
def page
|
||
|
@user = User.current
|
||
|
@all_blocks = Redmine::Views::MyPage::Block.all_blocks
|
||
|
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
|
||
|
end
|
||
| ... | ... | |
|
# User's page layout configuration
|
||
|
def page_layout
|
||
|
@user = User.current
|
||
|
@all_blocks = Redmine::Views::MyPage::Block.all_blocks
|
||
|
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
|
||
|
blocks_in_use = @blocks.values.flatten
|
||
|
# users may lose access to issue queries, it doesnt hurt to clean up their
|
||
|
# layout from time to time:
|
||
|
if (inaccessible_blocks = blocks_in_use - @all_blocks.keys).any?
|
||
|
%w(top left right).each do |f|
|
||
|
@blocks[f] -= inaccessible_blocks if @blocks[f]
|
||
|
end
|
||
|
@user.pref[:my_page_layout] = @blocks
|
||
|
@user.pref.save
|
||
|
end
|
||
|
@block_options = []
|
||
|
BLOCKS.each do |k, v|
|
||
|
unless @blocks.values.flatten.include?(k)
|
||
|
unless blocks_in_use.include?(k)
|
||
|
@block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]
|
||
|
end
|
||
|
end
|
||
|
@issue_query_block_options = []
|
||
|
Redmine::Views::MyPage::Block.issue_query_blocks.each do |id, name|
|
||
|
unless blocks_in_use.include?(id)
|
||
|
@issue_query_block_options << [name, id]
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
# Add a block to user's page
|
||
| ... | ... | |
|
# params[:block] : id of the block to add
|
||
|
def add_block
|
||
|
block = params[:block].to_s.underscore
|
||
|
if block.present? && BLOCKS.key?(block)
|
||
|
if block.present? && Redmine::Views::MyPage::Block.all_blocks.key?(block)
|
||
|
@user = User.current
|
||
|
layout = @user.pref[:my_page_layout] || {}
|
||
|
# remove if already present in a group
|
||
| app/helpers/my_helper.rb | ||
|---|---|---|
|
Document.visible.order("#{Document.table_name}.created_on DESC").limit(10).all
|
||
|
end
|
||
|
def mypage_available_block_options
|
||
|
options = options_for_select(@block_options)
|
||
|
options += grouped_options_for_select([[l(:label_query_plural), @issue_query_block_options]]) if @issue_query_block_options.any?
|
||
|
return options
|
||
|
end
|
||
|
def render_mypage_box(block, user = @user)
|
||
|
locals = { user: user }
|
||
|
partial = case block.to_s
|
||
|
when /^issue_query_(\w+)$/
|
||
|
locals[:query] = IssueQuery.visible.find $1
|
||
|
"my/blocks/issue_query"
|
||
|
else
|
||
|
"my/blocks/#{block}"
|
||
|
end
|
||
|
render partial: partial, locals: locals
|
||
|
end
|
||
|
def issuesassignedtome_items
|
||
|
Issue.visible.open.
|
||
|
where(:assigned_to_id => ([User.current.id] + User.current.group_ids)).
|
||
| app/views/my/_block.html.erb | ||
|---|---|---|
|
</div>
|
||
|
<div class="handle">
|
||
|
<%= render :partial => "my/blocks/#{block_name}", :locals => { :user => user } %>
|
||
|
<%= render_mypage_box block_name, user %>
|
||
|
</div>
|
||
|
</div>
|
||
| app/views/my/blocks/_issue_query.html.erb | ||
|---|---|---|
|
<h3>
|
||
|
<%= link_to query.name, query.project ? project_issues_path(query.project, query_id: query.id) : issues_path(query_id: query.id) %>
|
||
|
(<%= link_to_project(query.project) + ', ' if query.project %><%= query.issue_count %>)
|
||
|
</h3>
|
||
|
<% @issue_count_by_group = query.issue_count_by_group %>
|
||
|
<% if query.issue_count > 0 %>
|
||
|
<%= form_tag({}) do %>
|
||
|
<table class="list issues">
|
||
|
<thead><tr>
|
||
|
<% query.inline_columns.each do |column| %>
|
||
|
<th><%= column.caption %></th>
|
||
|
<% end %>
|
||
|
</tr></thead>
|
||
|
<% previous_group = false %>
|
||
|
<tbody>
|
||
|
<% issue_list(query.issues(limit: 10)) do |issue, level| -%>
|
||
|
<% if query.grouped? && (group = query.group_by_column.value(issue)) != previous_group %>
|
||
|
<% reset_cycle %>
|
||
|
<tr class="group open">
|
||
|
<td colspan="<%= query.inline_columns.size + 2 %>">
|
||
|
<span class="expander" onclick="toggleRowGroup(this);"> </span>
|
||
|
<%= group.blank? ? l(:label_none) : column_content(query.group_by_column, issue) %> <span class="count"><%= @issue_count_by_group[group] %></span>
|
||
|
<%= link_to_function("#{l(:button_collapse_all)}/#{l(:button_expand_all)}",
|
||
|
"toggleAllRowGroups(this)", :class => 'toggle-all') %>
|
||
|
</td>
|
||
|
</tr>
|
||
|
<% previous_group = group %>
|
||
|
<% end %>
|
||
|
<tr id="issue-<%= issue.id %>" class="hascontextmenu <%= cycle('odd', 'even') %> <%= issue.css_classes %> <%= level > 0 ? "idnt idnt-#{level}" : nil %>">
|
||
|
<td class="id">
|
||
|
<%= check_box_tag("ids[]", issue.id, false, :style => 'display:none;', :id => nil) %>
|
||
|
<%= link_to(issue.id, issue_path(issue)) %>
|
||
|
</td>
|
||
|
<%= raw query.inline_columns.reject{|c| c.name == :id}.map {|column| "<td class=\"#{column.css_classes}\">#{column_content(column, issue)}</td>"}.join %>
|
||
|
</tr>
|
||
|
<% end %>
|
||
|
</tbody>
|
||
|
</table>
|
||
|
<% end %>
|
||
|
<% else %>
|
||
|
<p class="nodata"><%= l(:label_no_data) %></p>
|
||
|
<% end %>
|
||
|
<% content_for :header_tags do %>
|
||
|
<%= auto_discovery_link_tag(:atom,
|
||
|
{controller: 'issues', action: 'index', query_id: query.id, project_id: query.project.try(:identifier),
|
||
|
format: 'atom', key: User.current.rss_key},
|
||
|
{:title => query.name}) %>
|
||
|
<% end %>
|
||
| app/views/my/page.html.erb | ||
|---|---|---|
|
<div id="list-top">
|
||
|
<% @blocks['top'].each do |b|
|
||
|
next unless MyController::BLOCKS.keys.include? b %>
|
||
|
next unless @all_blocks.keys.include? b %>
|
||
|
<div class="mypage-box">
|
||
|
<%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %>
|
||
|
<%= render_mypage_box b %>
|
||
|
</div>
|
||
|
<% end if @blocks['top'] %>
|
||
|
</div>
|
||
|
<div id="list-left" class="splitcontentleft">
|
||
|
<% @blocks['left'].each do |b|
|
||
|
next unless MyController::BLOCKS.keys.include? b %>
|
||
|
next unless @all_blocks.keys.include? b %>
|
||
|
<div class="mypage-box">
|
||
|
<%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %>
|
||
|
<%= render_mypage_box b %>
|
||
|
</div>
|
||
|
<% end if @blocks['left'] %>
|
||
|
</div>
|
||
|
<div id="list-right" class="splitcontentright">
|
||
|
<% @blocks['right'].each do |b|
|
||
|
next unless MyController::BLOCKS.keys.include? b %>
|
||
|
next unless @all_blocks.keys.include? b %>
|
||
|
<div class="mypage-box">
|
||
|
<%= render :partial => "my/blocks/#{b}", :locals => { :user => @user } %>
|
||
|
<%= render_mypage_box b %>
|
||
|
</div>
|
||
|
<% end if @blocks['right'] %>
|
||
|
</div>
|
||
| app/views/my/page_layout.html.erb | ||
|---|---|---|
|
<%= form_tag({:action => "add_block"}, :id => "block-form") do %>
|
||
|
<%= label_tag('block-select', l(:label_my_page_block)) %>:
|
||
|
<%= select_tag 'block',
|
||
|
content_tag('option') + options_for_select(@block_options),
|
||
|
content_tag('option') + mypage_available_block_options,
|
||
|
:id => "block-select" %>
|
||
|
<%= link_to l(:button_add), '#', :onclick => '$("#block-form").submit()', :class => 'icon icon-add' %>
|
||
|
<% end %>
|
||
| ... | ... | |
|
<div id="list-top" class="block-receiver">
|
||
|
<% @blocks['top'].each do |b|
|
||
|
next unless MyController::BLOCKS.keys.include? b %>
|
||
|
next unless @all_blocks.keys.include? b %>
|
||
|
<%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %>
|
||
|
<% end if @blocks['top'] %>
|
||
|
</div>
|
||
|
<div id="list-left" class="splitcontentleft block-receiver">
|
||
|
<% @blocks['left'].each do |b|
|
||
|
next unless MyController::BLOCKS.keys.include? b %>
|
||
|
next unless @all_blocks.keys.include? b %>
|
||
|
<%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %>
|
||
|
<% end if @blocks['left'] %>
|
||
|
</div>
|
||
|
<div id="list-right" class="splitcontentright block-receiver">
|
||
|
<% @blocks['right'].each do |b|
|
||
|
next unless MyController::BLOCKS.keys.include? b %>
|
||
|
next unless @all_blocks.keys.include? b %>
|
||
|
<%= render :partial => 'block', :locals => {:user => @user, :block_name => b} %>
|
||
|
<% end if @blocks['right'] %>
|
||
|
</div>
|
||
| lib/redmine/views/my_page/block.rb | ||
|---|---|---|
|
module Views
|
||
|
module MyPage
|
||
|
module Block
|
||
|
def self.all_blocks
|
||
|
MyController::BLOCKS.merge issue_query_blocks
|
||
|
end
|
||
|
def self.issue_query_blocks
|
||
|
Hash[IssueQuery.visible.map{|q| ["issue_query_#{q.id}", q.name]}]
|
||
|
end
|
||
|
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(/^_/, '')
|
||
| test/functional/my_controller_test.rb | ||
|---|---|---|
|
class MyControllerTest < ActionController::TestCase
|
||
|
fixtures :users, :user_preferences, :roles, :projects, :members, :member_roles,
|
||
|
:queries, :enabled_modules,
|
||
|
:issues, :issue_statuses, :trackers, :enumerations, :custom_fields, :auth_sources
|
||
|
def setup
|
||
| ... | ... | |
|
assert_template 'page'
|
||
|
end
|
||
|
def test_page_with_custom_query
|
||
|
preferences = User.find(2).pref
|
||
|
issue = Issue.find 1
|
||
|
issue.update_attribute :tracker_id, 3
|
||
|
q = IssueQuery.find 4
|
||
|
preferences[:my_page_layout] = {'top' => ["issue_query_#{q.id}"]}
|
||
|
preferences.save!
|
||
|
get :page
|
||
|
assert_response :success
|
||
|
assert_select 'h3', /#{q.name}/
|
||
|
assert_select 'td.id a', /#{issue.id}/
|
||
|
assert_select 'td.subject a', /print recipes/
|
||
|
end
|
||
|
def test_page_layout_should_remove_inaccessible_query
|
||
|
user = User.find 2
|
||
|
q = IssueQuery.find 3
|
||
|
assert !IssueQuery.visible(user).include?(q)
|
||
|
preferences = user.pref
|
||
|
preferences[:my_page_layout] = {'top' => ["issue_query_#{q.id}"]}
|
||
|
preferences.save!
|
||
|
get :page_layout
|
||
|
assert_response :success
|
||
|
user.reload
|
||
|
preferences = user.pref
|
||
|
assert_equal [], preferences[:my_page_layout]['top']
|
||
|
end
|
||
|
def test_page_with_timelog_block
|
||
|
preferences = User.find(2).pref
|
||
|
preferences[:my_page_layout] = {'top' => ['timelog']}
|
||