Commit 80b43289ad366f76999b4eaadb3d9457038b83e7

Authored by Victor Costa
1 parent 82c3dd7b

rails3: fix comment_classification plugin

Showing 29 changed files with 151 additions and 147 deletions   Show diff stats
plugins/comment_classification/features/step_definitions/plugin_steps.rb
1 1 Given /^CommentClassificationPlugin is enabled$/ do
2   - Given %{I am logged in as admin}
3   - And %{I am on the environment control panel}
4   - And %{I follow "Plugins"}
5   - And %{I check "Comment Classification"}
6   - And %{I press "Save changes"}
  2 + step %{I am logged in as admin}
  3 + step %{I am on the environment control panel}
  4 + step %{I follow "Plugins"}
  5 + step %{I check "Comment Classification"}
  6 + step %{I press "Save changes"}
7 7 Environment.default.enabled_plugins.should include("CommentClassificationPlugin")
8 8 end
9 9  
... ...
plugins/comment_classification/lib/comment_classification_plugin.rb
... ... @@ -20,15 +20,15 @@ class CommentClassificationPlugin < Noosfero::Plugin
20 20  
21 21 def comment_form_extra_contents(args)
22 22 comment = args[:comment]
23   - lambda {
24   - render :file => 'comment/comments_labels_select.rhtml', :locals => {:comment => comment }
  23 + proc {
  24 + render :file => 'comment/comments_labels_select', :locals => {:comment => comment }
25 25 }
26 26 end
27 27  
28 28 def comment_extra_contents(args)
29 29 comment = args[:comment]
30   - lambda {
31   - render :file => 'comment/comment_extra.rhtml', :locals => {:comment => comment}
  30 + proc {
  31 + render :file => 'comment/comment_extra', :locals => {:comment => comment}
32 32 }
33 33 end
34 34  
... ... @@ -46,10 +46,6 @@ class CommentClassificationPlugin < Noosfero::Plugin
46 46 end
47 47 end
48 48  
49   - def js_files
50   - 'comment_classification.js'
51   - end
52   -
53 49 def stylesheet?
54 50 true
55 51 end
... ...
plugins/comment_classification/lib/comment_classification_plugin/comment_label_user.rb
1   -class CommentClassificationPlugin::CommentLabelUser < Noosfero::Plugin::ActiveRecord
  1 +class CommentClassificationPlugin::CommentLabelUser < ActiveRecord::Base
2 2 set_table_name :comment_classification_plugin_comment_label_user
3 3  
4 4 belongs_to :profile
5 5 belongs_to :comment
6 6 belongs_to :label, :class_name => 'CommentClassificationPlugin::Label'
7 7  
  8 + attr_accessible :profile, :comment, :label
  9 +
8 10 validates_presence_of :profile
9 11 validates_presence_of :comment
10 12 validates_presence_of :label
... ...
plugins/comment_classification/lib/comment_classification_plugin/comment_status_user.rb
1   -class CommentClassificationPlugin::CommentStatusUser < Noosfero::Plugin::ActiveRecord
  1 +class CommentClassificationPlugin::CommentStatusUser < ActiveRecord::Base
2 2 set_table_name :comment_classification_plugin_comment_status_user
3 3  
4 4 belongs_to :profile
5 5 belongs_to :comment
6 6 belongs_to :status, :class_name => 'CommentClassificationPlugin::Status'
7 7  
  8 + attr_accessible :name, :enabled, :profile, :comment, :status_id, :reason
  9 +
8 10 validates_presence_of :profile
9 11 validates_presence_of :comment
10 12 validates_presence_of :status
... ...
plugins/comment_classification/lib/comment_classification_plugin/label.rb
... ... @@ -4,7 +4,9 @@ class CommentClassificationPlugin::Label &lt; Noosfero::Plugin::ActiveRecord
4 4  
5 5 validates_presence_of :name
6 6  
7   - named_scope :enabled, :conditions => { :enabled => true }
  7 + scope :enabled, :conditions => { :enabled => true }
  8 +
  9 + attr_accessible :name, :enabled, :color
8 10  
9 11 COLORS = ['red', 'green', 'yellow', 'gray', 'blue']
10 12 end
... ...
plugins/comment_classification/lib/comment_classification_plugin/status.rb
... ... @@ -2,7 +2,9 @@ class CommentClassificationPlugin::Status &lt; Noosfero::Plugin::ActiveRecord
2 2  
3 3 belongs_to :owner, :polymorphic => true
4 4  
  5 + attr_accessible :name, :enabled
  6 +
5 7 validates_presence_of :name
6 8  
7   - named_scope :enabled, :conditions => { :enabled => true }
  9 + scope :enabled, :conditions => { :enabled => true }
8 10 end
... ...
plugins/comment_classification/views/comment/comment_extra.html.erb 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +<div class='comment-classification-options'>
  2 +
  3 + <% unless comment.label.nil? %>
  4 + <p class='label-name' style='color:<%= comment.label.color %>'>
  5 + <%= comment.label.name %>
  6 + </p>
  7 + <% end %>
  8 +
  9 + <% statuses = CommentClassificationPlugin::Status.enabled %>
  10 + <% if profile.organization? && user && user.has_permission?(:moderate_comments, profile) && !statuses.empty? %>
  11 + <div class='comment-classification-status'>
  12 + <%= link_to(_('Status'), :profile => profile.identifier, :controller => :comment_classification_plugin_myprofile, :action => :add_status, :id => comment.id)
  13 + %>
  14 + </div>
  15 + <% end %>
  16 +
  17 +</div>
... ...
plugins/comment_classification/views/comment/comment_extra.rhtml
... ... @@ -1,17 +0,0 @@
1   -<div class='comment-classification-options'>
2   -
3   - <% unless comment.label.nil? %>
4   - <p class='label-name' style='color:<%= comment.label.color %>'>
5   - <%= comment.label.name %>
6   - </p>
7   - <% end %>
8   -
9   - <% statuses = CommentClassificationPlugin::Status.enabled %>
10   - <% if profile.organization? && user && user.has_permission?(:moderate_comments, profile) && !statuses.empty? %>
11   - <div class='comment-classification-status'>
12   - <%= link_to(_('Status'), :profile => profile.identifier, :controller => :comment_classification_plugin_myprofile, :action => :add_status, :id => comment.id)
13   - %>
14   - </div>
15   - <% end %>
16   -
17   -</div>
plugins/comment_classification/views/comment/comments_labels_select.html.erb 0 → 100644
... ... @@ -0,0 +1,4 @@
  1 +<% labels = CommentClassificationPlugin::Label.enabled %>
  2 +<% if logged_in? && user.has_permission?(:moderate_comments, profile) && !labels.empty? %>
  3 + <%= labelled_form_field(_('Label'), select_tag('comment_label_id', options_for_select( [[_('[Select ...]'), nil]] + labels.map{|l|[l.name,l.id]}, @comment.label.nil? ? '' : @comment.label.id))) %>
  4 +<% end %>
... ...
plugins/comment_classification/views/comment/comments_labels_select.rhtml
... ... @@ -1,4 +0,0 @@
1   -<% labels = CommentClassificationPlugin::Label.enabled %>
2   -<% if logged_in? && user.has_permission?(:moderate_comments, profile) && !labels.empty? %>
3   - <%= labelled_form_field(_('Label'), select_tag('comment_label_id', options_for_select( [[_('[Select ...]'), nil]] + labels.map{|l|[l.name,l.id]}, @comment.label.nil? ? '' : @comment.label.id))) %>
4   -<% end %>
plugins/comment_classification/views/comment_classification_plugin_admin/index.html.erb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +<h1><%= _('Comments classification options')%></h1>
  2 +
  3 +<ul>
  4 + <li><%= link_to _('Manage Labels'), :controller => 'comment_classification_plugin_labels' %></li>
  5 + <li><%= link_to _('Manage Status'), :controller => 'comment_classification_plugin_status' %></li>
  6 +</ul>
... ...
plugins/comment_classification/views/comment_classification_plugin_admin/index.rhtml
... ... @@ -1,6 +0,0 @@
1   -<h1><%= _('Comments classification options')%></h1>
2   -
3   -<ul>
4   - <li><%= link_to _('Manage Labels'), :controller => 'comment_classification_plugin_labels' %></li>
5   - <li><%= link_to _('Manage Status'), :controller => 'comment_classification_plugin_status' %></li>
6   -</ul>
plugins/comment_classification/views/comment_classification_plugin_labels/_form.html.erb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<%= error_messages_for :label %>
  2 +
  3 +<%= form_for :label do |f| %>
  4 + <%= required_fields_message %>
  5 +
  6 + <%= required labelled_form_field(_('Name'), f.text_field(:name)) %>
  7 + <%= labelled_form_field(_('Color'), f.select(:color, @colors.map{|s|[s.capitalize,s]})) %>
  8 + <%= labelled_form_field(f.check_box(:enabled) + _('Enable this label?'),'') %>
  9 +
  10 + <% button_bar do %>
  11 + <%= submit_button('save', _('Save'), :cancel => {:action => 'index'} ) %>
  12 + <% end %>
  13 +<% end %>
... ...
plugins/comment_classification/views/comment_classification_plugin_labels/_form.rhtml
... ... @@ -1,13 +0,0 @@
1   -<%= error_messages_for :label %>
2   -
3   -<% form_for :label, @label do |f| %>
4   - <%= required_fields_message %>
5   -
6   - <%= required labelled_form_field(_('Name'), f.text_field(:name)) %>
7   - <%= labelled_form_field(_('Color'), f.select(:color, @colors.map{|s|[s.capitalize,s]})) %>
8   - <%= labelled_form_field(f.check_box(:enabled) + _('Enable this label?'),'') %>
9   -
10   - <% button_bar do %>
11   - <%= submit_button('save', _('Save'), :cancel => {:action => 'index'} ) %>
12   - <% end %>
13   -<% end %>
plugins/comment_classification/views/comment_classification_plugin_labels/create.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<h2> <%= _("Add a new label") %> </h2>
  2 +
  3 +<%= render :partial => 'form' %>
... ...
plugins/comment_classification/views/comment_classification_plugin_labels/create.rhtml
... ... @@ -1,3 +0,0 @@
1   -<h2> <%= _("Add a new label") %> </h2>
2   -
3   -<%= render :partial => 'form' %>
plugins/comment_classification/views/comment_classification_plugin_labels/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<h2> <%= _("Editing label %s") % @label.name %> </h2>
  2 +
  3 +<%= render :partial => 'form' %>
... ...
plugins/comment_classification/views/comment_classification_plugin_labels/edit.rhtml
... ... @@ -1,3 +0,0 @@
1   -<h2> <%= _("Editing label %s") % @label.name %> </h2>
2   -
3   -<%= render :partial => 'form' %>
plugins/comment_classification/views/comment_classification_plugin_labels/index.html.erb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +<h1><%= _("Manage comments labels") %></h1>
  2 +
  3 +<div id='comment-classification-labels'>
  4 + <% if @labels.empty? %>
  5 + <%= _('(no label registered yet)') %>
  6 + <% else %>
  7 + <table>
  8 + <tr>
  9 + <th><%= _('Label') %></th>
  10 + <th><%= _('Color') %></th>
  11 + <th><%= _('Enabled') %></th>
  12 + <th><%= _('Actions') %></th>
  13 + </tr>
  14 + <% @labels.each do |label| %>
  15 + <tr>
  16 + <td><%= label.name %></td>
  17 + <td><%= label.color %></td>
  18 + <td><%= label.enabled %></td>
  19 + <td>
  20 + <%= button_without_text :edit, _('Edit'), {:action => 'edit', :id => label} %>
  21 + <%= button_without_text :delete, _('Remove'), {:action => 'destroy', :id => label}, :confirm => _('Are you sure you want to remove this label?') %>
  22 + </td>
  23 + </tr>
  24 + <% end %>
  25 + </table>
  26 + <% end %>
  27 +
  28 + <% button_bar do %>
  29 + <%= button(:add, _('Add a new label'), :action => 'create')%>
  30 + <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %>
  31 + <% end %>
  32 +</div>
... ...
plugins/comment_classification/views/comment_classification_plugin_labels/index.rhtml
... ... @@ -1,32 +0,0 @@
1   -<h1><%= _("Manage comments labels") %></h1>
2   -
3   -<div id='comment-classification-labels'>
4   - <% if @labels.empty? %>
5   - <%= _('(no label registered yet)') %>
6   - <% else %>
7   - <table>
8   - <tr>
9   - <th><%= _('Label') %></th>
10   - <th><%= _('Color') %></th>
11   - <th><%= _('Enabled') %></th>
12   - <th><%= _('Actions') %></th>
13   - </tr>
14   - <% @labels.each do |label| %>
15   - <tr>
16   - <td><%= label.name %></td>
17   - <td><%= label.color %></td>
18   - <td><%= label.enabled %></td>
19   - <td>
20   - <%= button_without_text :edit, _('Edit'), {:action => 'edit', :id => label} %>
21   - <%= button_without_text :delete, _('Remove'), {:action => 'destroy', :id => label}, :confirm => _('Are you sure you want to remove this label?') %>
22   - </td>
23   - </tr>
24   - <% end %>
25   - </table>
26   - <% end %>
27   -
28   - <% button_bar do %>
29   - <%= button(:add, _('Add a new label'), :action => 'create')%>
30   - <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %>
31   - <% end %>
32   -</div>
plugins/comment_classification/views/comment_classification_plugin_myprofile/_status_form.html.erb
1 1 <%= error_messages_for :status %>
2 2  
3   -<% form_for :status, @status do |f| %>
  3 +<%= form_for :status do |f| %>
4 4 <%= required_fields_message %>
5 5  
6 6 <%= labelled_form_field(_('Status'), f.select(:status_id, @statuses.map{|s|[s.name,s.id]})) %>
... ...
plugins/comment_classification/views/comment_classification_plugin_status/_form.html.erb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +<%= error_messages_for :status %>
  2 +
  3 +<%= form_for :status do |f| %>
  4 + <%= required_fields_message %>
  5 +
  6 + <%= required labelled_form_field(_('Name'), f.text_field(:name)) %>
  7 + <%= labelled_form_field(f.check_box(:enabled) + _('Enable this status?'),'') %>
  8 + <%#= labelled_form_field(f.check_box(:enable_reason) + _('This status allows reason?'),'') %>
  9 +
  10 + <% button_bar do %>
  11 + <%= submit_button('save', _('Save'), :cancel => {:action => 'index'} ) %>
  12 + <% end %>
  13 +<% end %>
... ...
plugins/comment_classification/views/comment_classification_plugin_status/_form.rhtml
... ... @@ -1,13 +0,0 @@
1   -<%= error_messages_for :status %>
2   -
3   -<% form_for :status, @status do |f| %>
4   - <%= required_fields_message %>
5   -
6   - <%= required labelled_form_field(_('Name'), f.text_field(:name)) %>
7   - <%= labelled_form_field(f.check_box(:enabled) + _('Enable this status?'),'') %>
8   - <%#= labelled_form_field(f.check_box(:enable_reason) + _('This status allows reason?'),'') %>
9   -
10   - <% button_bar do %>
11   - <%= submit_button('save', _('Save'), :cancel => {:action => 'index'} ) %>
12   - <% end %>
13   -<% end %>
plugins/comment_classification/views/comment_classification_plugin_status/create.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<h2> <%= _("Add a new status") %> </h2>
  2 +
  3 +<%= render :partial => 'form' %>
... ...
plugins/comment_classification/views/comment_classification_plugin_status/create.rhtml
... ... @@ -1,3 +0,0 @@
1   -<h2> <%= _("Add a new status") %> </h2>
2   -
3   -<%= render :partial => 'form' %>
plugins/comment_classification/views/comment_classification_plugin_status/edit.html.erb 0 → 100644
... ... @@ -0,0 +1,3 @@
  1 +<h2> <%= _("Editing status %s") % @status.name %> </h2>
  2 +
  3 +<%= render :partial => 'form' %>
... ...
plugins/comment_classification/views/comment_classification_plugin_status/edit.rhtml
... ... @@ -1,3 +0,0 @@
1   -<h2> <%= _("Editing status %s") % @status.name %> </h2>
2   -
3   -<%= render :partial => 'form' %>
plugins/comment_classification/views/comment_classification_plugin_status/index.html.erb 0 → 100644
... ... @@ -0,0 +1,32 @@
  1 +<h1> <%= _("Manage comments status") %></h1>
  2 +
  3 +<div id='comment-classification-status'>
  4 + <% if @status.empty? %>
  5 + <%= _('(no status registered yet)') %>
  6 + <% else %>
  7 + <table>
  8 + <tr>
  9 + <th><%= _('Status') %></th>
  10 + <th><%= _('Enabled') %></th>
  11 + <th><%= _('Reason enabled?') %></th>
  12 + <th><%= _('Actions') %></th>
  13 + </tr>
  14 + <% @status.each do |st| %>
  15 + <tr>
  16 + <td><%= st.name %></td>
  17 + <td><%= st.enabled %></td>
  18 + <td><%= st.enable_reason %></td>
  19 + <td>
  20 + <%= button_without_text :edit, _('Edit'), {:action => 'edit', :id => st} %>
  21 + <%= button_without_text :delete, _('Remove'), {:action => 'destroy', :id => st}, :confirm => _('Are you sure you want to remove this status?') %>
  22 + </td>
  23 + </tr>
  24 + <% end %>
  25 + </table>
  26 + <% end %>
  27 +
  28 + <% button_bar do %>
  29 + <%= button(:add, _('Add a new status'), :action => 'create')%>
  30 + <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %>
  31 + <% end %>
  32 +</div>
... ...
plugins/comment_classification/views/comment_classification_plugin_status/index.rhtml
... ... @@ -1,32 +0,0 @@
1   -<h1> <%= _("Manage comments status") %></h1>
2   -
3   -<div id='comment-classification-status'>
4   - <% if @status.empty? %>
5   - <%= _('(no status registered yet)') %>
6   - <% else %>
7   - <table>
8   - <tr>
9   - <th><%= _('Status') %></th>
10   - <th><%= _('Enabled') %></th>
11   - <th><%= _('Reason enabled?') %></th>
12   - <th><%= _('Actions') %></th>
13   - </tr>
14   - <% @status.each do |st| %>
15   - <tr>
16   - <td><%= st.name %></td>
17   - <td><%= st.enabled %></td>
18   - <td><%= st.enable_reason %></td>
19   - <td>
20   - <%= button_without_text :edit, _('Edit'), {:action => 'edit', :id => st} %>
21   - <%= button_without_text :delete, _('Remove'), {:action => 'destroy', :id => st}, :confirm => _('Are you sure you want to remove this status?') %>
22   - </td>
23   - </tr>
24   - <% end %>
25   - </table>
26   - <% end %>
27   -
28   - <% button_bar do %>
29   - <%= button(:add, _('Add a new status'), :action => 'create')%>
30   - <%= button :back, _('Back to admin panel'), :controller => 'admin_panel' %>
31   - <% end %>
32   -</div>