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
Refactor strages table in admininstration to use ViewComponents
Wieland Lindenthal75748643abe2
diff --git a/modules/storages/app/cells/storages/storages_row_cell.rb b/modules/storages/app/cells/storages/storages_row_cell.rbdeleted file mode 100644index f0b4ed1b3a9..00000000000--- a/modules/storages/app/cells/storages/storages_row_cell.rb+++ /dev/null@@ -1,45 +0,0 @@-# Purpose: Defines the row model for the table of Storage objects-# Used by: Storage table in storages_table_cell.rb-# Reference: https://trailblazer.to/2.0/gems/cells.html-module Storages- class StoragesRowCell < ::RowCell- include ::IconsHelper # Global helper for icons, defines op_icon and icon_wrapper?- include ::AvatarHelper # Global helper for avatar (image of a user)- include ::Redmine::I18n # Internationalization support (defines I18n.t(...) translation)-- def name- link_to model.name, admin_settings_storage_path(model)- end-- # Delegate delegates the execution of certain methods to :model.- # https://www.rubydoc.info/gems/activesupport/Module:delegate- delegate :host, to: :model- delegate :provider_type, to: :model-- def creator- icon = avatar model.creator, size: :mini- icon + model.creator.name- end-- def button_links- [edit_link, delete_link]- end-- def delete_link- link_to '',- admin_settings_storage_path(model),- class: 'icon icon-delete',- data: { confirm: I18n.t('storages.delete_warning.storage') },- title: I18n.t(:button_delete),- method: :delete- end-- def edit_link- link_to '',- edit_admin_settings_storage_path(model),- class: 'icon icon-edit',- accesskey: accesskey(:edit),- title: I18n.t(:button_edit)- end- end-enddiff --git a/modules/storages/app/components/storages/admin/row_component.rb b/modules/storages/app/components/storages/admin/row_component.rbnew file mode 100644index 00000000000..c218441d7d3--- /dev/null+++ b/modules/storages/app/components/storages/admin/row_component.rb@@ -0,0 +1,79 @@+#-- 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.+#++++# Purpose: Defines the row model for the table of Storage objects+# Used by: Storages table in table_component.rb+module Storages::Admin+ class RowComponent < ::RowComponent+ include ::IconsHelper # Global helper for icons, defines op_icon and icon_wrapper?+ include ::AvatarHelper # Global helper for avatar (image of a user)+ include ::Redmine::I18n # Internationalization support (defines I18n.t(...) translation)+ include ::ApplicationHelper # For `accesskey` method++ def storage+ row+ end++ delegate :created_at, to: :storage++ def name+ link_to storage.name, admin_settings_storage_path(storage)+ end++ # Delegate delegates the execution of certain methods to :storage.+ # https://www.rubydoc.info/gems/activesupport/Module:delegate+ delegate :host, to: :storage+ delegate :provider_type, to: :storage++ def creator+ icon = avatar storage.creator, size: :mini+ icon + storage.creator.name+ end++ def button_links+ [edit_link, delete_link]+ end++ def delete_link+ link_to '',+ admin_settings_storage_path(storage),+ class: 'icon icon-delete',+ data: { confirm: I18n.t('storages.delete_warning.storage') },+ title: I18n.t(:button_delete),+ method: :delete+ end++ def edit_link+ link_to '',+ edit_admin_settings_storage_path(storage),+ class: 'icon icon-edit',+ accesskey: accesskey(:edit),+ title: I18n.t(:button_edit)+ end+ end+enddiff --git a/modules/storages/app/cells/storages/storages_table_cell.rb b/modules/storages/app/components/storages/admin/table_component.rbsimilarity index 52%rename from modules/storages/app/cells/storages/storages_table_cell.rbrename to modules/storages/app/components/storages/admin/table_component.rbindex 6f83136ea3c..36d29579b99 100644--- a/modules/storages/app/cells/storages/storages_table_cell.rb+++ b/modules/storages/app/components/storages/admin/table_component.rb@@ -1,19 +1,40 @@+#-- 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.+#+++# Purpose: Defines a table with the list of Storages::Storage# objects in the global admin section of OpenProject# Used by: the admin list of all storages in the system# (storages/app/views/storages/admin/index.html.erb)-# Reference: https://trailblazer.to/2.0/gems/cells.html-# See also: storage_row_cell.rb with the row model of the table-module Storages- class StoragesTableCell < ::TableCell+# See also: row_component.rb defining the rows of the table+module Storages::Admin+ class TableComponent < ::TableComponentinclude ::IconsHelper # Global helper for icons, defines op_icon(...)- class << self- def row_class- ::Storages::StoragesRowCell- end- end-# Defines the list of columns in the table using symbols.# These symbols are used below to define header (top of the table)# and contents of the cells@@ -24,12 +45,12 @@ module Storages%i[created_at asc]end- # Should RubyCell show ^/v icons in the header to allow custom sorting?+ # Should the TableComponent show ^/v icons in the header to allow custom sorting?def sortable?falseend- # Used by: app/cells/views/table/show.erb and+ # Used by: app/components/table_component.html.erb# Purpose: return the link to be used to create the storagedef inline_create_linklink_to(new_admin_settings_storage_path,diff --git a/modules/storages/app/components/storages/projects_storages/row_component.rb b/modules/storages/app/components/storages/projects_storages/row_component.rbindex 30c66ab1598..08e38dc38cc 100644--- a/modules/storages/app/components/storages/projects_storages/row_component.rb+++ b/modules/storages/app/components/storages/projects_storages/row_component.rb@@ -1,8 +1,33 @@-# Purpose: Defines how to format the cells within a table of ProjectStorages+#-- 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.+#++++# Purpose: Defines how to format the cells within a table row of ProjectStorages# associated with a project-# Used by: projects_storages_table_cell.rb - the methods defined here-# correspond to the columns value in the table model.-# See for more comments: storage_row_cell.rbmodule Storages::ProjectsStoragesclass RowComponent < ::RowComponentinclude ::IconsHelperdiff --git a/modules/storages/app/components/storages/projects_storages/table_component.rb b/modules/storages/app/components/storages/projects_storages/table_component.rbindex 3427357dc0a..dee88e50228 100644--- a/modules/storages/app/components/storages/projects_storages/table_component.rb+++ b/modules/storages/app/components/storages/projects_storages/table_component.rb@@ -26,11 +26,10 @@# See COPYRIGHT and LICENSE files for more details.#++-# Purpose: Defines a table based on RubyCell for listing the+# Purpose: Defines a table based on TableComponent for listing the# Storages::ProjectStorage per project in the projects' settings# page.-# See for comments: storage_table_cell.rb-# See also: project_storages_row_cell.rb, which contains a method+# See also: row_component.rb, which contains a method# for every "column" defined below.module Storages::ProjectsStoragesclass TableComponent < ::TableComponentdiff --git a/modules/storages/app/views/storages/admin/storages/index.html.erb b/modules/storages/app/views/storages/admin/storages/index.html.erbindex dd31c803d24..60185750c5c 100644--- a/modules/storages/app/views/storages/admin/storages/index.html.erb+++ b/modules/storages/app/views/storages/admin/storages/index.html.erb@@ -28,4 +28,4 @@</div></div>-<%= rails_cell ::Storages::StoragesTableCell, @storages %>+<%= render(::Storages::Admin::TableComponent.new(rows: @storages)) %>