To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / controllers / my_controller.rb @ 1304:6137548ba453

History | View | Annotate | Download (7.12 KB)

1 0:513646585e45 Chris
# Redmine - project management software
2 909:cbb26bc654de Chris
# Copyright (C) 2006-2011  Jean-Philippe Lang
3 0:513646585e45 Chris
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8 909:cbb26bc654de Chris
#
9 0:513646585e45 Chris
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13 909:cbb26bc654de Chris
#
14 0:513646585e45 Chris
# You should have received a copy of the GNU General Public License
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.
17
18
class MyController < ApplicationController
19
  before_filter :require_login
20
21
  helper :issues
22 117:af80e5618e9b Chris
  helper :users
23 0:513646585e45 Chris
  helper :custom_fields
24 1086:5ebdeb79ea9c chris
  helper :projects
25 1217:875b5b4c574d chris
  helper :activities
26 0:513646585e45 Chris
27
  BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues,
28
             'issuesreportedbyme' => :label_reported_issues,
29
             'issueswatched' => :label_watched_issues,
30 344:1a514b9347d4 chris
             'activitymyprojects' => :label_activity_my_recent,
31 0:513646585e45 Chris
             'news' => :label_news_latest,
32 363:ce85aa993384 chris
             'tipoftheday' => :label_tipoftheday,
33 0:513646585e45 Chris
             'calendar' => :label_calendar,
34
             'documents' => :label_document_plural,
35 1086:5ebdeb79ea9c chris
             'timelog' => :label_spent_time,
36 1217:875b5b4c574d chris
             'myprojects' => :label_my_projects,
37
             'colleagues' => :label_my_colleagues
38 0:513646585e45 Chris
           }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze
39
40 1164:a943f341c99d chris
  DEFAULT_LAYOUT = {  'left' => ['myprojects', 'activitymyprojects'],
41 1304:6137548ba453 Chris
                      'right' => ['colleagues', 'tipoftheday', 'issueswatched']
42 0:513646585e45 Chris
                   }.freeze
43
44
  verify :xhr => true,
45
         :only => [:add_block, :remove_block, :order_blocks]
46
47
  def index
48
    page
49
    render :action => 'page'
50
  end
51
52
  # Show user's page
53
  def page
54
    @user = User.current
55
    @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT
56
  end
57
58
  # Edit user's account
59
  def account
60
    @user = User.current
61
    @pref = @user.pref
62 108:d70a0b926135 luisf
    @ssamr_user_details = @user.ssamr_user_detail
63 164:bb9724ba3d60 luisf
64 188:f9fe5ef6156e luisf
65
    if @user.ssamr_user_detail == nil
66
       @selected_institution_id = nil
67
     else
68
       @selected_institution_id = @ssamr_user_details.institution_id.to_i
69
     end
70
71 0:513646585e45 Chris
    if request.post?
72 117:af80e5618e9b Chris
      @user.safe_attributes = params[:user]
73 0:513646585e45 Chris
      @user.pref.attributes = params[:pref]
74
      @user.pref[:no_self_notified] = (params[:no_self_notified] == '1')
75 108:d70a0b926135 luisf
76
      if @user.ssamr_user_detail == nil
77
        @ssamr_user_details = SsamrUserDetail.new()
78
        @user.ssamr_user_detail = @ssamr_user_details
79
      else
80
        @ssamr_user_details = @user.ssamr_user_detail
81
      end
82
83
      if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty?
84
        @ssamr_user_details.description = @user.ssamr_user_detail.description
85
        @ssamr_user_details.institution_id = @user.ssamr_user_detail.institution_id
86 164:bb9724ba3d60 luisf
        @institution_type = @ssamr_user_details.institution_type
87
        @other_institution = @ssamr_user_details.other_institution
88 108:d70a0b926135 luisf
      else
89
        @ssamr_user_details.description = params[:ssamr_user_details][:description]
90
        @ssamr_user_details.institution_id = params[:ssamr_user_details][:institution_id]
91 164:bb9724ba3d60 luisf
        @ssamr_user_details.institution_type = params[:ssamr_user_details][:institution_type]
92
        @ssamr_user_details.other_institution = params[:ssamr_user_details][:other_institution]
93 108:d70a0b926135 luisf
      end
