From e579c8150f4c3d2d59ff09becca374e1512a2c38 Mon Sep 17 00:00:00 2001 From: Daniela Soares Feitosa Date: Thu, 21 Nov 2013 18:10:45 +0000 Subject: [PATCH] Added new db/schema --- app/views/memberships/new_community.rhtml | 2 +- db/schema.rb | 4 ++++ plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb | 2 +- plugins/community_track/controllers/public/community_track_plugin_public_controller.rb | 6 +++--- plugins/community_track/lib/community_track_plugin.rb | 2 +- plugins/community_track/lib/community_track_plugin/step.rb | 8 ++++---- plugins/community_track/lib/community_track_plugin/track.rb | 6 +++--- plugins/community_track/lib/community_track_plugin/track_helper.rb | 2 +- plugins/community_track/lib/community_track_plugin/track_list_block.rb | 4 ++-- plugins/community_track/public/style.css | 7 ++++++- plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb | 8 ++++---- plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb | 2 +- plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb | 2 +- plugins/community_track/test/unit/community_track_plugin/step_test.rb | 22 +++++++++++----------- plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb | 8 ++++---- plugins/community_track/test/unit/community_track_plugin/track_test.rb | 4 ++-- plugins/community_track/test/unit/community_track_plugin_test.rb | 4 ++-- plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml | 1 + plugins/community_track/views/cms/community_track_plugin/_track.rhtml | 26 ++++++++++++++------------ 19 files changed, 66 insertions(+), 54 deletions(-) diff --git a/app/views/memberships/new_community.rhtml b/app/views/memberships/new_community.rhtml index f21b56e..b78e923 100644 --- a/app/views/memberships/new_community.rhtml +++ b/app/views/memberships/new_community.rhtml @@ -45,7 +45,7 @@ <%= template_options(Community, 'community')%> - + <%= hidden_field_tag('back_to', @back_to) %> <% button_bar do %> diff --git a/db/schema.rb b/db/schema.rb index 2c1ffbf..b642d71 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -86,6 +86,8 @@ ActiveRecord::Schema.define(:version => 20131116165327) do t.string "language" t.string "source_name" t.integer "license_id" + t.integer "image_id" + t.integer "position" end add_index "article_versions", ["article_id"], :name => "index_article_versions_on_article_id" @@ -129,6 +131,8 @@ ActiveRecord::Schema.define(:version => 20131116165327) do t.string "language" t.string "source_name" t.integer "license_id" + t.integer "image_id" + t.integer "position" end add_index "articles", ["name"], :name => "index_articles_on_name" diff --git a/plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb b/plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb index 3a8123f..84999f8 100644 --- a/plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb +++ b/plugins/community_track/controllers/myprofile/community_track_plugin_myprofile_controller.rb @@ -1,6 +1,6 @@ class CommunityTrackPluginMyprofileController < MyProfileController append_view_path File.join(File.dirname(__FILE__) + '/../../views') - + before_filter :allow_edit_track, :only => :save_order def save_order diff --git a/plugins/community_track/controllers/public/community_track_plugin_public_controller.rb b/plugins/community_track/controllers/public/community_track_plugin_public_controller.rb index dca1770..cc0e2e5 100644 --- a/plugins/community_track/controllers/public/community_track_plugin_public_controller.rb +++ b/plugins/community_track/controllers/public/community_track_plugin_public_controller.rb @@ -15,7 +15,7 @@ class CommunityTrackPluginPublicController < PublicController render :update do |page| page.insert_html :bottom, "track_list_#{block.id}", :partial => "blocks/#{block.track_partial}", :collection => tracks, :locals => {:block => block} - + if block.has_page?(p+1, per_page) 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} else @@ -37,8 +37,8 @@ class CommunityTrackPluginPublicController < PublicController if request.post? community_identifier = params[:community_identifier] if community_identifier.nil? - @failed = [_('Select one community to proceed')] - else + @failed = [_('Select one community to proceed')] + else redirect_to :controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Track", :profile => community_identifier end end diff --git a/plugins/community_track/lib/community_track_plugin.rb b/plugins/community_track/lib/community_track_plugin.rb index adf5c47..e7a75b3 100644 --- a/plugins/community_track/lib/community_track_plugin.rb +++ b/plugins/community_track/lib/community_track_plugin.rb @@ -15,7 +15,7 @@ class CommunityTrackPlugin < Noosfero::Plugin def content_types if context.respond_to?(:params) && context.params types = [] - parent_id = context.params[:parent_id] + parent_id = context.params[:parent_id] types << CommunityTrackPlugin::Track if context.profile.community? && !parent_id parent = parent_id ? context.profile.articles.find(parent_id) : nil types << CommunityTrackPlugin::Step if parent.kind_of?(CommunityTrackPlugin::Track) diff --git a/plugins/community_track/lib/community_track_plugin/step.rb b/plugins/community_track/lib/community_track_plugin/step.rb index 4682766..0c2b9bc 100644 --- a/plugins/community_track/lib/community_track_plugin/step.rb +++ b/plugins/community_track/lib/community_track_plugin/step.rb @@ -13,7 +13,7 @@ class CommunityTrackPlugin::Step < Folder validate :belong_to_track validates_presence_of :start_date, :end_date validate :end_date_equal_or_after_start_date - + after_save :schedule_activation before_create do |step| @@ -23,13 +23,13 @@ class CommunityTrackPlugin::Step < Folder before_create :set_hidden_position before_save :set_hidden_position - + def set_hidden_position if hidden decrement_positions_on_lower_items self[:position] = 0 elsif position == 0 - add_to_list_bottom + add_to_list_bottom end end @@ -65,7 +65,7 @@ class CommunityTrackPlugin::Step < Folder def active? (start_date..end_date).include?(Date.today) end - + def finished? Date.today > end_date end diff --git a/plugins/community_track/lib/community_track_plugin/track.rb b/plugins/community_track/lib/community_track_plugin/track.rb index 371a223..0fe67ed 100644 --- a/plugins/community_track/lib/community_track_plugin/track.rb +++ b/plugins/community_track/lib/community_track_plugin/track.rb @@ -1,5 +1,5 @@ class CommunityTrackPlugin::Track < Folder - + settings_items :goals, :type => :string settings_items :expected_results, :type => :string @@ -32,7 +32,7 @@ class CommunityTrackPlugin::Track < Folder end end end - + def steps_unsorted children.where(:type => 'CommunityTrackPlugin::Step') end @@ -59,7 +59,7 @@ class CommunityTrackPlugin::Track < Folder category = categories.first category ? category.name : '' end - + def to_html(options = {}) track = self lambda do diff --git a/plugins/community_track/lib/community_track_plugin/track_helper.rb b/plugins/community_track/lib/community_track_plugin/track_helper.rb index a8753f8..d926589 100644 --- a/plugins/community_track/lib/community_track_plugin/track_helper.rb +++ b/plugins/community_track/lib/community_track_plugin/track_helper.rb @@ -1,5 +1,5 @@ module CommunityTrackPlugin::TrackHelper - + def category_class(track) 'category_' + (track.categories.empty? ? 'not_defined' : track.categories.first.name.to_slug) end diff --git a/plugins/community_track/lib/community_track_plugin/track_list_block.rb b/plugins/community_track/lib/community_track_plugin/track_list_block.rb index 705e119..477202e 100644 --- a/plugins/community_track/lib/community_track_plugin/track_list_block.rb +++ b/plugins/community_track/lib/community_track_plugin/track_list_block.rb @@ -1,7 +1,7 @@ class CommunityTrackPlugin::TrackListBlock < Block include CommunityTrackPlugin::StepHelper - + settings_items :limit, :type => :integer, :default => 3 settings_items :more_another_page, :type => :boolean, :default => false settings_items :category_ids, :type => Array, :default => [] @@ -33,7 +33,7 @@ class CommunityTrackPlugin::TrackListBlock < Block def category_ids=(ids) settings[:category_ids] = ids.uniq.map{|item| item.to_i unless item.to_i.zero?}.compact end - + def all_tracks tracks = owner.articles.where(:type => 'CommunityTrackPlugin::Track') if !category_ids.empty? diff --git a/plugins/community_track/public/style.css b/plugins/community_track/public/style.css index adbbcd8..d13e010 100644 --- a/plugins/community_track/public/style.css +++ b/plugins/community_track/public/style.css @@ -1,4 +1,5 @@ -.icon-newcommunity-track { +.icon-newcommunity-track, +.icon-community-track { background-image: url(/plugins/community_track/icons/community-track.png) } @@ -188,3 +189,7 @@ #step .tools .item .name a:hover { color: #888; } + +.community-track textarea { + width: 100%; +} diff --git a/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb b/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb index e82183c..02ba691 100644 --- a/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb +++ b/plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb @@ -2,13 +2,13 @@ require File.dirname(__FILE__) + '/../test_helper' class ContentViewerController append_view_path File.join(File.dirname(__FILE__) + '/../../views') - def rescue_action(e) - raise e - end + def rescue_action(e) + raise e + end end class ContentViewerControllerTest < ActionController::TestCase - + def setup @profile = fast_create(Community) @track = CommunityTrackPlugin::Track.create!(:abstract => 'abstract', :body => 'body', :name => 'track', :profile => @profile) diff --git a/plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb b/plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb index e9d5444..63660bb 100644 --- a/plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb +++ b/plugins/community_track/test/functional/community_track_plugin_public_controller_test.rb @@ -40,7 +40,7 @@ class CommunityTrackPluginPublicControllerTest < ActionController::TestCase xhr :get, :view_tracks, :id => @block.id, :page => 1 assert_equal @block.limit, @response.body.scan(/item/).size end - + should 'display page for all tracks' do get :all_tracks, :id => @block.id assert_match /track_list_#{@block.id}/, @response.body diff --git a/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb b/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb index 37e9718..edc1b85 100644 --- a/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/step_helper_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../../test_helper' class StepHelperTest < ActiveSupport::TestCase - + include CommunityTrackPlugin::StepHelper def setup diff --git a/plugins/community_track/test/unit/community_track_plugin/step_test.rb b/plugins/community_track/test/unit/community_track_plugin/step_test.rb index 95244d1..4803f55 100644 --- a/plugins/community_track/test/unit/community_track_plugin/step_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/step_test.rb @@ -16,7 +16,7 @@ class StepTest < ActiveSupport::TestCase should 'has a short description' do assert CommunityTrackPlugin::Step.short_description end - + should 'set published to false on create' do today = Date.today 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 < ActiveSupport::TestCase step = CommunityTrackPlugin::Step.new(:name => 'Step', :body => 'body', :profile => @profile, :parent => blog, :start_date => today, :end_date => today, :published => true) assert !step.save end - + should 'do not allow step creation without a parent' do today = Date.today 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 < ActiveSupport::TestCase @step.end_date_equal_or_after_start_date.inspect assert [], @step.errors end - + should 'be active if today is between start and end dates' do @step.start_date = Date.today @step.end_date = Date.today + 1.day assert @step.active? end - + should 'be finished if today is after the end date' do @step.start_date = Date.today - 2.day @step.end_date = Date.today - 1.day assert @step.finished? end - + should 'be waiting if today is before the end date' do @step.start_date = Date.today + 1.day @step.end_date = Date.today + 2.day assert @step.waiting? end - + should 'return delayed job created with a specific step_id' do step_id = 0 CommunityTrackPlugin::ActivationJob.new(step_id) @@ -97,7 +97,7 @@ class StepTest < ActiveSupport::TestCase assert_equal 1, Delayed::Job.count assert_equal @step.start_date, Delayed::Job.first.run_at.to_date end - + should 'do not duplicate delayed job' do @step.start_date = Date.today @step.end_date = Date.today @@ -105,7 +105,7 @@ class StepTest < ActiveSupport::TestCase @step.schedule_activation assert_equal 1, Delayed::Job.count end - + should 'create delayed job when a step is saved' do @step.start_date = Date.today @step.end_date = Date.today @@ -158,7 +158,7 @@ class StepTest < ActiveSupport::TestCase should 'do not schedule delayed job if save but do not modify date fields and published status' do @step.start_date = Date.today - @step.end_date = Date.today + @step.end_date = Date.today @step.published = false @step.save! assert_equal 1, Delayed::Job.count @@ -171,10 +171,10 @@ class StepTest < ActiveSupport::TestCase should 'set position on save' do assert !@step.position @step.save! - assert_equal 1, @step.position + assert_equal 1, @step.position step2 = CommunityTrackPlugin::Step.new(:name => 'Step2', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) step2.save! - assert_equal 2, step2.position + assert_equal 2, step2.position end should 'publish step if it is active' do diff --git a/plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb b/plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb index 4a724f2..6be91d2 100644 --- a/plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/track_helper_test.rb @@ -1,7 +1,7 @@ require File.dirname(__FILE__) + '/../../test_helper' class TrackHelperTest < ActiveSupport::TestCase - + include CommunityTrackPlugin::TrackHelper include NoosferoTestHelper include ActionView::Helpers::TextHelper @@ -9,7 +9,7 @@ class TrackHelperTest < ActiveSupport::TestCase def setup @track = CommunityTrackPlugin::Track.new end - + should 'return css class for track with category' do category = fast_create(Category, :name => 'education') @track.categories << category @@ -19,7 +19,7 @@ class TrackHelperTest < ActiveSupport::TestCase should 'return default css class for a track without category' do assert_equal 'category_not_defined', category_class(@track) end - + should 'return css class for first category that the class belongs' do category1 = fast_create(Category, :name => 'education') @track.categories << category1 @@ -27,7 +27,7 @@ class TrackHelperTest < ActiveSupport::TestCase @track.categories << category2 assert_equal 'category_education', category_class(@track) end - + should 'return css class with category name properly formated' do category = fast_create(Category, :name => 'not defined') @track.categories << category diff --git a/plugins/community_track/test/unit/community_track_plugin/track_test.rb b/plugins/community_track/test/unit/community_track_plugin/track_test.rb index da6b75f..376cf4a 100644 --- a/plugins/community_track/test/unit/community_track_plugin/track_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/track_test.rb @@ -68,7 +68,7 @@ class TrackTest < ActiveSupport::TestCase assert_equal 3, step3.position assert_equal [step1, step2, step3], @track.steps end - + should 'return steps with order defined by position attribute' do @track.children.destroy_all 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 < ActiveSupport::TestCase should 'save steps in a new order' do @track.children.destroy_all - + step1 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step1", :profile => @track.profile) step2 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step2", :profile => @track.profile) step3 = CommunityTrackPlugin::Step.create!(:parent => @track, :start_date => Date.today, :end_date => Date.today, :name => "step3", :profile => @track.profile) diff --git a/plugins/community_track/test/unit/community_track_plugin_test.rb b/plugins/community_track/test/unit/community_track_plugin_test.rb index 03b039e..7513cd6 100644 --- a/plugins/community_track/test/unit/community_track_plugin_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin_test.rb @@ -8,7 +8,7 @@ class CommunityTrackPluginTest < ActiveSupport::TestCase @params = {} @plugin.stubs(:context).returns(self) end - + attr_reader :profile, :params should 'has name' do @@ -61,7 +61,7 @@ class CommunityTrackPluginTest < ActiveSupport::TestCase @params = nil assert_equivalent [CommunityTrackPlugin::Step, CommunityTrackPlugin::Track], @plugin.content_types end - + should 'return track card as an extra block' do assert_includes CommunityTrackPlugin.extra_blocks, CommunityTrackPlugin::TrackListBlock end diff --git a/plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml b/plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml index e59222c..113b86a 100644 --- a/plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml +++ b/plugins/community_track/views/box_organizer/community_track_plugin/_track_list_block.rhtml @@ -2,4 +2,5 @@ <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> <%= labelled_form_field check_box(:block, :more_another_page) + _('Show more at another page'), '' %> <%= select_categories(:block, _('Select Categories')) %> +
diff --git a/plugins/community_track/views/cms/community_track_plugin/_track.rhtml b/plugins/community_track/views/cms/community_track_plugin/_track.rhtml index 09145ee..5a539f2 100644 --- a/plugins/community_track/views/cms/community_track_plugin/_track.rhtml +++ b/plugins/community_track/views/cms/community_track_plugin/_track.rhtml @@ -1,18 +1,20 @@ -<%= required_fields_message %> +
+ <%= required_fields_message %> -<%= render :file => 'shared/tiny_mce' %> + <%= render :file => 'shared/tiny_mce' %> -
- <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> -
+
+ <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> +
-<%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %> + <%= render :partial => 'shared/lead_and_body', :locals => {:tiny_mce => true, :body_label => 'Description:'} %> -
- <% f.fields_for :image_builder, @article.image do |i| %> - <%= file_field_or_thumbnail(_('Image:'), @article.image, i) %> - <% end %> +
+ <% f.fields_for :image_builder, @article.image do |i| %> + <%= file_field_or_thumbnail(_('Image:'), @article.image, i) %> + <% end %> - <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %> - <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %> + <%= labelled_form_field(_('Goals:'), text_area(:article, :goals, :rows => 3, :cols => 64)) %> + <%= labelled_form_field(_('Expected Results:'), text_area(:article, :expected_results, :rows => 3, :cols => 64)) %> +
-- libgit2 0.21.2