Commit 87648bee97a337c6e9f02f02cb8a41f7c0a72dbf
1 parent
4d52e142
Exists in
master
and in
29 other branches
ActionItem132: associating articles with categories and displaying them.
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1161 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
45 additions
and
3 deletions
Show diff stats
app/helpers/cms_helper.rb
| ... | ... | @@ -22,4 +22,23 @@ module CmsHelper |
| 22 | 22 | end |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | + attr_reader :environment | |
| 26 | + | |
| 27 | + def select_categories(object_name) | |
| 28 | + object = instance_variable_get("@#{object_name}") | |
| 29 | + | |
| 30 | + result = content_tag('h4', _('Categories')) | |
| 31 | + environment.top_level_categories.each do |toplevel| | |
| 32 | + toplevel.map_traversal do |cat| | |
| 33 | + if cat.top_level? | |
| 34 | + result << content_tag('h5', toplevel.name) | |
| 35 | + else | |
| 36 | + result << content_tag('div', check_box_tag("#{object_name}[category_ids][]", cat.id, object.category_ids.include?(cat.id)) + cat.full_name_without_leading(1)) | |
| 37 | + end | |
| 38 | + end | |
| 39 | + end | |
| 40 | + | |
| 41 | + content_tag('div', result) | |
| 42 | + end | |
| 43 | + | |
| 25 | 44 | end | ... | ... |
app/views/cms/edit.rhtml
| 1 | - | |
| 2 | - | |
| 3 | - | |
| 4 | 1 | <%= error_messages_for 'article' %> |
| 5 | 2 | |
| 6 | 3 | <% labelled_form_for 'article', @article, :html => { :multipart => true } do |f| %> |
| ... | ... | @@ -11,6 +8,8 @@ |
| 11 | 8 | |
| 12 | 9 | <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> |
| 13 | 10 | |
| 11 | + <%= select_categories(:article) %> | |
| 12 | + | |
| 14 | 13 | <%# TODO display the tooltip (title below) in a directly visible way %> |
| 15 | 14 | <%= f.text_field('tag_list', :size => 64, :title => _('Separate tags with commas')) %> |
| 16 | 15 | ... | ... |
app/views/cms/view.rhtml
| ... | ... | @@ -61,6 +61,10 @@ |
| 61 | 61 | <li> |
| 62 | 62 | <%= _('Public address of this article: %s') % (@article.public_path) %> |
| 63 | 63 | </li> |
| 64 | + <li> | |
| 65 | + <%= _('Tags:') %> <%= @article.tag_list %> | |
| 66 | + </li> | |
| 67 | + <%= _('Categories:') %> <%= @article.categories.map { |item| item.name }.join(', ') %> | |
| 64 | 68 | </ul> |
| 65 | 69 | |
| 66 | 70 | <%= button('edit', _('Edit'), { :action => 'edit', :id => @article}) %> | ... | ... |
app/views/content_viewer/view_page.rhtml
| ... | ... | @@ -25,6 +25,10 @@ |
| 25 | 25 | <% end %> |
| 26 | 26 | --> |
| 27 | 27 | |
| 28 | +<h3><%= _('Categories') %></h3> | |
| 29 | + | |
| 30 | +<%= @page.categories.map {|item| link_to_category(item) }.join(', ') %> | |
| 31 | + | |
| 28 | 32 | <h3><%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %></h3> |
| 29 | 33 | <%= render :partial => 'comment', :collection => @comments %> |
| 30 | 34 | <%= render :partial => 'comment_form' %> | ... | ... |
test/functional/cms_controller_test.rb
| ... | ... | @@ -225,4 +225,20 @@ class CmsControllerTest < Test::Unit::TestCase |
| 225 | 225 | end |
| 226 | 226 | end |
| 227 | 227 | |
| 228 | + should 'be able to associate articles with categories' do | |
| 229 | + | |
| 230 | + env = Environment.default | |
| 231 | + c1 = env.categories.build(:name => "Test category 1"); c1.save! | |
| 232 | + c2 = env.categories.build(:name => "Test category 2"); c2.save! | |
| 233 | + c3 = env.categories.build(:name => "Test Category 3"); c3.save! | |
| 234 | + | |
| 235 | + # post is in c1 and c3 | |
| 236 | + post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id] } | |
| 237 | + | |
| 238 | + saved = TextileArticle.find_by_name('adding-categories-test') | |
| 239 | + assert_includes saved.categories, c1 | |
| 240 | + assert_not_includes saved.categories, c2 | |
| 241 | + assert_includes saved.categories, c3 | |
| 242 | + end | |
| 243 | + | |
| 228 | 244 | end | ... | ... |