-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 #14442 from opf/implementation/51693-add-second-le…
…vel-navigation-for-the-members-page [51693] Add second level navigation for the members page
- Loading branch information
Showing
18 changed files
with
473 additions
and
14 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
52 changes: 52 additions & 0 deletions
52
app/components/open_project/common/submenu_component.html.erb
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,52 @@ | ||
<div class="op-sidebar"> | ||
<div class="op-sidebar--body"> | ||
<% top_level_sidebar_menu_items = @sidebar_menu_items.filter { |menu_item| menu_item.header.nil? } %> | ||
<% if top_level_sidebar_menu_items.any? %> | ||
<div class="op-sidemenu"> | ||
<ul class="op-sidemenu--items"> | ||
<% top_level_sidebar_menu_items.first.children.each do |menu_item| %> | ||
<li class="op-sidemenu--item"> | ||
<% selected = menu_item.selected ? 'selected' : '' %> | ||
<a class="op-sidemenu--item-action <%= selected %>" href="<%= menu_item.href %>"> | ||
<span class="op-sidemenu--item-title"><%= menu_item.title %></span> | ||
</a> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
|
||
|
||
<% nested_sidebar_menu_items = @sidebar_menu_items.filter { |menu_item| menu_item.header.present? } %> | ||
<% if nested_sidebar_menu_items.any? %> | ||
<% nested_sidebar_menu_items.each do |menu_item| %> | ||
<div class="op-sidemenu" | ||
data-controller="menus--expandable-sidemenu" | ||
data-application-target="dynamic"> | ||
|
||
<button class="op-sidemenu--title" | ||
type="button" | ||
data-action="click->menus--expandable-sidemenu#toggleContainer"> | ||
<%= menu_item.header %> | ||
<span class="icon-small icon-arrow-up1" | ||
aria-hidden="true" | ||
data-menus--expandable-sidemenu-target="indicator"> | ||
</span> | ||
</button> | ||
|
||
<ul class="op-sidemenu--items" | ||
data-menus--expandable-sidemenu-target="container"> | ||
<% menu_item.children.each do |child_item| %> | ||
<li class="op-sidemenu--item"> | ||
<% selected = child_item.selected ? 'selected' : '' %> | ||
<a class="op-sidemenu--item-action <%= selected %>" href="<%= child_item.href %>"> | ||
<span class="op-sidemenu--item-title"><%= child_item.title %></span> | ||
</a> | ||
</li> | ||
<% end %> | ||
</ul> | ||
</div> | ||
<% end %> | ||
<% end %> | ||
</div> | ||
</div> |
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,44 @@ | ||
# frozen_string_literal: true | ||
|
||
# -- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 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 OpenProject | ||
module Common | ||
class SubmenuComponent < ApplicationComponent | ||
def initialize(sidebar_menu_items: nil) | ||
super() | ||
@sidebar_menu_items = sidebar_menu_items | ||
end | ||
|
||
def render? | ||
@sidebar_menu_items.present? | ||
end | ||
end | ||
end | ||
end |
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,109 @@ | ||
#-- copyright | ||
# OpenProject is an open source project management software. | ||
# Copyright (C) 2012-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 Members | ||
class MenusController < ApplicationController | ||
before_action :find_project_by_project_id, | ||
:authorize | ||
|
||
def show | ||
@sidebar_menu_items = first_level_menu_items + nested_menu_items | ||
render layout: nil | ||
end | ||
|
||
private | ||
|
||
def first_level_menu_items | ||
[ | ||
OpenProject::Menu::MenuGroup.new(header: nil, children: user_status_options) | ||
] | ||
end | ||
|
||
def user_status_options | ||
[ | ||
OpenProject::Menu::MenuItem.new(title: I18n.t('members.menu.all'), | ||
href: project_members_path, | ||
selected: active_filter_count == 0), | ||
OpenProject::Menu::MenuItem.new(title: I18n.t('members.menu.locked'), | ||
href: project_members_path(status: :locked), | ||
selected: selected?(:status, :locked)), | ||
OpenProject::Menu::MenuItem.new(title: I18n.t('members.menu.invited'), | ||
href: project_members_path(status: :invited), | ||
selected: selected?(:status, :invited)) | ||
] | ||
end | ||
|
||
def nested_menu_items | ||
[ | ||
OpenProject::Menu::MenuGroup.new(header: I18n.t('members.menu.project_roles'), children: project_roles_entries), | ||
OpenProject::Menu::MenuGroup.new(header: I18n.t('members.menu.wp_shares'), children: permission_menu_entries), | ||
OpenProject::Menu::MenuGroup.new(header: I18n.t('members.menu.groups'), children: project_group_entries) | ||
] | ||
end | ||
|
||
private | ||
|
||
def project_roles_entries | ||
ProjectRole | ||
.where(id: MemberRole.where(member_id: @project.members.select(:id)).select(:role_id)) | ||
.distinct | ||
.pluck(:id, :name) | ||
.map { |id, name| menu_item(:role_id, id, name) } | ||
end | ||
|
||
def permission_menu_entries | ||
Members::UserFilterComponent | ||
.share_options | ||
.map { |name, id| menu_item(:shared_role_id, id, name) } | ||
end | ||
|
||
def project_group_entries | ||
@project | ||
.groups | ||
.order(lastname: :asc) | ||
.distinct | ||
.pluck(:id, :lastname) | ||
.map { |id, name| menu_item(:group_id, id, name) } | ||
end | ||
|
||
def menu_item(filter_key, id, name) | ||
OpenProject::Menu::MenuItem.new(title: name, | ||
href: project_members_path(filter_key => id), | ||
selected: selected?(filter_key, id)) | ||
end | ||
|
||
def selected?(filter_key, value) | ||
return false if active_filter_count > 1 | ||
|
||
params[filter_key] == value.to_s | ||
end | ||
|
||
def active_filter_count | ||
@active_filter_count ||= (params.keys & Members::UserFilterComponent.filter_param_keys.map(&:to_s)).count | ||
end | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= turbo_frame_tag "members_menu", | ||
src: project_members_menu_path(@project, params.permit(*Members::UserFilterComponent.filter_param_keys)), | ||
target: '_top', | ||
data: { turbo: false }, | ||
loading: :lazy do %> | ||
<% end %> |
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,3 @@ | ||
<%= turbo_frame_tag "members_menu" do %> | ||
<%= render OpenProject::Common::SubmenuComponent.new(sidebar_menu_items: @sidebar_menu_items) %> | ||
<% end %> |
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
Oops, something went wrong.