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 life cycles in the sidebar

Dombi Attila96d1f2eac2cd
diff --git a/app/models/project/gate.rb b/app/models/project/gate.rb
index 46ee6fffdb7..c2342505d2d 100644
--- a/app/models/project/gate.rb
+++ b/app/models/project/gate.rb
@@ -39,4 +39,8 @@ class Project::Gate < Project::LifeCycleStep
errors.add(:base, :end_date_not_allowed)
end
end
+
+ def not_set?
+ date.blank?
+ end
end
diff --git a/app/models/project/life_cycle_step.rb b/app/models/project/life_cycle_step.rb
index d4ffcf43842..abccc560a70 100644
--- a/app/models/project/life_cycle_step.rb
+++ b/app/models/project/life_cycle_step.rb
@@ -33,6 +33,8 @@ class Project::LifeCycleStep < ApplicationRecord
class_name: "Project::LifeCycleStepDefinition"
has_many :work_packages, inverse_of: :project_life_cycle_step, dependent: :nullify
+ delegate :name, to: :life_cycle
+
attr_readonly :definition_id, :type
validates :type, inclusion: { in: %w[Project::Stage Project::Gate], message: :must_be_a_stage_or_gate }
diff --git a/app/models/project/stage.rb b/app/models/project/stage.rb
index b49ca7787b7..cf9e456add5 100644
--- a/app/models/project/stage.rb
+++ b/app/models/project/stage.rb
@@ -30,4 +30,8 @@ class Project::Stage < Project::LifeCycleStep
# This ensures the type cannot be changed after initialising the class.
validates :type, inclusion: { in: %w[Project::Stage], message: :must_be_a_stage }
validates :start_date, :end_date, presence: true
+
+ def not_set?
+ start_date.blank? || end_date.blank?
+ end
end
diff --git a/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.html.erb b/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.html.erb
new file mode 100644
index 00000000000..ac45e374d7d
--- /dev/null
+++ b/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.html.erb
@@ -0,0 +1,23 @@
+<%=
+ flex_layout(align_items: :flex_start,
+ justify_content: :space_between,
+ classes: 'op-project-life-cycle-container',
+ data: {
+ test_selector: "project-life-cycle-#{@project_life_cycle.id}"
+ }) do |life_cycle_value_container|
+ # temporarily using inline styles in order to align the content as desired
+ life_cycle_container.with_row(mb: 1) do
+ render(Primer::Beta::Text.new(font_weight: :bold)) do
+ concat @project_life_cycle.name
+ end
+ end
+
+ life_cycle_container.with_row(w: :full) do
+ if not_set?
+ render(Primer::Beta::Text.new()) { t('placeholders.default') }
+ else
+ render_value
+ end
+ end
+ end
+%>
diff --git a/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb b/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb
new file mode 100644
index 00000000000..9f54f071385
--- /dev/null
+++ b/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb
@@ -0,0 +1,63 @@
+#-- 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 ProjectLifeCycles
+ module Sections
+ module ProjectLifeCycles
+ class ShowComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+
+ def initialize(project_life_cycle:)
+ super
+
+ @project_life_cycle = project_life_cycle
+ end
+
+ private
+
+ def not_set?
+ @project_life_cycle.not_set?
+ end
+
+ def render_value
+ case @project_life_cycle
+ when Project::Gate
+ render(Primer::Beta::Text.new) do
+ concat @project_life_cycle.date
+ end
+ when Project::Stage
+ render(Primer::Beta::Text.new) do
+ concat [@project_life_cycle.start_date, " - ", @project_life_cycle.end_date].join
+ end
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb b/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb
index cb1fcd5ac93..4a0c5187d9c 100644
--- a/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb
+++ b/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb
@@ -1,31 +1,18 @@
<%=
component_wrapper do
render(Primer::OpenProject::SidePanel::Section.new(
- classes: 'op-project-custom-field-section-container',
- test_selector: "project-custom-field-section-#{@project_custom_field_section.id}"
+ classes: 'op-project-life-cyle-section-container',
+ test_selector: "project-life-cycle-section"
)) do |section|
section.with_title { "Life Cycles" }
- if allowed_to_edit?
- section.with_action_icon(
- icon: :pencil,
- tag: :a,
- href: project_custom_field_section_dialog_path(project_id: @project.id, section_id: @project_custom_field_section.id),
- data: {
- controller: 'async-dialog'
- },
- test_selector: "project-custom-field-section-edit-button",
- aria: { label: I18n.t(:label_edit) }
- )
- end
flex_layout do |details_container|
- @project_custom_fields.each_with_index do |project_custom_field, i|
- margin = i == @project_custom_fields.size - 1 ? 0 : 3
+ @project_life_cycles.each_with_index do |project_life_cycle, i|
+ margin = i == @project_life_cycles.size - 1 ? 0 : 3
details_container.with_row(mb: margin) do
- render(ProjectCustomFields::Sections::ProjectCustomFields::ShowComponent.new(
- project_custom_field:,
- project_custom_field_values: get_eager_loaded_project_custom_field_values_for(project_custom_field.id)
+ render(ProjectLifeCycles::Sections::ProjectLifeCycles::ShowComponent.new(
+ project_life_cycle:
))
end
end
diff --git a/modules/overviews/app/components/project_life_cycles/sections/show_component.rb b/modules/overviews/app/components/project_life_cycles/sections/show_component.rb
index c629c990fa4..a2788ed9a98 100644
--- a/modules/overviews/app/components/project_life_cycles/sections/show_component.rb
+++ b/modules/overviews/app/components/project_life_cycles/sections/show_component.rb
@@ -33,14 +33,11 @@ module ProjectLifeCycles
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
- def initialize(project:, project_custom_field_section:, project_custom_fields:)
+ def initialize(project:)
super
@project = project
- @project_custom_field_section = project_custom_field_section
- @project_custom_fields = project_custom_fields
-
- eager_load_project_custom_field_values
+ @project_life_cycles = @project.project_life_cycles.includes(:life_cycle)
end
private
@@ -48,21 +45,6 @@ module ProjectLifeCycles
def allowed_to_edit?
User.current.allowed_in_project?(:edit_project_attributes, @project)
end
-
- def eager_load_project_custom_field_values
- # TODO: move to service
- @eager_loaded_project_custom_field_values = CustomValue
- .includes(custom_field: :custom_options)
- .where(
- custom_field_id: @project_custom_fields.pluck(:id),
- customized_id: @project.id
- )
- .to_a
- end
-
- def get_eager_loaded_project_custom_field_values_for(custom_field_id)
- @eager_loaded_project_custom_field_values.select { |pcfv| pcfv.custom_field_id == custom_field_id }
- end
end
end
end
diff --git a/modules/overviews/app/components/project_life_cycles/side_panel_component.html.erb b/modules/overviews/app/components/project_life_cycles/side_panel_component.html.erb
index 8af7ed711e3..763a30ed12c 100644
--- a/modules/overviews/app/components/project_life_cycles/side_panel_component.html.erb
+++ b/modules/overviews/app/components/project_life_cycles/side_panel_component.html.erb
@@ -1,20 +1,10 @@
<%=
component_wrapper do
- if available_project_custom_fields_grouped_by_section.any?
- render(Primer::OpenProject::SidePanel.new(
- spacious: true,
- test_selector: "project-life-cycles-sidebar-async-content"
- )) do |panel|
- available_project_custom_fields_grouped_by_section.each do |project_custom_field_section, project_custom_fields|
- panel.with_section(
- ProjectLifeCycles::Sections::ShowComponent.new(
- project: @project,
- project_custom_field_section:,
- project_custom_fields: project_custom_fields
- )
- )
- end
- end
+ render(Primer::OpenProject::SidePanel.new(
+ spacious: true,
+ test_selector: "project-life-cycles-sidebar-async-content"
+ )) do |panel|
+ panel.with_section(ProjectLifeCycles::Sections::ShowComponent.new(project: @project))
end
end
%>
diff --git a/modules/overviews/app/components/project_life_cycles/side_panel_component.rb b/modules/overviews/app/components/project_life_cycles/side_panel_component.rb
index c21cba59c50..d837969ffa3 100644
--- a/modules/overviews/app/components/project_life_cycles/side_panel_component.rb
+++ b/modules/overviews/app/components/project_life_cycles/side_panel_component.rb
@@ -37,12 +37,5 @@ module ProjectLifeCycles
@project = project
end
-
- private
-
- def available_project_custom_fields_grouped_by_section
- @available_project_custom_fields_grouped_by_section ||=
- @project.available_custom_fields.group_by(&:project_custom_field_section)
- end
end
end