Commit b2451593d2681e421b8e45fe2b57995f873ebe7e

Authored by Francisco Marcelo A. Lima Júnior
1 parent ce0d03ab

added support for attribute ordering in display content plugin

app/models/article.rb
... ... @@ -2,6 +2,8 @@ require 'hpricot'
2 2  
3 3 class Article < ActiveRecord::Base
4 4  
  5 + acts_as_having_image
  6 +
5 7 SEARCHABLE_FIELDS = {
6 8 :name => 10,
7 9 :abstract => 3,
... ...
db/migrate/20131113151730_add_image_to_article.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class AddImageToArticle < ActiveRecord::Migration
  2 +
  3 + def self.up
  4 + add_column :articles, :image_id, :integer
  5 + add_column :article_versions, :image_id, :integer
  6 + end
  7 +
  8 + def self.down
  9 + remove_column :articles, :image_id
  10 + remove_column :article_versions, :image_id
  11 + end
  12 +
  13 +end
... ...
db/migrate/20131113151835_add_position_to_article.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class AddPositionToArticle < ActiveRecord::Migration
  2 +
  3 + def self.up
  4 + add_column :articles, :position, :integer
  5 + add_column :article_versions, :position, :integer
  6 + end
  7 +
  8 + def self.down
  9 + remove_column :articles, :position
  10 + remove_column :article_versions, :position
  11 + end
  12 +
  13 +end
... ...
plugins/display_content/lib/display_content_block.rb
... ... @@ -2,8 +2,13 @@ class DisplayContentBlock &lt; Block
2 2  
3 3 settings_items :nodes, :type => Array, :default => []
4 4 settings_items :parent_nodes, :type => Array, :default => []
5   - settings_items :chosen_attributes, :type => Array, :default => ['title']
6   -
  5 + settings_items :sections,
  6 + :type => Array,
  7 + :default => [{:name => _('Title'), :checked => true},
  8 + {:name => _('Abstract'), :checked => true},
  9 + {:name => _('Body'), :checked => false},
  10 + {:name => _('Image'), :checked => false}]
  11 +
7 12 def self.description
8 13 _('Display your contents')
9 14 end
... ... @@ -39,13 +44,27 @@ class DisplayContentBlock &lt; Block
39 44 include ActionController::UrlWriter
40 45 def content(args={})
41 46 docs = owner.articles.find(:all, :conditions => {:id => self.nodes})
  47 +
  48 + content_sections = ''
  49 +
42 50 block_title(title) +
43   - content_tag('ul', docs.map {|item|
44   - content_tag('li',
45   - (display_attribute?('title') ? content_tag('div', link_to(h(item.title), item.url), :class => 'title') : '') +
46   - (display_attribute?('abstract') ? content_tag('div', item.abstract ,:class => 'lead') : '') +
47   - (display_attribute?('body') ? content_tag('div', item.body ,:class => 'body') : '')
48   - )
  51 + content_tag('ul', docs.map {|item|
  52 + sections.select { |section|
  53 + case section[:name]
  54 + when 'title'
  55 + content_sections += (display_section?(section) ? (content_tag('div', link_to(h(item.title), item.url), :class => 'title') ) : '')
  56 + when 'abstract'
  57 + content_sections += (display_section?(section) ? (content_tag('div', item.abstract ,:class => 'lead')) : '' )
  58 + when 'body'
  59 + content_sections += (display_section?(section) ? (content_tag('div', item.body ,:class => 'body')) : '' )
  60 + when 'image'
  61 + image_section = image_tag item.image.public_filename if item.image
  62 + if !image_section.blank?
  63 + content_sections += (display_section?(section) ? (content_tag('div', image_section ,:class => 'image')) : '' )
  64 + end
  65 + end
  66 + }
  67 + content_tag('li', content_sections)
49 68 }.join("\n"))
50 69  
51 70 end
... ... @@ -61,8 +80,8 @@ class DisplayContentBlock &lt; Block
61 80 params
62 81 end
63 82  
64   - def display_attribute?(attr)
65   - chosen_attributes.include?(attr)
  83 + def display_section?(section)
  84 + section[:checked]
66 85 end
67 86  
68 87 protected
... ...
plugins/display_content/lib/display_content_plugin.rb
... ... @@ -20,7 +20,6 @@ class DisplayContentPlugin &lt; Noosfero::Plugin
20 20 false
21 21 end
22 22  
23   - #FIXME make this test
24 23 def stylesheet?
25 24 true
26 25 end
... ...
plugins/display_content/public/style.css
1   -#display_content_plugin ul {
  1 +#display_content_plugin .sections {
  2 + width: auto;
  3 +}
  4 +
  5 +#display_content_plugin .sections td {
  6 + padding: 2px;
  7 +}
  8 +
  9 +.block.display-content-block ul {
2 10 list-style: none;
  11 + padding: 0px;
  12 +}
  13 +
  14 +.block.display-content-block li {
  15 + margin: 5px;
  16 +}
  17 +
  18 +.block.display-content-block .title,
  19 +.block.display-content-block .lead,
  20 +.block.display-content-block .body,
  21 +.block.display-content-block .image {
  22 + margin: 2px 0px 2px 0px;
3 23 }
4 24  
5   -#display_content_plugin .display_attributes li{
6   - display: inline;
  25 +.block.display-content-block .title {
  26 + //border: 1px solid green;
7 27 }
  28 +
  29 +.block.display-content-block .lead {
  30 + //border: 1px solid purple;
  31 +}
  32 +
  33 +.block.display-content-block .body {
  34 + //border: 1px solid blue;
  35 +}
  36 +
  37 +.block.display-content-block .image {
  38 + //border: 1px solid yellow;
  39 + display: table;
  40 +}
  41 +
... ...
plugins/display_content/views/box_organizer/_display_content_block.rhtml
1 1 <div id="display_content_plugin">
2 2  
3   -<h3> <%= _('Choose which attributes should be displayed:') %> </h3>
4   -<ul class='display_attributes'>
5   - <li> <%= _('Title: ')%> <%= check_box_tag "block[chosen_attributes][]", 'title', @block.display_attribute?('title') %> </li>
6   - <li> <%= _('Abstract: ')%> <%= check_box_tag "block[chosen_attributes][]", 'abstract', @block.display_attribute?('abstract') %> </li>
7   - <li> <%= _('Body: ')%> <%= check_box_tag "block[chosen_attributes][]", 'body', @block.display_attribute?('body') %> </li>
8   -</ul>
  3 +<h3> <%= _('Choose which attributes should be displayed and drag to reorder them:') %> </h3>
  4 +
  5 +<table class="sections">
  6 + <tbody id="sortable">
  7 + <% for section in @block.sections do %>
  8 + <tr>
  9 + <td><%= hidden_field_tag 'block[sections][][name]', section[:name] %> <%= check_box_tag 'block[sections][][checked]', section[:name], section[:checked] %></td>
  10 + <td><%= section[:name]%></td>
  11 + </tr>
  12 + <% end %>
  13 + </tbody>
  14 +</table>
9 15  
10 16 <h3> <%= _('Choose which content should be displayed:') %> </h3>
11 17 <div id="display_content">
... ... @@ -31,5 +37,7 @@ jQuery_1_8_3(&quot;#display_content&quot;).jstree({
31 37 }
32 38 });
33 39  
  40 +jQuery( "#sortable" ).sortable();
  41 +
34 42 </script>
35 43 </div>
... ...