Commit 1e34e5c28b14eb394921f7032f568c11cf0b37dd

Authored by Victor Costa
1 parent c6c0bf79

Change community track creation usability

plugins/community_track/lib/community_track_plugin/step.rb
1 class CommunityTrackPlugin::Step < Folder 1 class CommunityTrackPlugin::Step < Folder
2 2
3 settings_items :hidden, :type => :boolean, :default => false 3 settings_items :hidden, :type => :boolean, :default => false
  4 + settings_items :tool_type, :type => String
4 5
5 alias :tools :children 6 alias :tools :children
6 7
@@ -48,11 +49,11 @@ class CommunityTrackPlugin::Step &lt; Folder @@ -48,11 +49,11 @@ class CommunityTrackPlugin::Step &lt; Folder
48 end 49 end
49 50
50 def accept_comments? 51 def accept_comments?
51 - false 52 + true
52 end 53 end
53 54
54 - def enabled_tools  
55 - {TinyMceArticle => {:name => _('Article')}, Forum => {:name => _('Forum')}} 55 + def self.enabled_tools
  56 + [TinyMceArticle, Forum]
56 end 57 end
57 58
58 def to_html(options = {}) 59 def to_html(options = {})
@@ -89,6 +90,14 @@ class CommunityTrackPlugin::Step &lt; Folder @@ -89,6 +90,14 @@ class CommunityTrackPlugin::Step &lt; Folder
89 save! 90 save!
90 end 91 end
91 92
  93 + def tool_class
  94 + tool_type ? tool_type.constantize : nil
  95 + end
  96 +
  97 + def tool
  98 + tools.find(:first, :conditions => {:type => tool_type })
  99 + end
  100 +
92 class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id) 101 class CommunityTrackPlugin::ActivationJob < Struct.new(:step_id)
93 102
94 def self.find(step_id) 103 def self.find(step_id)
plugins/community_track/public/style.css
@@ -199,3 +199,18 @@ @@ -199,3 +199,18 @@
199 width: 115px; 199 width: 115px;
200 background: url(/plugins/community_track/icons/calendar.png) right center no-repeat; 200 background: url(/plugins/community_track/icons/calendar.png) right center no-repeat;
201 } 201 }
  202 +
  203 +.step_list .step .tools {
  204 + text-align: center;
  205 +}
  206 +
  207 +.step_list .step .actions {
  208 + float: right;
  209 +}
  210 +
  211 +#article .step_list .step .actions .button {
  212 + color: #888;
  213 + background-color: transparent;
  214 + border: 0px;
  215 + background-image: none;
  216 +}
plugins/community_track/test/functional/community_track_plugin_content_viewer_controller_test.rb
@@ -15,7 +15,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -15,7 +15,7 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
15 category = fast_create(Category, :name => "education") 15 category = fast_create(Category, :name => "education")
16 @track.add_category(category) 16 @track.add_category(category)
17 17
18 - @step = CommunityTrackPlugin::Step.create!(:name => 'step1', :body => 'body', :profile => @profile, :parent => @track, :published => false, :end_date => Date.today, :start_date => Date.today) 18 + @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)
19 19
20 user = create_user('testinguser') 20 user = create_user('testinguser')
21 login_as(user.login) 21 login_as(user.login)
@@ -27,12 +27,12 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -27,12 +27,12 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
27 assert_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } 27 assert_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } }
28 end 28 end
29 29
30 - should 'do not show actions for tracks when user has not permission for edit' do 30 + should 'do not show actions for tracks when user has not permission to edit' do
31 user = create_user('intruder') 31 user = create_user('intruder')
32 logout 32 logout
33 login_as(user.login) 33 login_as(user.login)
34 get :view_page, @track.url 34 get :view_page, @track.url
35 - assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } 35 + assert_no_tag :tag => 'div', :attributes => {:id => 'track' }, :descendant => { :tag => 'div', :attributes => { :class => 'track actions' } }
36 end 36 end
37 37
38 should 'do not show new button at article toolbar for tracks' do 38 should 'do not show new button at article toolbar for tracks' do
@@ -64,17 +64,23 @@ class ContentViewerControllerTest &lt; ActionController::TestCase @@ -64,17 +64,23 @@ class ContentViewerControllerTest &lt; ActionController::TestCase
64 assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } } 64 assert_tag :tag => 'div', :attributes => { :class => 'tools' }, :descendant => { :tag => 'div', :attributes => { :class => 'item' } }
65 end 65 end
66 66
67 - should 'show actions for steps when user has permission for edit' do 67 + should 'show actions for steps when user has permission to edit' do
68 get :view_page, @step.url 68 get :view_page, @step.url
69 assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } } 69 assert_tag :tag => 'div', :attributes => {:id => 'step' }, :descendant => { :tag => 'div', :attributes => { :class => 'actions' } }
70 end 70 end
71 71
72 - should 'show actions for enabled tools in step' do 72 + should 'show action for tiny mce article tool in step' do
73 get :view_page, @step.url 73 get :view_page, @step.url
74 - assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } }  
75 assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newtext-html' } } 74 assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newtext-html' } }
76 end 75 end
77 76
  77 + should 'show action for forum tool in step' do
  78 + @step.tool_type = Forum.name
  79 + @step.save!
  80 + get :view_page, @step.url
  81 + assert_tag 'div', :attributes => {:class => 'actions' }, :descendant => { :tag => 'a', :attributes => { :class => 'button with-text icon-new icon-newforum' } }
  82 + end
  83 +
