Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation/53233 replace sidemenu of work package page with rails component #15982

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</div>
<% end %>

<div class="op-sidebar--body">
<div class="op-sidebar--body" data-test-selector="op-sidebar--body">
<% if top_level_sidebar_menu_items.any? %>
<div class="op-sidemenu">
<ul class="op-sidemenu--items">
Expand Down
37 changes: 37 additions & 0 deletions app/controllers/work_packages/menus_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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 WorkPackages
class MenusController < ApplicationController
before_action :load_and_authorize_in_optional_project

def show
@sidebar_menu_items = WorkPackages::Menu.new(project: @project, params:, request:).menu_items
render layout: nil
end
end
end
5 changes: 4 additions & 1 deletion app/menus/submenu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def starred_queries
.where("starred" => "t")
.pluck(:id, :name)
.map { |id, name| menu_item(name, query_params(id)) }
.sort_by(&:title)
end

def default_queries
Expand All @@ -61,6 +62,7 @@ def global_queries
.where("public" => "t")
.pluck(:id, :name)
.map { |id, name| menu_item(name, query_params(id)) }
.sort_by(&:title)
end

def custom_queries
Expand All @@ -69,6 +71,7 @@ def custom_queries
.where("public" => "f")
.pluck(:id, :name)
.map { |id, name| menu_item(name, query_params(id)) }
.sort_by(&:title)
end

def base_query
Expand Down Expand Up @@ -102,7 +105,7 @@ def selected?(query_params)
end
end

if query_params.empty? && params[:filters].present?
if query_params.empty? && (%i[filters query_props query_id name].any? { |k| params.key? k })
return false
end

Expand Down
91 changes: 91 additions & 0 deletions app/menus/work_packages/menu.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# -- 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 WorkPackages
class Menu < Submenu
attr_reader :view_type, :project, :params

def initialize(project: nil, params: nil, request: nil)
@view_type = "work_packages_table"
@request = request

super(view_type:, project:, params:)
end

def default_queries
query_generator = WorkPackages::DefaultQueryGeneratorService.new(with_project: project)
WorkPackages::DefaultQueryGeneratorService::QUERY_OPTIONS.filter_map do |query_key|
params = query_generator.call(query_key:)
next if params.nil?

menu_item(
I18n.t("js.work_packages.default_queries.#{query_key}"),
params
)
end
end

def query_path(query_params)
if !EnterpriseToken.allows_to?(:work_package_sharing) &&
%i[shared_with_users shared_with_me].any?(query_params[:name])
return ee_upsale_path(query_params)
end

if project.present?
return report_project_work_packages_path(project, { name: query_params[:name] }) if query_params[:name] == :summary

project_work_packages_path(project, query_params)
else
work_packages_path(query_params)
end
end

def selected?(query_params)
return true if check_for_redirected_urls(query_params)

if query_params[:work_package_default] &&
(%i[filters query_props query_id name].none? { |k| params.key? k }) &&
@request.referer.include?("work_packages")
return true
end

super
end

def ee_upsale_path(query_params)
share_upsale_work_packages_path({ name: query_params[:name] })
end

def check_for_redirected_urls(query_params)
# Special rules, as those are redirected to completely new pages where only the name parameter is preserved
return true if query_params[:name] == :shared_with_me && params[:name] == "shared_with_me"
return true if query_params[:name] == :shared_with_users && params[:name] == "shared_with_users"

true if query_params[:name] == :summary && params[:name] == "summary"
end
end
end
174 changes: 174 additions & 0 deletions app/services/work_packages/default_query_generator_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-2024 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 ::WorkPackages
class DefaultQueryGeneratorService
DEFAULT_QUERY = :all_open
QUERY_OPTIONS = [
DEFAULT_QUERY,
:latest_activity,
:recently_created,
:overdue,
:summary,
:created_by_me,
:assigned_to_me,
:shared_with_users,
:shared_with_me
].freeze

DEFAULT_PARAMS =
{
g: "",
hi: false,
t: "updatedAt:desc,id:asc"
}.freeze

attr_reader :project

def initialize(with_project:)
@project = with_project
end

def call(query_key: DEFAULT_QUERY)
return { work_package_default: true } if query_key == DEFAULT_QUERY