94 164:bb9724ba3d60 luisf
95 0:513646585e45 Chris
      if @user.save
96
        @user.pref.save
97 117:af80e5618e9b Chris
        @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : [])
98 0:513646585e45 Chris
        set_language_if_valid @user.language
99
        flash[:notice] = l(:notice_account_updated)
100
        redirect_to :action => 'account'
101
        return
102
      end
103
    end
104
  end
105
106
  # Manage user's password
107
  def password
108
    @user = User.current
109
    unless @user.change_password_allowed?
110
      flash[:error] = l(:notice_can_t_change_password)
111
      redirect_to :action => 'account'
112
      return
113
    end
114
    if request.post?
115
      if @user.check_password?(params[:password])
116
        @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation]
117
        if @user.save
118
          flash[:notice] = l(:notice_account_password_updated)
119
          redirect_to :action => 'account'
120
        end
121
      else
122
        flash[:error] = l(:notice_account_wrong_password)
123
      end
124
    end
125
  end
126 909:cbb26bc654de Chris
127 0:513646585e45 Chris
  # Create a new feeds key
128
  def reset_rss_key
129
    if request.post?
130
      if User.current.rss_token
131
        User.current.rss_token.destroy
132
        User.current.reload
133
      end
134
      User.current.rss_key
135
      flash[:notice] = l(:notice_feeds_access_key_reseted)
136
    end
137
    redirect_to :action => 'account'
138
  end
139
140
  # Create a new API key
141
  def reset_api_key
142
    if request.post?
143
      if User.current.api_token
144
        User.current.api_token.destroy
145
        User.current.reload
146
      end
147
      User.current.api_key
148
      flash[:notice] = l(:notice_api_access_key_reseted)
149
    end
150
    redirect_to :action => 'account'
151
  end
152
153
  # User's page layout configuration
154
  def page_layout
155
    @user = User.current
156
    @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup
157
    @block_options = []
158
    BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]}
159
  end
160 909:cbb26bc654de Chris
161 0:513646585e45 Chris
  # Add a block to user's page
162
  # The block is added on top of the page
163
  # params[:block] : id of the block to add
164
  def add_block
165
    block = params[:block].to_s.underscore
166
    (render :nothing => true; return) unless block && (BLOCKS.keys.include? block)
167
    @user = User.current
168
    layout = @user.pref[:my_page_layout] || {}
169
    # remove if already present in a group
170
    %w(top left right).each {|f| (layout[f] ||= []).delete block }
171
    # add it on top
172
    layout['top'].unshift block
173
    @user.pref[:my_page_layout] = layout
174 909:cbb26bc654de Chris
    @user.pref.save
175 0:513646585e45 Chris
    render :partial => "block", :locals => {:user => @user, :block_name => block}
176
  end
177 909:cbb26bc654de Chris
178 0:513646585e45 Chris
  # Remove a block to user's page
179
  # params[:block] : id of the block to remove
180
  def remove_block
181
    block = params[:block].to_s.underscore
182
    @user = User.current
183
    # remove block in all groups
184
    layout = @user.pref[:my_page_layout] || {}
185
    %w(top left right).each {|f| (layout[f] ||= []).delete block }
186
    @user.pref[:my_page_layout] = layout
187 909:cbb26bc654de Chris
    @user.pref.save
188 0:513646585e45 Chris
    render :nothing => true
189
  end
190
191
  # Change blocks order on user's page
192
  # params[:group] : group to order (top, left or right)
193
  # params[:list-(top|left|right)] : array of block ids of the group
194
  def order_blocks
195
    group = params[:group]
196
    @user = User.current
197
    if group.is_a?(String)
198
      group_items = (params["list-#{group}"] || []).collect(&:underscore)
199
      if group_items and group_items.is_a? Array
200
        layout = @user.pref[:my_page_layout] || {}
201
        # remove group blocks if they are presents in other groups
202
        %w(top left right).each {|f|
203
          layout[f] = (layout[f] || []) - group_items
204
        }
205
        layout[group] = group_items
206
        @user.pref[:my_page_layout] = layout
207 909:cbb26bc654de Chris
        @user.pref.save
208 0:513646585e45 Chris
      end
209
    end
210
    render :nothing => true
211
  end
212
end