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
fall back to "Projects" when changing filters of a persisted or static list
ulferts820fc9b56122
diff --git a/app/components/projects/index_page_header_component.html.erb b/app/components/projects/index_page_header_component.html.erbindex cbc28f0e7dd..8a510d4ee3d 100644--- a/app/components/projects/index_page_header_component.html.erb+++ b/app/components/projects/index_page_header_component.html.erb@@ -40,7 +40,7 @@<%= render(Primer::Alpha::ActionMenu.new) do |menu|menu.with_show_button(icon: 'op-kebab-vertical', 'aria-label': t(:label_more), data: { 'test-selector': 'project-more-dropdown-menu' })- if current_user.logged?+ if current_user.logged? && query_saveable?menu.with_item(label: t('button_save'),href: new_projects_query_path,diff --git a/app/components/projects/index_page_header_component.rb b/app/components/projects/index_page_header_component.rbindex 35622f0a174..84e1fa0a4f7 100644--- a/app/components/projects/index_page_header_component.rb+++ b/app/components/projects/index_page_header_component.rb@@ -34,7 +34,8 @@ class Projects::IndexPageHeaderComponent < ApplicationComponentattr_accessor :current_user,:query,- :state+ :state,+ :paramsBUTTON_MARGIN_RIGHT = 2SAVE_MODAL_ID = 'op-project-list-save-dialog'@@ -44,12 +45,13 @@ class Projects::IndexPageHeaderComponent < ApplicationComponentSTATE_EDIT = :editSTATE_OPTIONS = [STATE_DEFAULT, STATE_EDIT].freeze- def initialize(current_user:, query:, state: :show)+ def initialize(current_user:, query:, params:, state: :show)superself.current_user = current_userself.query = queryself.state = fetch_or_fallback(STATE_OPTIONS, state)+ self.params = paramsenddef gantt_portfolio_query_link@@ -70,6 +72,10 @@ class Projects::IndexPageHeaderComponent < ApplicationComponentquery.name || t(:label_project_plural)end+ def query_saveable?+ query.name.blank?+ end+def gantt_portfolio_titletitle = t('projects.index.open_as_gantt_title')diff --git a/app/components/projects/table_component.rb b/app/components/projects/table_component.rbindex 9e74e62912d..9ee2bba361b 100644--- a/app/components/projects/table_component.rb+++ b/app/components/projects/table_component.rb@@ -38,9 +38,6 @@ module Projectssuper(rows: [], **options)end- # TODO: consider moving this out of the component again.- # It was moved inside so that rendering the table only requires having a query- # making it easier to render the component from different controllersdef before_render@model = projects(query)superdiff --git a/app/contracts/queries/projects/project_queries/loading_contract.rb b/app/contracts/queries/projects/project_queries/loading_contract.rbnew file mode 100644index 00000000000..b97d69ade07--- /dev/null+++ b/app/contracts/queries/projects/project_queries/loading_contract.rb@@ -0,0 +1,34 @@+# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-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 Queries::Projects::ProjectQueries+ class LoadingContract < ::ModelContract+ attribute :filters+ attribute :orders+ end+enddiff --git a/app/controllers/projects/query_loading.rb b/app/controllers/projects/query_loading.rbindex b5555985b02..e03e04650c5 100644--- a/app/controllers/projects/query_loading.rb+++ b/app/controllers/projects/query_loading.rb@@ -27,17 +27,27 @@# ++module Projectsmodule QueryLoading- def load_query(existing: true, contract: EmptyContract)+ def load_query(existing: true)query = if existingQueries::Projects::Factory.find(params[:query_id])elseQueries::Projects::ProjectQuery.newend+ contract_class = if existing+ # This one allows to change the name of the query.+ # Semantically, it would be better to use the UpdateContract+ # but there wasn't the need to create that yet and for now it+ # would be the same as the CreateContract anyway.+ Queries::Projects::ProjectQueries::CreateContract+ else+ Queries::Projects::ProjectQueries::LoadingContract+ end+Queries::Projects::ProjectQueries::SetAttributesService.new(user: current_user,model: query,- contract_class: contract)+ contract_class:).call(permitted_query_params)enddiff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rbindex d189bfdaf78..5168aaaf29e 100644--- a/app/controllers/projects_controller.rb+++ b/app/controllers/projects_controller.rb@@ -48,7 +48,7 @@ class ProjectsController < ApplicationControllerenddef index- call = load_query(contract: Queries::Projects::ProjectQueries::CreateContract)+ call = load_query(existing: params[:filters].blank?)respond_to do |format|format.html dodiff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erbindex 670bcbc5413..c1b2804e8a4 100644--- a/app/views/projects/index.html.erb+++ b/app/views/projects/index.html.erb@@ -32,7 +32,8 @@ See COPYRIGHT and LICENSE files for more details.Projects::IndexPageHeaderComponent.new(query:,current_user:,- state:+ state:,+ params:))%>@@ -58,7 +59,7 @@ See COPYRIGHT and LICENSE files for more details.<%= render Projects::TableComponent.new(query:,current_user: current_user,- params: params) %>+ params:) %></div><%= render Projects::StorageInformationComponent.new(diff --git a/spec/contracts/queries/projects/project_queries/loading_contract_spec.rb b/spec/contracts/queries/projects/project_queries/loading_contract_spec.rbnew file mode 100644index 00000000000..f3391a996d0--- /dev/null+++ b/spec/contracts/queries/projects/project_queries/loading_contract_spec.rb@@ -0,0 +1,53 @@+# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-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.+# ++++require 'spec_helper'+require 'contracts/shared/model_contract_shared_context'++RSpec.describe Queries::Projects::ProjectQueries::LoadingContract do+ include_context 'ModelContract shared context'++ let(:current_user) { build_stubbed(:user) }+ let(:query_user) { current_user }+ let(:query_filters) { [[:active, '=', 't']] }+ let(:query_orders) { [%w[name asc]] }+ let(:query) do+ Queries::Projects::ProjectQuery.new do |query|+ query_filters.each do |key, operator, values|+ query.where(key, operator, values)+ end++ query.order(query_orders)+ end+ end+ let(:contract) { described_class.new(query, current_user) }++ describe 'validation' do+ it_behaves_like 'contract is valid'+ end+end