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

display project phase dates in project list using component

ulfertsf9b769934a2c
diff --git a/app/components/projects/phase_component.html.erb b/app/components/projects/phase_component.html.erb
new file mode 100644
index 00000000000..1079ff7a7af
--- /dev/null
+++ b/app/components/projects/phase_component.html.erb
@@ -0,0 +1,23 @@
+<%=
+ flex_layout(align_items: :center, classes: "gap-2") do |type_container|
+ if display_start_gate?
+ type_container.with_column(classes: icon_color_class) do
+ render Primer::Beta::Octicon.new(icon: gate_icon)
+ end
+ end
+ type_container.with_column do
+ render(Primer::Beta::Text.new) { start_date }
+ end
+ type_container.with_column do
+ render(Primer::Beta::Text.new) { "-" }
+ end
+ type_container.with_column do
+ render(Primer::Beta::Text.new) { finish_date }
+ end
+ if display_finish_gate?
+ type_container.with_column(classes: icon_color_class) do
+ render Primer::Beta::Octicon.new(icon: gate_icon)
+ end
+ end
+ end
+%>
diff --git a/app/components/projects/phase_component.rb b/app/components/projects/phase_component.rb
new file mode 100644
index 00000000000..70eed681048
--- /dev/null
+++ b/app/components/projects/phase_component.rb
@@ -0,0 +1,77 @@
+# 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
+ class PhaseComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+
+ def initialize(phase:, **)
+ @phase = phase
+
+ super(**)
+ end
+
+ def start_date
+ if phase.start_date.present?
+ helpers.format_date(phase.start_date)
+ else
+ helpers.t("js.label_no_start_date")
+ end
+ end
+
+ def finish_date
+ if phase.end_date.present?
+ helpers.format_date(phase.end_date)
+ else
+ helpers.t("js.label_no_due_date")
+ end
+ end
+
+ def display_start_gate?
+ phase.start_gate? && phase.start_date.present?
+ end
+
+ def display_finish_gate?
+ phase.end_gate? && phase.end_date.present?
+ end
+
+ def gate_icon
+ # TODO: use op-gate once octicons is released and merged in
+ :"git-commit"
+ end
+
+ def icon_color_class
+ helpers.hl_inline_class("project_phase_definition", phase.definition_id)
+ end
+
+ private
+
+ attr_reader :phase
+ end
+end
diff --git a/app/components/projects/row_component.rb b/app/components/projects/row_component.rb
index f139a931510..d5b48d232fb 100644
--- a/app/components/projects/row_component.rb
+++ b/app/components/projects/row_component.rb
@@ -71,8 +71,8 @@ module Projects
def column_value(column)
if custom_field_column?(column)
custom_field_column(column)
- elsif life_cycle_step_column?(column)
- life_cycle_step_column(column)
+ elsif project_phase_column?(column)
+ project_phase_column(column)
else
send(column.attribute)
end
@@ -98,14 +98,14 @@ module Projects
end
end
- def life_cycle_step_column(column)
+ def project_phase_column(column)
return nil unless user_can_view_project_phases?
- life_cycle_step = project_phase_by_definition(column.project_phase_definition, project)
+ phase = project_phase_by_definition(column.project_phase_definition, project)
- return nil if life_cycle_step.blank?
+ return nil if phase.blank?
- fmt_date_or_range(life_cycle_step.start_date, life_cycle_step.end_date)
+ render Projects::PhaseComponent.new(phase:)
end
def created_at
@@ -392,29 +392,12 @@ module Projects
column.is_a?(::Queries::Projects::Selects::CustomField)
end
- def life_cycle_step_column?(column)
+ def project_phase_column?(column)
column.is_a?(::Queries::Projects::Selects::ProjectPhase)
end
def current_page
table.model.current_page.to_s
end
-
- private
-
- # If only the `start_date` is given, will return a formatted version of that date as string.
- # When `end_date` is given as well, will return a representation of the date range from start to end.
- # @example
- # fmt_date_or_range(Date.new(2024, 12, 4))
- # "04/12/2024"
- #
- # fmt_date_or_range(Date.new(2024, 12, 4), Date.new(2024, 12, 10))
- # "04/12/2024 - 10/12/2024"
- def fmt_date_or_range(start_date, end_date = nil)
- [start_date, end_date]
- .compact
- .map { |d| helpers.format_date(d) }
- .join(" - ")
- end
end
end
diff --git a/app/models/project/phase.rb b/app/models/project/phase.rb
index 76a2d0dbaf0..5e1978b76b7 100644
--- a/app/models/project/phase.rb
+++ b/app/models/project/phase.rb
@@ -35,7 +35,11 @@ class Project::Phase < ApplicationRecord
validate :validate_date_range
- delegate :name, :position, to: :definition
+ delegate :name,
+ :position,
+ :start_gate?,
+ :end_gate?,
+ to: :definition
attr_readonly :definition_id, :type
diff --git a/app/views/highlighting/styles.css.erb b/app/views/highlighting/styles.css.erb
index e963618168d..2582f25c686 100644
--- a/app/views/highlighting/styles.css.erb
+++ b/app/views/highlighting/styles.css.erb
@@ -3,7 +3,7 @@
<%= resources_scope_color_css("priority", ::IssuePriority) %>
<%= resources_scope_color_css("type", ::Type, inline_foreground: true) %>
<%# Color coded icons %>
-<%= resources_scope_color_css("life_cycle_step_definition", Project::PhaseDefinition, inline_foreground: true) %>
+<%= resources_scope_color_css("project_phase_definition", Project::PhaseDefinition, inline_foreground: true) %>
<% Meetings::Statuses::AVAILABLE.each do |meeting_status| %>
<%= resource_color_css("meeting_status", meeting_status) %>
diff --git a/frontend/src/global_styles/layout/_colors.sass b/frontend/src/global_styles/layout/_colors.sass
index 83b3f1db669..bad6dd16ef3 100644
--- a/frontend/src/global_styles/layout/_colors.sass
+++ b/frontend/src/global_styles/layout/_colors.sass
@@ -95,8 +95,8 @@
font-weight: var(--base-text-weight-bold)
// Inline: all except type
-[class^='__hl_inline_']:not([class^='__hl_inline_type'], [class^='__hl_inline_life_cycle_step_definition']),
-[class*=' __hl_inline_']:not([class*='__hl_inline_type'], [class*='__hl_inline_life_cycle_step_definition'])
+[class^='__hl_inline_']:not([class^='__hl_inline_type'], [class^='__hl_inline_project_phase_definition']),
+[class*=' __hl_inline_']:not([class*='__hl_inline_type'], [class*='__hl_inline_project_phase_definition'])
&::before
content: ''
display: inline-block
diff --git a/lookbook/previews/open_project/projects/phase_component_preview.rb b/lookbook/previews/open_project/projects/phase_component_preview.rb
new file mode 100644
index 00000000000..f22fc0c5603
--- /dev/null
+++ b/lookbook/previews/open_project/projects/phase_component_preview.rb
@@ -0,0 +1,88 @@
+# 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 OpenProject::Projects
+ # @logical_path OpenProject/Projects
+ class PhaseComponentPreview < Lookbook::Preview
+ def phase_with_both_gates
+ phase = Project::Phase.new(id: 1,
+ definition: definition(start_gate: true, end_gate: true),
+ start_date: Date.current - 2.days,
+ end_date: Date.current + 2.days)
+
+ render_with_template(locals: { phase: })
+ end
+
+ def phase_with_both_gates_dates_not_set
+ phase = Project::Phase.new(id: 1,
+ definition: definition(start_gate: true, end_gate: true))
+
+ render_with_template(locals: { phase: })
+ end
+
+ def phase_with_start_gate
+ phase = Project::Phase.new(id: 1,
+ definition: definition(start_gate: true),
+ start_date: Date.current - 2.days,
+ end_date: Date.current + 2.days)
+
+ render_with_template(locals: { phase: })
+ end
+
+ def phase_with_end_gate
+ phase = Project::Phase.new(id: 1,
+ definition: definition(end_gate: true),
+ start_date: Date.current - 2.days,
+ end_date: Date.current + 2.days)
+
+ render_with_template(locals: { phase: })
+ end
+
+ def phase_without_gate
+ phase = Project::Phase.new(id: 1,
+ definition: definition,
+ start_date: Date.current - 2.days,
+ end_date: Date.current + 2.days)
+
+ render_with_template(locals: { phase: })
+ end
+
+ private
+
+ def definition(start_gate: false, end_gate: false)
+ Project::PhaseDefinition.new(id: 1,
+ name: "The first gate",
+ start_gate: start_gate,
+ start_gate_name: start_gate ? "Before the phase" : nil,
+ end_gate: end_gate,
+ end_gate_name: end_gate ? "After the phase" : nil)
+ end
+ end
+end
diff --git a/lookbook/previews/open_project/projects/phase_component_preview/phase_with_both_gates.html.erb b/lookbook/previews/open_project/projects/phase_component_preview/phase_with_both_gates.html.erb
new file mode 100644
index 00000000000..5ceebf8efac
--- /dev/null
+++ b/lookbook/previews/open_project/projects/phase_component_preview/phase_with_both_gates.html.erb
@@ -0,0 +1,6 @@
+<!-- Depends on having the color defined in the highlighting/styles.css.erb file. -->
+<style>
+ .__hl_inline_project_phase_definition_1 { color: red; }
+</style>
+
+<%= render(::Projects::PhaseComponent.new(phase:)) %>
diff --git a/lookbook/previews/open_project/projects/phase_component_preview/phase_with_both_gates_dates_not_set.html.erb b/lookbook/previews/open_project/projects/phase_component_preview/phase_with_both_gates_dates_not_set.html.erb
new file mode 100644
index 00000000000..5ceebf8efac
--- /dev/null
+++ b/lookbook/previews/open_project/projects/phase_component_preview/phase_with_both_gates_dates_not_set.html.erb
@@ -0,0 +1,6 @@
+<!-- Depends on having the color defined in the highlighting/styles.css.erb file. -->
+<style>
+ .__hl_inline_project_phase_definition_1 { color: red; }
+</style>
+
+<%= render(::Projects::PhaseComponent.new(phase:)) %>
diff --git a/lookbook/previews/open_project/projects/phase_component_preview/phase_with_end_gate.html.erb b/lookbook/previews/open_project/projects/phase_component_preview/phase_with_end_gate.html.erb
new file mode 100644
index 00000000000..5ceebf8efac
--- /dev/null
+++ b/lookbook/previews/open_project/projects/phase_component_preview/phase_with_end_gate.html.erb
@@ -0,0 +1,6 @@
+<!-- Depends on having the color defined in the highlighting/styles.css.erb file. -->
+<style>
+ .__hl_inline_project_phase_definition_1 { color: red; }
+</style>
+
+<%= render(::Projects::PhaseComponent.new(phase:)) %>
diff --git a/lookbook/previews/open_project/projects/phase_component_preview/phase_with_start_gate.html.erb b/lookbook/previews/open_project/projects/phase_component_preview/phase_with_start_gate.html.erb
new file mode 100644
index 00000000000..5ceebf8efac
--- /dev/null
+++ b/lookbook/previews/open_project/projects/phase_component_preview/phase_with_start_gate.html.erb
@@ -0,0 +1,6 @@
+<!-- Depends on having the color defined in the highlighting/styles.css.erb file. -->
+<style>
+ .__hl_inline_project_phase_definition_1 { color: red; }
+</style>
+
+<%= render(::Projects::PhaseComponent.new(phase:)) %>
diff --git a/lookbook/previews/open_project/projects/phase_component_preview/phase_without_gate.html.erb b/lookbook/previews/open_project/projects/phase_component_preview/phase_without_gate.html.erb
new file mode 100644
index 00000000000..ea252c10bcd
--- /dev/null
+++ b/lookbook/previews/open_project/projects/phase_component_preview/phase_without_gate.html.erb
@@ -0,0 +1 @@
+<%= render(::Projects::PhaseComponent.new(phase:)) %>