diff --git a/app/helpers/kanbans_helper.rb b/app/helpers/kanbans_helper.rb index 9dda6f4..6d0409b 100644 --- a/app/helpers/kanbans_helper.rb +++ b/app/helpers/kanbans_helper.rb @@ -39,20 +39,6 @@ def updated_note_on_issue?(issue) end end - def pane_configured?(pane) - (@settings['panes'] && @settings['panes'][pane] && !@settings['panes'][pane]['status'].blank?) - end - - def display_pane?(pane) - if pane == 'quick-tasks' - pane_configured?('backlog') && - @settings['panes']['quick-tasks']['limit'].present? && - @settings['panes']['quick-tasks']['limit'].to_i > 0 - else - pane_configured?(pane) - end - end - def kanban_issue_css_classes(issue) css = 'kanban-issue ' + issue.css_classes if User.current.logged? && !issue.assigned_to_id.nil? && issue.assigned_to_id != User.current.id @@ -77,9 +63,9 @@ def issue_icon_link(issue) def column_configured?(column) case column when :unstaffed - pane_configured?('incoming') || pane_configured?('backlog') + KanbanPane::IncomingPane.configured? || KanbanPane::BacklogPane.configured? when :selected - display_pane?('quick-tasks') || pane_configured?('selected') + KanbanPane::QuickPane.configured? || KanbanPane::SelectedPane.configured? when :staffed true # always end @@ -116,17 +102,17 @@ def staffed_column_width(column) :finished => 2, :canceled => 2 } - return 0.0 if column == :active && !pane_configured?(:active) - return 0.0 if column == :testing && !pane_configured?(:testing) - return 0.0 if column == :finished && !pane_configured?(:finished) - return 0.0 if column == :canceled && !pane_configured?(:canceled) + return 0.0 if column == :active && !KanbanPane::ActivePane.configured? + return 0.0 if column == :testing && !KanbanPane::TestingPane.configured? + return 0.0 if column == :finished && !KanbanPane::FinishedPane.configured? + return 0.0 if column == :canceled && !KanbanPane::CanceledPane.configured? visible = 0 visible += column_ratios[:user] - visible += column_ratios[:active] if pane_configured?(:active) - visible += column_ratios[:testing] if pane_configured?(:testing) - visible += column_ratios[:finished] if pane_configured?(:finished) - visible += column_ratios[:canceled] if pane_configured?(:canceled) + visible += column_ratios[:active] if KanbanPane::ActivePane.configured? + visible += column_ratios[:testing] if KanbanPane::TestingPane.configured? + visible += column_ratios[:finished] if KanbanPane::FinishedPane.configured? + visible += column_ratios[:canceled] if KanbanPane::CanceledPane.configured? return ((column_ratios[column].to_f / visible) * 96).round(2) end diff --git a/app/models/kanban_pane.rb b/app/models/kanban_pane.rb index f6272c2..d641b20 100644 --- a/app/models/kanban_pane.rb +++ b/app/models/kanban_pane.rb @@ -1,5 +1,9 @@ class KanbanPane def settings + KanbanPane.settings + end + + def self.settings Setting.plugin_redmine_kanban end @@ -7,6 +11,15 @@ def get_issues(options={}) nil end + def self.pane_name + self.to_s.demodulize.gsub(/pane/i, '').downcase + end + + def self.configured? + pane = self.pane_name + (settings['panes'] && settings['panes'][pane] && !settings['panes'][pane]['status'].blank?) + end + private def missing_settings(pane, options={}) diff --git a/app/models/kanban_pane/quick_pane.rb b/app/models/kanban_pane/quick_pane.rb index 6e13d22..5e43a82 100644 --- a/app/models/kanban_pane/quick_pane.rb +++ b/app/models/kanban_pane/quick_pane.rb @@ -14,6 +14,18 @@ def get_issues(options={}) return group_by_priority_position(issues) end + + def self.pane_name + 'quick-tasks' + end + + # QuickPane uses different configuration logic since it requires the + # backlog pane and doesn't have it's own status + def self.configured? + KanbanPane::BacklogPane.configured? && + settings['panes']['quick-tasks']['limit'].present? && + settings['panes']['quick-tasks']['limit'].to_i > 0 + end end diff --git a/app/views/kanbans/_user.html.erb b/app/views/kanbans/_user.html.erb index 4480b15..6307178 100644 --- a/app/views/kanbans/_user.html.erb +++ b/app/views/kanbans/_user.html.erb @@ -4,22 +4,22 @@ <%= call_hook(:view_kanbans_user_name, :user => user) %> - <% if pane_configured?('active') %> + <% if KanbanPane::ActivePane.configured? %>
<%= render(:partial => 'active', :locals => {:user => user}) %>
<% end %> - <% if pane_configured?('testing') %> + <% if KanbanPane::TestingPane.configured? %>
<%= render(:partial => 'testing', :locals => {:user => user}) %>
<% end %> - <% if pane_configured?('finished') %> + <% if KanbanPane::FinishedPane.configured? %>
<%= render(:partial => 'finished', :locals => {:user => user}) %>
<% end %> - <% if pane_configured?('canceled') %> + <% if KanbanPane::CanceledPane.configured? %>
<%= render(:partial => 'canceled', :locals => {:user => user}) %>
diff --git a/app/views/kanbans/show.html.erb b/app/views/kanbans/show.html.erb index 4bcb914..ab5fbac 100644 --- a/app/views/kanbans/show.html.erb +++ b/app/views/kanbans/show.html.erb @@ -11,28 +11,28 @@

