Skip to content

Commit

Permalink
Refactor: Move the pane configuration helper into KanbanPane
Browse files Browse the repository at this point in the history
  • Loading branch information
edavis10 committed Apr 14, 2010
1 parent 7ed8f8a commit 06107a6
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 60 deletions.
34 changes: 10 additions & 24 deletions app/helpers/kanbans_helper.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions app/models/kanban_pane.rb
@@ -1,12 +1,25 @@
class KanbanPane
def settings
KanbanPane.settings
end

def self.settings
Setting.plugin_redmine_kanban
end

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={})
Expand Down
12 changes: 12 additions & 0 deletions app/models/kanban_pane/quick_pane.rb
Expand Up @@ -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

8 changes: 4 additions & 4 deletions app/views/kanbans/_user.html.erb
Expand Up @@ -4,22 +4,22 @@
<%= call_hook(:view_kanbans_user_name, :user => user) %>
</div>
<% if pane_configured?('active') %>
<% if KanbanPane::ActivePane.configured? %>
<div id="active-<%= h user.id -%>" class="staffed-column pane active user-<%= h user.id -%>" style="width: <%= staffed_column_width(:active) %>%">
<%= render(:partial => 'active', :locals => {:user => user}) %>
</div>
<% end %>
<% if pane_configured?('testing') %>
<% if KanbanPane::TestingPane.configured? %>
<div id="testing-<%= h user.id -%>" class="staffed-column pane testing user-<%= h user.id -%>" style="width: <%= staffed_column_width(:testing) %>%">
<%= render(:partial => 'testing', :locals => {:user => user}) %>
</div>
<% end %>
<% if pane_configured?('finished') %>
<% if KanbanPane::FinishedPane.configured? %>
<div id="finished-<%= h user.id -%>" class="staffed-column pane finished user-<%= h user.id -%>" style="width: <%= staffed_column_width(:finished) %>%">
<%= render(:partial => 'finished', :locals => {:user => user}) %>
</div>
<% end %>
<% if pane_configured?('canceled') %>
<% if KanbanPane::CanceledPane.configured? %>
<div id="canceled-<%= h user.id -%>" class="staffed-column pane canceled user-<%= h user.id -%>" style="width: <%= staffed_column_width(:canceled) %>%">
<%= render(:partial => 'canceled', :locals => {:user => user}) %>
</div>
Expand Down
20 changes: 10 additions & 10 deletions app/views/kanbans/show.html.erb
Expand Up @@ -11,28 +11,28 @@
<p class="general-help"><%= l(:kanban_text_general_help) %></p>

<div id="kanban">
<% if pane_configured?('incoming') || pane_configured?('backlog') %>
<% if KanbanPane::IncomingPane.configured? || KanbanPane::BacklogPane.configured? %>
<div id="unstaffed-requests" class="column" style="width: <%= column_width(:unstaffed) %>%">
<% if pane_configured?('incoming') %>
<% if KanbanPane::IncomingPane.configured? %>
<div id="incoming" class="pane">
<%= render :partial => 'incoming' %>
</div>
<% end %>
<% if pane_configured?('backlog') %>
<% if KanbanPane::BacklogPane.configured? %>
<div id="backlog" class="pane">
<%= render :partial => 'backlog' %>
</div>
<% end %>
</div>
<% end %>
<% if display_pane?('quick-tasks') || pane_configured?('selected') %>
<% if KanbanPane::QuickPane.configured? || KanbanPane::SelectedPane.configured? %>
<div id="selected-requests" class="column" style="width: <%= column_width(:selected) %>%">
<% if display_pane?('quick-tasks') %>
<% if KanbanPane::QuickPane.configured? %>
<div id="quick-tasks" class="pane">
<%= render :partial => 'quick' %>
</div>
<% end %>
<% if pane_configured?('selected') %>
<% if KanbanPane::SelectedPane.configured? %>
<div id="selected-tasks"class="pane">
<%= render :partial => 'selected' %>
</div>
Expand All @@ -42,10 +42,10 @@
<div id="staffed-requests" class="column" style="width: <%= column_width(:staffed) %>%">
<div id="staffed-requests-header" class="staff">
<%= 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? %>
</div>
<div style="clear:both"></div>

Expand Down
44 changes: 22 additions & 22 deletions test/unit/helpers/kanbans_helper_test.rb
Expand Up @@ -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
Expand All @@ -28,9 +31,6 @@ def enable_pane(pane)
'finished' => {},
'canceled' => {}
}})

@settings = Setting['plugin_redmine_kanban']

end

context "for unstaffed" do
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -99,16 +99,16 @@ 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

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
Expand All @@ -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
Expand Down

0 comments on commit 06107a6

Please sign in to comment.