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