78 should 'do not show actions for steps when user has not permission for edit' do 84 should 'do not show actions for steps when user has not permission for edit' do
79 user = create_user('intruder') 85 user = create_user('intruder')
80 logout 86 logout
plugins/community_track/test/unit/community_track_plugin/step_test.rb
@@ -258,8 +258,28 @@ class StepTest &lt; ActiveSupport::TestCase @@ -258,8 +258,28 @@ class StepTest &lt; ActiveSupport::TestCase
258 end 258 end
259 259
260 should 'return enabled tools for a step' do 260 should 'return enabled tools for a step' do
261 - assert_includes @step.enabled_tools, TinyMceArticle  
262 - assert_includes @step.enabled_tools, Forum 261 + assert_includes CommunityTrackPlugin::Step.enabled_tools, TinyMceArticle
  262 + assert_includes CommunityTrackPlugin::Step.enabled_tools, Forum
  263 + end
  264 +
  265 + should 'return class for selected tool' do
  266 + @step.tool_type = 'Forum'
  267 + assert_equal Forum, @step.tool_class
  268 + end
  269 +
  270 + should 'return tool for selected type' do
  271 + @step.tool_type = 'Forum'
  272 + @step.save!
  273 + article = fast_create(Article, :parent_id => @step.id)
  274 + forum = fast_create(Forum, :parent_id => @step.id)
  275 + assert_equal forum, @step.tool
  276 + end
  277 +
  278 + should 'not return tool with different type' do
  279 + @step.tool_type = 'Forum'
  280 + @step.save!
  281 + article = fast_create(Article, :parent_id => @step.id)
  282 + assert_not_equal article, @step.tool
263 end 283 end
264 284
265 end 285 end
plugins/community_track/views/cms/community_track_plugin/_step.rhtml
@@ -12,6 +12,8 @@ @@ -12,6 +12,8 @@
12 { :size => 14 }) 12 { :size => 14 })
13 )) %> 13 )) %>
14 14
  15 + <%= labelled_form_field(_('Tool type'), select(:article, :tool_type, CommunityTrackPlugin::Step.enabled_tools.map {|t| [t.short_description, t.name]} )) %>
  16 + <%= hidden_field_tag('success_back_to', url_for(@article.parent.view_url)) %>
15 </div> 17 </div>
16 18
17 <%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %> 19 <%= labelled_form_field check_box(:article, :hidden) + _('Hidden Step'), '' %>
plugins/community_track/views/content_viewer/_step_item.rhtml 0 → 100644
@@ -0,0 +1,25 @@ @@ -0,0 +1,25 @@
  1 +<li class="step <%= status_class(step_item) %>">
  2 + <%= hidden_field_tag "step_ids[]", step_item.id %>
  3 + <div class="position"><%= step_item.hidden ? '' : step_item.position %></div>
  4 + <div class="actions">
  5 + <% if step_item.allow_edit?(user) && !remove_content_button(:edit) %>
  6 + <% content = content_tag('span', label_for_edit_article(step_item)) %>
  7 + <% url = profile.admin_url.merge({ :controller => 'cms', :action => 'edit', :id => step_item.id, :success_back_to => url_for(step_item.parent.view_url) }) %>
  8 + <%= expirable_button step_item, :edit, content, url %>
  9 + <% end %>
  10 + </div>
  11 + <div class="content">
  12 + <div class="date">
  13 + <%= show_period(step_item.start_date, step_item.end_date) %>
  14 + </div>
  15 + <div class="name"><%= link_to step_item.name, step_item.url %></div>
  16 + <div class="lead"><%= step_item.body %></div>
  17 + </div>
  18 + <div class="tools">
  19 + <% if step_item.tool %>
  20 + <%= link_to step_item.tool.name, step_item.tool.view_url %>
  21 + <% elsif step_item.allow_create?(user) && step_item.tool_class %>
  22 + <a href="<%= url_for({:controller => 'cms', :action => 'new', :type => step_item.tool_class, :parent_id => step_item}) %>" class="button icon-new with-text icon-new<%= step_item.tool_class.icon_name %>"><%= _('Create %s' % step_item.tool_class.short_description) %></a>
  23 + <% end %>
  24 + </div>
  25 +</li>
