From f5703d915c051ab9d4358b51a5639bb85e5ca693 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Thu, 9 Dec 2010 16:23:48 -0300 Subject: [PATCH] Improvements on article suggestion feature --- app/controllers/my_profile/cms_controller.rb | 2 +- app/models/suggest_article.rb | 19 +++++++++++++++++-- app/views/cms/suggest_an_article.rhtml | 14 ++++++++------ app/views/content_viewer/view_page.rhtml | 4 +++- app/views/tasks/_approve_article.rhtml | 6 +++++- app/views/tasks/_suggest_article.rhtml | 12 ++++++------ db/schema.rb | 4 +++- public/stylesheets/application.css | 14 -------------- test/factories.rb | 4 ++++ test/functional/cms_controller_test.rb | 2 -- test/unit/suggest_article_test.rb | 33 +++++++++++++++++++++++++++++++++ 11 files changed, 80 insertions(+), 34 deletions(-) diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index d916cd8..cb0394d 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -289,7 +289,7 @@ class CmsController < MyProfileController if request.post? @task.target = profile if @task.save - session[:notice] = _('You make your suggestion successfully. Please wait the article approval.') + session[:notice] = _('Thanks for your suggestion. The community administrators were notified.') redirect_to @back_to end end diff --git a/app/models/suggest_article.rb b/app/models/suggest_article.rb index 586c199..d98e761 100644 --- a/app/models/suggest_article.rb +++ b/app/models/suggest_article.rb @@ -8,7 +8,7 @@ class SuggestArticle < Task validates_presence_of :target_id, :article_name, :email, :name, :article_body def description - _('%{email} suggested to publish "%{article}" on %{community}') % { :email => email, :article => article_name, :community => target.name } + _('%{sender} suggested to publish "%{article}" on %{community}') % { :sender => sender, :article => article_name, :community => target.name } end settings_items :email, :type => String @@ -18,9 +18,24 @@ class SuggestArticle < Task settings_items :article_abstract, :type => String settings_items :article_parent_id, :type => String settings_items :source, :type => String + settings_items :source_name, :type => String + settings_items :highlighted, :type => :boolean + + def sender + "#{name} (#{email})" + end def perform - TinyMceArticle.create!(:profile => target, :name => article_name, :body => article_body, :abstract => article_abstract, :parent_id => article_parent_id, :source => source, :source_name => name) + TinyMceArticle.create!( + :profile => target, + :name => article_name, + :body => article_body, + :abstract => article_abstract, + :parent_id => article_parent_id, + :source => source, + :source_name => source_name, + :highlighted => highlighted + ) end end diff --git a/app/views/cms/suggest_an_article.rhtml b/app/views/cms/suggest_an_article.rhtml index a5b6a8a..1dca653 100644 --- a/app/views/cms/suggest_an_article.rhtml +++ b/app/views/cms/suggest_an_article.rhtml @@ -6,23 +6,25 @@ <% labelled_form_for 'task', @task do |f| %> - <%= required labelled_form_field(_('Title'), text_field(:task, 'article_name')) %> + <%= required labelled_form_field(_('Title'), text_field(:task, 'article_name', :size => 50)) %> - <%= labelled_form_field(_('Url Source'), text_field(:task, 'source')) %> + <%= labelled_form_field(_('Source'), text_field(:task, 'source_name')) %> - <%= required labelled_form_field(_('Name'), text_field(:task, 'name')) %> + <%= labelled_form_field(_('Source link'), text_field(:task, 'source')) %> + + <%= required labelled_form_field(_('Your name'), text_field(:task, 'name')) %> <%= required labelled_form_field(_('Email'), text_field(:task, 'email')) %>
<%= button :add, _("Lead"), '#', :id => "lead-button", :style => "margin-left: 0px;" %> - <%= _('Used when a short version your text is needed.') %> + <%= _('Used when a short version of your text is needed.') %>
- <%= labelled_form_field(_('Lead'), text_area(:task , 'article_abstract', :style => 'width: 100%; height: 300px;')) %> + <%= labelled_form_field(_('Lead'), text_area(:task , 'article_abstract', :style => 'width: 100%; height: 200px;')) %>
- <%= labelled_form_field(_('Text'), text_area(:task, 'article_body', :style => 'width:100%')) %> + <%= labelled_form_field(_('Text'), text_area(:task, 'article_body', :style => 'width:100%; height: 500px;')) %>
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml index 7f23a65..5e4bada 100644 --- a/app/views/content_viewer/view_page.rhtml +++ b/app/views/content_viewer/view_page.rhtml @@ -46,7 +46,9 @@ <% end %>
<% else %> - <%= link_to content_tag( 'span', _('Suggest an article') ), profile.admin_url.merge({ :controller => 'cms', :action => 'suggest_an_article'}), :class => 'button with-text icon-new' %> + <% if profile.community? %> + <%= link_to content_tag( 'span', _('Suggest an article') ), profile.admin_url.merge({ :controller => 'cms', :action => 'suggest_an_article'}), :class => 'button with-text icon-new' %> + <% end %> <% end %>
<%= link_to(image_tag('icons-mime/rss-feed.png'), @page.feed.url, :class => 'blog-feed-link') if @page.has_posts? && @page.feed %> diff --git a/app/views/tasks/_approve_article.rhtml b/app/views/tasks/_approve_article.rhtml index 87c56ea..f7d3730 100644 --- a/app/views/tasks/_approve_article.rhtml +++ b/app/views/tasks/_approve_article.rhtml @@ -26,7 +26,11 @@ <%= labelled_form_field _('Name for publishing'), f.text_field(:name, :style => 'width:80%;') %> <%= select_folder(_('Select the folder where the article must be published'), 'task', 'article_parent_id', task.target.folders) %> - <%= labelled_form_field( _('Highlight this article'), f.check_box(:highlighted)) %> +
+ <%= f.check_box(:highlighted) %> + +
+ <%= labelled_form_field _('Comment for author'), f.text_field(:closing_statment, :style => 'width:80%;') %> <%= render :partial => partial_for_class(task.article.class), :locals => { :f => f } %> diff --git a/app/views/tasks/_suggest_article.rhtml b/app/views/tasks/_suggest_article.rhtml index a716226..3eb5917 100644 --- a/app/views/tasks/_suggest_article.rhtml +++ b/app/views/tasks/_suggest_article.rhtml @@ -4,24 +4,24 @@ <% form_for('task', task, :url => { :action => 'close', :id => task.id}) do |f| %> -

