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

Add title to explain what the button does and disable if no results

Oliver Günther3a0020f17a75
diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 7d15c9bcb00..7cefaf2ec32 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -225,6 +225,17 @@ module ProjectsHelper
work_packages_path query_props: generator.call
end
+ def gantt_portfolio_title
+ title = t('projects.index.open_as_gantt_title')
+
+ if current_user.admin?
+ title << ' '
+ title << t('projects.index.open_as_gantt_title_admin')
+ end
+
+ title
+ end
+
def short_project_description(project, length = 255)
unless project.description.present?
return ''
diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb
index fe4f5ad1999..513844882c0 100644
--- a/app/views/projects/index.html.erb
+++ b/app/views/projects/index.html.erb
@@ -53,8 +53,11 @@ See docs/COPYRIGHT.rdoc for more details.
<%= link_to t(:label_overall_activity), activities_path, class: 'button' %>
</li>
<li class="toolbar-item">
- <%= link_to gantt_portfolio_query_link(@projects.select(:id).uniq.pluck(:id)),
- class: 'button',
+ <% 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' : ''}",
+ title: gantt_portfolio_title,
target: '_blank' do %>
<%= op_icon("button--icon icon-view-timeline") %>
<%= t('projects.index.open_as_gantt') %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 1db17791cf3..30dd19cf3b3 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -230,6 +230,8 @@ en:
completed_text: "The request to delete project '%{name}' has been completed."
index:
open_as_gantt: 'Open as Gantt view'
+ open_as_gantt_title: "Use this button to generate a Gantt view that filters work packages for the projects visible on this page."
+ open_as_gantt_title_admin: "You can modify the view settings (such as selected work package types) in the administration under project settings."
no_results_title_text: There are currently no projects
no_results_content_text: Create a new project
settings:
diff --git a/spec/features/projects/projects_portfolio_spec.rb b/spec/features/projects/projects_portfolio_spec.rb
index d52eb1ca0eb..2692a5130b3 100644
--- a/spec/features/projects/projects_portfolio_spec.rb
+++ b/spec/features/projects/projects_portfolio_spec.rb
@@ -35,19 +35,6 @@ describe 'Projects index page',
with_settings: { login_required?: false } do
using_shared_fixtures :admin
- let!(:string_cf) { FactoryBot.create(:string_project_custom_field, name: 'Foobar') }
-
- let(:cv_a) { FactoryBot.build :custom_value, custom_field: string_cf, value: 'A' }
- let(:cv_b) { FactoryBot.build :custom_value, custom_field: string_cf, value: 'B' }
-
- let!(:project_a) { FactoryBot.create :project, name: 'A', types: [type_milestone], custom_values: [cv_a] }
- let!(:project_b) { FactoryBot.create :project, name: 'B', types: [type_milestone], custom_values: [cv_b] }
-
- let!(:type_milestone) { FactoryBot.create :type, name: 'Milestone', is_milestone: true }
-
- let!(:work_package_a) { FactoryBot.create :work_package, subject: 'WP A', type: type_milestone, project: project_a }
- let!(:work_package_b) { FactoryBot.create :work_package, subject: 'WP B', type: type_milestone, project: project_b }
-
let(:modal) { ::Components::WorkPackages::TableConfigurationModal.new }
let(:model_filters) { ::Components::WorkPackages::TableConfiguration::Filters.new }
let(:columns) { ::Components::WorkPackages::Columns.new }
@@ -58,81 +45,103 @@ describe 'Projects index page',
login_as admin
end
- it 'can manage and browse the project portfolio Gantt' do
- visit projects_settings_path
-
- # It has checked all selected settings
- Setting.enabled_projects_columns.each do |name|
- expect(page).to have_selector(%(input[value="#{name}"]:checked))
+ describe 'with no projects on index' do
+ it 'disables the button' do
+ visit projects_path
+ expect(page).to have_selector('.button.-disabled', text: 'Open as Gantt view')
end
+ end
- # Uncheck all selected columns
- page.all('.form--matrix input[type="checkbox"]').each do |el|
- el.uncheck if el.checked?
- end
+ describe 'with projects defined' do
+ let!(:string_cf) { FactoryBot.create(:string_project_custom_field, name: 'Foobar') }
- # Check the status and custom field only
- find('input[value="project_status"]').check
- find(%(input[value="cf_#{string_cf.id}"])).check
+ let(:cv_a) { FactoryBot.build :custom_value, custom_field: string_cf, value: 'A' }
+ let(:cv_b) { FactoryBot.build :custom_value, custom_field: string_cf, value: 'B' }
- expect(page).to have_selector('input[value="project_status"]:checked')
- expect(page).to have_selector(%(input[value="cf_#{string_cf.id}"]:checked))
+ let!(:project_a) { FactoryBot.create :project, name: 'A', types: [type_milestone], custom_values: [cv_a] }
+ let!(:project_b) { FactoryBot.create :project, name: 'B', types: [type_milestone], custom_values: [cv_b] }
- # Edit the project gantt query
- scroll_to_and_click(find('a', text: 'Edit query'))
+ let!(:type_milestone) { FactoryBot.create :type, name: 'Milestone', is_milestone: true }
- columns.assume_opened
- columns.uncheck_all save_changes: false
- columns.add 'ID', save_changes: false
- columns.add 'Subject', save_changes: false
- columns.add 'Project', save_changes: false
+ let!(:work_package_a) { FactoryBot.create :work_package, subject: 'WP A', type: type_milestone, project: project_a }
+ let!(:work_package_b) { FactoryBot.create :work_package, subject: 'WP B', type: type_milestone, project: project_b }
- modal.switch_to 'Filters'
+ it 'can manage and browse the project portfolio Gantt' do
+ visit projects_settings_path
- model_filters.expect_filter_count 2
- # Add a project filter that gets overridden
- model_filters.add_filter_by('Project', 'is', project_a.name)
+ # It has checked all selected settings
+ Setting.enabled_projects_columns.each do |name|
+ expect(page).to have_selector(%(input[value="#{name}"]:checked))
+ end
- model_filters.add_filter_by('Type', 'is', type_milestone.name)
- model_filters.save
+ # Uncheck all selected columns
+ page.all('.form--matrix input[type="checkbox"]').each do |el|
+ el.uncheck if el.checked?
+ end
- # Save the page
- scroll_to_and_click(find('.button', text: 'Save'))
+ # Check the status and custom field only
+ find('input[value="project_status"]').check
+ find(%(input[value="cf_#{string_cf.id}"])).check
- expect(page).to have_selector('.flash.notice', text: 'Successful update.')
+ expect(page).to have_selector('input[value="project_status"]:checked')
+ expect(page).to have_selector(%(input[value="cf_#{string_cf.id}"]:checked))
- RequestStore.clear!
- query = JSON.parse Setting.project_gantt_query
- expect(query['f']).to include({ 'n' => 'type', 'o' => '=', 'v' => [type_milestone.id.to_s] })
+ # Edit the project gantt query
+ scroll_to_and_click(find('a', text: 'Edit query'))
- # Go to project page
- visit projects_path
+ columns.assume_opened
+ columns.uncheck_all save_changes: false
+ columns.add 'ID', save_changes: false
+ columns.add 'Subject', save_changes: false
+ columns.add 'Project', save_changes: false
- # Click the gantt button
- new_window = window_opened_by { click_on 'Open as Gantt view' }
- switch_to_window new_window
+ modal.switch_to 'Filters'
- wp_table.expect_work_package_listed work_package_a, work_package_b
+ model_filters.expect_filter_count 2
+ # Add a project filter that gets overridden
+ model_filters.add_filter_by('Project', 'is', project_a.name)
- # Expect grouped and filtered for both projects
- expect(page).to have_selector '.group--value', text: 'A'
- expect(page).to have_selector '.group--value', text: 'B'
+ model_filters.add_filter_by('Type', 'is', type_milestone.name)
+ model_filters.save
- # Expect status, type and project filters
- filters.expect_filter_count 3
- filters.open
+ # Save the page
+ scroll_to_and_click(find('.button', text: 'Save'))
- filters.expect_filter_by('Type', 'is', [type_milestone.name])
- filters.expect_filter_by('Project', 'is', [project_a.name, project_b.name])
+ expect(page).to have_selector('.flash.notice', text: 'Successful update.')
- # Expect columns
- columns.open_modal
- columns.expect_checked 'ID'
- columns.expect_checked 'Subject'
- columns.expect_checked 'Project'
+ RequestStore.clear!
+ query = JSON.parse Setting.project_gantt_query
+ expect(query['f']).to include({ 'n' => 'type', 'o' => '=', 'v' => [type_milestone.id.to_s] })
- columns.expect_unchecked 'Assignee'
- columns.expect_unchecked 'Type'
- columns.expect_unchecked 'Priority'
+ # Go to project page
+ visit projects_path
+
+ # Click the gantt button
+ new_window = window_opened_by { click_on 'Open as Gantt view' }
+ switch_to_window new_window
+
+ wp_table.expect_work_package_listed work_package_a, work_package_b
+
+ # Expect grouped and filtered for both projects
+ expect(page).to have_selector '.group--value', text: 'A'
+ expect(page).to have_selector '.group--value', text: 'B'
+
+ # Expect status, type and project filters
+ filters.expect_filter_count 3
+ filters.open
+
+ filters.expect_filter_by('Type', 'is', [type_milestone.name])
+ filters.expect_filter_by('Project', 'is', [project_a.name, project_b.name])
+
+ # Expect columns
+ columns.open_modal
+ columns.expect_checked 'ID'
+ columns.expect_checked 'Subject'
+ columns.expect_checked 'Project'
+
+ columns.expect_unchecked 'Assignee'
+ columns.expect_unchecked 'Type'
+ columns.expect_unchecked 'Priority'
+ end
end
end