To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / app / controllers / my_controller.rb @ 912:5e80956cc792
History | View | Annotate | Download (6.95 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 | |||
| 25 | BLOCKS = { 'issuesassignedtome' => :label_assigned_to_me_issues, |
||
| 26 | 'issuesreportedbyme' => :label_reported_issues, |
||
| 27 | 'issueswatched' => :label_watched_issues, |
||
| 28 | 344:1a514b9347d4 | chris | 'activitymyprojects' => :label_activity_my_recent, |
| 29 | 0:513646585e45 | Chris | 'news' => :label_news_latest, |
| 30 | 363:ce85aa993384 | chris | 'tipoftheday' => :label_tipoftheday, |
| 31 | 0:513646585e45 | Chris | 'calendar' => :label_calendar, |
| 32 | 'documents' => :label_document_plural, |
||
| 33 | 'timelog' => :label_spent_time |
||
| 34 | }.merge(Redmine::Views::MyPage::Block.additional_blocks).freeze |
||
| 35 | |||
| 36 | 363:ce85aa993384 | chris | DEFAULT_LAYOUT = { 'left' => ['tipoftheday', 'activitymyprojects'], |
| 37 | 485:ef125e1f3a10 | chris | 'right' => ['issueswatched'] |
| 38 | 0:513646585e45 | Chris | }.freeze |
| 39 | |||
| 40 | verify :xhr => true, |
||
| 41 | :only => [:add_block, :remove_block, :order_blocks] |
||
| 42 | |||
| 43 | def index |
||
| 44 | page |
||
| 45 | render :action => 'page' |
||
| 46 | end
|
||
| 47 | |||
| 48 | # Show user's page
|
||
| 49 | def page |
||
| 50 | @user = User.current |
||
| 51 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT |
||
| 52 | end
|
||
| 53 | |||
| 54 | # Edit user's account
|
||
| 55 | def account |
||
| 56 | @user = User.current |
||
| 57 | @pref = @user.pref |
||
| 58 | 108:d70a0b926135 | luisf | @ssamr_user_details = @user.ssamr_user_detail |
| 59 | 164:bb9724ba3d60 | luisf | |
| 60 | 188:f9fe5ef6156e | luisf | |
| 61 | if @user.ssamr_user_detail == nil |
||
| 62 | @selected_institution_id = nil |
||
| 63 | else
|
||
| 64 | @selected_institution_id = @ssamr_user_details.institution_id.to_i |
||
| 65 | end
|
||
| 66 | |||
| 67 | 0:513646585e45 | Chris | if request.post?
|
| 68 | 117:af80e5618e9b | Chris | @user.safe_attributes = params[:user] |
| 69 | 0:513646585e45 | Chris | @user.pref.attributes = params[:pref] |
| 70 | @user.pref[:no_self_notified] = (params[:no_self_notified] == '1') |
||
| 71 | 108:d70a0b926135 | luisf | |
| 72 | if @user.ssamr_user_detail == nil |
||
| 73 | @ssamr_user_details = SsamrUserDetail.new() |
||
| 74 | @user.ssamr_user_detail = @ssamr_user_details |
||
| 75 | else
|
||
| 76 | @ssamr_user_details = @user.ssamr_user_detail |
||
| 77 | end
|
||
| 78 | |||
| 79 | if params[:ssamr_user_details].nil? or params[:ssamr_user_details].empty? |
||
| 80 | @ssamr_user_details.description = @user.ssamr_user_detail.description |
||
| 81 | @ssamr_user_details.institution_id = @user.ssamr_user_detail.institution_id |
||
| 82 | 164:bb9724ba3d60 | luisf | @institution_type = @ssamr_user_details.institution_type |
| 83 | @other_institution = @ssamr_user_details.other_institution |
||
| 84 | 108:d70a0b926135 | luisf | else
|
| 85 | @ssamr_user_details.description = params[:ssamr_user_details][:description] |
||
| 86 | @ssamr_user_details.institution_id = params[:ssamr_user_details][:institution_id] |
||
| 87 | 164:bb9724ba3d60 | luisf | @ssamr_user_details.institution_type = params[:ssamr_user_details][:institution_type] |
| 88 | @ssamr_user_details.other_institution = params[:ssamr_user_details][:other_institution] |
||
| 89 | 108:d70a0b926135 | luisf | end
|
| 90 | 164:bb9724ba3d60 | luisf | |
| 91 | 0:513646585e45 | Chris | if @user.save |
| 92 | @user.pref.save
|
||
| 93 | 117:af80e5618e9b | Chris | @user.notified_project_ids = (@user.mail_notification == 'selected' ? params[:notified_project_ids] : []) |
| 94 | 0:513646585e45 | Chris | set_language_if_valid @user.language
|
| 95 | flash[:notice] = l(:notice_account_updated) |
||
| 96 | redirect_to :action => 'account' |
||
| 97 | return
|
||
| 98 | end
|
||
| 99 | end
|
||
| 100 | end
|
||
| 101 | |||
| 102 | # Manage user's password
|
||
| 103 | def password |
||
| 104 | @user = User.current |
||
| 105 | unless @user.change_password_allowed? |
||
| 106 | flash[:error] = l(:notice_can_t_change_password) |
||
| 107 | redirect_to :action => 'account' |
||
| 108 | return
|
||
| 109 | end
|
||
| 110 | if request.post?
|
||
| 111 | if @user.check_password?(params[:password]) |
||
| 112 | @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] |
||
| 113 | if @user.save |
||
| 114 | flash[:notice] = l(:notice_account_password_updated) |
||
| 115 | redirect_to :action => 'account' |
||
| 116 | end
|
||
| 117 | else
|
||
| 118 | flash[:error] = l(:notice_account_wrong_password) |
||
| 119 | end
|
||
| 120 | end
|
||
| 121 | end
|
||
| 122 | 909:cbb26bc654de | Chris | |
| 123 | 0:513646585e45 | Chris | # Create a new feeds key
|
| 124 | def reset_rss_key |
||
| 125 | if request.post?
|
||
| 126 | if User.current.rss_token |
||
| 127 | User.current.rss_token.destroy
|
||
| 128 | User.current.reload
|
||
| 129 | end
|
||
| 130 | User.current.rss_key
|
||
| 131 | flash[:notice] = l(:notice_feeds_access_key_reseted) |
||
| 132 | end
|
||
| 133 | redirect_to :action => 'account' |
||
| 134 | end
|
||
| 135 | |||
| 136 | # Create a new API key
|
||
| 137 | def reset_api_key |
||
| 138 | if request.post?
|
||
| 139 | if User.current.api_token |
||
| 140 | User.current.api_token.destroy
|
||
| 141 | User.current.reload
|
||
| 142 | end
|
||
| 143 | User.current.api_key
|
||
| 144 | flash[:notice] = l(:notice_api_access_key_reseted) |
||
| 145 | end
|
||
| 146 | redirect_to :action => 'account' |
||
| 147 | end
|
||
| 148 | |||
| 149 | # User's page layout configuration
|
||
| 150 | def page_layout |
||
| 151 | @user = User.current |
||
| 152 | @blocks = @user.pref[:my_page_layout] || DEFAULT_LAYOUT.dup |
||
| 153 | @block_options = []
|
||
| 154 | BLOCKS.each {|k, v| @block_options << [l("my.blocks.#{v}", :default => [v, v.to_s.humanize]), k.dasherize]} |
||
| 155 | end
|
||
| 156 | 909:cbb26bc654de | Chris | |
| 157 | 0:513646585e45 | Chris | # Add a block to user's page
|
| 158 | # The block is added on top of the page
|
||
| 159 | # params[:block] : id of the block to add
|
||
| 160 | def add_block |
||
| 161 | block = params[:block].to_s.underscore
|
||
| 162 | (render :nothing => true; return) unless block && (BLOCKS.keys.include? block) |
||
| 163 | @user = User.current |
||
| 164 | layout = @user.pref[:my_page_layout] || {} |
||
| 165 | # remove if already present in a group
|
||
| 166 | %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||
| 167 | # add it on top
|
||
| 168 | layout['top'].unshift block
|
||
| 169 | @user.pref[:my_page_layout] = layout |
||
| 170 | 909:cbb26bc654de | Chris | @user.pref.save
|
| 171 | 0:513646585e45 | Chris | render :partial => "block", :locals => {:user => @user, :block_name => block} |
| 172 | end
|
||
| 173 | 909:cbb26bc654de | Chris | |
| 174 | 0:513646585e45 | Chris | # Remove a block to user's page
|
| 175 | # params[:block] : id of the block to remove
|
||
| 176 | def remove_block |
||
| 177 | block = params[:block].to_s.underscore
|
||
| 178 | @user = User.current |
||
| 179 | # remove block in all groups
|
||
| 180 | layout = @user.pref[:my_page_layout] || {} |
||
| 181 | %w(top left right).each {|f| (layout[f] ||= []).delete block }
|
||
| 182 | @user.pref[:my_page_layout] = layout |
||
| 183 | 909:cbb26bc654de | Chris | @user.pref.save
|
| 184 | 0:513646585e45 | Chris | render :nothing => true |
| 185 | end
|
||
| 186 | |||
| 187 | # Change blocks order on user's page
|
||
| 188 | # params[:group] : group to order (top, left or right)
|
||
| 189 | # params[:list-(top|left|right)] : array of block ids of the group
|
||
| 190 | def order_blocks |
||
| 191 | group = params[:group]
|
||
| 192 | @user = User.current |
||
| 193 | if group.is_a?(String) |
||
| 194 | group_items = (params["list-#{group}"] || []).collect(&:underscore) |
||
| 195 | if group_items and group_items.is_a? Array |
||
| 196 | layout = @user.pref[:my_page_layout] || {} |
||
| 197 | # remove group blocks if they are presents in other groups
|
||
| 198 | %w(top left right).each {|f|
|
||
| 199 | layout[f] = (layout[f] || []) - group_items |
||
| 200 | } |
||
| 201 | layout[group] = group_items |
||
| 202 | @user.pref[:my_page_layout] = layout |
||
| 203 | 909:cbb26bc654de | Chris | @user.pref.save
|
| 204 | 0:513646585e45 | Chris | end
|
| 205 | end
|
||
| 206 | render :nothing => true |
||
| 207 | end
|
||
| 208 | end |