Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Handle special case that there are milestones configured but not activated in the current project

Henriette Dargecf73c118d12a
diff --git a/modules/gantt/app/controllers/gantt/gantt_controller.rb b/modules/gantt/app/controllers/gantt/gantt_controller.rb
index 86ad61479de..fc4b17d97f7 100644
--- a/modules/gantt/app/controllers/gantt/gantt_controller.rb
+++ b/modules/gantt/app/controllers/gantt/gantt_controller.rb
@@ -17,12 +17,12 @@ module ::Gantt
return redirect_to(
project_gantt_index_path(
@project,
- ::Gantt::DefaultQueryGeneratorService.new(with_project_context: true).call
+ ::Gantt::DefaultQueryGeneratorService.new(with_project: @project).call
)
)
else
return redirect_to(
- gantt_index_path(Gantt::DefaultQueryGeneratorService.new(with_project_context: false).call)
+ gantt_index_path(Gantt::DefaultQueryGeneratorService.new(with_project: nil).call)
)
end
end
diff --git a/modules/gantt/app/controllers/gantt/menus_controller.rb b/modules/gantt/app/controllers/gantt/menus_controller.rb
index 9e2dd962d1c..b9c77279589 100644
--- a/modules/gantt/app/controllers/gantt/menus_controller.rb
+++ b/modules/gantt/app/controllers/gantt/menus_controller.rb
@@ -53,7 +53,7 @@ module Gantt
end
def default_queries
- query_generator = Gantt::DefaultQueryGeneratorService.new(with_project_context: @project.present?)
+ query_generator = Gantt::DefaultQueryGeneratorService.new(with_project: @project)
queries = []
Gantt::DefaultQueryGeneratorService::QUERY_OPTIONS.each do |query_key|
queries << menu_item(
diff --git a/modules/gantt/app/services/gantt/default_query_generator_service.rb b/modules/gantt/app/services/gantt/default_query_generator_service.rb
index b975cbdedca..77172e88f7c 100644
--- a/modules/gantt/app/services/gantt/default_query_generator_service.rb
+++ b/modules/gantt/app/services/gantt/default_query_generator_service.rb
@@ -48,20 +48,20 @@ module ::Gantt
t: 'start_date:asc'
}.to_json.freeze
- attr_reader :with_project_context
+ attr_reader :project
- def initialize(with_project_context:)
- @with_project_context = with_project_context
+ def initialize(with_project:)
+ @project = with_project
end
def call(query_key: DEFAULT_QUERY)
case query_key
when DEFAULT_QUERY
- params = self.class.all_open_query(@with_project_context)
+ params = self.class.all_open_query(@project)
when :timeline
- params = self.class.timeline_query(@with_project_context)
+ params = self.class.timeline_query(@project)
when :milestones
- params = self.class.milestones_query(@with_project_context)
+ params = self.class.milestones_query(@project)
else
return
end
@@ -70,44 +70,45 @@ module ::Gantt
end
class << self
- def all_open_query(with_project_context)
- default_with_filter = add_columns(with_project_context)
+ def all_open_query(project)
+ default_with_filter = add_columns(project)
default_with_filter['f'] = [{ 'n' => 'status', 'o' => 'o', 'v' => [] }]
default_with_filter
end
- def timeline_query(with_project_context)
- default_with_filter = add_columns(with_project_context)
+ def timeline_query(project)
+ default_with_filter = add_columns(project)
- milestones = milestone_ids
- phase = ::Type.where(name: 'Phase').pluck(:id).map(&:to_s)
-
- type_filter_values = milestones.concat(phase)
- if type_filter_values.any?
- default_with_filter['f'] = [{ 'n' => 'type', 'o' => '=', 'v' => type_filter_values }]
- end
+ type_filter_values = milestone_ids(project).concat(phase_ids(project))
+ default_with_filter['f'] = if type_filter_values.any?
+ [{ 'n' => 'type', 'o' => '=', 'v' => type_filter_values }]
+ else
+ []
+ end
default_with_filter
end
- def milestones_query(with_project_context)
- default_with_filter = add_columns(with_project_context)
+ def milestones_query(project)
+ default_with_filter = add_columns(project)
- milestones = milestone_ids
- if milestone_ids.any?
- default_with_filter['f'] = [{ 'n' => 'type', 'o' => '=', 'v' => milestones }]
- end
+ milestones = milestone_ids(project)
+ default_with_filter['f'] = if milestones.any?
+ [{ 'n' => 'type', 'o' => '=', 'v' => milestones }]
+ else
+ []
+ end
default_with_filter
end
- def add_columns(with_project_context)
+ def add_columns(project)
default_with_filter = JSON
.parse(Gantt::DefaultQueryGeneratorService::DEFAULT_PARAMS)
- default_with_filter['c'] = if with_project_context
+ default_with_filter['c'] = if project.present?
Gantt::DefaultQueryGeneratorService::PROJECT_DEFAULT_COLUMNS
else
Gantt::DefaultQueryGeneratorService::GLOBAL_DEFAULT_COLUMNS
@@ -116,8 +117,20 @@ module ::Gantt
default_with_filter
end
- def milestone_ids
- ::Type.milestone.pluck(:id).map(&:to_s)
+ def milestone_ids(project)
+ if project.present?
+ ::Type.milestone.enabled_in(project.id).pluck(:id).map(&:to_s)
+ else
+ ::Type.milestone.pluck(:id).map(&:to_s)
+ end
+ end
+
+ def phase_ids(project)
+ if project.present?
+ ::Type.enabled_in(project.id).where(name: 'Phase').pluck(:id).map(&:to_s)
+ else
+ ::Type.where(name: 'Phase').pluck(:id).map(&:to_s)
+ end
end
end
end