diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-10-15 19:06:22 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2015-10-15 19:06:22 +0000 |
commit | 589bde0899cc72c7a5c253a6f1da4e0408de031f (patch) | |
tree | e3d4c23d04dea43b7db4505dcd641e273910bf32 | |
parent | 486a4dfbc82a5ffc5dd89f94bb44edd5a7f127cd (diff) | |
download | redmine-589bde0899cc72c7a5c253a6f1da4e0408de031f.tar.gz redmine-589bde0899cc72c7a5c253a6f1da4e0408de031f.zip |
Activity page to remember user's selection of activities (#1605).
git-svn-id: http://svn.redmine.org/redmine/trunk@14678 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/activities_controller.rb | 15 | ||||
-rw-r--r-- | app/models/user_preference.rb | 3 | ||||
-rw-r--r-- | app/views/activities/index.html.erb | 2 | ||||
-rw-r--r-- | test/functional/activities_controller_test.rb | 19 |
4 files changed, 37 insertions, 2 deletions
diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index 717997d90..00d03487a 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -37,8 +37,21 @@ class ActivitiesController < ApplicationController @activity = Redmine::Activity::Fetcher.new(User.current, :project => @project, :with_subprojects => @with_subprojects, :author => @author) + pref = User.current.pref @activity.scope_select {|t| !params["show_#{t}"].nil?} - @activity.scope = (@author.nil? ? :default : :all) if @activity.scope.empty? + if @activity.scope.present? + if params[:submit].present? + pref.activity_scope = @activity.scope + pref.save + end + else + if @author.nil? + scope = pref.activity_scope & @activity.event_types + @activity.scope = scope.present? ? scope : :default + else + @activity.scope = :all + end + end events = @activity.events(@date_from, @date_to) diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 3b671c244..80b3e6b9d 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -59,4 +59,7 @@ class UserPreference < ActiveRecord::Base def no_self_notified; (self[:no_self_notified] == true || self[:no_self_notified] == '1'); end def no_self_notified=(value); self[:no_self_notified]=value; end + + def activity_scope; Array(self[:activity_scope]) ; end + def activity_scope=(value); self[:activity_scope]=value ; end end diff --git a/app/views/activities/index.html.erb b/app/views/activities/index.html.erb index 0a996a052..830f408d3 100644 --- a/app/views/activities/index.html.erb +++ b/app/views/activities/index.html.erb @@ -61,7 +61,7 @@ <p><label><%= check_box_tag 'with_subprojects', 1, @with_subprojects %> <%=l(:label_subproject_plural)%></label></p> <% end %> <%= hidden_field_tag('user_id', params[:user_id]) unless params[:user_id].blank? %> -<p><%= submit_tag l(:button_apply), :class => 'button-small', :name => nil %></p> +<p><%= submit_tag l(:button_apply), :class => 'button-small', :name => 'submit' %></p> <% end %> <% end %> diff --git a/test/functional/activities_controller_test.rb b/test/functional/activities_controller_test.rb index 6a1d2a7db..34a15ee71 100644 --- a/test/functional/activities_controller_test.rb +++ b/test/functional/activities_controller_test.rb @@ -157,4 +157,23 @@ class ActivitiesControllerTest < ActionController::TestCase assert_response :success assert_not_include journal, assigns(:events_by_day).values.flatten end + + def test_index_with_submitted_scope_should_save_as_preference + @request.session[:user_id] = 2 + + get :index, :show_issues => '1', :show_messages => '1', :submit => 'Apply' + assert_response :success + assert_equal %w(issues messages), User.find(2).pref.activity_scope.sort + end + + def test_index_scope_should_default_to_user_preference + pref = User.find(2).pref + pref.activity_scope = %w(issues news) + pref.save! + @request.session[:user_id] = 2 + + get :index + assert_response :success + assert_equal %w(issues news), assigns(:activity).scope + end end |