Commit e579c8150f4c3d2d59ff09becca374e1512a2c38

Authored by Daniela Feitosa
1 parent 316ad8fb

Added new db/schema

Also:
- removed whitespaces
- added class with plugin name to style a view

(ActionItem2837)
app/views/memberships/new_community.rhtml
... ... @@ -45,7 +45,7 @@
45 45 </div>
46 46  
47 47 <%= template_options(Community, 'community')%>
48   -
  48 +
49 49 <%= hidden_field_tag('back_to', @back_to) %>
50 50  
51 51 <% button_bar do %>
... ...
db/schema.rb
... ... @@ -86,6 +86,8 @@ ActiveRecord::Schema.define(:version =&gt; 20131116165327) do
86 86 t.string "language"
87 87 t.string "source_name"
88 88 t.integer "license_id"
  89 + t.integer "image_id"
  90 + t.integer "position"
89 91 end
90 92  
91 93 add_index "article_versions", ["article_id"], :name => "index_article_versions_on_article_id"
... ... @@ -129,6 +131,8 @@ ActiveRecord::Schema.define(:version =&gt; 20131116165327) do
129 131 t.string "language"
130 132 t.string "source_name"
131 133 t.integer "license_id"
  134 + t.integer "image_id"
  135 + t.integer "position"
132 136 end
133 137  
134 138 add_index "articles", ["name"], :name => "index_articles_on_name"
... ...
plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb
1 1 class CommunityTrackPluginMyprofileController < MyProfileController
2 2 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
3   -
  3 +
4 4 before_filter :allow_edit_track, :only => :save_order
5 5  
6 6 def save_order
... ...
plugins/community_track/controllers/public/community_track_plugin_public_controller.rb
... ... @@ -15,7 +15,7 @@ class CommunityTrackPluginPublicController &lt; PublicController
15 15  
16 16 render :update do |page|
17 17 page.insert_html :bottom, "track_list_#{block.id}", :partial => "blocks/#{block.track_partial}", :collection => tracks, :locals => {:block => block}
18   -
  18 +
19 19 if block.has_page?(p+1, per_page)
20 20 page.replace_html "track_list_more_#{block.id}", :partial => 'blocks/track_list_more', :locals => {:block => block, :page => p+1, :force_same_page => params[:force_same_page], :per_page => per_page}
21 21 else
... ... @@ -37,8 +37,8 @@ class CommunityTrackPluginPublicController &lt; PublicController
37 37 if request.post?
38 38 community_identifier = params[:community_identifier]
39 39 if community_identifier.nil?
40   - @failed = [_('Select one community to proceed')]
41   - else
  40 + @failed = [_('Select one community to proceed')]
  41 + else
42 42 redirect_to :controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Track", :profile => community_identifier
43 43 end
44 44 end
... ...
plugins/community_track/lib/community_track_plugin.rb
... ... @@ -15,7 +15,7 @@ class CommunityTrackPlugin &lt; Noosfero::Plugin
15 15 def content_types
16 16 if context.respond_to?(:params) && context.params
17 17 types = []
18   - parent_id = context.params[:parent_id]
  18 + parent_id = context.params[:parent_id]
19 19 types << CommunityTrackPlugin::Track if context.profile.community? && !parent_id
20 20 parent = parent_id ? context.profile.articles.find(parent_id) : nil
21 21 types << CommunityTrackPlugin::Step if parent.kind_of?(CommunityTrackPlugin::Track)
... ...
plugins/community_track/lib/community_track_plugin/step.rb
... ... @@ -13,7 +13,7 @@ class CommunityTrackPlugin::Step &lt; Folder
13 13 validate :belong_to_track
14 14 validates_presence_of :start_date, :end_date
15 15 validate :end_date_equal_or_after_start_date
16   -
  16 +
17 17 after_save :schedule_activation
18 18  
19 19 before_create do |step|
... ... @@ -23,13 +23,13 @@ class CommunityTrackPlugin::Step &lt; Folder
23 23  
24 24 before_create :set_hidden_position
25 25 before_save :set_hidden_position
26   -
  26 +
