annotate app/controllers/.svn/text-base/my_controller.rb.svn-base @ 45:65d9e2cabaa3 luisf

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