params = self.class.assign_params(query_key, project)

return if params.nil?

{ query_props: params.to_json, name: query_key }
end

class << self
def latest_activity_query
DEFAULT_PARAMS.merge(
{
c: %w[id subject type status assignee updatedAt],
t: "updatedAt:desc",
f: [{ "n" => "status", "o" => "*", "v" => [] }]
}
)
end

def recently_created_query
DEFAULT_PARAMS.merge(
{
c: %w[id subject type status assignee createdAt],
t: "createdAt:desc",
f: [{ "n" => "status", "o" => "o", "v" => [] }]
}
)
end

def overdue_query
DEFAULT_PARAMS.merge(
{
c: %w[id type subject status startDate dueDate duration],
t: "createdAt:desc",
f: [{ "n" => "dueDate", "o" => "<t-", "v" => ["1"] },
{ "n" => "status", "o" => "o", "v" => [] }]
}
)
end

def summary_query
{}
end

def created_by_me_query
DEFAULT_PARAMS.merge(
{
c: %w[id subject type status assignee updatedAt],
f: [{ "n" => "status", "o" => "o", "v" => [] },
{ "n" => "author", "o" => "=", "v" => ["me"] }]
}
)
end

def assigned_to_me_query
DEFAULT_PARAMS.merge(
{
c: %w[id subject type status author updatedAt],
f: [{ "n" => "status", "o" => "o", "v" => [] },
{ "n" => "assigneeOrGroup", "o" => "=", "v" => ["me"] }]
}
)
end

def shared_with_users_query
DEFAULT_PARAMS.merge(
{
c: %w[id subject type project sharedWithUsers],
f: [{ "n" => "sharedWithUser", "o" => "*", "v" => [] }]
}
)
end

def shared_with_me_query
DEFAULT_PARAMS.merge(
{
c: %w[id subject type project],
f: [{ "n" => "sharedWithMe", "o" => "=", "v" => "t" }]
}
)
end

def assign_params(query_key, project)
case query_key
when :latest_activity
latest_activity_query
when :recently_created
recently_created_query
when :overdue
overdue_query
when :summary
return if project.blank?

summary_query
else
return unless User.current.logged?

user_specific_queries(query_key)
end
end

def user_specific_queries(query_key)
case query_key
when :created_by_me
created_by_me_query
when :assigned_to_me
assigned_to_me_query
when :shared_with_users
shared_with_users_query
when :shared_with_me
shared_with_me_query
end
end
end
end
end
12 changes: 0 additions & 12 deletions app/views/work_packages/_menu_query_select.html.erb

This file was deleted.

5 changes: 5 additions & 0 deletions app/views/work_packages/menus/_menu.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= turbo_frame_tag "work_packages_sidemenu",
src: @project ? menu_project_work_packages_path(@project, params.permit(:query_props, :query_id, :name)) : work_packages_menu_path(params.permit(:query_props, :query_id, :name)),
target: "_top",
data: { turbo: false },
loading: :lazy %>
3 changes: 3 additions & 0 deletions app/views/work_packages/menus/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= turbo_frame_tag "work_packages_sidemenu" do %>
<%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @sidebar_menu_items, searchable: true) %>
<% end %>
4 changes: 2 additions & 2 deletions config/initializers/menus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
menu.push :work_packages_query_select,
{ controller: "/work_packages", action: "index" },
parent: :work_packages,
partial: "work_packages/menu_query_select"
partial: "work_packages/menus/menu"

# News
menu.push :news,
Expand Down Expand Up @@ -580,7 +580,7 @@
menu.push :work_packages_query_select,
{ controller: "/work_packages", action: "index" },
parent: :work_packages,
partial: "work_packages/menu_query_select",
partial: "work_packages/menus/menu",
last: true,
caption: :label_all_open_wps

Expand Down
3 changes: 2 additions & 1 deletion config/initializers/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@
journals: %i[index],
work_packages: %i[show index],
work_packages_api: [:get],
"work_packages/reports": %i[report report_details]
"work_packages/reports": %i[report report_details],
"work_packages/menus": %i[show]
},
permissible_on: %i[work_package project],
contract_actions: { work_packages: %i[read] }
Expand Down
Loading
Loading