forked from opf/openproject
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opf#14639 from opf/implementation/51246-default-qu…
…ery-for-new-gantt-module-2 [51246] Default query for new Gantt module
- Loading branch information
Showing
16 changed files
with
419 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
modules/gantt/app/controllers/gantt/menus_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# -- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2010-2023 the OpenProject GmbH | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License version 3. | ||
# | ||
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: | ||
# Copyright (C) 2006-2013 Jean-Philippe Lang | ||
# Copyright (C) 2010-2013 the ChiliProject Team | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU General Public License | ||
# as published by the Free Software Foundation; either version 2 | ||
# of the License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, write to the Free Software | ||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
# | ||
# See COPYRIGHT and LICENSE files for more details. | ||
# ++ | ||
module Gantt | ||
class MenusController < ApplicationController | ||
before_action :find_optional_project | ||
|
||
def show | ||
@sidebar_menu_items = menu_items | ||
render layout: nil | ||
end | ||
|
||
private | ||
|
||
def menu_items | ||
[ | ||
OpenProject::Menu::MenuGroup.new(header: I18n.t('js.label_starred_queries'), children: starred_queries), | ||
OpenProject::Menu::MenuGroup.new(header: I18n.t('js.label_default_queries'), children: default_queries), | ||
OpenProject::Menu::MenuGroup.new(header: I18n.t('js.label_global_queries'), children: global_queries), | ||
OpenProject::Menu::MenuGroup.new(header: I18n.t('js.label_custom_queries'), children: custom_queries) | ||
] | ||
end | ||
|
||
def starred_queries | ||
base_query | ||
.where('starred' => 't') | ||
.pluck(:id, :name) | ||
.map { |id, name| menu_item({ query_id: id }, name) } | ||
end | ||
|
||
def default_queries | ||
query_generator = Gantt::DefaultQueryGeneratorService.new(with_project: @project) | ||
queries = [] | ||
Gantt::DefaultQueryGeneratorService::QUERY_OPTIONS.each do |query_key| | ||
queries << menu_item( | ||
query_generator.call(query_key:), | ||
Gantt::DefaultQueryGeneratorService::QUERY_MAPPINGS[query_key] | ||
) | ||
end | ||
|
||
queries | ||
end | ||
|
||
def global_queries | ||
base_query | ||
.where('starred' => 'f') | ||
.where('public' => 't') | ||
.pluck(:id, :name) | ||
.map { |id, name| menu_item({ query_id: id }, name) } | ||
end | ||
|
||
def custom_queries | ||
base_query | ||
.where('starred' => 'f') | ||
.where('public' => 'f') | ||
.pluck(:id, :name) | ||
.map { |id, name| menu_item({ query_id: id }, name) } | ||
end | ||
|
||
def base_query | ||
base_query ||= Query | ||
.visible(current_user) | ||
.joins(:views, :project) | ||
.where('views.type' => 'gantt') | ||
|
||
if @project.present? | ||
base_query = base_query.where('queries.project_id' => @project.id) | ||
end | ||
|
||
base_query | ||
end | ||
|
||
def menu_item(query_params, name) | ||
OpenProject::Menu::MenuItem.new(title: name, | ||
href: gantt_path(query_params), | ||
selected: selected?(query_params)) | ||
end | ||
|
||
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(query_params) | ||
if @project.present? | ||
project_gantt_index_path(@project, params.permit(query_params.keys).merge!(query_params)) | ||
else | ||
gantt_index_path(params.permit(query_params.keys).merge!(query_params)) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.