diff --git a/app/views/settings/_better_gantt_chart_settings.rhtml b/app/views/settings/_better_gantt_chart_settings.rhtml index e88c3f4..050b61e 100644 --- a/app/views/settings/_better_gantt_chart_settings.rhtml +++ b/app/views/settings/_better_gantt_chart_settings.rhtml @@ -7,3 +7,8 @@
Disabled: 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.
Note, that with any value of the setting start and due dates can always be set to a weekend manually.

+

+
+ +<%= check_box_tag('settings[smart_sorting]', @settings['smart_sorting'], @settings['smart_sorting']) %> +

diff --git a/config/locales/en.yml b/config/locales/en.yml index dc4302f..cecd46b 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2,3 +2,4 @@ en: field_duration: "Duration" work_on_weekends_label: "Work on weekends" + smart_sorting_label: "Smart sorting" diff --git a/init.rb b/init.rb index 7cd7a37..5994a16 100644 --- a/init.rb +++ b/init.rb @@ -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 diff --git a/lib/redmine/helpers/better_gantt.rb b/lib/redmine/helpers/better_gantt.rb index 28c762c..0ac3da4 100644 --- a/lib/redmine/helpers/better_gantt.rb +++ b/lib/redmine/helpers/better_gantt.rb @@ -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 diff --git a/lib/redmine_better_gantt_chart/redmine_better_gantt_chart.rb b/lib/redmine_better_gantt_chart/redmine_better_gantt_chart.rb index a5a0261..a36eaed 100644 --- a/lib/redmine_better_gantt_chart/redmine_better_gantt_chart.rb +++ b/lib/redmine_better_gantt_chart/redmine_better_gantt_chart.rb @@ -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