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
[#65137] add feature toggle to enable all projects for a wp type
Eric Schuberte007ca0cc23f
diff --git a/app/components/work_package_types/projects_component.html.erb b/app/components/work_package_types/projects_component.html.erbindex 75fb3eee67e..88663766395 100644--- a/app/components/work_package_types/projects_component.html.erb+++ b/app/components/work_package_types/projects_component.html.erb@@ -27,35 +27,61 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<%=- settings_primer_form_with(**form_options) do |form|- component_wrapper do- flex_layout do |container|- container.with_row(mb: 3) do- render(- Primer::OpenProject::TreeView.new(- expanded: true,- data: {- "admin--work-package-type-projects-target": "treeView",- action: "click->admin--work-package-type-projects#updateSelectedProjects"- },- select_variant: :multiple- )- ) do |tree_view|- build_project_tree(tree_view)+<%= component_wrapper do %>+ <%=+ render(Primer::BaseComponent.new(tag: :div, classes: "op-admin-settings-form-wrapper")) do+ render(+ Primer::Forms::ToggleSwitchForm.new(+ name: "enable_work_package_type_all_projects",+ label: t("types.edit.projects.enable_all"),+ src: enable_all_type_projects_path(model),+ csrf_token: form_authenticity_token,+ status_label_position: :start,+ checked: enabled_for_all_projects?,+ data: { turbo: true },+ mb: 3+ )+ )+ end+ %>+ <%=+ unless enabled_for_all_projects?+ render(Primer::Beta::Subhead.new) do |subhead|+ subhead.with_heading(tag: :h3, size: :medium) { t("types.edit.projects.select_projects") }+ subhead.with_description { t("types.edit.projects.select_projects_description") }+ end+ end+ %>+ <%=+ unless enabled_for_all_projects?+ settings_primer_form_with(**form_options) do |form|+ flex_layout do |container|+ container.with_row(mb: 3) do+ render(+ Primer::OpenProject::TreeView.new(+ expanded: true,+ data: {+ "admin--work-package-type-projects-target": "treeView",+ action: "click->admin--work-package-type-projects#updateSelectedProjects"+ },+ select_variant: :multiple+ )+ ) do |tree_view|+ build_project_tree(tree_view)+ endend- end- container.with_row do- form.hidden_field :project_ids,- value: "[]",- data: { "admin--work-package-type-projects-target": "selectedProjects" }- end+ container.with_row do+ form.hidden_field :project_ids,+ value: "[]",+ data: { "admin--work-package-type-projects-target": "selectedProjects" }+ end- container.with_row do- render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { t(:button_save) }+ container.with_row do+ render(Primer::Beta::Button.new(scheme: :primary, type: :submit)) { t(:button_save) }+ endendendend- end-%>+ %>+<% end %>diff --git a/app/components/work_package_types/projects_component.rb b/app/components/work_package_types/projects_component.rbindex 91994a746d1..b25699a80d5 100644--- a/app/components/work_package_types/projects_component.rb+++ b/app/components/work_package_types/projects_component.rb@@ -46,16 +46,20 @@ module WorkPackageTypes}end- def projects = options[:projects]-def build_project_tree(tree)nested_project_list = Project.build_projects_hierarchy(projects)add_sub_tree(tree, nested_project_list)end+ def enabled_for_all_projects?+ model.projects.pluck(:id).sort == projects.pluck(:id).sort+ end+private+ def projects = options[:projects]+def add_sub_tree(tree, project_list)project_list.each do |project_hash|if project_hash[:children].empty?diff --git a/app/controllers/work_package_types/projects_tab_controller.rb b/app/controllers/work_package_types/projects_tab_controller.rbindex 54695a4ad7c..239a7562b47 100644--- a/app/controllers/work_package_types/projects_tab_controller.rb+++ b/app/controllers/work_package_types/projects_tab_controller.rb@@ -30,7 +30,9 @@module WorkPackageTypesclass ProjectsTabController < BaseTabController- before_action :load_projects, only: :edit+ include OpTurbo::ComponentStream++ before_action :load_projects, only: %i[edit enable_all_projects]current_menu_item [:edit, :update] do:types@@ -43,7 +45,7 @@ module WorkPackageTypes.call(permitted_project_params)if result.success?- redirect_to edit_type_projects_path(type_id: @type.id), notice: I18n.t(:notice_successful_update)+ redirect_to edit_type_projects_path(@type), notice: I18n.t(:notice_successful_update)elseflash_error(result)load_projects@@ -51,6 +53,24 @@ module WorkPackageTypesendend+ def enable_all_projects+ project_ids = if params[:value] == "1"+ @projects.pluck(:id).map(&:to_s)+ else+ []+ end++ result = UpdateService.new(user: current_user, model: @type, contract_class: UpdateProjectsContract)+ .call({ project_ids: })++ if result.success?+ replace_via_turbo_stream(component: ProjectsComponent.new(@type, projects: @projects))+ respond_with_turbo_streams+ else+ render :edit, status: :unprocessable_entity+ end+ end+privatedef flash_error(result)diff --git a/app/views/work_package_types/projects_tab/edit.turbo-stream.erb b/app/views/work_package_types/projects_tab/edit.turbo-stream.erbnew file mode 100644index 00000000000..0d2babb3419--- /dev/null+++ b/app/views/work_package_types/projects_tab/edit.turbo-stream.erb@@ -0,0 +1,32 @@+<%#-- copyright+OpenProject is an open source project management software.+Copyright (C) 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.++++#%>++<%= turbo_stream.replace do %>+ <%= render WorkPackageTypes::ProjectsComponent.new(@type, projects: @projects) %>+<% end %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 174ca71f110..cc9fc291186 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -741,8 +741,10 @@ en:form_configuration:tab: "Form configuration"projects:- tab: "Projects"- enabled_projects: "Enabled projects"+ tab: Projects+ enable_all: Enable for all projects+ select_projects: Select projects+ select_projects_description: Select the projects in which you would like to use this type.settings:tab: "Settings"type_color_text: The selected color distinguishes different types in Gantt charts or work packages tables. It is therefore recommended to use a strong color.diff --git a/config/routes.rb b/config/routes.rbindex c65b188f148..54cd39ab3ee 100644--- a/config/routes.rb+++ b/config/routes.rb@@ -139,7 +139,11 @@ Rails.application.routes.draw doresources :types doresource :form_configuration, only: %i[edit update], controller: "work_package_types/form_configuration_tab"- resource :projects, controller: "work_package_types/projects_tab", only: %i[update edit]+ resource :projects, controller: "work_package_types/projects_tab", only: %i[update edit] do+ collection do+ post :enable_all, to: "work_package_types/projects_tab#enable_all_projects"+ end+ endresource :settings, controller: "work_package_types/settings_tab", only: %i[update edit]resource :subject_configuration, controller: "work_package_types/subject_configuration_tab", only: %i[update edit]