Skip to content

Commit

Permalink
Added plugin setting 'Smart sorting'
Browse files Browse the repository at this point in the history
  • Loading branch information
kulesa committed Feb 22, 2012
1 parent ab801af commit b2dba62
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/views/settings/_better_gantt_chart_settings.rhtml
Expand Up @@ -7,3 +7,8 @@
<br /><strong>Disabled</strong>: a week has 5 working days. If start or due date falls on a weekend when the issue is rescheduled automatically, it is moved to the next Monday.
<br />Note, that with any value of the setting start and due dates can always be set to a weekend manually.
</p>
<p>
<br />
<label for="settings_smart_sorting"><%= h l(:smart_sorting_label) %>:</label>
<%= check_box_tag('settings[smart_sorting]', @settings['smart_sorting'], @settings['smart_sorting']) %>
</p>
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -2,3 +2,4 @@
en:
field_duration: "Duration"
work_on_weekends_label: "Work on weekends"
smart_sorting_label: "Smart sorting"
3 changes: 2 additions & 1 deletion init.rb
Expand Up @@ -39,7 +39,8 @@
requires_redmine :version_or_higher => '1.1.0'

settings(:default => {
'work_on_weekends' => true
'work_on_weekends' => true,
'smart_sorting' => true
}, :partial => "settings/better_gantt_chart_settings")
end

Expand Down
14 changes: 10 additions & 4 deletions lib/redmine/helpers/better_gantt.rb
Expand Up @@ -694,11 +694,17 @@ def gantt_issue_compare(x, y, issues = nil)
end

def get_compare_params(issue)
start_date = issue.start_date or Date.new()
identifying_id = issue.leaf? ? issue.parent_id : issue.id
identifying_start = issue.leaf? && issue.parent.present? ? issue.parent.start_date : start_date
if RedmineBetterGanttChart.smart_sorting?
# Smart sorting: issues sorted first by start date of their parent issue, then by id of parent issue, then by start date
start_date = issue.start_date or Date.new()
identifying_id = issue.leaf? ? issue.parent_id : issue.id
identifying_start = issue.leaf? && issue.parent.present? ? issue.parent.start_date : start_date

[issue.root_id, identifying_start, identifying_id, start_date, issue.lft]
[issue.root_id, identifying_start, identifying_id, start_date, issue.lft]
else
# Default Redmine sorting
[issue.root_id, issue.lft]
end
end

def current_limit
Expand Down
4 changes: 4 additions & 0 deletions lib/redmine_better_gantt_chart/redmine_better_gantt_chart.rb
Expand Up @@ -2,4 +2,8 @@ module RedmineBetterGanttChart
def self.work_on_weekends?
Setting['plugin_redmine_better_gantt_chart']['work_on_weekends']
end

def self.smart_sorting?
Setting['plugin_redmine_better_gantt_chart']['smart_sorting']
end
end

0 comments on commit b2dba62

Please sign in to comment.