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

Only filter for active projects

Oliver Günther1774f3fc45cb
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 7cefaf2ec32..39bde1981b7 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -225,6 +225,14 @@ module ProjectsHelper
work_packages_path query_props: generator.call
end
+ def gantt_portfolio_project_ids(project_scope)
+ project_scope
+ .where(active: true)
+ .select(:id)
+ .uniq
+ .pluck(:id)
+ end
+
def gantt_portfolio_title
title = t('projects.index.open_as_gantt_title')
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index 513844882c0..f756245cc1c 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -53,10 +53,10 @@ See docs/COPYRIGHT.rdoc for more details.
<%= link_to t(:label_overall_activity), activities_path, class: 'button' %>
</li>
<li class="toolbar-item">
- <% all_projects = @projects.select(:id).uniq.pluck(:id) %>
- <%= link_to gantt_portfolio_query_link(all_projects),
- disabled: all_projects.empty?,
- class: "button #{all_projects.empty? ? '-disabled' : ''}",
+ <% gantt_project_ids = gantt_portfolio_project_ids(@projects) %>
+ <%= link_to gantt_portfolio_query_link(gantt_project_ids),
+ disabled: gantt_project_ids.empty?,
+ class: "button #{gantt_project_ids.empty? ? '-disabled' : ''}",
title: gantt_portfolio_title,
target: '_blank' do %>
<%= op_icon("button--icon icon-view-timeline") %>
diff --git a/spec/features/projects/projects_portfolio_spec.rb b/spec/features/projects/projects_portfolio_spec.rb
index 2692a5130b3..187cd4bf487 100644
--- a/spec/features/projects/projects_portfolio_spec.rb
+++ b/spec/features/projects/projects_portfolio_spec.rb
@@ -40,6 +40,7 @@ describe 'Projects index page',
let(:columns) { ::Components::WorkPackages::Columns.new }
let(:filters) { ::Components::WorkPackages::Filters.new }
let(:wp_table) { ::Pages::WorkPackagesTable.new }
+ let(:projects_page) { Pages::Projects::Index.new }
before do
login_as admin
@@ -48,6 +49,20 @@ describe 'Projects index page',
describe 'with no projects on index' do
it 'disables the button' do
visit projects_path
+
+ projects_page.open_filters
+ projects_page.filter_by_active('yes')
+
+ expect(page).to have_selector('.button.-disabled', text: 'Open as Gantt view', wait: 10)
+ end
+ end
+
+ describe 'with only an archived project on index' do
+ let!(:project) { FactoryBot.create :project, active: false }
+
+ it 'disables the button' do
+ visit projects_path
+
expect(page).to have_selector('.button.-disabled', text: 'Open as Gantt view')
end
end