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

added project count on global project attributes settings page

Jonas Jabari5d97caf300f7
diff --git a/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb b/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
index e558b1d5915..d376d4ebcb3 100644
--- a/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
+++ b/app/components/settings/project_custom_field_sections/custom_field_row_component.html.erb
@@ -16,11 +16,16 @@
@project_custom_field.name
end
end
- content_container.with_column do
+ content_container.with_column(mr: 2) do
render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) do
@project_custom_field.field_format.capitalize
end
end
+ content_container.with_column do
+ render(Primer::Beta::Text.new(font_size: :small)) do
+ project_count_text
+ end
+ end
end
main_container.with_column do
render(Primer::Alpha::ActionMenu.new) do |menu|
diff --git a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
index b36e95c8ef7..3dc7976b6d7 100644
--- a/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
+++ b/app/components/settings/project_custom_field_sections/custom_field_row_component.rb
@@ -79,6 +79,16 @@ module Settings
item.with_leading_visual_icon(icon: :trash)
end
end
+
+ def project_count_text
+ project_count = @project_custom_field.project_custom_field_project_mappings.size
+
+ if project_count == 1
+ "#{project_count} #{t('activerecord.models.project')}"
+ else
+ "#{project_count} #{t('label_project_plural')}"
+ end
+ end
end
end
end
diff --git a/app/controllers/admin/settings/project_custom_fields_controller.rb b/app/controllers/admin/settings/project_custom_fields_controller.rb
index 67317050e22..617b6cc23ca 100644
--- a/app/controllers/admin/settings/project_custom_fields_controller.rb
+++ b/app/controllers/admin/settings/project_custom_fields_controller.rb
@@ -116,7 +116,9 @@ module Admin::Settings
end
def set_sections
- @project_custom_field_sections = ProjectCustomFieldSection.all
+ @project_custom_field_sections = ProjectCustomFieldSection
+ .includes(custom_fields: :project_custom_field_project_mappings)
+ .all
end
def find_custom_field