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

[34312] Update and use default settings for gantt query

Oliver Günther8db5e901938d
diff --git a/app/services/projects/gantt_query_generator_service.rb b/app/services/projects/gantt_query_generator_service.rb
index 9a9e5aea8fe..19c8572ef46 100644
--- a/app/services/projects/gantt_query_generator_service.rb
+++ b/app/services/projects/gantt_query_generator_service.rb
@@ -31,10 +31,23 @@
module Projects
class GanttQueryGeneratorService
DEFAULT_GANTT_QUERY ||=
- '{"c":["type","id","subject","status","project"],"tv":true,"hi":false,"g":"project"}'.freeze
+ {
+ c: %w[type id subject status],
+ tll: '{"left":"startDate","right":"dueDate","farRight":null}',
+ tzl: "auto",
+ tv: true,
+ hi: false,
+ g: "project"
+ }.to_json.freeze
attr_reader :selected_project_ids
+ ##
+ # Returns the current query or the default one if none was saved
+ def self.current_query
+ Setting.project_gantt_query.presence || DEFAULT_GANTT_QUERY
+ end
+
def initialize(selected_project_ids)
@selected_project_ids = selected_project_ids
end
@@ -67,8 +80,7 @@ module Projects
private
def params_from_settings
- setting = Setting.project_gantt_query.presence || DEFAULT_GANTT_QUERY
- JSON.parse(setting)
+ JSON.parse(self.class.current_query)
rescue JSON::JSONError => e
Rails.logger.error "Failed to read project gantt view, resetting to default. Error was: #{e.message}"
Setting.project_gantt_query = DEFAULT_GANTT_QUERY
diff --git a/app/views/settings/_projects.html.erb b/app/views/settings/_projects.html.erb
index dc6f3842799..17b4c46fe02 100644
--- a/app/views/settings/_projects.html.erb
+++ b/app/views/settings/_projects.html.erb
@@ -68,7 +68,7 @@ See docs/COPYRIGHT.rdoc for more details.
data: {
name: 'settings[project_gantt_query]',
id: 'settings_project_gantt_query',
- query: Setting.project_gantt_query,
+ query: ::Projects::GanttQueryGeneratorService.current_query,
'url-params': 'true'
}
%>