@@ -27,19 +27,6 class MyController < ApplicationController | |||
|
27 | 27 | helper :users |
|
28 | 28 | helper :custom_fields |
|
29 | 29 | |
|
30 | BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, | |
|
31 | 'issuesreportedbyme' => :label_reported_issues, | |
|
32 | 'issueswatched' => :label_watched_issues, | |
|
33 | 'news' => :label_news_latest, | |
|
34 | 'calendar' => :label_calendar, | |
|
35 | 'documents' => :label_document_plural, | |
|
36 | 'timelog' => :label_spent_time | |
|
37 | }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze | |
|
38 | ||
|
39 | DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'], | |
|
40 | 'right' => ['issuesreportedbyme'] | |
|
41 | }.freeze | |
|
42 | ||
|
43 | 30 | def index |
|
44 | 31 | page |
|
45 | 32 | render :action => 'page' |
@@ -48,7 +35,7 class MyController < ApplicationController | |||
|
48 | 35 | # Show user's page |
|
49 | 36 | def page |
|
50 | 37 | @user = User.current |
|
51 |
@blocks = @user.pref |
|
|
38 | @blocks = @user.pref.my_page_layout | |
|
52 | 39 | end |
|
53 | 40 | |
|
54 | 41 | # Edit user's account |
@@ -146,13 +133,7 class MyController < ApplicationController | |||
|
146 | 133 | # User's page layout configuration |
|
147 | 134 | def page_layout |
|
148 | 135 | @user = User.current |
|
149 |
@blocks = @user.pref |
|
|
150 | @block_options = [] | |
|
151 | BLOCKS.each do |k, v| | |
|
152 | unless @blocks.values.flatten.include?(k) | |
|
153 | @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize] | |
|
154 | end | |
|
155 | end | |
|
136 | @blocks = @user.pref.my_page_layout | |
|
156 | 137 | end |
|
157 | 138 | |
|
158 | 139 | # Add a block to user's page |
@@ -160,14 +141,14 class MyController < ApplicationController | |||
|
160 | 141 | # params[:block] : id of the block to add |
|
161 | 142 | def add_block |
|
162 | 143 | block = params[:block].to_s.underscore |
|
163 |
if block.present? && |
|
|
144 | if block.present? && Redmine::MyPage.blocks.key?(block) | |
|
164 | 145 | @user = User.current |
|
165 |
layout = @user.pref |
|
|
146 | layout = @user.pref.my_page_layout | |
|
166 | 147 | # remove if already present in a group |
|
167 | 148 | %w(top left right).each {|f| (layout[f] ||= []).delete block } |
|
168 | 149 | # add it on top |
|
169 | 150 | layout['top'].unshift block |
|
170 |
@user.pref |
|
|
151 | @user.pref.my_page_layout = layout | |
|
171 | 152 | @user.pref.save |
|
172 | 153 | end |
|
173 | 154 | redirect_to my_page_layout_path |
@@ -179,9 +160,9 class MyController < ApplicationController | |||
|
179 | 160 | block = params[:block].to_s.underscore |
|
180 | 161 | @user = User.current |
|
181 | 162 | # remove block in all groups |
|
182 |
layout = @user.pref |
|
|
163 | layout = @user.pref.my_page_layout | |
|
183 | 164 | %w(top left right).each {|f| (layout[f] ||= []).delete block } |
|
184 |
@user.pref |
|
|
165 | @user.pref.my_page_layout = layout | |
|
185 | 166 | @user.pref.save |
|
186 | 167 | redirect_to my_page_layout_path |
|
187 | 168 | end |
@@ -196,13 +177,13 class MyController < ApplicationController | |||
|
196 | 177 | group_items = (params["blocks"] || []).collect(&:underscore) |
|
197 | 178 | group_items.each {|s| s.sub!(/^block_/, '')} |
|
198 | 179 | if group_items and group_items.is_a? Array |
|
199 |
layout = @user.pref |
|
|
180 | layout = @user.pref.my_page_layout | |
|
200 | 181 | # remove group blocks if they are presents in other groups |
|
201 | 182 | %w(top left right).each {|f| |
|
202 | 183 | layout[f] = (layout[f] || []) - group_items |
|
203 | 184 | } |
|
204 | 185 | layout[group] = group_items |
|
205 |
@user.pref |
|
|
186 | @user.pref.my_page_layout = layout | |
|
206 | 187 | @user.pref.save |
|
207 | 188 | end |
|
208 | 189 | end |
@@ -40,7 +40,7 module MyHelper | |||
|
40 | 40 | |
|
41 | 41 | # Renders a single block content |
|
42 | 42 | def render_block_content(block, user) |
|
43 | unless MyController::BLOCKS.keys.include?(block) | |
|
43 | unless Redmine::MyPage.blocks.key?(block) | |
|
44 | 44 | Rails.logger.warn("Unknown block \"#{block}\" found in #{user.login} (id=#{user.id}) preferences") |
|
45 | 45 | return |
|
46 | 46 | end |
@@ -53,6 +53,15 module MyHelper | |||
|
53 | 53 | end |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | def block_select_tag(user) | |
|
57 | disabled = user.pref.my_page_layout.values.flatten | |
|
58 | options = content_tag('option') | |
|
59 | Redmine::MyPage.block_options.each do |label, block| | |
|
60 | options << content_tag('option', label, :value => block, :disabled => disabled.include?(block)) | |
|
61 | end | |
|
62 | content_tag('select', options, :id => "block-select") | |
|
63 | end | |
|
64 | ||
|
56 | 65 | def calendar_items(startdt, enddt) |
|
57 | 66 | Issue.visible. |
|
58 | 67 | where(:project_id => User.current.projects.map(&:id)). |
@@ -82,4 +82,12 class UserPreference < ActiveRecord::Base | |||
|
82 | 82 | |
|
83 | 83 | def textarea_font; self[:textarea_font] end |
|
84 | 84 | def textarea_font=(value); self[:textarea_font]=value; end |
|
85 | ||
|
86 | def my_page_layout | |
|
87 | self[:my_page_layout] ||= Redmine::MyPage.default_layout.deep_dup | |
|
88 | end | |
|
89 | ||
|
90 | def my_page_layout=(arg) | |
|
91 | self[:my_page_layout] = arg | |
|
92 | end | |
|
85 | 93 | end |
@@ -1,12 +1,9 | |||
|
1 | 1 | <div class="contextual"> |
|
2 | <% if @block_options.present? %> | |
|
3 |
|
|
|
2 | ||
|
3 | <%= form_tag({:action => "add_block"}, :id => "block-form") do %> | |
|
4 | 4 | <%= label_tag('block-select', l(:label_my_page_block)) %>: |
|
5 | <%= select_tag 'block', | |
|
6 | content_tag('option') + options_for_select(@block_options), | |
|
7 | :id => "block-select" %> | |
|
5 | <%= block_select_tag(@user) %> | |
|
8 | 6 | <%= link_to l(:button_add), '#', :onclick => '$("#block-form").submit()', :class => 'icon icon-add' %> |
|
9 | <% end %> | |
|
10 | 7 | <% end %> |
|
11 | 8 | <%= link_to l(:button_back), {:action => 'page'}, :class => 'icon icon-cancel' %> |
|
12 | 9 | </div> |
@@ -16,17 +16,47 | |||
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | module Redmine |
|
19 |
module |
|
|
20 | module MyPage | |
|
21 | module Block | |
|
22 | def self.additional_blocks | |
|
23 | @@additional_blocks ||= Dir.glob("#{Redmine::Plugin.directory}/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file| | |
|
24 | name = File.basename(file).split('.').first.gsub(/^_/, '') | |
|
25 | h[name] = name.to_sym | |
|
26 | h | |
|
27 | end | |
|
28 | end | |
|
19 | module MyPage | |
|
20 | include Redmine::I18n | |
|
21 | ||
|
22 | CORE_BLOCKS = { | |
|
23 | 'issuesassignedtome' => :label_assigned_to_me_issues, | |
|
24 | 'issuesreportedbyme' => :label_reported_issues, | |
|
25 | 'issueswatched' => :label_watched_issues, | |
|
26 | 'news' => :label_news_latest, | |
|
27 | 'calendar' => :label_calendar, | |
|
28 | 'documents' => :label_document_plural, | |
|
29 | 'timelog' => :label_spent_time | |
|
30 | } | |
|
31 | ||
|
32 | # Returns the available blocks | |
|
33 | def self.blocks | |
|
34 | CORE_BLOCKS.merge(additional_blocks).freeze | |
|
35 | end | |
|
36 | ||
|
37 | def self.block_options | |
|
38 | options = [] | |
|
39 | blocks.each do |k, v| | |
|
40 | options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize] | |
|
29 | 41 | end |
|
42 | options | |
|
43 | end | |
|
44 | ||
|
45 | # Returns the additional blocks that are defined by plugin partials | |
|
46 | def self.additional_blocks | |
|
47 | @@additional_blocks ||= Dir.glob("#{Redmine::Plugin.directory}/*/app/views/my/blocks/_*.{rhtml,erb}").inject({}) do |h,file| | |
|
48 | name = File.basename(file).split('.').first.gsub(/^_/, '') | |
|
49 | h[name] = name.to_sym | |
|
50 | h | |
|
51 | end | |
|
52 | end | |
|
53 | ||
|
54 | # Returns the default layout for My Page | |
|
55 | def self.default_layout | |
|
56 | { | |
|
57 | 'left' => ['issuesassignedtome'], | |
|
58 | 'right' => ['issuesreportedbyme'] | |
|
59 | } | |
|
30 | 60 | end |
|
31 | 61 | end |
|
32 | 62 | end |
@@ -52,7 +52,7 class MyControllerTest < Redmine::ControllerTest | |||
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_page_with_all_blocks |
|
55 | blocks = MyController::BLOCKS.keys | |
|
55 | blocks = Redmine::MyPage.blocks.keys | |
|
56 | 56 | preferences = User.find(2).pref |
|
57 | 57 | preferences[:my_page_layout] = {'top' => blocks} |
|
58 | 58 | preferences.save! |
General Comments 0
You need to be logged in to leave comments.
Login now