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 shared component methods to Projects::Phases::Shared

Ivan Kuchin46e3c6133947
diff --git a/app/components/projects/phase_component.rb b/app/components/projects/phase_component.rb
index eb3d02a0a10..c48f4ae2539 100644
--- a/app/components/projects/phase_component.rb
+++ b/app/components/projects/phase_component.rb
@@ -30,6 +30,7 @@
module Projects
class PhaseComponent < ApplicationComponent
include OpPrimer::ComponentHelpers
+ include Projects::Phases::Shared
def initialize(phase:, **)
@phase = phase
@@ -61,21 +62,6 @@ module Projects
phase.finish_gate? && phase.finish_date.present?
end
- def self.gate_icon
- :"op-gate"
- end
- delegate :gate_icon, to: :class
-
- def self.icon_color_class(definition_id)
- # FIXME: this is a workaround so that this class method can be called from another component
- helper = Object.new.extend(ColorsHelper)
- helper.hl_inline_class("project_phase_definition", definition_id)
- end
-
- def icon_color_class
- self.class.icon_color_class(phase.definition_id)
- end
-
def hover_card_data_args(gate:)
raise ArgumentError, "gate must be either :start or :finish" unless %i[start finish].include?(gate)
diff --git a/app/components/projects/phases/hover_card_component.html.erb b/app/components/projects/phases/hover_card_component.html.erb
index 5b589aaa9e8..085db25eec6 100644
--- a/app/components/projects/phases/hover_card_component.html.erb
+++ b/app/components/projects/phases/hover_card_component.html.erb
@@ -35,7 +35,7 @@ See COPYRIGHT and LICENSE files for more details.
f.with_column(classes: "op-phase-gate-hover-card--name flex-self-start") do
flex_layout do |fl|
fl.with_column(classes: icon_color_class, mr: 1) do
- render Primer::Beta::Octicon.new(icon: Projects::PhaseComponent.gate_icon)
+ render Primer::Beta::Octicon.new(icon: gate_icon)
end
fl.with_column do
render(Primer::Beta::Text.new(data: { test_selector: "phase-gate-hover-card-name" })) { phase_gate_name }
diff --git a/app/components/projects/phases/hover_card_component.rb b/app/components/projects/phases/hover_card_component.rb
index ae61eb0b9e2..f200067825a 100644
--- a/app/components/projects/phases/hover_card_component.rb
+++ b/app/components/projects/phases/hover_card_component.rb
@@ -32,6 +32,7 @@ module Projects
module Phases
class HoverCardComponent < ApplicationComponent
include OpPrimer::ComponentHelpers
+ include Projects::Phases::Shared
attr_reader :phase
@@ -63,10 +64,6 @@ module Projects
helpers.format_date(date)
end
-
- def icon_color_class
- Projects::PhaseComponent.icon_color_class(@phase.definition.id)
- end
end
end
end
diff --git a/app/components/projects/phases/shared.rb b/app/components/projects/phases/shared.rb
new file mode 100644
index 00000000000..ff17be388e7
--- /dev/null
+++ b/app/components/projects/phases/shared.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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
+ module Phases
+ module Shared
+ def gate_icon = :"op-gate"
+
+ def icon_color_class
+ helpers.hl_inline_class("project_phase_definition", phase.definition_id)
+ end
+ end
+ end
+end