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
[#47013] Replace Projects::TableCell by ViewComponent
Dombi Attila5ce9405ee8d5
diff --git a/app/cells/views/projects/row/show.erb b/app/components/projects/row_component.html.erbsimilarity index 95%rename from app/cells/views/projects/row/show.erbrename to app/components/projects/row_component.html.erbindex 042077c9f0a..9ea66e45be2 100644--- a/app/cells/views/projects/row/show.erb+++ b/app/components/projects/row_component.html.erb@@ -27,7 +27,10 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<tr <%= "id=\"#{row_css_id}\"" if row_css_id %> class="<%= row_css_class %>">+<tr+ <%= "id=\"#{row_css_id}\"".html_safe if row_css_id %>+ <%= "class=\"#{row_css_class}\"".html_safe if row_css_class %>+><% columns.each do |column| %><td class="<%= column_css_class(column) %>"><%= column_value(column) %>diff --git a/app/cells/projects/row_cell.rb b/app/components/projects/row_component.rbsimilarity index 68%rename from app/cells/projects/row_cell.rbrename to app/components/projects/row_component.rbindex d0fc73b7d10..fc51ff72d1e 100644--- a/app/cells/projects/row_cell.rb+++ b/app/components/projects/row_component.rb@@ -1,8 +1,37 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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- class RowCell < ::RowCell+ class RowComponent < ::RowComponentinclude ProjectsHelperinclude ProjectStatusHelper- include ApplicationHelperinclude ::Redmine::I18ndef project@@ -20,7 +49,7 @@ module Projectsdef column_value(column)if column.to_s.start_with? 'cf_'- escaped(custom_field_column(column))+ custom_field_column(column)elsesuperend@@ -31,7 +60,7 @@ module Projectscustom_value = project.formatted_custom_value_for(cf)if cf.field_format == 'text'- custom_value.html_safe+ custom_value.html_safe # rubocop:disable Rails/OutputSafetyelsif custom_value.is_a?(Array)safe_join(Array(custom_value).compact_blank, ', ')else@@ -111,7 +140,7 @@ module Projectsenddef project_css_classes- s = ' project '+ s = ' project '.html_safes << ' root' if project.root?s << ' child' if project.child?diff --git a/app/cells/views/projects/table/show.erb b/app/components/projects/table_component.html.erbsimilarity index 97%rename from app/cells/views/projects/table/show.erbrename to app/components/projects/table_component.html.erbindex 1d333dd9246..c65dee4e690 100644--- a/app/cells/views/projects/table/show.erb+++ b/app/components/projects/table_component.html.erb@@ -30,7 +30,7 @@ See COPYRIGHT and LICENSE files for more details.<div class="generic-table--flex-container"><div class="generic-table--container"><div class="generic-table--results-container">- <table class="generic-table" <%= table_id ? "id=\"#{table_id}\"" : '' %>>+ <table class="generic-table" <%= table_id ? "id=\"#{table_id}\"".html_safe : '' %>><colgroup><% headers.each do |_name, _options| %><col <%= "opHighlightCol" unless _name == :hierarchy %> >@@ -85,9 +85,7 @@ See COPYRIGHT and LICENSE files for more details.<td colspan="<%= headers.length + 1 %>"><%= empty_row_message %></td></tr><% end %>- <% for row in rows do -%>- <%= render_row row %>- <% end -%>+ <%= render_collection rows %></tbody></table><% if inline_create_link && show_inline_create %>diff --git a/app/cells/projects/table_cell.rb b/app/components/projects/table_component.rbsimilarity index 67%rename from app/cells/projects/table_cell.rbrename to app/components/projects/table_component.rbindex c7a84fd4c68..72d681f4104 100644--- a/app/cells/projects/table_cell.rb+++ b/app/components/projects/table_component.rb@@ -1,5 +1,35 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-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- class TableCell < ::TableCell+ class TableComponent < ::TableComponentinclude ProjectsHelperoptions :params # We read collapsed state from params@@ -22,7 +52,7 @@ module Projects# We don't return the project row# but the [project, level] array from the helperdef rows- @rows ||= to_enum(:projects_with_levels_order_sensitive, model).to_a+ @rows ||= to_enum(:projects_with_levels_order_sensitive, model).to_a # rubocop:disable Lint/ToEnumArgumentsenddef initialize_sorted_modeldiff --git a/app/components/table_component.rb b/app/components/table_component.rbindex e646bd7b3ec..8746edfe2db 100644--- a/app/components/table_component.rb+++ b/app/components/table_component.rb@@ -34,7 +34,7 @@ class TableComponent < RailsComponentinclude SortHelperinclude PaginationHelper- def initialize(rows:, **options)+ def initialize(rows: [], **options)super(rows, **options)enddiff --git a/app/models/projects/exports/query_exporter.rb b/app/models/projects/exports/query_exporter.rbindex e39528c2eb1..bc418ec86c9 100644--- a/app/models/projects/exports/query_exporter.rb+++ b/app/models/projects/exports/query_exporter.rb@@ -61,8 +61,8 @@ module Projects::Exportsenddef selected_columns- ::Projects::TableCell- .new(nil, current_user: User.current)+ ::Projects::TableComponent+ .new(current_user: User.current).all_columns.reject { |_, options| options[:builtin] } # We add builtin columns ourselves.select { |name, _| Setting.enabled_projects_columns.include?(name.to_s) }diff --git a/app/views/admin/settings/projects_settings/show.html.erb b/app/views/admin/settings/projects_settings/show.html.erbindex c4e9a987f4c..e8d40db7d41 100644--- a/app/views/admin/settings/projects_settings/show.html.erb+++ b/app/views/admin/settings/projects_settings/show.html.erb@@ -48,13 +48,13 @@ See COPYRIGHT and LICENSE files for more details.<fieldset class="form--fieldset"><legend class="form--fieldset-legend"><%= t('settings.projects.section_project_overview') %></legend><%- column_choices = ::Projects::TableCell- .new(nil, current_user: current_user)+ column_choices = ::Projects::TableComponent+ .new(current_user: current_user).all_columns.reject { |_, options| !options[:caption] }.map { |name, options| [options[:caption], name.to_s, checked: options[:builtin], disabled: options[:builtin]] }%>-+<% unless EnterpriseToken.allows_to?(:custom_fields_in_projects_list) %><div class="form--field"><%=diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erbindex c32c77452b8..b1a88703ca8 100644--- a/app/views/projects/index.html.erb+++ b/app/views/projects/index.html.erb@@ -96,11 +96,11 @@ See COPYRIGHT and LICENSE files for more details.<%= render partial: 'projects/filters/form', locals: { query: @query } %>-<%= rails_cell Projects::TableCell,- @projects,+<%= render Projects::TableComponent.new(+ rows: @projects,current_user: current_user,orders: @orders,- params: params %>+ params: params) %><% if User.current.admin? %><p class="information-section">diff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex 10439cfed9a..4f127484e4c 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -417,7 +417,7 @@ module Settings},enabled_projects_columns: {default: %w[project_status public created_at latest_activity_at required_disk_space],- allowed: -> { Projects::TableCell.new(nil, current_user: User.admin.first).all_columns.map(&:first).map(&:to_s) }+ allowed: -> { Projects::TableComponent.new(current_user: User.admin.first).all_columns.map(&:first).map(&:to_s) }},enabled_scm: {default: %w[subversion git]