##// END OF EJS Templates
remove trailing white-spaces from app/controllers/my_controller.rb....
Toshi MARUYAMA -
r6680:b840af0db061
parent child
Show More
@@ -1,177 +1,177
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2009 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
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 class MyController < ApplicationController
18 class MyController < ApplicationController
19 before_filter :require_login
19 before_filter :require_login
20
20
21 helper :issues
21 helper :issues
22 helper :users
22 helper :users
23 helper :custom_fields
23 helper :custom_fields
24
24
25 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
25 BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
26 'issuesreportedbyme' => :label_reported_issues,
26 'issuesreportedbyme' => :label_reported_issues,
27 'issueswatched' => :label_watched_issues,
27 'issueswatched' => :label_watched_issues,
28 'news' => :label_news_latest,
28 'news' => :label_news_latest,
29 'calendar' => :label_calendar,
29 'calendar' => :label_calendar,
30 'documents' => :label_document_plural,
30 'documents' => :label_document_plural,
31 'timelog' => :label_spent_time
31 'timelog' => :label_spent_time
32 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
32 }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
33
33
34 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
34 DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
35 'right' => ['issuesreportedbyme']
35 'right' => ['issuesreportedbyme']
36 }.freeze
36 }.freeze
37
37
38 verify :xhr => true,
38 verify :xhr => true,
39 :only => [:add_block, :remove_block, :order_blocks]
39 :only => [:add_block, :remove_block, :order_blocks]
40
40
41 def index
41 def index
42 page
42 page
43 render :action => 'page'
43 render :action => 'page'
44 end
44 end
45
45
46 # Show user's page
46 # Show user's page
47 def page
47 def page
48 @user = User.current
48 @user = User.current
49 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
49 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
50 end
50 end
51
51
52 # Edit user's account
52 # Edit user's account
53 def account
53 def account
54 @user = User.current
54 @user = User.current
55 @pref = @user.pref
55 @pref = @user.pref
56 if request.post?
56 if request.post?
57 @user.safe_attributes = params[:user]
57 @user.safe_attributes = params[:user]
58 @user.pref.attributes = params[:pref]
58 @user.pref.attributes = params[:pref]
59 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
59 @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
60 if @user.save
60 if @user.save
61 @user.pref.save
61 @user.pref.save
62 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
62 @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
63 set_language_if_valid @user.language
63 set_language_if_valid @user.language
64 flash[:notice] = l(:notice_account_updated)
64 flash[:notice] = l(:notice_account_updated)
65 redirect_to :action => 'account'
65 redirect_to :action => 'account'
66 return
66 return
67 end
67 end
68 end
68 end
69 end
69 end
70
70
71 # Manage user's password
71 # Manage user's password
72 def password
72 def password
73 @user = User.current
73 @user = User.current
74 unless @user.change_password_allowed?
74 unless @user.change_password_allowed?
75 flash[:error] = l(:notice_can_t_change_password)
75 flash[:error] = l(:notice_can_t_change_password)
76 redirect_to :action => 'account'
76 redirect_to :action => 'account'
77 return
77 return
78 end
78 end
79 if request.post?
79 if request.post?
80 if @user.check_password?(params[:password])
80 if @user.check_password?(params[:password])
81 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
81 @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
82 if @user.save
82 if @user.save
83 flash[:notice] = l(:notice_account_password_updated)
83 flash[:notice] = l(:notice_account_password_updated)
84 redirect_to :action => 'account'
84 redirect_to :action => 'account'
85 end
85 end
86 else
86 else
87 flash[:error] = l(:notice_account_wrong_password)
87 flash[:error] = l(:notice_account_wrong_password)
88 end
88 end
89 end
89 end
90 end
90 end
91
91
92 # Create a new feeds key
92 # Create a new feeds key
93 def reset_rss_key
93 def reset_rss_key
94 if request.post?
94 if request.post?
95 if User.current.rss_token
95 if User.current.rss_token
96 User.current.rss_token.destroy
96 User.current.rss_token.destroy
97 User.current.reload
97 User.current.reload
98 end
98 end
99 User.current.rss_key
99 User.current.rss_key
100 flash[:notice] = l(:notice_feeds_access_key_reseted)
100 flash[:notice] = l(:notice_feeds_access_key_reseted)
101 end
101 end
102 redirect_to :action => 'account'
102 redirect_to :action => 'account'
103 end
103 end
104
104
105 # Create a new API key
105 # Create a new API key
106 def reset_api_key
106 def reset_api_key
107 if request.post?
107 if request.post?
108 if User.current.api_token
108 if User.current.api_token
109 User.current.api_token.destroy
109 User.current.api_token.destroy
110 User.current.reload
110 User.current.reload
111 end
111 end
112 User.current.api_key
112 User.current.api_key
113 flash[:notice] = l(:notice_api_access_key_reseted)
113 flash[:notice] = l(:notice_api_access_key_reseted)
114 end
114 end
115 redirect_to :action => 'account'
115 redirect_to :action => 'account'
116 end
116 end
117
117
118 # User's page layout configuration
118 # User's page layout configuration
119 def page_layout
119 def page_layout
120 @user = User.current
120 @user = User.current
121 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
121 @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
122 @block_options = []
122 @block_options = []
123 BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
123 BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
124 end
124 end
125
125
126 # Add a block to user's page
126 # Add a block to user's page
127 # The block is added on top of the page
127 # The block is added on top of the page
128 # params[:block] : id of the block to add
128 # params[:block] : id of the block to add
129 def add_block
129 def add_block
130 block = params[:block].to_s.underscore
130 block = params[:block].to_s.underscore
131 (render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
131 (render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
132 @user = User.current
132 @user = User.current
133 layout = @user.pref[:my_page_layout] || {}
133 layout = @user.pref[:my_page_layout] || {}
134 # remove if already present in a group
134 # remove if already present in a group
135 %w(top left right).each {|f| (layout[f] ||= []).delete block }
135 %w(top left right).each {|f| (layout[f] ||= []).delete block }
136 # add it on top
136 # add it on top
137 layout['top'].unshift block
137 layout['top'].unshift block
138 @user.pref[:my_page_layout] = layout
138 @user.pref[:my_page_layout] = layout
139 @user.pref.save
139 @user.pref.save
140 render :partial => "block", :locals => {:user => @user, :block_name => block}
140 render :partial => "block", :locals => {:user => @user, :block_name => block}
141 end
141 end
142
142
143 # Remove a block to user's page
143 # Remove a block to user's page
144 # params[:block] : id of the block to remove
144 # params[:block] : id of the block to remove
145 def remove_block
145 def remove_block
146 block = params[:block].to_s.underscore
146 block = params[:block].to_s.underscore
147 @user = User.current
147 @user = User.current
148 # remove block in all groups
148 # remove block in all groups
149 layout = @user.pref[:my_page_layout] || {}
149 layout = @user.pref[:my_page_layout] || {}
150 %w(top left right).each {|f| (layout[f] ||= []).delete block }
150 %w(top left right).each {|f| (layout[f] ||= []).delete block }
151 @user.pref[:my_page_layout] = layout
151 @user.pref[:my_page_layout] = layout
152 @user.pref.save
152 @user.pref.save
153 render :nothing => true
153 render :nothing => true
154 end
154 end
155
155
156 # Change blocks order on user's page
156 # Change blocks order on user's page
157 # params[:group] : group to order (top, left or right)
157 # params[:group] : group to order (top, left or right)
158 # params[:list-(top|left|right)] : array of block ids of the group
158 # params[:list-(top|left|right)] : array of block ids of the group
159 def order_blocks
159 def order_blocks
160 group = params[:group]
160 group = params[:group]
161 @user = User.current
161 @user = User.current
162 if group.is_a?(String)
162 if group.is_a?(String)
163 group_items = (params["list-#{group}"] || []).collect(&:underscore)
163 group_items = (params["list-#{group}"] || []).collect(&:underscore)
164 if group_items and group_items.is_a? Array
164 if group_items and group_items.is_a? Array
165 layout = @user.pref[:my_page_layout] || {}
165 layout = @user.pref[:my_page_layout] || {}
166 # remove group blocks if they are presents in other groups
166 # remove group blocks if they are presents in other groups
167 %w(top left right).each {|f|
167 %w(top left right).each {|f|
168 layout[f] = (layout[f] || []) - group_items
168 layout[f] = (layout[f] || []) - group_items
169 }
169 }
170 layout[group] = group_items
170 layout[group] = group_items
171 @user.pref[:my_page_layout] = layout
171 @user.pref[:my_page_layout] = layout
172 @user.pref.save
172 @user.pref.save
173 end
173 end
174 end
174 end
175 render :nothing => true
175 render :nothing => true
176 end
176 end
177 end
177 end
General Comments 0
You need to be logged in to leave comments. Login now