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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add the `Projects` menu item with sidebar filters to the global menu
Aaron Contrerasadb589bab970
diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex 51466ac18b6..fbe354fae79 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -41,7 +41,7 @@ class ProjectsController < ApplicationControllerinclude ProjectsHelpercurrent_menu_item :index do- :list_projects+ :projectsenddef index@@ -56,7 +56,7 @@ class ProjectsController < ApplicationControllerrespond_to do |format|format.html do- render layout: 'no_menu'+ render layout: 'global'endformat.any(*supported_export_formats) dodiff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rbindex 95f673dc847..df54a433b32 100644--- a/app/helpers/projects_helper.rb+++ b/app/helpers/projects_helper.rb@@ -64,6 +64,65 @@ module ProjectsHelperendend+ def global_menu_items+ [+ global_menu_all_projects_item,+ global_menu_public_projects_item,+ global_menu_archived_projects_item+ ]+ end++ def global_menu_all_projects_item+ path = projects_path++ [+ t(:label_all_projects),+ path,+ { class: global_menu_item_css_class(path),+ title: t(:label_all_projects) }+ ]+ end++ def global_menu_public_projects_item+ path = projects_path_with_filters(+ [{ public: { operator: '=', values: ['t'] } }]+ )++ [+ t(:label_public_projects),+ path,+ { class: global_menu_item_css_class(path),+ title: t(:label_public_projects) }+ ]+ end++ def global_menu_archived_projects_item+ path = projects_path_with_filters(+ [{ active: { operator: '=', values: ['f'] } }]+ )++ [+ t(:label_archived_projects),+ path,+ { class: global_menu_item_css_class(path),+ title: t(:label_archived_projects) }+ ]+ end++ def projects_path_with_filters(filters)+ return projects_path if filters.empty?++ projects_path(filters: filters.to_json)+ end++ def global_menu_item_css_class(path)+ "op-sidemenu--item-action #{global_menu_item_selected(path) ? 'selected' : ''}"+ end++ def global_menu_item_selected(menu_item_path)+ menu_item_path == request.fullpath+ end+def project_more_menu_items(project)[project_more_menu_subproject_item(project),project_more_menu_settings_item(project),diff --git a/app/views/projects/_menu_query_select.html.erb b/app/views/projects/_menu_query_select.html.erbnew file mode 100644index 00000000000..ca845f86afc--- /dev/null+++ b/app/views/projects/_menu_query_select.html.erb@@ -0,0 +1,26 @@+<div class="op-sidebar">+ <div class="op-sidebar--body">+ <div class="op-sidemenu">+ <ul class="op-sidemenu--items">+ <% global_menu_items.each do |menu_item| %>+ <li class="op-sidemenu--item">+ <%= link_to *menu_item %>+ </li>+ <% end %>+ </ul>+ </div>+ </div>++ <div class="op-sidebar--footer">+ <% if User.current.allowed_to_globally?(:add_project) %>+ <%= button_to new_project_path,+ { method: :get,+ class: 'button -alt-highlight -expand',+ aria: { label: t(:label_project_new) },+ title: t(:label_project_new) } do %>+ <%= spot_icon('add') %>+ <span><%= Project.model_name.human %></span>+ <% end %>+ <% end %>+ </div>+</div>diff --git a/config/initializers/menus.rb b/config/initializers/menus.rbindex a4ffe77bd2b..d535e226a12 100644--- a/config/initializers/menus.rb+++ b/config/initializers/menus.rb@@ -128,11 +128,26 @@ Redmine::MenuManager.map :global_menu do |menu|icon: 'home',first: true+ # Projects+ menu.push :projects,+ { controller: '/projects', project_id: nil, action: 'index' },+ caption: I18n.t('label_projects_menu'),+ icon: 'projects',+ after: :home,+ if: Proc.new {+ (User.current.logged? || !Setting.login_required?)+ }++ menu.push :projects_query_select,+ { controller: '/projects', project_id: nil, action: 'index' },+ parent: :projects,+ partial: 'projects/menu_query_select'+# Activitymenu.push :activity,{ controller: '/activities', action: 'index' },icon: 'checkmark',- after: :home+ after: :projectsmenu.push :activity_filters,{ controller: '/activities', action: 'index' },diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 6213fde3fb9..9bc3ab5552b 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -1578,6 +1578,7 @@ en:label_age: "Age"label_ago: "days ago"label_all: "all"+ label_all_projects: "All projects"label_all_time: "all time"label_all_words: "All words"label_all_open_wps: "All open"@@ -1594,6 +1595,7 @@ en:label_ical_access_key_revoke: "Revoke"label_applied_status: "Applied status"label_archive_project: "Archive project"+ label_archived_projects: "Archived projects"label_ascending: "Ascending"label_assigned_to_me_work_packages: "Work packages assigned to me"label_associated_revisions: "Associated revisions"diff --git a/modules/reporting/app/views/cost_reports/_report_menu.html.erb b/modules/reporting/app/views/cost_reports/_report_menu.html.erbindex 3fd6ae370ea..d1d0a0bf659 100644--- a/modules/reporting/app/views/cost_reports/_report_menu.html.erb+++ b/modules/reporting/app/views/cost_reports/_report_menu.html.erb@@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.++#%><% [:private, :public].each do |report_type| %>- <div class="tree-menu--container" data-selected-page="<%= @query ? @query.name : '' %>">+ <div class="tree-menu--container"><ul class="pages-hierarchy -with-hierarchy"><li class="-hierarchy-expanded"><span class="tree-menu--item">diff --git a/spec/features/projects/create_spec.rb b/spec/features/projects/create_spec.rbindex 9e0eee03b15..bf226bcaa0a 100644--- a/spec/features/projects/create_spec.rb+++ b/spec/features/projects/create_spec.rb@@ -29,20 +29,38 @@require 'spec_helper'RSpec.describe 'Projects', 'creation',- js: true,- with_cuprite: true do- let(:name_field) { FormFields::InputFormField.new :name }+ :js,+ :with_cuprite do+ shared_let(:name_field) { FormFields::InputFormField.new :name }current_user { create(:admin) }shared_let(:project) { create(:project, name: 'Foo project', identifier: 'foo-project') }+ let(:projects_page) { Pages::Projects::Index.new }+before do- visit projects_path+ projects_page.visit!+ end++ context 'within the button on the global sidebar' do+ it 'can navigate to the create project page' do+ projects_page.navigate_to_new_project_page_from_global_sidebar++ expect(page).to have_current_path(new_project_path)+ end+ end++ context 'with the button on the toolbar items' do+ it 'can navigate to the create project page' do+ projects_page.navigate_to_new_project_page_from_toolbar_items++ expect(page).to have_current_path(new_project_path)+ endendit 'can create a project' do- click_on 'New project'+ projects_page.navigate_to_new_project_page_from_toolbar_itemsname_field.set_value 'Foo bar'click_button 'Save'@@ -52,7 +70,7 @@ RSpec.describe 'Projects', 'creation',endit 'does not create a project with an already existing identifier' do- click_on 'New project'+ projects_page.navigate_to_new_project_page_from_toolbar_itemsname_field.set_value 'Foo project'click_on 'Save'@@ -68,7 +86,7 @@ RSpec.describe 'Projects', 'creation',let(:list_field) { FormFields::SelectFormField.new list_custom_field }it 'can create a project' do- click_on 'New project'+ projects_page.navigate_to_new_project_page_from_toolbar_itemsname_field.set_value 'Foo bar'diff --git a/spec/features/projects/global_menu_item_spec.rb b/spec/features/projects/global_menu_item_spec.rbnew file mode 100644index 00000000000..5b4864050d5--- /dev/null+++ b/spec/features/projects/global_menu_item_spec.rb@@ -0,0 +1,65 @@+# 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.+# +++#++require 'spec_helper'++RSpec.describe 'Projects global menu item', :js, :with_cuprite do+ let(:user) { create(:user) }++ before do+ login_as user+ visit root_path+ end++ it 'navigates to the projects#index page' do+ within '#main-menu' do+ click_link text: 'Projects'+ end++ expect(page).to have_current_path(projects_path)+ end++ context 'when navigated to the projects#index page' do+ before do+ within '#main-menu' do+ click_link text: 'Projects'+ end+ end++ it 'renders the preset filters' do+ within '#main-menu' do+ expect(page).to have_link text: I18n.t(:label_all_projects)+ expect(page).to have_link text: I18n.t(:label_public_projects)+ expect(page).to have_link text: I18n.t(:label_archived_projects)+ end+ end+ end+enddiff --git a/spec/features/projects/projects_index_spec.rb b/spec/features/projects/projects_index_spec.rbindex 0939bb7c114..309e3b0596e 100644--- a/spec/features/projects/projects_index_spec.rb+++ b/spec/features/projects/projects_index_spec.rb@@ -212,6 +212,63 @@ RSpec.describe 'Projects index page',endend+ context 'when filtering with the global sidebar' do+ before do+ login_as admin+ projects_page.visit!+ end++ context 'with the "All projects" filter' do+ before do+ projects_page.set_sidebar_filter 'All projects'+ end++ it 'shows all active projects (default)' do+ projects_page.expect_projects_listed(project,+ public_project,+ development_project)++ expect(page).to have_selector('li[filter-name="active"]', visible: :hidden)+ end+ end++ context 'with the "Public projects" filter' do+ before do+ projects_page.set_sidebar_filter 'Public projects'+ end++ it 'shows all public projects' do+ projects_page.expect_projects_listed(public_project)+ projects_page.expect_projects_not_listed(project,+ development_project)++ expect(page).to have_selector('li[filter-name="public"]')+ end+ end++ context 'with the "Archived projects" filter' do+ shared_let(:archived_project) do+ create(:project,+ name: 'Archived project',+ identifier: 'archived-project',+ active: false)+ end++ before do+ projects_page.set_sidebar_filter 'Archived projects'+ end++ it 'shows all archived projects' do+ projects_page.expect_projects_listed(archived_project, archived: true)+ projects_page.expect_projects_not_listed(public_project,+ project,+ development_project)++ expect(page).to have_selector('li[filter-name="active"]')+ end+ end+ end+context 'with a filter set' doit 'only shows the matching projects and filters' doload_and_open_filters admin@@ -223,8 +280,8 @@ RSpec.describe 'Projects index page',click_on 'Apply'# Filter is applied: Only the project that contains the the word "Plain" gets listed- expect(page).not_to have_text(public_project.name)- expect(page).to have_text(project.name)+ projects_page.expect_projects_listed(project)+ projects_page.expect_projects_not_listed(public_project)# Filter form is visible and the filter is still set.expect(page).to have_selector('li[filter-name="name_and_identifier"]')end@@ -251,10 +308,10 @@ RSpec.describe 'Projects index page',wait_for_reload# Results should be filtered and ordered ASC by name- expect(page).to have_text(development_project.name)- expect(page).not_to have_text(project.name) # as it filtered away+ projects_page.expect_projects_listed(development_project)+ projects_page.expect_projects_not_listed(project, # as it is filtered out+ public_project) # as it is on the second pageexpect(page).to have_text('Next') # as the result set is larger than 1- expect(page).not_to have_text(public_project.name) # as it is on the second page# Changing the page size to 5 and back to 1 should not change the filters (which we test later on the second page)find('.op-pagination--options .op-pagination--item', text: '5').click # click page size '5'@@ -264,20 +321,21 @@ RSpec.describe 'Projects index page',click_on '2' # Go to pagination page 2# On page 2 you should see the second page of the filtered set ordered ASC by name- expect(page).to have_text(public_project.name)- expect(page).not_to have_text(project.name) # Filtered away- expect(page).not_to have_text('Next') # Filters kept active, so there is no third page.- expect(page).not_to have_text(development_project.name) # That one should be on page 1+ projects_page.expect_projects_listed(public_project)+ projects_page.expect_projects_not_listed(project, # Filtered out+ development_project) # Present on page 1+ expect(page).not_to have_text('Next') # Filters kept active, so there is no third page.# Sorts DESC by nameclick_on 'Ascending sorted by "Name"'wait_for_reload# On page 2 the same filters should still be intact but the order should be DESC on name- expect(page).to have_text(development_project.name)- expect(page).not_to have_text(project.name) # Filtered away- expect(page).not_to have_text('Next') # Filters kept active, so there is no third page.- expect(page).not_to have_text(public_project.name) # That one should be on page 1+ projects_page.expect_projects_listed(development_project)+ projects_page.expect_projects_not_listed(project, # Filtered out+ public_project) # Present on page 1++ expect(page).not_to have_text('Next') # Filters kept active, so there is no third page.expect(page).to have_selector('.sort.desc', text: 'NAME')# Sending the filter form again what implies to compose the request freshly@@ -286,9 +344,9 @@ RSpec.describe 'Projects index page',# We should see page 1, resetting pagination, as it is a new filter, but keeping the DESC order on the project# name- expect(page).to have_text(public_project.name)- expect(page).not_to have_text(development_project.name) # as it is on the second page- expect(page).not_to have_text(project.name) # as it filtered away+ projects_page.expect_projects_listed(public_project)+ projects_page.expect_projects_not_listed(development_project, # as it is on the second page+ project) # as it filtered outexpect(page).to have_text('Next') # as the result set is larger than 1expect(page).to have_selector('.sort.desc', text: 'NAME')end@@ -307,9 +365,8 @@ RSpec.describe 'Projects index page',click_on 'Apply'wait_for_reload- expect(page).to have_text(development_project.name)- expect(page).to have_text(public_project.name)- expect(page).not_to have_text(project.name)+ projects_page.expect_projects_listed(development_project, public_project)+ projects_page.expect_projects_not_listed(project)# Filter on model attribute 'identifier'remove_filter('name_and_identifier')@@ -322,9 +379,8 @@ RSpec.describe 'Projects index page',click_on 'Apply'wait_for_reload- expect(page).to have_text(project.name)- expect(page).not_to have_text(development_project.name)- expect(page).not_to have_text(public_project.name)+ projects_page.expect_projects_listed(project)+ projects_page.expect_projects_not_listed(development_project, public_project)enddescribe 'Active or archived' do@@ -346,23 +402,21 @@ RSpec.describe 'Projects index page',# value selection defaults to "active"'expect(page).to have_selector('li[filter-name="active"]')- expect(page).to have_text(parent_project.name)- expect(page).to have_text(child_project.name)- expect(page).to have_text('Plain project')- expect(page).to have_text('Development project')- expect(page).to have_text('Public project')+ projects_page.expect_projects_listed(parent_project,+ child_project,+ project,+ development_project,+ public_project)accept_alert doprojects_page.click_menu_item_of('Archive', parent_project)endwait_for_reload- expect(page).not_to have_text(parent_project.name)- # The child project gets archived automatically- expect(page).not_to have_text(child_project.name)- expect(page).to have_text('Plain project')- expect(page).to have_text('Development project')- expect(page).to have_text('Public project')+ projects_page.expect_projects_not_listed(parent_project,+ child_project) # The child project gets archived automatically++ projects_page.expect_projects_listed(project, development_project, public_project)visit project_overview_path(parent_project)expect(page).to have_text("The project you're trying to access has been archived.")@@ -375,8 +429,7 @@ RSpec.describe 'Projects index page',projects_page.filter_by_active('no')- expect(page).to have_text("ARCHIVED #{parent_project.name}")- expect(page).to have_text("ARCHIVED #{child_project.name}")+ projects_page.expect_projects_listed(parent_project, child_project, archived: true)# Test visibility of 'more' menu list itemsprojects_page.activate_menu_of(parent_project) do |menu|@@ -401,11 +454,11 @@ RSpec.describe 'Projects index page',projects_page.filter_by_active('yes')- expect(page).to have_text(parent_project.name)- expect(page).not_to have_text(child_project.name)- expect(page).to have_text('Plain project')- expect(page).to have_text('Development project')- expect(page).to have_text('Public project')+ projects_page.expect_projects_listed(parent_project,+ project,+ development_project,+ public_project)+ projects_page.expect_projects_not_listed(child_project)endend@@ -719,22 +772,21 @@ RSpec.describe 'Projects index page',it 'filters on "public" status' doload_and_open_filters admin- expect(page).to have_text(project.name)- expect(page).to have_text(public_project.name)+ projects_page.expect_projects_listed(project, public_project)projects_page.filter_by_public('no')wait_for_reload- expect(page).to have_text(project.name)- expect(page).not_to have_text(public_project.name)+ projects_page.expect_projects_listed(project)+ projects_page.expect_projects_not_listed(public_project)load_and_open_filters adminprojects_page.filter_by_public('yes')wait_for_reload- expect(page).to have_text(public_project.name)- expect(page).not_to have_text(project.name)+ projects_page.expect_projects_listed(public_project)+ projects_page.expect_projects_not_listed(project)endendenddiff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rbindex b5439cb885f..84b62f6195f 100644--- a/spec/helpers/projects_helper_spec.rb+++ b/spec/helpers/projects_helper_spec.rb@@ -111,6 +111,16 @@ RSpec.describe ProjectsHelper doendend+ describe '#global_menu_items' do+ subject { global_menu_items.map(&:first) }++ it do+ expect(subject).to eq([t(:label_all_projects),+ t(:label_public_projects),+ t(:label_archived_projects)])+ end+ end+describe '#project_more_menu_items' do# need to use refind: true because @allowed_permissions is cached in the instanceshared_let(:project, refind: true) { create(:project) }diff --git a/spec/lib/redmine/menu_manager_spec.rb b/spec/lib/redmine/menu_manager_spec.rbindex ef08f1cbe86..70b45d4ba48 100644--- a/spec/lib/redmine/menu_manager_spec.rb+++ b/spec/lib/redmine/menu_manager_spec.rb@@ -53,6 +53,7 @@ RSpec.describe Redmine::MenuManager doit 'includes the expected items' doexpect(described_class.items(:global_menu).map(&:name)).to include(:home,+ :projects,:activity,:work_packages,:calendar_view,diff --git a/spec/support/pages/projects/index.rb b/spec/support/pages/projects/index.rbindex a771601a109..88918ff0972 100644--- a/spec/support/pages/projects/index.rb+++ b/spec/support/pages/projects/index.rb@@ -40,6 +40,34 @@ module Pagesexpect(rows.map(&:text)).to eq(users.map(&:login))end+ def expect_projects_listed(*projects, archived: false)+ within '#project-table' do+ projects.each do |project|+ displayed_name = if archived+ "ARCHIVED #{project.name}"+ else+ project.name+ end++ expect(page).to have_text(displayed_name)+ end+ end+ end++ def expect_projects_not_listed(*projects)+ within '#project-table' do+ projects.each do |project|+ expect(page).not_to have_text(project)+ end+ end+ end++ def set_sidebar_filter(filter_name)+ within '#main-menu' do+ click_link text: filter_name+ end+ end+def filter_by_active(value)set_filter('active','Active',@@ -154,6 +182,18 @@ module Pagesendend+ def navigate_to_new_project_page_from_global_sidebar+ within '#main-menu' do+ click_on 'New project'+ end+ end++ def navigate_to_new_project_page_from_toolbar_items+ within '.toolbar-items' do+ click_on 'New project'+ end+ end+privatedef boolean_filter?(filter)