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

[#47015] Replace Statuses::TableCell by ViewComponent

Dombi Attila51e6bdeb4734
diff --git a/app/cells/statuses/row_cell.rb b/app/cells/statuses/row_cell.rb
deleted file mode 100644
index 2bdda96dc18..00000000000
--- a/app/cells/statuses/row_cell.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-module Statuses
- class RowCell < ::RowCell
- include ::IconsHelper
- include ::ColorsHelper
- include ReorderLinksHelper
-
- def status
- model
- end
-
- def name
- link_to status.name, edit_status_path(status)
- end
-
- def is_default
- checkmark(status.is_default?)
- end
-
- def is_closed
- checkmark(status.is_closed?)
- end
-
- def is_readonly
- checkmark(status.is_readonly?)
- end
-
- def color
- icon_for_color status.color
- end
-
- def done_ratio
- h(status.default_done_ratio)
- end
-
- def sort
- reorder_links 'status',
- { action: 'update', id: status },
- method: :patch
- end
-
- def button_links
- [
- delete_link
- ]
- end
-
- def delete_link
- link_to(
- op_icon('icon icon-delete'),
- status_path(status),
- method: :delete,
- data: { confirm: I18n.t(:text_are_you_sure) },
- title: t(:button_delete)
- )
- end
- end
-end
diff --git a/app/cells/statuses/table_cell.rb b/app/cells/statuses/table_cell.rb
deleted file mode 100644
index 48f3f467b63..00000000000
--- a/app/cells/statuses/table_cell.rb
+++ /dev/null
@@ -1,47 +0,0 @@
-module Statuses
- class TableCell < ::TableCell
- def initial_sort
- %i[id asc]
- end
-
- def sortable?
- false
- end
-
- def columns
- headers.map(&:first)
- end
-
- def inline_create_link
- link_to new_status_path,
- aria: { label: t(:label_work_package_status_new) },
- class: 'wp-inline-create--add-link',
- title: t(:label_work_package_status_new) do
- op_icon('icon icon-add')
- end
- end
-
- def empty_row_message
- I18n.t :no_results_title_text
- end
-
- def row_class
- ::Statuses::RowCell
- end
-
- def headers
- [
- [:name, { caption: Status.human_attribute_name(:name) }],
- [:color, { caption: Status.human_attribute_name(:color) }],
- [:is_default, { caption: Status.human_attribute_name(:is_default) }],
- [:is_closed, { caption: Status.human_attribute_name(:is_closed) }],
- [:is_readonly, { caption: Status.human_attribute_name(:is_readonly) }],
- [:sort, { caption: I18n.t(:label_sort) }]
- ].tap do |default|
- if WorkPackage.use_status_for_done_ratio?
- default.insert 2, [:done_ratio, { caption: WorkPackage.human_attribute_name(:done_ratio) }]
- end
- end
- end
- end
-end
diff --git a/app/components/statuses/row_component.rb b/app/components/statuses/row_component.rb
new file mode 100644
index 00000000000..21a6963d825
--- /dev/null
+++ b/app/components/statuses/row_component.rb
@@ -0,0 +1,87 @@
+# 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 Statuses
+ class RowComponent < ::RowComponent
+ include ::IconsHelper
+ include ::ColorsHelper
+ include ReorderLinksHelper
+
+ def status
+ model
+ end
+
+ def name
+ link_to status.name, edit_status_path(status)
+ end
+
+ def default?
+ checkmark(status.is_default?)
+ end
+
+ def closed?
+ checkmark(status.is_closed?)
+ end
+
+ def readonly?
+ checkmark(status.is_readonly?)
+ end
+
+ def color
+ icon_for_color status.color
+ end
+
+ def done_ratio
+ h(status.default_done_ratio)
+ end
+
+ def sort
+ reorder_links 'status',
+ { action: 'update', id: status },
+ method: :patch
+ end
+
+ def button_links
+ [
+ delete_link
+ ]
+ end
+
+ def delete_link
+ link_to(
+ op_icon('icon icon-delete'),
+ status_path(status),
+ method: :delete,
+ data: { confirm: I18n.t(:text_are_you_sure) },
+ title: t(:button_delete)
+ )
+ end
+ end
+end
diff --git a/app/components/statuses/table_component.rb b/app/components/statuses/table_component.rb
new file mode 100644
index 00000000000..013e86cb422
--- /dev/null
+++ b/app/components/statuses/table_component.rb
@@ -0,0 +1,73 @@
+# 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 Statuses
+ class TableComponent < ::TableComponent
+ def initial_sort
+ %i[id asc]
+ end
+
+ def sortable?
+ false
+ end
+
+ def columns
+ headers.map(&:first)
+ end
+
+ def inline_create_link
+ link_to new_status_path,
+ aria: { label: t(:label_work_package_status_new) },
+ class: 'wp-inline-create--add-link',
+ title: t(:label_work_package_status_new) do
+ op_icon('icon icon-add')
+ end
+ end
+
+ def empty_row_message
+ I18n.t :no_results_title_text
+ end
+
+ def headers
+ [
+ [:name, { caption: Status.human_attribute_name(:name) }],
+ [:color, { caption: Status.human_attribute_name(:color) }],
+ [:default?, { caption: Status.human_attribute_name(:is_default) }],
+ [:closed?, { caption: Status.human_attribute_name(:is_closed) }],
+ [:readonly?, { caption: Status.human_attribute_name(:is_readonly) }],
+ [:sort, { caption: I18n.t(:label_sort) }]
+ ].tap do |default|
+ if WorkPackage.use_status_for_done_ratio?
+ default.insert 2, [:done_ratio, { caption: WorkPackage.human_attribute_name(:done_ratio) }]
+ end
+ end
+ end
+ end
+end
diff --git a/app/views/statuses/index.html.erb b/app/views/statuses/index.html.erb
index 508dcb77eae..f1a96ffceca 100644
--- a/app/views/statuses/index.html.erb
+++ b/app/views/statuses/index.html.erb
@@ -48,4 +48,4 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<% end %>
-<%= rails_cell ::Statuses::TableCell, @statuses %>
+<%= render ::Statuses::TableComponent.new(rows: @statuses) %>