From 1e34e5c28b14eb394921f7032f568c11cf0b37dd Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Tue, 26 Nov 2013 19:31:30 -0300 Subject: [PATCH] Change community track creation usability --- plugins/community_track/lib/community_track_plugin/step.rb | 15 ++++++++++++--- plugins/community_track/public/style.css | 15 +++++++++++++++ plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb | 18 ++++++++++++------ plugins/community_track/test/unit/community_track_plugin/step_test.rb | 24 ++++++++++++++++++++++-- plugins/community_track/views/cms/community_track_plugin/_step.rhtml | 2 ++ plugins/community_track/views/content_viewer/_step_item.rhtml | 25 +++++++++++++++++++++++++ plugins/community_track/views/content_viewer/step.rhtml | 18 ++++++------------ plugins/community_track/views/content_viewer/track.rhtml | 44 ++++++++++---------------------------------- 8 files changed, 104 insertions(+), 57 deletions(-) create mode 100644 plugins/community_track/views/content_viewer/_step_item.rhtml diff --git a/plugins/community_track/lib/community_track_plugin/step.rb b/plugins/community_track/lib/community_track_plugin/step.rb index 92bb905..32d4f2a 100644 --- a/plugins/community_track/lib/community_track_plugin/step.rb +++ b/plugins/community_track/lib/community_track_plugin/step.rb @@ -1,6 +1,7 @@ class CommunityTrackPlugin::Step < Folder settings_items :hidden, :type => :boolean, :default => false + settings_items :tool_type, :type => String alias :tools :children @@ -48,11 +49,11 @@ class CommunityTrackPlugin::Step < Folder end def accept_comments? - false + true end - def enabled_tools - {TinyMceArticle => {:name => _('Article')}, Forum => {:name => _('Forum')}} + def self.enabled_tools + [TinyMceArticle, Forum] end def to_html(options = {}) @@ -89,6 +90,14 @@ class CommunityTrackPlugin::Step < Folder save! end + def tool_class + tool_type ? tool_type.constantize : nil + end + + def tool + tools.find(:first, :conditions => {:type => tool_type }) + end + class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id) def self.find(step_id) diff --git a/plugins/community_track/public/style.css b/plugins/community_track/public/style.css index 2125a35..686293e 100644 --- a/plugins/community_track/public/style.css +++ b/plugins/community_track/public/style.css @@ -199,3 +199,18 @@ width: 115px; background: url(/plugins/community_track/icons/calendar.png) right center no-repeat; } + +.step_list .step .tools { + text-align: center; +} + +.step_list .step .actions { + float: right; +} + +#article .step_list .step .actions .button { + color: #888; + background-color: transparent; + border: 0px; + background-image: none; +} 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 02ba691..5684718 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 @@ -15,7 +15,7 @@ class ContentViewerControllerTest < ActionController::TestCase category = fast_create(Category, :name => "education") @track.add_category(category) - @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) + @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today, :tool_type => TinyMceArticle.name) user = create_user('testinguser') login_as(user.login) @@ -27,12 +27,12 @@ class ContentViewerControllerTest < ActionController::TestCase assert_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } end - should 'do not show actions for tracks when user has not permission for edit' do + should 'do not show actions for tracks when user has not permission to edit' do user = create_user('intruder') logout login_as(user.login) get :view_page, @track.url - assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } + assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'track actions' } } end should 'do not show new button at article toolbar for tracks' do @@ -64,17 +64,23 @@ class ContentViewerControllerTest < ActionController::TestCase assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } } end - should 'show actions for steps when user has permission for edit' do + should 'show actions for steps when user has permission to edit' do get :view_page, @step.url assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } end - should 'show actions for enabled tools in step' do + should 'show action for tiny mce article tool in step' do get :view_page, @step.url - assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } } assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newtext-html' } } end + should 'show action for forum tool in step' do + @step.tool_type = Forum.name + @step.save! + get :view_page, @step.url + assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } } + end + should 'do not show actions for steps when user has not permission for edit' do user = create_user('intruder') logout 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 4803f55..35d7214 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 @@ -258,8 +258,28 @@ class StepTest < ActiveSupport::TestCase end should 'return enabled tools for a step' do - assert_includes @step.enabled_tools, TinyMceArticle - assert_includes @step.enabled_tools, Forum + assert_includes CommunityTrackPlugin::Step.enabled_tools, TinyMceArticle + assert_includes CommunityTrackPlugin::Step.enabled_tools, Forum + end + + should 'return class for selected tool' do + @step.tool_type = 'Forum' + assert_equal Forum, @step.tool_class + end + + should 'return tool for selected type' do + @step.tool_type = 'Forum' + @step.save! + article = fast_create(Article, :parent_id => @step.id) + forum = fast_create(Forum, :parent_id => @step.id) + assert_equal forum, @step.tool + end + + should 'not return tool with different type' do + @step.tool_type = 'Forum' + @step.save! + article = fast_create(Article, :parent_id => @step.id) + assert_not_equal article, @step.tool end end diff --git a/plugins/community_track/views/cms/community_track_plugin/_step.rhtml b/plugins/community_track/views/cms/community_track_plugin/_step.rhtml index b371993..a807569 100644 --- a/plugins/community_track/views/cms/community_track_plugin/_step.rhtml +++ b/plugins/community_track/views/cms/community_track_plugin/_step.rhtml @@ -12,6 +12,8 @@ { :size => 14 }) )) %> + <%= labelled_form_field(_('Tool type'), select(:article, :tool_type, CommunityTrackPlugin::Step.enabled_tools.map {|t| [t.short_description, t.name]} )) %> + <%= hidden_field_tag('success_back_to', url_for(@article.parent.view_url)) %> <%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %> diff --git a/plugins/community_track/views/content_viewer/_step_item.rhtml b/plugins/community_track/views/content_viewer/_step_item.rhtml new file mode 100644 index 0000000..0765c7e --- /dev/null +++ b/plugins/community_track/views/content_viewer/_step_item.rhtml @@ -0,0 +1,25 @@ +
  • + <%= hidden_field_tag "step_ids[]", step_item.id %> +
    <%= step_item.hidden ? '' : step_item.position %>
    +
    + <% if step_item.allow_edit?(user) && !remove_content_button(:edit) %> + <% content = content_tag('span', label_for_edit_article(step_item)) %> + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => step_item.id, :success_back_to => url_for(step_item.parent.view_url) }) %> + <%= expirable_button step_item, :edit, content, url %> + <% end %> +
    +
    +
    + <%= show_period(step_item.start_date, step_item.end_date) %> +
    +
    <%= link_to step_item.name, step_item.url %>
    +
    <%= step_item.body %>
    +
    +
    + <% if step_item.tool %> + <%= link_to step_item.tool.name, step_item.tool.view_url %> + <% elsif step_item.allow_create?(user) && step_item.tool_class %> + <%= _('Create %s' % step_item.tool_class.short_description) %> + <% end %> +
    +
  • diff --git a/plugins/community_track/views/content_viewer/step.rhtml b/plugins/community_track/views/content_viewer/step.rhtml index 895dac8..a637b59 100644 --- a/plugins/community_track/views/content_viewer/step.rhtml +++ b/plugins/community_track/views/content_viewer/step.rhtml @@ -9,23 +9,17 @@
    <%= step.body %>
    -

    <%= _("Tools") %>

    - <% if step.allow_create?(user) %> +

    <%= _("Tool") %>

    + <% if step.allow_create?(user) && !step.tool && step.tool_class %>
    - <% step.enabled_tools.each do |klass, attrs| %> - <% content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => klass.name, :parent_id => @page}), :class => "button with-text icon-new icon-new#{klass.icon_name}") do %> - <%= _("New #{attrs[:name]}") %> - <% end %> - <% end %> + <%= _('Create %s' % step.tool_class.short_description) %>
    <% end %>
    - <% step.tools.each do |tool| %> -
    -
    - <%= link_to tool.name, tool.url, :class=>"button with-text icon-new icon-new#{tool.class.icon_name}" %> +
    +
    + <%= link_to(step.tool.name, step.tool.view_url, :class=>"button with-text icon-new icon-new#{step.tool.class.icon_name}") if step.tool %>
    - <% end %>
    diff --git a/plugins/community_track/views/content_viewer/track.rhtml b/plugins/community_track/views/content_viewer/track.rhtml index f71edab..5db477a 100644 --- a/plugins/community_track/views/content_viewer/track.rhtml +++ b/plugins/community_track/views/content_viewer/track.rhtml @@ -9,7 +9,7 @@

    <%= _("Steps") %>

    <% if track.allow_create?(user) %> -
    +
    <% content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Step", :parent_id => track.id}), :class => 'button with-text icon-add') do %> <%= _("New %s") % CommunityTrackPlugin::Step.short_description %> <% end %> @@ -28,40 +28,16 @@ <% end %>
      - <% track.steps.each do |step| %> -
    • - <%= hidden_field_tag "step_ids[]", step.id %> -
      <%= step.position %>
      -
      -
      - <%= show_period(step.start_date, step.end_date) %> -
      -
      <%= link_to step.name, step.url %>
      -
      <%= step.body %>
      -
      -
    • - <% end %> + <%= render :partial => 'step_item', :collection => track.steps %>
    - <% if track.allow_create?(user) && !track.hidden_steps.empty? %> -
    -

    <%= _('Hidden Steps') %>

    -
      - <% track.hidden_steps.each do |step| %> -
    • - <%= hidden_field_tag "step_ids[]", step.id %> -
      -
      -
      - <%= show_period(step.start_date, step.end_date) %> -
      -
      <%= link_to step.name, step.url %>
      -
      <%= step.body %>
      -
      -
    • - <% end %> -
    -
    - <% end %> + <% if track.allow_create?(user) && !track.hidden_steps.empty? %> +
    +

    <%= _('Hidden Steps') %>

    +
      + <%= render :partial => 'step_item', :collection => track.hidden_steps %> +
    +
    + <% end %>
    <% end %>
    -- libgit2 0.21.2