Skip to content

Commit

Permalink
Merge pull request #15191 from opf/feature/51793-split-existing-proje…
Browse files Browse the repository at this point in the history
…ct-administration-settings-into-multiple-pages

[#51793] Split existing project administration settings into multiple pages
  • Loading branch information
dombesz committed Apr 10, 2024
2 parents 5fdaf52 + 641789a commit 92b3d11
Show file tree
Hide file tree
Showing 10 changed files with 403 additions and 275 deletions.
71 changes: 71 additions & 0 deletions app/controllers/admin/settings/new_project_settings_controller.rb
@@ -0,0 +1,71 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 2012-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 Admin::Settings
class NewProjectSettingsController < ::Admin::SettingsController
menu_item :new_project_settings

before_action :validate_enabled_modules, only: :update # rubocop:disable Rails/LexicallyScopedActionFilter

def default_breadcrumb
t(:label_project_new)
end

private

# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
def validate_enabled_modules
return if settings_params[:default_projects_modules].blank?

enabled_modules = settings_params[:default_projects_modules].map(&:to_sym)

module_missing_deps = OpenProject::AccessControl
.modules
.filter_map do |m|
if m[:dependencies] &&
enabled_modules.include?(m[:name]) &&
(m[:dependencies] & enabled_modules) != m[:dependencies]

I18n.t(
"settings.projects.missing_dependencies",
module: I18n.t("project_module_#{m[:name]}"),
dependencies: m[:dependencies].map { |dep| I18n.t("project_module_#{dep}") }.join(", ")
)
end
end

if module_missing_deps.any?
flash[:error] = helpers.list_of_messages(module_missing_deps)

redirect_to action: :show
end
end

# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
end
end
31 changes: 2 additions & 29 deletions app/controllers/admin/settings/projects_settings_controller.rb
Expand Up @@ -28,37 +28,10 @@

module Admin::Settings
class ProjectsSettingsController < ::Admin::SettingsController
menu_item :projects_settings

before_action :validate_enabled_modules, only: :update
menu_item :project_lists_settings

def default_breadcrumb
t(:label_project_settings)
end

private

def validate_enabled_modules
return if settings_params[:default_projects_modules].blank?

enabled_modules = settings_params[:default_projects_modules].map(&:to_sym)

module_missing_deps = OpenProject::AccessControl
.modules
.select { |m| m[:dependencies] && enabled_modules.include?(m[:name]) && (m[:dependencies] & enabled_modules) != m[:dependencies] }
.map do |m|
I18n.t(
"settings.projects.missing_dependencies",
module: I18n.t("project_module_#{m[:name]}"),
dependencies: m[:dependencies].map { |dep| I18n.t("project_module_#{dep}") }.join(", ")
)
end

if module_missing_deps.any?
flash[:error] = helpers.list_of_messages(module_missing_deps)

redirect_to action: :show
end
t(:label_project_list_plural)
end
end
end
45 changes: 45 additions & 0 deletions app/views/admin/settings/new_project_settings/show.html.erb
@@ -0,0 +1,45 @@
<%#-- copyright
OpenProject is an open source project management software.
Copyright (C) 2012-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.
++#%>
<%= toolbar title: t(:label_project_new) %>
<%= styled_form_tag(admin_settings_new_project_path, method: :patch) do %>
<fieldset class="form--fieldset">
<div class="form--field"><%= setting_check_box :default_projects_public %></div>
<div class="form--field">
<%= setting_multiselect(:default_projects_modules,
OpenProject::AccessControl.available_project_modules.collect {|m| [l_or_humanize(m, prefix: "project_module_"), m.to_s]}) %>
</div>
<div class="form--field"><%= setting_select :new_project_user_role_id,
Role.givable.collect {|r| [r.name, r.id.to_s]},
blank: "--- #{t(:actionview_instancetag_blank_option)} ---",
container_class: '-middle' %></div>
</fieldset>

<%= styled_button_tag t(:button_save), class: '-primary -with-icon icon-checkmark' %>
<% end %>
113 changes: 47 additions & 66 deletions app/views/admin/settings/projects_settings/show.html.erb
Expand Up @@ -26,80 +26,61 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
++#%>
<%= toolbar title: t(:label_project_settings) %>
<%= toolbar title: t(:label_project_list_plural) %>
<%= styled_form_tag(admin_settings_projects_path, method: :patch) do %>
<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= t('settings.projects.section_new_projects') %></legend>
<div class="form--field"><%= setting_check_box :default_projects_public %></div>
<fieldset class="form--fieldset">
<% unless EnterpriseToken.allows_to?(:custom_fields_in_projects_list) %>
<div class="form--field">
<%= setting_multiselect(:default_projects_modules,
OpenProject::AccessControl.available_project_modules.collect {|m| [l_or_humanize(m, prefix: "project_module_"), m.to_s]}) %>
<%=
angular_component_tag 'op-enterprise-banner',
inputs: {
textMessage: t('text_project_custom_field_html'),
collapsible: true,
moreInfoLink: OpenProject::Static::Links.links[:enterprise_docs][:custom_field_projects][:href],
}
%>
</div>
<div class="form--field"><%= setting_select :new_project_user_role_id,
Role.givable.collect {|r| [r.name, r.id.to_s]},
blank: "--- #{t(:actionview_instancetag_blank_option)} ---",
container_class: '-middle' %></div>
</fieldset>
</section>

<section class="form--section">
<fieldset class="form--fieldset">
<legend class="form--fieldset-legend"><%= t('settings.projects.section_project_overview') %></legend>
<% unless EnterpriseToken.allows_to?(:custom_fields_in_projects_list) %>
<div class="form--field">
<%=
angular_component_tag 'op-enterprise-banner',
inputs: {
textMessage: t('text_project_custom_field_html'),
collapsible: true,
moreInfoLink: OpenProject::Static::Links.links[:enterprise_docs][:custom_field_projects][:href],
}
%>
</div>
<% end %>
<% end %>


<div class="form--field -full-width">
<div class="form--text-field-container -xwide">
<%= angular_component_tag 'opce-draggable-autocompleter',
inputs: {
options: projects_columns_options,
selected: selected_projects_columns_options,
protected: protected_projects_columns_options,
name: 'settings[enabled_projects_columns][]',
id: 'settings_enabled_projects_columns',
inputLabel: I18n.t(:'queries.configure_view.columns.input_label'),
inputPlaceholder: I18n.t(:'queries.configure_view.columns.input_placeholder'),
dragAreaLabel: I18n.t(:'queries.configure_view.columns.drag_area_label')
}%>
</div>
<div class="form--field -full-width">
<div class="form--text-field-container -xwide">
<%= angular_component_tag 'opce-draggable-autocompleter',
inputs: {
options: projects_columns_options,
selected: selected_projects_columns_options,
protected: protected_projects_columns_options,
name: 'settings[enabled_projects_columns][]',
id: 'settings_enabled_projects_columns',
inputLabel: I18n.t(:'queries.configure_view.columns.input_label'),
inputPlaceholder: I18n.t(:'queries.configure_view.columns.input_placeholder'),
dragAreaLabel: I18n.t(:'queries.configure_view.columns.drag_area_label')
}%>
</div>
</div>

<div class="form--field -vertical">
<div class="form--label -bold">
<%= I18n.t(:setting_project_gantt_query) %>
</div>
<span class="form--field-container">
<span class="form--text-field-container">
<%= content_tag 'editable-query-props',
'',
data: {
name: 'settings[project_gantt_query]',
id: 'settings_project_gantt_query',
query: ::Projects::GanttQueryGeneratorService.current_query,
'url-params': 'true'
}
%>
</span>
<div class="form--field -vertical">
<div class="form--label -bold">
<%= I18n.t(:setting_project_gantt_query) %>
</div>
<span class="form--field-container">
<span class="form--text-field-container">
<%= content_tag 'editable-query-props',
'',
data: {
name: 'settings[project_gantt_query]',
id: 'settings_project_gantt_query',
query: ::Projects::GanttQueryGeneratorService.current_query,
'url-params': 'true'
}
%>
</span>
<div class="form--field-instructions">
<%= I18n.t(:setting_project_gantt_query_text) %>
</div>
</span>
<div class="form--field-instructions">
<%= I18n.t(:setting_project_gantt_query_text) %>
</div>
</fieldset>
</section>

</div>
</fieldset>
<%= styled_button_tag t(:button_save), class: '-primary -with-icon icon-checkmark' %>
<% end %>
<% end %>
18 changes: 12 additions & 6 deletions config/initializers/menus.rb
Expand Up @@ -331,21 +331,27 @@
parent: :admin_work_packages

menu.push :admin_projects_settings,
{ controller: '/admin/settings/project_custom_fields', action: :index },
{ controller: "/admin/settings/project_custom_fields", action: :index },
if: Proc.new { User.current.admin? },
caption: :label_project_plural,
icon: 'projects'
icon: "projects"

menu.push :project_custom_fields_settings,
{ controller: '/admin/settings/project_custom_fields', action: :index },
{ controller: "/admin/settings/project_custom_fields", action: :index },
if: Proc.new { User.current.admin? },
caption: :label_project_attributes_plural,
parent: :admin_projects_settings

menu.push :projects_settings,
{ controller: '/admin/settings/projects_settings', action: :show },
menu.push :new_project_settings,
{ controller: "/admin/settings/new_project_settings", action: :show },
if: Proc.new { User.current.admin? },
caption: :label_setting_plural,
caption: :label_project_new,
parent: :admin_projects_settings

menu.push :project_lists_settings,
{ controller: "/admin/settings/projects_settings", action: :show },
if: Proc.new { User.current.admin? },
caption: :label_project_list_plural,
parent: :admin_projects_settings

menu.push :custom_fields,
Expand Down
1 change: 1 addition & 0 deletions config/locales/en.yml
Expand Up @@ -2241,6 +2241,7 @@ Project attributes and sections are defined in the <a href=%{admin_settings_url}
label_project_hierarchy: "Project hierarchy"
label_project_new: "New project"
label_project_plural: "Projects"
label_project_list_plural: "Project lists"
label_project_attributes_plural: "Project attributes"
label_project_custom_field_plural: "Project attributes"
label_project_settings: "Project settings"
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -447,6 +447,7 @@
resource :api, controller: "/admin/settings/api_settings", only: %i[show update]
resource :work_packages, controller: "/admin/settings/work_packages_settings", only: %i[show update]
resource :projects, controller: "/admin/settings/projects_settings", only: %i[show update]
resource :new_project, controller: "/admin/settings/new_project_settings", only: %i[show update]
resources :project_custom_fields, controller: "/admin/settings/project_custom_fields" do
member do
delete "options/:option_id", action: "delete_option", as: :delete_option_of
Expand Down
2 changes: 1 addition & 1 deletion modules/storages/spec/features/storages_module_spec.rb
Expand Up @@ -73,7 +73,7 @@

context "when showing system project settings page" do
it_behaves_like "has storages module", sections: [:content] do
let(:path) { admin_settings_projects_path }
let(:path) { admin_settings_new_project_path }
end
end

Expand Down

0 comments on commit 92b3d11

Please sign in to comment.