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

Extract header into separate components for separation of concerns

Henriette Darge2ece709b23d1
diff --git a/app/components/admin/quarantined_attachments/index_page_header_component.html.erb b/app/components/admin/quarantined_attachments/index_page_header_component.html.erb
new file mode 100644
index 00000000000..994462d0815
--- /dev/null
+++ b/app/components/admin/quarantined_attachments/index_page_header_component.html.erb
@@ -0,0 +1,6 @@
+<%=
+ render(Primer::OpenProject::PageHeader.new) do |header|
+ header.with_title { t('antivirus_scan.quarantined_attachments.title') }
+ header.with_breadcrumbs(breadcrumb_items)
+ end
+%>
diff --git a/app/components/admin/quarantined_attachments/index_page_header_component.rb b/app/components/admin/quarantined_attachments/index_page_header_component.rb
new file mode 100644
index 00000000000..ed0adf5629a
--- /dev/null
+++ b/app/components/admin/quarantined_attachments/index_page_header_component.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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::QuarantinedAttachments
+ # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class IndexPageHeaderComponent < ApplicationComponent
+ include ApplicationHelper
+
+ def breadcrumb_items
+ [{ href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_attachments_path, text: t("attributes.attachments") },
+ t("antivirus_scan.quarantined_attachments.title")]
+ end
+ end
+end
diff --git a/app/components/admin/virus_scanning/index_page_header_component.html.erb b/app/components/admin/virus_scanning/index_page_header_component.html.erb
new file mode 100644
index 00000000000..44a4a26f3f3
--- /dev/null
+++ b/app/components/admin/virus_scanning/index_page_header_component.html.erb
@@ -0,0 +1,6 @@
+<%= render(Primer::OpenProject::PageHeader.new) do |header| %>
+ <% header.with_title do %>
+ <%= t('settings.antivirus.title') %>
+ <% end %>
+ <% header.with_breadcrumbs(breadcrumb_items)%>
+<% end %>
diff --git a/app/components/admin/virus_scanning/index_page_header_component.rb b/app/components/admin/virus_scanning/index_page_header_component.rb
new file mode 100644
index 00000000000..1ccf9648cb6
--- /dev/null
+++ b/app/components/admin/virus_scanning/index_page_header_component.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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::VirusScanning
+ # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class IndexPageHeaderComponent < ApplicationComponent
+ include ApplicationHelper
+
+ def breadcrumb_items
+ [{ href: admin_index_path, text: t("label_administration") },
+ { href: admin_settings_attachments_path, text: t("attributes.attachments") },
+ t("settings.antivirus.title")]
+ end
+ end
+end
diff --git a/app/components/projects/settings/project_custom_field_sections/index_page_header_component.html.erb b/app/components/projects/settings/project_custom_field_sections/index_page_header_component.html.erb
new file mode 100644
index 00000000000..7cbbd5903e1
--- /dev/null
+++ b/app/components/projects/settings/project_custom_field_sections/index_page_header_component.html.erb
@@ -0,0 +1,8 @@
+<%= render Primer::OpenProject::PageHeader.new do |header| %>
+ <%= header.with_title(variant: :default) { t('projects.settings.project_custom_fields.header.title') } %>
+ <%= header.with_description { t('projects.settings.project_custom_fields.header.description',
+ overview_url: project_path(@project),
+ admin_settings_url: admin_settings_project_custom_fields_path
+ ).html_safe } %>
+ <%= header.with_breadcrumbs(breadcrumb_items) %>
+<% end %>
diff --git a/app/components/projects/settings/project_custom_field_sections/index_page_header_component.rb b/app/components/projects/settings/project_custom_field_sections/index_page_header_component.rb
new file mode 100644
index 00000000000..645e9f17f43
--- /dev/null
+++ b/app/components/projects/settings/project_custom_field_sections/index_page_header_component.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2023 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 Projects::Settings::ProjectCustomFieldSections
+ # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class IndexPageHeaderComponent < ApplicationComponent
+ include ApplicationHelper
+
+ def initialize(project: nil)
+ super
+ @project = project
+ end
+
+ def breadcrumb_items
+ [{ href: project_overview_path(@project.id), text: @project.name },
+ { href: project_settings_general_path(@project.id), text: I18n.t("label_project_settings") },
+ t("settings.project_attributes.heading")]
+ end
+ end
+end
diff --git a/app/controllers/admin/attachments/quarantined_attachments_controller.rb b/app/controllers/admin/attachments/quarantined_attachments_controller.rb
index ab85b24b67e..c3fba094ea5 100644
--- a/app/controllers/admin/attachments/quarantined_attachments_controller.rb
+++ b/app/controllers/admin/attachments/quarantined_attachments_controller.rb
@@ -76,13 +76,6 @@ module Admin
rescue ActiveRecord::RecordNotFound
render_404
end
-
- def breadcrumb_items
- [{ href: admin_index_path, text: t("label_administration") },
- { href: admin_settings_attachments_path, text: t("attributes.attachments") },
- t("antivirus_scan.quarantined_attachments.title")]
- end
- helper_method :breadcrumb_items
end
end
end
diff --git a/app/controllers/admin/settings/virus_scanning_settings_controller.rb b/app/controllers/admin/settings/virus_scanning_settings_controller.rb
index 841464c503e..047391403b7 100644
--- a/app/controllers/admin/settings/virus_scanning_settings_controller.rb
+++ b/app/controllers/admin/settings/virus_scanning_settings_controller.rb
@@ -101,12 +101,5 @@ module Admin::Settings
file_count: t(:label_x_files, count: Attachment.status_quarantined.count))
redirect_to action: :show
end
-
- def breadcrumb_items
- [{ href: admin_index_path, text: t("label_administration") },
- { href: admin_settings_attachments_path, text: t("attributes.attachments") },
- t("settings.antivirus.title")]
- end
- helper_method :breadcrumb_items
end
end
diff --git a/app/controllers/projects/settings/project_custom_fields_controller.rb b/app/controllers/projects/settings/project_custom_fields_controller.rb
index 66fea6fb2dd..9dbcb329fe5 100644
--- a/app/controllers/projects/settings/project_custom_fields_controller.rb
+++ b/app/controllers/projects/settings/project_custom_fields_controller.rb
@@ -106,11 +106,4 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsCont
project_custom_field_section: @project_custom_field_section
)
end
-
- def breadcrumb_items
- [{ href: project_overview_path(@project.id), text: @project.name },
- { href: project_settings_general_path(@project.id), text: I18n.t("label_project_settings") },
- t("settings.project_attributes.heading")]
- end
- helper_method :breadcrumb_items
end
diff --git a/app/views/admin/attachments/quarantined_attachments/index.html.erb b/app/views/admin/attachments/quarantined_attachments/index.html.erb
index 55eefb1f37e..adc11766647 100644
--- a/app/views/admin/attachments/quarantined_attachments/index.html.erb
+++ b/app/views/admin/attachments/quarantined_attachments/index.html.erb
@@ -1,10 +1,5 @@
<% html_title t('antivirus_scan.quarantined_attachments.title') %>
-<%=
- render(Primer::OpenProject::PageHeader.new) do |header|
- header.with_title { t('antivirus_scan.quarantined_attachments.title') }
- header.with_breadcrumbs(breadcrumb_items)
- end
-%>
+<%= render ::Admin::QuarantinedAttachments::IndexPageHeaderComponent.new %>
<%= render ::Admin::QuarantinedAttachments::TableComponent.new(rows: @attachments) %>
diff --git a/app/views/admin/settings/virus_scanning_settings/show.html.erb b/app/views/admin/settings/virus_scanning_settings/show.html.erb
index 1550ba9bba9..b036a72431b 100644
--- a/app/views/admin/settings/virus_scanning_settings/show.html.erb
+++ b/app/views/admin/settings/virus_scanning_settings/show.html.erb
@@ -28,12 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<% html_title t(:label_administration), t('settings.antivirus.title') %>
-<%= render(Primer::OpenProject::PageHeader.new) do |header| %>
- <% header.with_title do %>
- <%= t('settings.antivirus.title') %>
- <% end %>
- <% header.with_breadcrumbs(breadcrumb_items)%>
-<% end %>
+<%= render ::Admin::VirusScanning::IndexPageHeaderComponent.new %>
<%= styled_form_tag(
admin_settings_virus_scanning_path,
diff --git a/app/views/projects/settings/project_custom_fields/show.html.erb b/app/views/projects/settings/project_custom_fields/show.html.erb
index d0e42b6b05a..9ca23bd11ef 100644
--- a/app/views/projects/settings/project_custom_fields/show.html.erb
+++ b/app/views/projects/settings/project_custom_fields/show.html.erb
@@ -27,17 +27,10 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<div data-turbo="true">
- <%= render Primer::OpenProject::PageHeader.new do |header| %>
- <%= header.with_title(variant: :default) { t('projects.settings.project_custom_fields.header.title') } %>
- <%= header.with_description { t('projects.settings.project_custom_fields.header.description',
- overview_url: project_path(@project),
- admin_settings_url: admin_settings_project_custom_fields_path
- ).html_safe } %>
- <%= header.with_breadcrumbs(breadcrumb_items) %>
- <% end %>
+ <%= render Projects::Settings::ProjectCustomFieldSections::IndexPageHeaderComponent.new(project: @project) %>
+
<%= render(Projects::Settings::ProjectCustomFieldSections::IndexComponent.new(
project: @project,
project_custom_field_sections: @project_custom_field_sections,
)) %>
</div>
-