27 27 def set_hidden_position
28 28 if hidden
29 29 decrement_positions_on_lower_items
30 30 self[:position] = 0
31 31 elsif position == 0
32   - add_to_list_bottom
  32 + add_to_list_bottom
33 33 end
34 34 end
35 35  
... ... @@ -65,7 +65,7 @@ class CommunityTrackPlugin::Step &lt; Folder
65 65 def active?
66 66 (start_date..end_date).include?(Date.today)
67 67 end
68   -
  68 +
69 69 def finished?
70 70 Date.today > end_date
71 71 end
... ...
plugins/community_track/lib/community_track_plugin/track.rb
1 1 class CommunityTrackPlugin::Track < Folder
2   -
  2 +
3 3 settings_items :goals, :type => :string
4 4 settings_items :expected_results, :type => :string
5 5  
... ... @@ -32,7 +32,7 @@ class CommunityTrackPlugin::Track &lt; Folder
32 32 end
33 33 end
34 34 end
35   -
  35 +
36 36 def steps_unsorted
37 37 children.where(:type => 'CommunityTrackPlugin::Step')
38 38 end
... ... @@ -59,7 +59,7 @@ class CommunityTrackPlugin::Track &lt; Folder
59 59 category = categories.first
60 60 category ? category.name : ''
61 61 end
62   -
  62 +
63 63 def to_html(options = {})
64 64 track = self
65 65 lambda do
... ...
plugins/community_track/lib/community_track_plugin/track_helper.rb
1 1 module CommunityTrackPlugin::TrackHelper
2   -
  2 +
3 3 def category_class(track)
4 4 'category_' + (track.categories.empty? ? 'not_defined' : track.categories.first.name.to_slug)
5 5 end
... ...
plugins/community_track/lib/community_track_plugin/track_list_block.rb
1 1 class CommunityTrackPlugin::TrackListBlock < Block
2 2  
3 3 include CommunityTrackPlugin::StepHelper
4   -
  4 +
5 5 settings_items :limit, :type => :integer, :default => 3
6 6 settings_items :more_another_page, :type => :boolean, :default => false
7 7 settings_items :category_ids, :type => Array, :default => []
... ... @@ -33,7 +33,7 @@ class CommunityTrackPlugin::TrackListBlock &lt; Block
33 33 def category_ids=(ids)
34 34 settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact
35 35 end
36   -
  36 +
37 37 def all_tracks
38 38 tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track')
39 39 if !category_ids.empty?
... ...
plugins/community_track/public/style.css
1   -.icon-newcommunity-track {
  1 +.icon-newcommunity-track,
  2 +.icon-community-track {
2 3 background-image: url(/plugins/community_track/icons/community-track.png)
3 4 }
4 5  
... ... @@ -188,3 +189,7 @@
188 189 #step .tools .item .name a:hover {
189 190 color: #888;
190 191 }
  192 +
  193 +.community-track textarea {
  194 + width: 100%;
  195 +}
... ...
plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
... ... @@ -2,13 +2,13 @@ require File.dirname(__FILE__) + &#39;/../test_helper&#39;
2 2  
3 3 class ContentViewerController
4 4 append_view_path File.join(File.dirname(__FILE__) + '/../../views')
5   - def rescue_action(e)
6   - raise e
7   - end
  5 + def rescue_action(e)
  6 + raise e
  7 + end
8 8 end
9 9  
10 10 class ContentViewerControllerTest < ActionController::TestCase
11   -
  11 +
12 12 def setup
13 13 @profile = fast_create(Community)
14 14 @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile)
... ...
plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb
... ... @@ -40,7 +40,7 @@ class CommunityTrackPluginPublicControllerTest &lt; ActionController::TestCase
40 40 xhr :get, :view_tracks, :id => @block.id, :page => 1
41 41 assert_equal @block.limit, @response.body.scan(/item/).size
42 42 end
43   -
  43 +
44 44 should 'display page for all tracks' do
45 45 get :all_tracks, :id => @block.id
46 46 assert_match /track_list_#{@block.id}/, @response.body
... ...
plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb
1 1 require File.dirname(__FILE__) + '/../../test_helper'
2 2  
3 3 class StepHelperTest < ActiveSupport::TestCase
4   -
  4 +