<%= label_tag(_("Sent by: %s") % task.name) %>

+

<%= label_tag(_("Sent by: %s") % task.name) %>

<%= label_tag(_("Email: %s") % task.email) %>

-

<%= label_tag(_("Source: %s") % task.source) %>

- <%= required labelled_form_field(_('Title'), text_field_tag('task[article_name]', task.article_name)) %> + <%= required labelled_form_field(_('Title'), f.text_field(:article_name, :size => 50)) %> + <%= labelled_form_field(_('Source'), f.text_field(:source_name)) %> + <%= labelled_form_field(_("Source URL"), f.text_field(:source)) %> <%= select_folder(_('Select the folder where the article must be published'), 'task', 'article_parent_id', task.target.folders) %> -
<%= button :add, _("Lead"), '#', :id => "lead-button", :style => "margin-left: 0px;" %> <%= _('Used when a short version your text is needed.') %>
- <%= labelled_form_field(_('Lead'), text_area_tag('task[article_abstract]', task.article_abstract, :style => 'width: 100%; height: 300px;')) %> + <%= labelled_form_field(_('Lead'), text_area_tag('task[article_abstract]', task.article_abstract, :style => 'width: 100%; height: 200px;')) %>
- <%= labelled_form_field(_('Text'), text_area_tag('task[article_body]', task.article_body, :style => 'width:100%')) %> + <%= labelled_form_field(_('Text'), text_area_tag('task[article_body]', task.article_body, :style => 'width:100%; height: 500px;')) %>
diff --git a/db/schema.rb b/db/schema.rb index 39678c9..05d6d37 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20101205034144) do +ActiveRecord::Schema.define(:version => 20101209001631) do create_table "action_tracker", :force => true do |t| t.integer "user_id" @@ -74,6 +74,7 @@ ActiveRecord::Schema.define(:version => 20101205034144) do t.boolean "is_image", :default => false t.integer "translation_of_id" t.string "language" + t.string "source_name" end create_table "articles", :force => true do |t| @@ -113,6 +114,7 @@ ActiveRecord::Schema.define(:version => 20101205034144) do t.boolean "is_image", :default => false t.integer "translation_of_id" t.string "language" + t.string "source_name" end add_index "articles", ["translation_of_id"], :name => "index_articles_on_translation_of_id" diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index be83b6a..bcba090 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -5237,17 +5237,3 @@ h1#agenda-title { .forum-posts .pagination { margin-top: 20px; } - -#captcha input { - border: 1px solid #ccc; - margin: 4px 0px 2px 10px !important; - padding: 0px !important; - width: 150px !important; - font-size: 24px; - float: left; -} - -#captcha label{ - float: left; - font-size: 24px; -} diff --git a/test/factories.rb b/test/factories.rb index 8ef87b2..d21216b 100644 --- a/test/factories.rb +++ b/test/factories.rb @@ -427,4 +427,8 @@ module Noosfero::Factory { :profile_id => 1, :path => name, :name => name, :slug => name.to_slug }.merge(params) end + def defaults_for_suggest_article + { :name => 'Sender', :email => 'sender@example.com', :article_name => 'Some title', :article_body => 'some body text', :article_abstract => 'some abstract text'} + end + end diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb index d55f3d0..a90b9db 100644 --- a/test/functional/cms_controller_test.rb +++ b/test/functional/cms_controller_test.rb @@ -1438,8 +1438,6 @@ class CmsControllerTest < Test::Unit::TestCase c = Community.create!(:name => 'test comm', :identifier => 'test_comm', :moderated_articles => true) get :suggest_an_article, :profile => c.identifier assert_response :success - assert_template 'suggest_an_article' - assert_tag :tag => 'input', :attributes => { :value => "https://colivre.net/profile/test_comm", :id => 'back_to' } end end diff --git a/test/unit/suggest_article_test.rb b/test/unit/suggest_article_test.rb index dd47632..12f7f23 100644 --- a/test/unit/suggest_article_test.rb +++ b/test/unit/suggest_article_test.rb @@ -86,4 +86,37 @@ class SuggestArticleTest < ActiveSupport::TestCase assert_equal count + 1, TinyMceArticle.count end + should 'fill source name and URL into created article' do + t = build(SuggestArticle, :target => @profile) + t.source_name = 'GNU project' + t.source = 'http://www.gnu.org/' + t.perform + + article = TinyMceArticle.last + assert_equal 'GNU project', article.source_name + assert_equal 'http://www.gnu.org/', article.source + end + + should 'use sender name in description' do + t = build(SuggestArticle, :target => @profile) + t.stubs(:sender).returns('XYZ') + assert_match(/XYZ/, t.description) + end + + should 'use name and e-mail as sender info' do + t = build(SuggestArticle, :target => @profile) + t.name = 'Some One' + t.email = 'someone@example.com' + assert_match(/.*Some One.*someone@example.com/, t.sender) + end + + should 'highlight created article' do + t = build(SuggestArticle, :target => @profile) + t.highlighted = true + t.perform + + article = TinyMceArticle.last(:conditions => { :name => t.article_name}) # just to be sure + assert article.highlighted + end + end -- libgit2 0.21.2