Commit 738808cfbc4e0527a7839143925d1af013df6818
1 parent
0cc53433
Exists in
article_blog_visualization_format
Remove date_format from profile and add it to environment
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
15 changed files
with
79 additions
and
116 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -188,18 +188,6 @@ class CmsController < MyProfileController |
188 | 188 | render :action => 'edit' |
189 | 189 | end |
190 | 190 | |
191 | - def general_configuration | |
192 | - @profile_data = profile | |
193 | - if request.post? | |
194 | - if @profile_data.update_attributes(params[:profile_data]) | |
195 | - session[:notice] = _("Article date format updated successfully") | |
196 | - else | |
197 | - session[:notice] = _("Could not update article's date format") | |
198 | - end | |
199 | - redirect_to :action => 'index' | |
200 | - end | |
201 | - end | |
202 | - | |
203 | 191 | post_only :set_home_page |
204 | 192 | def set_home_page |
205 | 193 | return render_access_denied unless user.can_change_homepage? | ... | ... |
app/helpers/content_viewer_helper.rb
app/models/environment.rb
... | ... | @@ -3,7 +3,17 @@ |
3 | 3 | # domains. |
4 | 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, :highlighted_news_amount, :portal_news_amount | |
6 | + attr_accessible :name, :is_default, :signup_welcome_text_subject, | |
7 | + :signup_welcome_text_body, :terms_of_use, | |
8 | + :message_for_disabled_enterprise, :news_amount_by_folder, | |
9 | + :default_language, :languages, :description, | |
10 | + :organization_approval_method, :enabled_plugins, | |
11 | + :enabled_features, :redirection_after_login, | |
12 | + :redirection_after_signup, :contact_email, :theme, | |
13 | + :reports_lower_bound, :noreply_email, | |
14 | + :signup_welcome_screen_body, :members_whitelist_enabled, | |
15 | + :members_whitelist, :highlighted_news_amount, | |
16 | + :portal_news_amount, :date_format | |
7 | 17 | |
8 | 18 | has_many :users |
9 | 19 | |
... | ... | @@ -14,6 +24,12 @@ class Environment < ActiveRecord::Base |
14 | 24 | |
15 | 25 | IDENTIFY_SCRIPTS = /(php[0-9s]?|[sp]htm[l]?|pl|py|cgi|rb)/ |
16 | 26 | |
27 | + validates_inclusion_of :date_format, | |
28 | + :in => [ 'numbers_with_year', 'numbers', | |
29 | + 'month_name_with_year', 'month_name', | |
30 | + 'past_time'], | |
31 | + :if => :date_format | |
32 | + | |
17 | 33 | def self.verify_filename(filename) |
18 | 34 | filename += '.txt' if File.extname(filename) =~ IDENTIFY_SCRIPTS |
19 | 35 | filename | ... | ... |
app/models/profile.rb
... | ... | @@ -13,7 +13,7 @@ class Profile < ActiveRecord::Base |
13 | 13 | :contact_email, :redirect_l10n, |
14 | 14 | :notification_time, :redirection_after_login, |
15 | 15 | :email_suggestions, :allow_members_to_invite, |
16 | - :invite_friends_only, :secret, :date_format | |
16 | + :invite_friends_only, :secret | |
17 | 17 | |
18 | 18 | # use for internationalizable human type names in search facets |
19 | 19 | # reimplement on subclasses |
... | ... | @@ -191,12 +191,6 @@ class Profile < ActiveRecord::Base |
191 | 191 | |
192 | 192 | validates_length_of :description, :maximum => 550, :allow_nil => true |
193 | 193 | |
194 | - validates_inclusion_of :date_format, | |
195 | - :in => [ 'numbers_with_year', 'numbers', | |
196 | - 'month_name_with_year', 'month_name', | |
197 | - 'past_time'], | |
198 | - :if => :date_format | |
199 | - | |
200 | 194 | # Valid identifiers must match this format. |
201 | 195 | IDENTIFIER_FORMAT = /^#{Noosfero.identifier_format}$/ |
202 | 196 | ... | ... |
app/views/admin_panel/_site_info.html.erb
... | ... | @@ -3,6 +3,21 @@ |
3 | 3 | <%= labelled_form_field(_('No reply email'), text_field(:environment, :noreply_email)) %> |
4 | 4 | <% themes_options = Theme.system_themes.map {|theme| [theme.name, theme.id] }.sort %> |
5 | 5 | <%= labelled_form_field(_('Theme'), select(:environment, :theme, options_for_select(themes_options, environment.theme))) %> |
6 | + | |
7 | +<%= labelled_form_field( | |
8 | + _("Article's date format"), | |
9 | + select(:environment, :date_format, | |
10 | + options_for_select([ | |
11 | + [ _('mm/dd/yyyy'), 'numbers_with_year'], | |
12 | + [ _('mm/dd'), 'numbers'], | |
13 | + [ _('Month dd, yyyy'), 'month_name_with_year'], | |
14 | + [ _('Month dd'), 'month_name'], | |
15 | + [ _('X minutes/hours/days/months/years ago'), 'past_time'] | |
16 | + ], environment.date_format | |
17 | + ) | |
18 | + ) | |
19 | +) %> | |
20 | + | |
6 | 21 | <%= required f.text_field(:reports_lower_bound, :size => 3) %> |
7 | 22 | <%= labelled_form_field(_('Default language'), select(:environment, :default_language, environment.locales.invert, { :selected => environment.default_locale, :include_blank => true })) %> |
8 | 23 | <%= label_tag :languages, _('Available languages') %> | ... | ... |
app/views/cms/general_configuration.html.erb
... | ... | @@ -1,25 +0,0 @@ |
1 | -<div class="general-configuration"> | |
2 | - | |
3 | -<h2> <%= _('General Configuration:') %> </h2> | |
4 | -<%= labelled_form_for :profile_data do |f|%> | |
5 | - <h2><%= _("Article's date format") %> </h2> | |
6 | - | |
7 | - <%= _("This option will define how article's date will be showed") %> | |
8 | - <br> | |
9 | - <br> | |
10 | - <%= select_tag('profile_data[date_format]', options_for_select([ | |
11 | - [ _('mm/dd/yyyy'), 'numbers_with_year'], | |
12 | - [ _('mm/dd'), 'numbers'], | |
13 | - [ _('Month dd, yyyy'), 'month_name_with_year'], | |
14 | - [ _('Month dd'), 'month_name'], | |
15 | - [ _('X minutes/hours/days/months/years ago'), 'past_time'] | |
16 | - ], @profile_data.date_format)) %> | |
17 | - | |
18 | - <br> | |
19 | - <br> | |
20 | - | |
21 | - <%= submit_button('save', _('Save')) %> | |
22 | - <%= modal_close_button(_('Cancel')) %> | |
23 | -<% end %> | |
24 | - | |
25 | -</div> |
app/views/cms/view.html.erb
... | ... | @@ -18,7 +18,6 @@ |
18 | 18 | <% parent_id = ((@article && @article.allow_children?) ? @article : nil) %> |
19 | 19 | |
20 | 20 | <%= modal_button('new', _('New content'), :action => 'new', :parent_id => parent_id, :cms => true) %> |
21 | - <%= modal_button('edit', _('General Configuration'), :action => 'general_configuration', :parent_id => parent_id, :cms => true) %> | |
22 | 21 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor', :action => "index") %> |
23 | 22 | <% end %> |
24 | 23 | ... | ... |
db/migrate/20150529180110_add_date_format_to_environment.rb
0 → 100644
db/migrate/20150529180110_add_date_format_to_profile.rb
db/schema.rb
... | ... | @@ -331,6 +331,7 @@ ActiveRecord::Schema.define(:version => 20150602142030) do |
331 | 331 | t.string "default_language" |
332 | 332 | t.string "noreply_email" |
333 | 333 | t.string "redirection_after_signup", :default => "keep_on_same_page" |
334 | + t.string "date_format", :default => "month_name_with_year" | |
334 | 335 | end |
335 | 336 | |
336 | 337 | create_table "external_feeds", :force => true do |t| |
... | ... | @@ -535,16 +536,15 @@ ActiveRecord::Schema.define(:version => 20150602142030) do |
535 | 536 | t.boolean "is_template", :default => false |
536 | 537 | t.integer "template_id" |
537 | 538 | t.string "redirection_after_login" |
538 | - t.integer "friends_count", :default => 0, :null => false | |
539 | - t.integer "members_count", :default => 0, :null => false | |
540 | - t.integer "activities_count", :default => 0, :null => false | |
539 | + t.integer "friends_count", :default => 0, :null => false | |
540 | + t.integer "members_count", :default => 0, :null => false | |
541 | + t.integer "activities_count", :default => 0, :null => false | |
541 | 542 | t.string "personal_website" |
542 | 543 | t.string "jabber_id" |
543 | 544 | t.integer "welcome_page_id" |
544 | 545 | t.boolean "allow_members_to_invite", :default => true |
545 | 546 | t.boolean "invite_friends_only", :default => false |
546 | 547 | t.boolean "secret", :default => false |
547 | - t.string "date_format", :default => "month_name_with_year" | |
548 | 548 | end |
549 | 549 | |
550 | 550 | add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" | ... | ... |
public/stylesheets/application.css
test/functional/cms_controller_test.rb
... | ... | @@ -1869,24 +1869,6 @@ class CmsControllerTest < ActionController::TestCase |
1869 | 1869 | assert_equal '[{"label":"linux","value":"linux"}]', @response.body |
1870 | 1870 | end |
1871 | 1871 | |
1872 | - should 'save general configuration when is passed a valid value' do | |
1873 | - post :general_configuration, profile: profile.identifier, :profile_data => { date_format: "numbers_with_year" } | |
1874 | - profile.reload | |
1875 | - | |
1876 | - assert_equal profile.date_format, "numbers_with_year" | |
1877 | - end | |
1878 | - | |
1879 | - should 'not save general configuration when is not passed a valid value' do | |
1880 | - profile.date_format = "month_name_with_year" | |
1881 | - profile.save! | |
1882 | - | |
1883 | - post :general_configuration, profile: profile.identifier, :profile_data => { date_format: "invalid_format" } | |
1884 | - profile.reload | |
1885 | - | |
1886 | - assert_equal profile.date_format, "month_name_with_year" | |
1887 | - end | |
1888 | - | |
1889 | - | |
1890 | 1872 | protected |
1891 | 1873 | |
1892 | 1874 | # FIXME this is to avoid adding an extra dependency for a proper JSON parser. | ... | ... |
test/unit/content_viewer_helper_test.rb
... | ... | @@ -113,37 +113,37 @@ class ContentViewerHelperTest < ActionView::TestCase |
113 | 113 | end |
114 | 114 | |
115 | 115 | should 'show date with mm/dd/yyyy' do |
116 | + Environment.any_instance.stubs(:date_format).returns('numbers_with_year') | |
116 | 117 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) |
117 | 118 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) |
118 | 119 | article.save! |
119 | - profile.date_format = "numbers_with_year" | |
120 | 120 | result = show_with_right_format_date article |
121 | 121 | assert_match /2\/1\/2007/, result |
122 | 122 | end |
123 | 123 | |
124 | 124 | should 'show date with mm/dd' do |
125 | + Environment.any_instance.stubs(:date_format).returns('numbers') | |
125 | 126 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) |
126 | 127 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) |
127 | 128 | article.save! |
128 | - profile.date_format = "numbers" | |
129 | 129 | result = show_with_right_format_date article |
130 | 130 | assert_match /2\/1/, result |
131 | 131 | end |
132 | 132 | |
133 | 133 | should 'show date with month name' do |
134 | + Environment.any_instance.stubs(:date_format).returns('month_name') | |
134 | 135 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) |
135 | 136 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) |
136 | 137 | article.save! |
137 | - profile.date_format = "month_name" | |
138 | 138 | result = show_with_right_format_date article |
139 | 139 | assert_match /February 1/, result |
140 | 140 | end |
141 | 141 | |
142 | 142 | should 'show date with month name and year' do |
143 | + Environment.any_instance.stubs(:date_format).returns('month_name_with_year') | |
143 | 144 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) |
144 | 145 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) |
145 | 146 | article.save! |
146 | - profile.date_format = "month_name_with_year" | |
147 | 147 | result = show_with_right_format_date article |
148 | 148 | assert_match /February 1, 2007/, result |
149 | 149 | end | ... | ... |
test/unit/environment_test.rb
... | ... | @@ -1703,4 +1703,32 @@ class EnvironmentTest < ActiveSupport::TestCase |
1703 | 1703 | assert !e.has_license? |
1704 | 1704 | end |
1705 | 1705 | |
1706 | + should 'validates_inclusion_of date format' do | |
1707 | + environment = fast_create(Environment) | |
1708 | + | |
1709 | + environment.date_format = "invalid_format" | |
1710 | + environment.valid? | |
1711 | + assert environment.errors[:date_format.to_s].present? | |
1712 | + | |
1713 | + environment.date_format = "numbers_with_year" | |
1714 | + environment.valid? | |
1715 | + assert !environment.errors[:date_format.to_s].present? | |
1716 | + | |
1717 | + environment.date_format = "numbers" | |
1718 | + environment.valid? | |
1719 | + assert !environment.errors[:date_format.to_s].present? | |
1720 | + | |
1721 | + environment.date_format = "month_name_with_year" | |
1722 | + environment.valid? | |
1723 | + assert !environment.errors[:date_format.to_s].present? | |
1724 | + | |
1725 | + environment.date_format = "month_name" | |
1726 | + environment.valid? | |
1727 | + assert !environment.errors[:date_format.to_s].present? | |
1728 | + | |
1729 | + environment.date_format = "past_time" | |
1730 | + environment.valid? | |
1731 | + assert !environment.errors[:date_format.to_s].present? | |
1732 | + end | |
1733 | + | |
1706 | 1734 | end | ... | ... |
test/unit/profile_test.rb
... | ... | @@ -2176,33 +2176,4 @@ class ProfileTest < ActiveSupport::TestCase |
2176 | 2176 | assert_includes Profile.enabled, p2 |
2177 | 2177 | assert_not_includes Profile.enabled, p3 |
2178 | 2178 | end |
2179 | - | |
2180 | - should 'validates_inclusion_of date format' do | |
2181 | - profile = fast_create(Profile) | |
2182 | - | |
2183 | - profile.date_format = "invalid_format" | |
2184 | - profile.valid? | |
2185 | - assert profile.errors[:date_format.to_s].present? | |
2186 | - | |
2187 | - profile.date_format = "numbers_with_year" | |
2188 | - profile.valid? | |
2189 | - assert !profile.errors[:date_format.to_s].present? | |
2190 | - | |
2191 | - profile.date_format = "numbers" | |
2192 | - profile.valid? | |
2193 | - assert !profile.errors[:date_format.to_s].present? | |
2194 | - | |
2195 | - profile.date_format = "month_name_with_year" | |
2196 | - profile.valid? | |
2197 | - assert !profile.errors[:date_format.to_s].present? | |
2198 | - | |
2199 | - profile.date_format = "month_name" | |
2200 | - profile.valid? | |
2201 | - assert !profile.errors[:date_format.to_s].present? | |
2202 | - | |
2203 | - profile.date_format = "past_time" | |
2204 | - profile.valid? | |
2205 | - assert !profile.errors[:date_format.to_s].present? | |
2206 | - | |
2207 | - end | |
2208 | 2179 | end | ... | ... |