plugins/community_track/views/content_viewer/step.rhtml
@@ -9,23 +9,17 @@ @@ -9,23 +9,17 @@
9 <div> 9 <div>
10 <%= step.body %> 10 <%= step.body %>
11 </div> 11 </div>
12 - <h3><%= _("Tools") %></h3>  
13 - <% if step.allow_create?(user) %> 12 + <h3><%= _("Tool") %></h3>
  13 + <% if step.allow_create?(user) && !step.tool && step.tool_class %>
14 <div class="actions"> 14 <div class="actions">
15 - <% step.enabled_tools.each do |klass, attrs| %>  
16 - <% 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 %>  
17 - <%= _("New #{attrs[:name]}") %>  
18 - <% end %>  
19 - <% end %> 15 + <a href="<%= url_for({:controller => 'cms', :action => 'new', :type => step.tool_type.constantize, :parent_id => @page}) %>" class="button with-text icon-new icon-new<%= step.tool_class.icon_name %>"><%= _('Create %s' % step.tool_class.short_description) %></a>
20 </div> 16 </div>
21 <% end %> 17 <% end %>
22 <div class="tools"> 18 <div class="tools">
23 - <% step.tools.each do |tool| %>  
24 - <div class="item">  
25 - <div class="name">  
26 - <%= link_to tool.name, tool.url, :class=>"button with-text icon-new icon-new#{tool.class.icon_name}" %> 19 + <div class="item">
  20 + <div class="name">
  21 + <%= 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 %>
27 </div> 22 </div>
28 </div> 23 </div>
29 - <% end %>  
30 </div> 24 </div>
31 </div> 25 </div>
plugins/community_track/views/content_viewer/track.rhtml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 <h3><%= _("Steps") %></h3> 9 <h3><%= _("Steps") %></h3>
10 10
11 <% if track.allow_create?(user) %> 11 <% if track.allow_create?(user) %>
12 - <div class="actions"> 12 + <div class="track actions">
13 <% content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Step", :parent_id => track.id}), :class => 'button with-text icon-add') do %> 13 <% content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "CommunityTrackPlugin::Step", :parent_id => track.id}), :class => 'button with-text icon-add') do %>
14 <strong><%= _("New %s") % CommunityTrackPlugin::Step.short_description %></strong> 14 <strong><%= _("New %s") % CommunityTrackPlugin::Step.short_description %></strong>
15 <% end %> 15 <% end %>
@@ -28,40 +28,16 @@ @@ -28,40 +28,16 @@
28 <% end %> 28 <% end %>
29 29
30 <ul id="sortable" class="step_list"> 30 <ul id="sortable" class="step_list">
31 - <% track.steps.each do |step| %>  
32 - <li class="step">  
33 - <%= hidden_field_tag "step_ids[]", step.id %>  
34 - <div class="position"><%= step.position %></div>  
35 - <div class="content">  
36 - <div class="date">  
37 - <%= show_period(step.start_date, step.end_date) %>  
38 - </div>  
39 - <div class="name"><%= link_to step.name, step.url %></div>  
40 - <div class="lead"><%= step.body %></div>  
41 - </div>  
42 - </li>  
43 - <% end %> 31 + <%= render :partial => 'step_item', :collection => track.steps %>
44 </ul> 32 </ul>
45 - <% if track.allow_create?(user) && !track.hidden_steps.empty? %>  
46 - <div id="hidden_steps">  
47 - <h3><%= _('Hidden Steps') %></h3>  
48 - <ul class="step_list">  
49 - <% track.hidden_steps.each do |step| %>  
50 - <li class="step">  
51 - <%= hidden_field_tag "step_ids[]", step.id %>  
52 - <div class="position"></div>  
53 - <div class="content">  
54 - <div class="date">  
55 - <%= show_period(step.start_date, step.end_date) %>  
56 - </div>  
57 - <div class="name"><%= link_to step.name, step.url %></div>  
58 - <div class="lead"><%= step.body %></div>  
59 - </div>  
60 - </li>  
61 - <% end %>  
62 - </ul>  
63 - </div>  
64 - <% end %> 33 + <% if track.allow_create?(user) && !track.hidden_steps.empty? %>
  34 + <div id="hidden_steps">
  35 + <h3><%= _('Hidden Steps') %></h3>
  36 + <ul class="step_list">
  37 + <%= render :partial => 'step_item', :collection => track.hidden_steps %>
  38 + </ul>
  39 + </div>
  40 + <% end %>
65 </div> 41 </div>
66 <% end %> 42 <% end %>
67 </div> 43 </div>