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

Add "name" as a query parameter to be able to pass the name for the unsaved default queries to the frontend

Henriette Darge4c93f8139a4a
diff --git a/frontend/src/app/features/work-packages/routing/work-packages-gantt-routes.ts b/frontend/src/app/features/work-packages/routing/work-packages-gantt-routes.ts
index 938525ea8bc..aef995ba07a 100644
--- a/frontend/src/app/features/work-packages/routing/work-packages-gantt-routes.ts
+++ b/frontend/src/app/features/work-packages/routing/work-packages-gantt-routes.ts
@@ -39,7 +39,7 @@ export const WORK_PACKAGES_GANTT_ROUTES:Ng2StateDeclaration[] = [
{
name: 'gantt',
parent: 'optional_project',
- url: '/gantt?query_id&query_props&start_onboarding_tour',
+ url: '/gantt?query_id&query_props&name&start_onboarding_tour',
redirectTo: 'gantt.partitioned.list',
views: {
'!$default': { component: WorkPackagesBaseComponent },
@@ -54,6 +54,7 @@ export const WORK_PACKAGES_GANTT_ROUTES:Ng2StateDeclaration[] = [
query_props: { type: 'opQueryString' },
// Optional initial tour param
start_onboarding_tour: { type: 'query', squash: true, value: undefined },
+ name: { type: 'string', dynamic: true },
},
},
{
diff --git a/frontend/src/app/shared/components/op-view-select/op-static-queries.service.ts b/frontend/src/app/shared/components/op-view-select/op-static-queries.service.ts
index 3b85809c52b..0cf48c4cab8 100644
--- a/frontend/src/app/shared/components/op-view-select/op-static-queries.service.ts
+++ b/frontend/src/app/shared/components/op-view-select/op-static-queries.service.ts
@@ -91,6 +91,11 @@ export class StaticQueriesService {
if (matched) {
return matched.title;
}
+
+ if (this.$state.params.name) {
+ const nameKey = this.$state.params.name as string;
+ return this.I18n.t(`js.queries.${nameKey}`);
+ }
}
// Try to detect the all open filter
diff --git a/modules/gantt/app/controllers/gantt/gantt_controller.rb b/modules/gantt/app/controllers/gantt/gantt_controller.rb
index 2950e0d8c3f..86ad61479de 100644
--- a/modules/gantt/app/controllers/gantt/gantt_controller.rb
+++ b/modules/gantt/app/controllers/gantt/gantt_controller.rb
@@ -17,14 +17,12 @@ module ::Gantt
return redirect_to(
project_gantt_index_path(
@project,
- query_props: ::Gantt::DefaultQueryGeneratorService.new(with_project_context: true).call
+ ::Gantt::DefaultQueryGeneratorService.new(with_project_context: true).call
)
)
else
return redirect_to(
- gantt_index_path(
- query_props: ::Gantt::DefaultQueryGeneratorService.new(with_project_context: false).call
- )
+ gantt_index_path(Gantt::DefaultQueryGeneratorService.new(with_project_context: false).call)
)
end
end
diff --git a/modules/gantt/app/controllers/gantt/menus_controller.rb b/modules/gantt/app/controllers/gantt/menus_controller.rb
index 9e86583fffa..9e2dd962d1c 100644
--- a/modules/gantt/app/controllers/gantt/menus_controller.rb
+++ b/modules/gantt/app/controllers/gantt/menus_controller.rb
@@ -49,7 +49,7 @@ module Gantt
base_query
.where('starred' => 't')
.pluck(:id, :name)
- .map { |id, name| menu_item(:query_id, id, name) }
+ .map { |id, name| menu_item({ query_id: id }, name) }
end
def default_queries
@@ -57,7 +57,6 @@ module Gantt
queries = []
Gantt::DefaultQueryGeneratorService::QUERY_OPTIONS.each do |query_key|
queries << menu_item(
- :query_props,
query_generator.call(query_key:),
Gantt::DefaultQueryGeneratorService::QUERY_MAPPINGS[query_key]
)
@@ -71,7 +70,7 @@ module Gantt
.where('starred' => 'f')
.where('public' => 't')
.pluck(:id, :name)
- .map { |id, name| menu_item(:query_id, id, name) }
+ .map { |id, name| menu_item({ query_id: id }, name) }
end
def custom_queries
@@ -79,7 +78,7 @@ module Gantt
.where('starred' => 'f')
.where('public' => 'f')
.pluck(:id, :name)
- .map { |id, name| menu_item(:query_id, id, name) }
+ .map { |id, name| menu_item({ query_id: id }, name) }
end
def base_query
@@ -95,21 +94,27 @@ module Gantt
base_query
end
- def menu_item(filter_key, filter_val, name)
+ def menu_item(query_params, name)
OpenProject::Menu::MenuItem.new(title: name,
- href: gantt_path(filter_key, filter_val),
- selected: selected?(filter_key, filter_val))
+ href: gantt_path(query_params),
+ selected: selected?(query_params))
end
- def selected?(filter_key, value)
- params[filter_key] == value.to_s
+ def selected?(query_params)
+ query_params.each_key do |filter_key|
+ if params[filter_key] != query_params[filter_key].to_s
+ return false
+ end
+ end
+
+ true
end
- def gantt_path(filter_key, id)
+ def gantt_path(query_params)
if @project.present?
- project_gantt_index_path(@project, params.permit(filter_key).merge!(filter_key => id))
+ project_gantt_index_path(@project, params.permit(query_params.keys).merge!(query_params))
else
- gantt_index_path(params.permit(filter_key).merge!(filter_key => id))
+ gantt_index_path(params.permit(query_params.keys).merge!(query_params))
end
end
end
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 4056ebdeb5e..b975cbdedca 100644
--- a/modules/gantt/app/services/gantt/default_query_generator_service.rb
+++ b/modules/gantt/app/services/gantt/default_query_generator_service.rb
@@ -30,9 +30,9 @@ module ::Gantt
class DefaultQueryGeneratorService
DEFAULT_QUERY = :all_open
QUERY_MAPPINGS = {
- DEFAULT_QUERY => I18n.t('queries.all_open'),
- :timeline => I18n.t('queries.timeline'),
- :milestones => I18n.t('queries.milestones')
+ DEFAULT_QUERY => I18n.t('js.queries.all_open'),
+ :timeline => I18n.t('js.queries.timeline'),
+ :milestones => I18n.t('js.queries.milestones')
}.freeze
QUERY_OPTIONS = QUERY_MAPPINGS.keys
@@ -66,7 +66,7 @@ module ::Gantt
return
end
- params.to_json
+ { query_props: params.to_json, name: query_key }
end
class << self
diff --git a/modules/gantt/app/views/gantt/menus/_menu.html.erb b/modules/gantt/app/views/gantt/menus/_menu.html.erb
index 929fd074c6a..a2167a1442c 100644
--- a/modules/gantt/app/views/gantt/menus/_menu.html.erb
+++ b/modules/gantt/app/views/gantt/menus/_menu.html.erb
@@ -1,5 +1,5 @@
<%= turbo_frame_tag "gantt_menu",
- src: @project ? menu_project_gantt_index_path(@project, params.permit(:query_props, :query_id)) : gantt_menu_path(params.permit(:query_props, :query_id)),
+ src: @project ? menu_project_gantt_index_path(@project, params.permit(:query_props, :query_id, :name)) : gantt_menu_path(params.permit(:query_props, :query_id, :name)),
target: '_top',
data: { turbo: false },
loading: :lazy %>
diff --git a/modules/gantt/config/locales/en.yml b/modules/gantt/config/locales/en.yml
index ea1a8eb5fb2..13d8dabe726 100644
--- a/modules/gantt/config/locales/en.yml
+++ b/modules/gantt/config/locales/en.yml
@@ -1,7 +1,3 @@
# English strings go here
en:
project_module_gantt: "Gantt"
- queries:
- all_open: 'All open'
- timeline: 'Timeline'
- milestones: 'Milestones'
diff --git a/modules/gantt/config/locales/js-en.yml b/modules/gantt/config/locales/js-en.yml
new file mode 100644
index 00000000000..cac5469b08a
--- /dev/null
+++ b/modules/gantt/config/locales/js-en.yml
@@ -0,0 +1,6 @@
+en:
+ js:
+ queries:
+ all_open: 'All open'
+ timeline: 'Timeline'
+ milestones: 'Milestones'