<%= l(:kanban_text_general_help) %>

- <% if pane_configured?('incoming') || pane_configured?('backlog') %> + <% if KanbanPane::IncomingPane.configured? || KanbanPane::BacklogPane.configured? %>
- <% if pane_configured?('incoming') %> + <% if KanbanPane::IncomingPane.configured? %>
<%= render :partial => 'incoming' %>
<% end %> - <% if pane_configured?('backlog') %> + <% if KanbanPane::BacklogPane.configured? %>
<%= render :partial => 'backlog' %>
<% end %>
<% end %> - <% if display_pane?('quick-tasks') || pane_configured?('selected') %> + <% if KanbanPane::QuickPane.configured? || KanbanPane::SelectedPane.configured? %>
- <% if display_pane?('quick-tasks') %> + <% if KanbanPane::QuickPane.configured? %>
<%= render :partial => 'quick' %>
<% end %> - <% if pane_configured?('selected') %> + <% if KanbanPane::SelectedPane.configured? %>
<%= render :partial => 'selected' %>
@@ -42,10 +42,10 @@
<%= content_tag(:div, content_tag(:h3, l(:kanban_text_user)), :class => "staffed-column user", :style => "width: #{staffed_column_width(:user)}%") %> - <%= content_tag(:div, content_tag(:h3, l(:kanban_text_active)), :class => "staffed-column active", :style => "width: #{staffed_column_width(:active)}%") if pane_configured?('active') %> - <%= content_tag(:div, content_tag(:h3, l(:kanban_text_testing)), :class => "staffed-column testing", :style => "width: #{staffed_column_width(:testing)}%") if pane_configured?('testing') %> - <%= content_tag(:div, content_tag(:h3, l(:kanban_text_finished_requests)), :class => "staffed-column finished", :style => "width: #{staffed_column_width(:finished)}%") if pane_configured?('finished') %> - <%= content_tag(:div, content_tag(:h3, l(:kanban_text_canceled_requests)), :class => "staffed-column canceled", :style => "width: #{staffed_column_width(:canceled)}%") if pane_configured?('canceled') %> + <%= content_tag(:div, content_tag(:h3, l(:kanban_text_active)), :class => "staffed-column active", :style => "width: #{staffed_column_width(:active)}%") if KanbanPane::ActivePane.configured? %> + <%= content_tag(:div, content_tag(:h3, l(:kanban_text_testing)), :class => "staffed-column testing", :style => "width: #{staffed_column_width(:testing)}%") if KanbanPane::TestingPane.configured? %> + <%= content_tag(:div, content_tag(:h3, l(:kanban_text_finished_requests)), :class => "staffed-column finished", :style => "width: #{staffed_column_width(:finished)}%") if KanbanPane::FinishedPane.configured? %> + <%= content_tag(:div, content_tag(:h3, l(:kanban_text_canceled_requests)), :class => "staffed-column canceled", :style => "width: #{staffed_column_width(:canceled)}%") if KanbanPane::CanceledPane.configured? %>
diff --git a/test/unit/helpers/kanbans_helper_test.rb b/test/unit/helpers/kanbans_helper_test.rb index 9cdeaaf..24ac809 100644 --- a/test/unit/helpers/kanbans_helper_test.rb +++ b/test/unit/helpers/kanbans_helper_test.rb @@ -8,12 +8,15 @@ class KanbansHelperTest < HelperTestCase def setup super + # Stub KanbanPane#settings so it will bypass the Settings cache. + def KanbanPane.settings + return Setting['plugin_redmine_kanban'] + end end def enable_pane(pane) new_panes = Setting['plugin_redmine_kanban']['panes'].merge({pane.to_s => {'status' => '1'}}) reconfigure_plugin(Setting['plugin_redmine_kanban'].merge('panes' => new_panes)) - @settings = Setting['plugin_redmine_kanban'] end context "#column_width" do @@ -28,9 +31,6 @@ def enable_pane(pane) 'finished' => {}, 'canceled' => {} }}) - - @settings = Setting['plugin_redmine_kanban'] - end context "for unstaffed" do @@ -42,9 +42,9 @@ def enable_pane(pane) enable_pane(:incoming) enable_pane(:backlog) - assert pane_configured?('incoming') - assert pane_configured?('backlog') - assert !pane_configured?('selected') + assert KanbanPane::IncomingPane.configured? + assert KanbanPane::BacklogPane.configured? + assert !KanbanPane::SelectedPane.configured? assert_equal 19.2, column_width(:unstaffed) end @@ -54,9 +54,9 @@ def enable_pane(pane) enable_pane(:backlog) enable_pane(:selected) - assert pane_configured?('incoming') - assert pane_configured?('backlog') - assert pane_configured?('selected') + assert KanbanPane::IncomingPane.configured? + assert KanbanPane::BacklogPane.configured? + assert KanbanPane::SelectedPane.configured? assert_equal 16.0, column_width(:unstaffed) end @@ -70,9 +70,9 @@ def enable_pane(pane) should "be 19.2 if selected and staffed are enabled" do enable_pane(:selected) - assert !pane_configured?('incoming') - assert !pane_configured?('backlog') - assert pane_configured?('selected') + assert !KanbanPane::IncomingPane.configured? + assert !KanbanPane::BacklogPane.configured? + assert KanbanPane::SelectedPane.configured? assert_equal 19.2, column_width(:selected) end @@ -82,9 +82,9 @@ def enable_pane(pane) enable_pane(:backlog) enable_pane(:selected) - assert pane_configured?('incoming') - assert pane_configured?('backlog') - assert pane_configured?('selected') + assert KanbanPane::IncomingPane.configured? + assert KanbanPane::BacklogPane.configured? + assert KanbanPane::SelectedPane.configured? assert_equal 16.0, column_width(:selected) end @@ -99,8 +99,8 @@ def enable_pane(pane) enable_pane(:incoming) enable_pane(:backlog) - assert pane_configured?('incoming') - assert pane_configured?('backlog') + assert KanbanPane::IncomingPane.configured? + assert KanbanPane::BacklogPane.configured? assert_equal 76.8, column_width(:staffed) end @@ -108,7 +108,7 @@ def enable_pane(pane) should "be 76.8 if selected and staffed are enabled" do enable_pane(:selected) - assert pane_configured?('selected') + assert KanbanPane::SelectedPane.configured? assert_equal 76.8, column_width(:staffed) end @@ -118,9 +118,9 @@ def enable_pane(pane) enable_pane(:backlog) enable_pane(:selected) - assert pane_configured?('incoming') - assert pane_configured?('backlog') - assert pane_configured?('selected') + assert KanbanPane::IncomingPane.configured? + assert KanbanPane::BacklogPane.configured? + assert KanbanPane::SelectedPane.configured? assert_equal 64.0, column_width(:staffed) end