|
@@
-1,131
+1,135
|
|
1
|
1
|
# redMine - project management software
|
|
2
|
2
|
# Copyright (C) 2006 Jean-Philippe Lang
|
|
3
|
3
|
#
|
|
4
|
4
|
# This program is free software; you can redistribute it and/or
|
|
5
|
5
|
# modify it under the terms of the GNU General Public License
|
|
6
|
6
|
# as published by the Free Software Foundation; either version 2
|
|
7
|
7
|
# of the License, or (at your option) any later version.
|
|
8
|
8
|
#
|
|
9
|
9
|
# This program is distributed in the hope that it will be useful,
|
|
10
|
10
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
11
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
12
|
# GNU General Public License for more details.
|
|
13
|
13
|
#
|
|
14
|
14
|
# You should have received a copy of the GNU General Public License
|
|
15
|
15
|
# along with this program; if not, write to the Free Software
|
|
16
|
16
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
17
|
17
|
|
|
18
|
18
|
class MyController < ApplicationController
|
|
19
|
19
|
layout 'base'
|
|
20
|
20
|
before_filter :require_login
|
|
21
|
21
|
|
|
22
|
|
BLOCKS = { 'issues_assigned_to_me' => :label_assigned_to_me_issues,
|
|
23
|
|
'issues_reported_by_me' => :label_reported_issues,
|
|
24
|
|
'latest_news' => :label_news_latest,
|
|
|
22
|
BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
|
|
|
23
|
'issuesreportedbyme' => :label_reported_issues,
|
|
|
24
|
'news' => :label_news_latest,
|
|
25
|
25
|
'calendar' => :label_calendar,
|
|
26
|
26
|
'documents' => :label_document_plural
|
|
27
|
27
|
}.freeze
|
|
28
|
28
|
|
|
|
29
|
DEFAULT_LAYOUT = { 'left' => ['issuesassignedtome'],
|
|
|
30
|
'right' => ['issuesreportedbyme']
|
|
|
31
|
}.freeze
|
|
|
32
|
|
|
29
|
33
|
verify :xhr => true,
|
|
30
|
34
|
:session => :page_layout,
|
|
31
|
35
|
:only => [:add_block, :remove_block, :order_blocks]
|
|
32
|
36
|
|
|
33
|
37
|
def index
|
|
34
|
38
|
page
|
|
35
|
39
|
render :action => 'page'
|
|
36
|
40
|
end
|
|
37
|
41
|
|
|
38
|
42
|
# Show user's page
|
|
39
|
43
|
def page
|
|
40
|
44
|
@user = self.logged_in_user
|
|
41
|
|
@blocks = @user.pref[:my_page_layout] || { 'left' => ['issues_assigned_to_me'], 'right' => ['issues_reported_by_me'] }
|
|
|
45
|
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
|
|
42
|
46
|
end
|
|
43
|
47
|
|
|
44
|
48
|
# Edit user's account
|
|
45
|
49
|
def account
|
|
46
|
50
|
@user = self.logged_in_user
|
|
47
|
51
|
@pref = @user.pref
|
|
48
|
52
|
@user.attributes = params[:user]
|
|
49
|
53
|
@user.pref.attributes = params[:pref]
|
|
50
|
54
|
if request.post? and @user.save
|
|
51
|
55
|
set_localization
|
|
52
|
56
|
flash.now[:notice] = l(:notice_account_updated)
|
|
53
|
57
|
self.logged_in_user.reload
|
|
54
|
58
|
end
|
|
55
|
59
|
end
|
|
56
|
60
|
|
|
57
|
61
|
# Change user's password
|
|
58
|
62
|
def change_password
|
|
59
|
63
|
@user = self.logged_in_user
|
|
60
|
64
|
flash[:notice] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id
|
|
61
|
65
|
if @user.check_password?(params[:password])
|
|
62
|
66
|
@user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
|
63
|
67
|
if @user.save
|
|
64
|
68
|
flash[:notice] = l(:notice_account_password_updated)
|
|
65
|
69
|
else
|
|
66
|
70
|
render :action => 'account'
|
|
67
|
71
|
return
|
|
68
|
72
|
end
|
|
69
|
73
|
else
|
|
70
|
74
|
flash[:notice] = l(:notice_account_wrong_password)
|
|
71
|
75
|
end
|
|
72
|
76
|
redirect_to :action => 'account'
|
|
73
|
77
|
end
|
|
74
|
78
|
|
|
75
|
79
|
# User's page layout configuration
|
|
76
|
80
|
def page_layout
|
|
77
|
81
|
@user = self.logged_in_user
|
|
78
|
|
@blocks = @user.pref[:my_page_layout] || { 'left' => ['issues_assigned_to_me'], 'right' => ['issues_reported_by_me'] }
|
|
|
82
|
@blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
|
|
79
|
83
|
session[:page_layout] = @blocks
|
|
80
|
84
|
%w(top left right).each {|f| session[:page_layout][f] ||= [] }
|
|
81
|
85
|
@block_options = []
|
|
82
|
86
|
BLOCKS.each {|k, v| @block_options << [l(v), k]}
|
|
83
|
87
|
end
|
|
84
|
88
|
|
|
85
|
89
|
# Add a block to user's page
|
|
86
|
90
|
# The block is added on top of the page
|
|
87
|
91
|
# params[:block] : id of the block to add
|
|
88
|
92
|
def add_block
|
|
89
|
93
|
@user = self.logged_in_user
|
|
90
|
94
|
block = params[:block]
|
|
91
|
95
|
# remove if already present in a group
|
|
92
|
96
|
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
|
93
|
97
|
# add it on top
|
|
94
|
98
|
session[:page_layout]['top'].unshift block
|
|
95
|
99
|
render :partial => "block", :locals => {:user => @user, :block_name => block}
|
|
96
|
100
|
end
|
|
97
|
101
|
|
|
98
|
102
|
# Remove a block to user's page
|
|
99
|
103
|
# params[:block] : id of the block to remove
|
|
100
|
104
|
def remove_block
|
|
101
|
105
|
block = params[:block]
|
|
102
|
106
|
# remove block in all groups
|
|
103
|
107
|
%w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block }
|
|
104
|
108
|
render :nothing => true
|
|
105
|
109
|
end
|
|
106
|
110
|
|
|
107
|
111
|
# Change blocks order on user's page
|
|
108
|
112
|
# params[:group] : group to order (top, left or right)
|
|
109
|
113
|
# params[:list-(top|left|right)] : array of block ids of the group
|
|
110
|
114
|
def order_blocks
|
|
111
|
115
|
group = params[:group]
|
|
112
|
116
|
group_items = params["list-#{group}"]
|
|
113
|
117
|
if group_items and group_items.is_a? Array
|
|
114
|
118
|
# remove group blocks if they are presents in other groups
|
|
115
|
119
|
%w(top left right).each {|f|
|
|
116
|
120
|
session[:page_layout][f] = (session[:page_layout][f] || []) - group_items
|
|
117
|
121
|
}
|
|
118
|
122
|
session[:page_layout][group] = group_items
|
|
119
|
123
|
end
|
|
120
|
124
|
render :nothing => true
|
|
121
|
125
|
end
|
|
122
|
126
|
|
|
123
|
127
|
# Save user's page layout
|
|
124
|
128
|
def page_layout_save
|
|
125
|
129
|
@user = self.logged_in_user
|
|
126
|
130
|
@user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout]
|
|
127
|
131
|
@user.pref.save
|
|
128
|
132
|
session[:page_layout] = nil
|
|
129
|
133
|
redirect_to :action => 'page'
|
|
130
|
134
|
end
|
|
131
|
135
|
end
|