5 5 include CommunityTrackPlugin::StepHelper
6 6  
7 7 def setup
... ...
plugins/community_track/test/unit/community_track_plugin/step_test.rb
... ... @@ -16,7 +16,7 @@ class StepTest &lt; ActiveSupport::TestCase
16 16 should 'has a short description' do
17 17 assert CommunityTrackPlugin::Step.short_description
18 18 end
19   -
  19 +
20 20 should 'set published to false on create' do
21 21 today = Date.today
22 22 step = CommunityTrackPlugin::Step.create(:name => 'Step', :body => 'body', :profile => @profile, :parent => @track, :start_date => today, :end_date => today, :published => true)
... ... @@ -29,7 +29,7 @@ class StepTest &lt; ActiveSupport::TestCase
29 29 step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true)
30 30 assert !step.save
31 31 end
32   -
  32 +
33 33 should 'do not allow step creation without a parent' do
34 34 today = Date.today
35 35 step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => nil, :start_date => today, :end_date => today, :published => true)
... ... @@ -65,25 +65,25 @@ class StepTest &lt; ActiveSupport::TestCase
65 65 @step.end_date_equal_or_after_start_date.inspect
66 66 assert [], @step.errors
67 67 end
68   -
  68 +
69 69 should 'be active if today is between start and end dates' do
70 70 @step.start_date = Date.today
71 71 @step.end_date = Date.today + 1.day
72 72 assert @step.active?
73 73 end
74   -
  74 +
75 75 should 'be finished if today is after the end date' do
76 76 @step.start_date = Date.today - 2.day
77 77 @step.end_date = Date.today - 1.day
78 78 assert @step.finished?
79 79 end
80   -
  80 +
81 81 should 'be waiting if today is before the end date' do
82 82 @step.start_date = Date.today + 1.day
83 83 @step.end_date = Date.today + 2.day
84 84 assert @step.waiting?
85 85 end
86   -
  86 +
87 87 should 'return delayed job created with a specific step_id' do
88 88 step_id = 0
89 89 CommunityTrackPlugin::ActivationJob.new(step_id)
... ... @@ -97,7 +97,7 @@ class StepTest &lt; ActiveSupport::TestCase
97 97 assert_equal 1, Delayed::Job.count
98 98 assert_equal @step.start_date, Delayed::Job.first.run_at.to_date
99 99 end
100   -
  100 +
101 101 should 'do not duplicate delayed job' do
102 102 @step.start_date = Date.today
103 103 @step.end_date = Date.today
... ... @@ -105,7 +105,7 @@ class StepTest &lt; ActiveSupport::TestCase
105 105 @step.schedule_activation
106 106 assert_equal 1, Delayed::Job.count
107 107 end
108   -
  108 +
109 109 should 'create delayed job when a step is saved' do
110 110 @step.start_date = Date.today
111 111 @step.end_date = Date.today
... ... @@ -158,7 +158,7 @@ class StepTest &lt; ActiveSupport::TestCase
158 158  
159 159 should 'do not schedule delayed job if save but do not modify date fields and published status' do
160 160 @step.start_date = Date.today
161   - @step.end_date = Date.today
  161 + @step.end_date = Date.today
162 162 @step.published = false
163 163 @step.save!
164 164 assert_equal 1, Delayed::Job.count
... ... @@ -171,10 +171,10 @@ class StepTest &lt; ActiveSupport::TestCase
171 171 should 'set position on save' do
172 172 assert !@step.position
173 173 @step.save!
174   - assert_equal 1, @step.position
  174 + assert_equal 1, @step.position
175 175 step2 = CommunityTrackPlugin::Step.new(:name => 'Step2', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today)
176 176 step2.save!
177   - assert_equal 2, step2.position
  177 + assert_equal 2, step2.position
178 178 end
179 179  
180 180 should 'publish step if it is active' do
... ...
plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb
1 1 require File.dirname(__FILE__) + '/../../test_helper'
2 2  
3 3 class TrackHelperTest < ActiveSupport::TestCase
4   -
  4 +
