From 362633d486e31503e1b9d82368cd274db4615f9d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sun, 3 Dec 2006 19:55:45 +0000 Subject: [PATCH] - new controller "myController" - account/my_page moved to my/page - account/my_account mmoved to my/account - "my page" is now customizable (table user_preferences added) git-svn-id: http://redmine.rubyforge.org/svn/trunk@62 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- redmine/app/controllers/account_controller.rb | 37 +---- redmine/app/controllers/my_controller.rb | 128 ++++++++++++++++++ redmine/app/helpers/my_helper.rb | 19 +++ redmine/app/models/user.rb | 6 + redmine/app/models/user_preference.rb | 44 ++++++ redmine/app/views/account/my_page.rhtml | 22 --- redmine/app/views/layouts/base.rhtml | 4 +- redmine/app/views/my/_block.rhtml | 16 +++ .../my_account.rhtml => my/account.rhtml} | 2 +- redmine/app/views/my/blocks/_calendar.rhtml | 45 ++++++ redmine/app/views/my/blocks/_documents.rhtml | 15 ++ .../my/blocks/_issues_assigned_to_me.rhtml | 10 ++ .../my/blocks/_issues_reported_by_me.rhtml | 10 ++ .../app/views/my/blocks/_latest_news.rhtml | 13 ++ redmine/app/views/my/page.rhtml | 30 ++++ redmine/app/views/my/page_layout.rhtml | 121 +++++++++++++++++ .../db/migrate/008_create_user_preferences.rb | 12 ++ redmine/doc/CHANGELOG | 1 + redmine/lang/de.yml | 2 + redmine/lang/en.yml | 2 + redmine/lang/es.yml | 2 + redmine/lang/fr.yml | 4 +- redmine/public/images/close.png | Bin 0 -> 200 bytes redmine/public/images/close_hl.png | Bin 0 -> 199 bytes redmine/public/images/loading.gif | Bin 0 -> 1553 bytes redmine/public/stylesheets/application.css | 36 +++++ redmine/test/fixtures/user_preferences.yml | 5 + redmine/test/functional/my_controller_test.rb | 18 +++ redmine/test/integration/account_test.rb | 34 ++--- redmine/test/test_helper.rb | 2 +- redmine/test/unit/user_preference_test.rb | 10 ++ 31 files changed, 570 insertions(+), 80 deletions(-) create mode 100644 redmine/app/controllers/my_controller.rb create mode 100644 redmine/app/helpers/my_helper.rb create mode 100644 redmine/app/models/user_preference.rb delete mode 100644 redmine/app/views/account/my_page.rhtml create mode 100644 redmine/app/views/my/_block.rhtml rename redmine/app/views/{account/my_account.rhtml => my/account.rhtml} (95%) create mode 100644 redmine/app/views/my/blocks/_calendar.rhtml create mode 100644 redmine/app/views/my/blocks/_documents.rhtml create mode 100644 redmine/app/views/my/blocks/_issues_assigned_to_me.rhtml create mode 100644 redmine/app/views/my/blocks/_issues_reported_by_me.rhtml create mode 100644 redmine/app/views/my/blocks/_latest_news.rhtml create mode 100644 redmine/app/views/my/page.rhtml create mode 100644 redmine/app/views/my/page_layout.rhtml create mode 100644 redmine/db/migrate/008_create_user_preferences.rb create mode 100644 redmine/public/images/close.png create mode 100644 redmine/public/images/close_hl.png create mode 100644 redmine/public/images/loading.gif create mode 100644 redmine/test/fixtures/user_preferences.yml create mode 100644 redmine/test/functional/my_controller_test.rb create mode 100644 redmine/test/unit/user_preference_test.rb diff --git a/redmine/app/controllers/account_controller.rb b/redmine/app/controllers/account_controller.rb index 7031d71ec..ffd2419b3 100644 --- a/redmine/app/controllers/account_controller.rb +++ b/redmine/app/controllers/account_controller.rb @@ -40,7 +40,7 @@ class AccountController < ApplicationController user = User.try_to_login(params[:login], params[:password]) if user self.logged_in_user = user - redirect_back_or_default :controller => 'account', :action => 'my_page' + redirect_back_or_default :controller => 'my', :action => 'page' else flash.now[:notice] = l(:notice_account_invalid_creditentials) end @@ -52,41 +52,6 @@ class AccountController < ApplicationController self.logged_in_user = nil redirect_to :controller => '' end - - # Show logged in user's page - def my_page - @user = self.logged_in_user - @reported_issues = Issue.find(:all, :conditions => ["author_id=?", @user.id], :limit => 10, :include => [ :status, :project, :tracker ], :order => 'issues.updated_on DESC') - @assigned_issues = Issue.find(:all, :conditions => ["assigned_to_id=?", @user.id], :limit => 10, :include => [ :status, :project, :tracker ], :order => 'issues.updated_on DESC') - end - - # Edit logged in user's account - def my_account - @user = self.logged_in_user - if request.post? and @user.update_attributes(@params[:user]) - set_localization - flash.now[:notice] = l(:notice_account_updated) - self.logged_in_user.reload - end - end - - # Change logged in user's password - def change_password - @user = self.logged_in_user - flash[:notice] = l(:notice_can_t_change_password) and redirect_to :action => 'my_account' and return if @user.auth_source_id - if @user.check_password?(@params[:password]) - @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] - if @user.save - flash[:notice] = l(:notice_account_password_updated) - else - render :action => 'my_account' - return - end - else - flash[:notice] = l(:notice_account_wrong_password) - end - redirect_to :action => 'my_account' - end # Enable user to choose a new password def lost_password diff --git a/redmine/app/controllers/my_controller.rb b/redmine/app/controllers/my_controller.rb new file mode 100644 index 000000000..25f362df2 --- /dev/null +++ b/redmine/app/controllers/my_controller.rb @@ -0,0 +1,128 @@ +# redMine - project management software +# Copyright (C) 2006 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class MyController < ApplicationController + layout 'base' + before_filter :require_login + + BLOCKS = { 'issues_assigned_to_me' => :label_assigned_to_me_issues, + 'issues_reported_by_me' => :label_reported_issues, + 'latest_news' => :label_news_latest, + 'calendar' => :label_calendar, + 'documents' => :label_document_plural + }.freeze + + verify :xhr => true, + :session => :page_layout, + :only => [:add_block, :remove_block, :order_blocks] + + def index + page + render :action => 'page' + end + + # Show user's page + def page + @user = self.logged_in_user + @blocks = @user.pref[:my_page_layout] || { 'left' => ['issues_assigned_to_me'], 'right' => ['issues_reported_by_me'] } + end + + # Edit user's account + def account + @user = self.logged_in_user + if request.post? and @user.update_attributes(@params[:user]) + set_localization + flash.now[:notice] = l(:notice_account_updated) + self.logged_in_user.reload + end + end + + # Change user's password + def change_password + @user = self.logged_in_user + flash[:notice] = l(:notice_can_t_change_password) and redirect_to :action => 'account' and return if @user.auth_source_id + if @user.check_password?(@params[:password]) + @user.password, @user.password_confirmation = params[:new_password], params[:new_password_confirmation] + if @user.save + flash[:notice] = l(:notice_account_password_updated) + else + render :action => 'account' + return + end + else + flash[:notice] = l(:notice_account_wrong_password) + end + redirect_to :action => 'account' + end + + # User's page layout configuration + def page_layout + @user = self.logged_in_user + @blocks = @user.pref[:my_page_layout] || { 'left' => ['issues_assigned_to_me'], 'right' => ['issues_reported_by_me'] } + session[:page_layout] = @blocks + %w(top left right).each {|f| session[:page_layout][f] ||= [] } + @block_options = [] + BLOCKS.each {|k, v| @block_options << [l(v), k]} + end + + # Add a block to user's page + # The block is added on top of the page + # params[:block] : id of the block to add + def add_block + @user = self.logged_in_user + block = params[:block] + # remove if already present in a group + %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block } + # add it on top + session[:page_layout]['top'].unshift block + render :partial => "block", :locals => {:user => @user, :block_name => block} + end + + # Remove a block to user's page + # params[:block] : id of the block to remove + def remove_block + block = params[:block] + # remove block in all groups + %w(top left right).each {|f| (session[:page_layout][f] ||= []).delete block } + render :nothing => true + end + + # Change blocks order on user's page + # params[:group] : group to order (top, left or right) + # params[:list-(top|left|right)] : array of block ids of the group + def order_blocks + group = params[:group] + group_items = params["list-#{group}"] + if group_items and group_items.is_a? Array + # remove group blocks if they are presents in other groups + %w(top left right).each {|f| + session[:page_layout][f] = (session[:page_layout][f] || []) - group_items + } + session[:page_layout][group] = group_items + end + render :nothing => true + end + + # Save user's page layout + def page_layout_save + @user = self.logged_in_user + @user.pref[:my_page_layout] = session[:page_layout] if session[:page_layout] + @user.pref.save + session[:page_layout] = nil + redirect_to :action => 'page' + end +end diff --git a/redmine/app/helpers/my_helper.rb b/redmine/app/helpers/my_helper.rb new file mode 100644 index 000000000..9098f67bc --- /dev/null +++ b/redmine/app/helpers/my_helper.rb @@ -0,0 +1,19 @@ +# redMine - project management software +# Copyright (C) 2006 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +module MyHelper +end diff --git a/redmine/app/models/user.rb b/redmine/app/models/user.rb index 7f09ef550..a82c98a88 100644 --- a/redmine/app/models/user.rb +++ b/redmine/app/models/user.rb @@ -19,7 +19,9 @@ require "digest/sha1" class User < ActiveRecord::Base has_many :memberships, :class_name => 'Member', :include => [ :project, :role ], :dependent => true + has_many :projects, :through => :memberships has_many :custom_values, :dependent => true, :as => :customized + has_one :preference, :dependent => true, :class_name => 'UserPreference' belongs_to :auth_source attr_accessor :password, :password_confirmation @@ -114,6 +116,10 @@ class User < ActiveRecord::Base end @role_for_projects[project_id] end + + def pref + self.preference ||= UserPreference.new(:user => self) + end private # Return password digest diff --git a/redmine/app/models/user_preference.rb b/redmine/app/models/user_preference.rb new file mode 100644 index 000000000..5240c9757 --- /dev/null +++ b/redmine/app/models/user_preference.rb @@ -0,0 +1,44 @@ +# redMine - project management software +# Copyright (C) 2006 Jean-Philippe Lang +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +class UserPreference < ActiveRecord::Base + belongs_to :user + serialize :others, Hash + + attr_protected :others + + def initialize(attributes = nil) + super + self.others ||= {} + end + + def [](attr_name) + if attribute_present? attr_name + super + else + others[attr_name] + end + end + + def []=(attr_name, value) + if attribute_present? attr_name + super + else + others.store attr_name, value + end + end +end diff --git a/redmine/app/views/account/my_page.rhtml b/redmine/app/views/account/my_page.rhtml deleted file mode 100644 index 54b5685e8..000000000 --- a/redmine/app/views/account/my_page.rhtml +++ /dev/null @@ -1,22 +0,0 @@ -

<%=l(:label_my_page)%>

- -

-<% unless @user.last_before_login_on.nil? %> - <%=l(:label_last_login)%>: <%= format_time(@user.last_before_login_on) %> -<% end %> -

- -
-

<%=l(:label_reported_issues)%>

- <%= render :partial => 'issues/list_simple', :locals => { :issues => @reported_issues } %> - <% if @reported_issues.length > 0 %> -

<%=lwr(:label_last_updates, @reported_issues.length)%>

- <% end %> -
-
-

<%=l(:label_assigned_to_me_issues)%>

- <%= render :partial => 'issues/list_simple', :locals => { :issues => @assigned_issues } %> - <% if @assigned_issues.length > 0 %> -

<%=lwr(:label_last_updates, @assigned_issues.length)%>

- <% end %> -
\ No newline at end of file diff --git a/redmine/app/views/layouts/base.rhtml b/redmine/app/views/layouts/base.rhtml index 767f51f61..951fa88f7 100644 --- a/redmine/app/views/layouts/base.rhtml +++ b/redmine/app/views/layouts/base.rhtml @@ -70,7 +70,7 @@ var menu_contenu=' \