Commit e645e6a1ee226c6f0eb1afe583ae4237f64606b0
1 parent
68f2511a
Exists in
master
and in
29 other branches
Allow admins to define the number of news on portal
Showing
6 changed files
with
38 additions
and
8 deletions
Show diff stats
app/controllers/public/home_controller.rb
@@ -2,13 +2,13 @@ class HomeController < PublicController | @@ -2,13 +2,13 @@ class HomeController < PublicController | ||
2 | 2 | ||
3 | def index | 3 | def index |
4 | @has_news = false | 4 | @has_news = false |
5 | - if environment.enabled?('use_portal_community') && environment.portal_community | 5 | + if environment.portal_enabled |
6 | @has_news = true | 6 | @has_news = true |
7 | @news_cache_key = environment.portal_news_cache_key(FastGettext.locale) | 7 | @news_cache_key = environment.portal_news_cache_key(FastGettext.locale) |
8 | if !read_fragment(@news_cache_key) | 8 | if !read_fragment(@news_cache_key) |
9 | portal_community = environment.portal_community | 9 | portal_community = environment.portal_community |
10 | - @highlighted_news = portal_community.news(2, true) | ||
11 | - @portal_news = portal_community.news(7, true) - @highlighted_news | 10 | + @highlighted_news = portal_community.news(environment.highlighted_news_amount, true) |
11 | + @portal_news = portal_community.news(environment.portal_news_amount, true).offset(environment.highlighted_news_amount) | ||
12 | @area_news = environment.portal_folders | 12 | @area_news = environment.portal_folders |
13 | end | 13 | end |
14 | end | 14 | end |
app/models/environment.rb
@@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
3 | # domains. | 3 | # domains. |
4 | class Environment < ActiveRecord::Base | 4 | class Environment < ActiveRecord::Base |
5 | 5 | ||
6 | - attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound, :noreply_email, :signup_welcome_screen_body, :members_whitelist_enabled, :members_whitelist | 6 | + attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound, :noreply_email, :signup_welcome_screen_body, :members_whitelist_enabled, :members_whitelist, :highlighted_news_amount, :portal_news_amount |
7 | 7 | ||
8 | has_many :users | 8 | has_many :users |
9 | 9 | ||
@@ -268,6 +268,8 @@ class Environment < ActiveRecord::Base | @@ -268,6 +268,8 @@ class Environment < ActiveRecord::Base | ||
268 | settings_items :description, :type => String, :default => '<div style="text-align: center"><a href="http://noosfero.org/"><img src="/images/noosfero-network.png" alt="Noosfero"/></a></div>' | 268 | settings_items :description, :type => String, :default => '<div style="text-align: center"><a href="http://noosfero.org/"><img src="/images/noosfero-network.png" alt="Noosfero"/></a></div>' |
269 | settings_items :local_docs, :type => Array, :default => [] | 269 | settings_items :local_docs, :type => Array, :default => [] |
270 | settings_items :news_amount_by_folder, :type => Integer, :default => 4 | 270 | settings_items :news_amount_by_folder, :type => Integer, :default => 4 |
271 | + settings_items :highlighted_news_amount, :type => Integer, :default => 2 | ||
272 | + settings_items :portal_news_amount, :type => Integer, :default => 5 | ||
271 | settings_items :help_message_to_add_enterprise, :type => String, :default => '' | 273 | settings_items :help_message_to_add_enterprise, :type => String, :default => '' |
272 | settings_items :tip_message_enterprise_activation_question, :type => String, :default => '' | 274 | settings_items :tip_message_enterprise_activation_question, :type => String, :default => '' |
273 | 275 |
app/views/admin_panel/set_portal_community.html.erb
@@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
18 | <%= button 'ok', _('Enable'), {:action => 'manage_portal_community', :activate => 1} %> | 18 | <%= button 'ok', _('Enable'), {:action => 'manage_portal_community', :activate => 1} %> |
19 | <% end %> | 19 | <% end %> |
20 | <%= button 'folder', _('Select Portal Folders'), {:action => 'set_portal_folders'} %> | 20 | <%= button 'folder', _('Select Portal Folders'), {:action => 'set_portal_folders'} %> |
21 | - <%= button 'edit', _('Define Amount by Folder'), {:action => 'set_portal_news_amount'} %> | 21 | + <%= button 'edit', _('Define news amount on portal'), {:action => 'set_portal_news_amount'} %> |
22 | <%= button 'delete', _('Remove'), { :action => 'unset_portal_community'} %> | 22 | <%= button 'delete', _('Remove'), { :action => 'unset_portal_community'} %> |
23 | <% end %> | 23 | <% end %> |
24 | <% end %> | 24 | <% end %> |
app/views/admin_panel/set_portal_news_amount.html.erb
1 | -<h1><%= _('News amount by folder') %></h1> | 1 | +<h1><%= _('News amount on portal') %></h1> |
2 | 2 | ||
3 | <%= labelled_form_for :environment do |f| %> | 3 | <%= labelled_form_for :environment do |f| %> |
4 | 4 | ||
5 | - <%= labelled_form_field _('Number of news'), select(:environment, :news_amount_by_folder, (1..10).to_a) %> | 5 | + <%= labelled_form_field _('Number of highlighted news'), select(:environment, :highlighted_news_amount, (0..10).to_a) %> |
6 | + <%= labelled_form_field _('Number of portal news'), select(:environment, :portal_news_amount, (0..10).to_a) %> | ||
7 | + <%= labelled_form_field _('Number of news by folder'), select(:environment, :news_amount_by_folder, (1..10).to_a) %> | ||
6 | 8 | ||
7 | <% button_bar do %> | 9 | <% button_bar do %> |
8 | <%= submit_button(:save, _('Save')) %> | 10 | <%= submit_button(:save, _('Save')) %> |
test/functional/admin_panel_controller_test.rb
@@ -334,10 +334,12 @@ class AdminPanelControllerTest < ActionController::TestCase | @@ -334,10 +334,12 @@ class AdminPanelControllerTest < ActionController::TestCase | ||
334 | end | 334 | end |
335 | 335 | ||
336 | should 'save amount of news' do | 336 | should 'save amount of news' do |
337 | - post :set_portal_news_amount, :environment => { :news_amount_by_folder => '3' } | 337 | + post :set_portal_news_amount, :environment => { :news_amount_by_folder => '3', :highlighted_news_amount => '2', :portal_news_amount => '5' } |
338 | assert_redirected_to :action => 'index' | 338 | assert_redirected_to :action => 'index' |
339 | 339 | ||
340 | assert_equal 3, Environment.default.news_amount_by_folder | 340 | assert_equal 3, Environment.default.news_amount_by_folder |
341 | + assert_equal 2, Environment.default.highlighted_news_amount | ||
342 | + assert_equal 5, Environment.default.portal_news_amount | ||
341 | end | 343 | end |
342 | 344 | ||
343 | should 'display plugins links' do | 345 | should 'display plugins links' do |
test/unit/environment_test.rb
@@ -1056,6 +1056,30 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -1056,6 +1056,30 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
1056 | assert_equal 4, e.news_amount_by_folder | 1056 | assert_equal 4, e.news_amount_by_folder |
1057 | end | 1057 | end |
1058 | 1058 | ||
1059 | + should 'have amount of highlighted news' do | ||
1060 | + e = Environment.default | ||
1061 | + | ||
1062 | + assert_respond_to e, :highlighted_news_amount | ||
1063 | + | ||
1064 | + assert_equal 2, e.highlighted_news_amount | ||
1065 | + e.highlighted_news_amount = 4 | ||
1066 | + e.save! | ||
1067 | + | ||
1068 | + assert_equal 4, Environment.default.highlighted_news_amount | ||
1069 | + end | ||
1070 | + | ||
1071 | + should 'have amount of portal news' do | ||
1072 | + e = Environment.default | ||
1073 | + | ||
1074 | + assert_respond_to e, :portal_news_amount | ||
1075 | + | ||
1076 | + assert_equal 5, e.portal_news_amount | ||
1077 | + e.portal_news_amount = 2 | ||
1078 | + e.save! | ||
1079 | + | ||
1080 | + assert_equal 2, Environment.default.portal_news_amount | ||
1081 | + end | ||
1082 | + | ||
1059 | should 'list tags with their counts' do | 1083 | should 'list tags with their counts' do |
1060 | person = fast_create(Person) | 1084 | person = fast_create(Person) |
1061 | person.articles.create!(:name => 'article 1', :tag_list => 'first-tag') | 1085 | person.articles.create!(:name => 'article 1', :tag_list => 'first-tag') |