]> source.dussan.org Git - redmine.git/commitdiff
Activity page to remember user's selection of activities (#1605).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 15 Oct 2015 19:06:22 +0000 (19:06 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Thu, 15 Oct 2015 19:06:22 +0000 (19:06 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@14678 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/activities_controller.rb
app/models/user_preference.rb
app/views/activities/index.html.erb
test/functional/activities_controller_test.rb

index 717997d90ccda01d42881f85ab4d62e61bd8d09e..00d03487a72133d2676d8edf3e10d6f81893f320 100644 (file)
@@ -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)
 
index 3b671c244be54d75d31b0817443789e73be9bccc..80b3e6b9deb7938fcdde502fddaf75852e6eb48e 100644 (file)
@@ -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
index 0a996a052559922c354be8012e16128b376884d1..830f408d3c79ea08b6a4cf4a117d38b14dbab254 100644 (file)
@@ -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 %>
 
index 6a1d2a7db68f5f0ce42d48ae4052fe6734cdac27..34a15ee71a43644686a17c58c979d88b4db4da2b 100644 (file)
@@ -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