5 5 include CommunityTrackPlugin::TrackHelper
6 6 include NoosferoTestHelper
7 7 include ActionView::Helpers::TextHelper
... ... @@ -9,7 +9,7 @@ class TrackHelperTest &lt; ActiveSupport::TestCase
9 9 def setup
10 10 @track = CommunityTrackPlugin::Track.new
11 11 end
12   -
  12 +
13 13 should 'return css class for track with category' do
14 14 category = fast_create(Category, :name => 'education')
15 15 @track.categories << category
... ... @@ -19,7 +19,7 @@ class TrackHelperTest &lt; ActiveSupport::TestCase
19 19 should 'return default css class for a track without category' do
20 20 assert_equal 'category_not_defined', category_class(@track)
21 21 end
22   -
  22 +
23 23 should 'return css class for first category that the class belongs' do
24 24 category1 = fast_create(Category, :name => 'education')
25 25 @track.categories << category1
... ... @@ -27,7 +27,7 @@ class TrackHelperTest &lt; ActiveSupport::TestCase
27 27 @track.categories << category2
28 28 assert_equal 'category_education', category_class(@track)
29 29 end
30   -
  30 +
31 31 should 'return css class with category name properly formated' do
32 32 category = fast_create(Category, :name => 'not defined')
33 33 @track.categories << category
... ...
plugins/community_track/test/unit/community_track_plugin/track_test.rb
... ... @@ -68,7 +68,7 @@ class TrackTest &lt; ActiveSupport::TestCase
68 68 assert_equal 3, step3.position
69 69 assert_equal [step1, step2, step3], @track.steps
70 70 end
71   -
  71 +
72 72 should 'return steps with order defined by position attribute' do
73 73 @track.children.destroy_all
74 74 step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile)
... ... @@ -85,7 +85,7 @@ class TrackTest &lt; ActiveSupport::TestCase
85 85  
86 86 should 'save steps in a new order' do
87 87 @track.children.destroy_all
88   -
  88 +
89 89 step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile)
90 90 step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step2", :profile => @track.profile)
91 91 step3 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step3", :profile => @track.profile)
... ...
plugins/community_track/test/unit/community_track_plugin_test.rb
... ... @@ -8,7 +8,7 @@ class CommunityTrackPluginTest &lt; ActiveSupport::TestCase
8 8 @params = {}
9 9 @plugin.stubs(:context).returns(self)
10 10 end
11   -
  11 +
12 12 attr_reader :profile, :params
13 13  
14 14 should 'has name' do
... ... @@ -61,7 +61,7 @@ class CommunityTrackPluginTest &lt; ActiveSupport::TestCase
61 61 @params = nil
62 62 assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types
63 63 end
64   -
  64 +
65 65 should 'return track card as an extra block' do
66 66 assert_includes CommunityTrackPlugin.extra_blocks, CommunityTrackPlugin::TrackListBlock
67 67 end
... ...
plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml
... ... @@ -2,4 +2,5 @@
2 2 <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %>
3 3 <%= labelled_form_field check_box(:block, :more_another_page) + _('Show more at another page'), '' %>
4 4 <%= select_categories(:block, _('Select Categories')) %>
  5 +<br/>
5 6 </div>
... ...
plugins/community_track/views/cms/community_track_plugin/_track.rhtml
1   -<%= required_fields_message %>
  1 +<div class='community-track'>
  2 + <%= required_fields_message %>
2 3  
3   -<%= render :file => 'shared/tiny_mce' %>
  4 + <%= render :file => 'shared/tiny_mce' %>
4 5  
5   -<div>
6   - <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %>
7   -</div>
  6 + <div>
  7 + <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %>
  8 + </div>
8 9  
9   -<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %>
  10 + <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %>
10 11  
11   -<div>
12   - <% f.fields_for :image_builder, @article.image do |i| %>
13   - <%= file_field_or_thumbnail(_('Image:'), @article.image, i) %>
14   - <% end %>
  12 + <div>
  13 + <% f.fields_for :image_builder, @article.image do |i| %>
  14 + <%= file_field_or_thumbnail(_('Image:'), @article.image, i) %>
  15 + <% end %>
15 16  
16   - <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %>
17   - <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %>
  17 + <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %>
  18 + <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %>
  19 + </div>
18 20 </div>
... ...