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

first draft for phase gate hover cards

Tobias Dillmann747bcb05a45f
diff --git a/app/components/projects/hover_card_component.html.erb b/app/components/projects/hover_card_component.html.erb
new file mode 100644
index 00000000000..5598d0cb303
--- /dev/null
+++ b/app/components/projects/hover_card_component.html.erb
@@ -0,0 +1,66 @@
+<%#-- 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.
+
+++#%>
+
+<%=
+ if @phase.present?
+ flex_layout(classes: "op-phase-gate-hover-card", data: { test_selector: "phase-gate-hover-card-#{phase.id}" }) do |flex|
+ flex.with_row do
+ flex_layout(classes: "op-phase-gate-hover-card--info", justify_content: :space_between) do |f|
+ 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)
+ end
+ fl.with_column do
+ render(Primer::Beta::Text.new(data: { test_selector: "phase-gate-hover-card-name" })) { phase_gate_name }
+ end
+ end
+ end
+
+ f.with_column(classes: "op-phase-gate-hover-card--date flex-self-end") do
+ flex_layout do |fl|
+ fl.with_column(mr: 1) do
+ render Primer::Beta::Octicon.new(icon: :calendar, color: :muted)
+ end
+ fl.with_column do
+ render(Primer::Beta::Text.new(data: { test_selector: "phase-gate-hover-card-date" })) { phase_gate_date }
+ end
+ end
+ end
+ end
+ end
+ end
+ else
+ render Primer::Beta::Blankslate.new(border: false, narrow: true) do |component|
+ component.with_visual_icon(icon: "x-circle")
+ # Show a generic error message to avoid leaking information
+ component.with_heading(tag: :h3).with_content(I18n.t("http.response.unexpected"))
+ end
+ end
+%>
diff --git a/app/components/projects/hover_card_component.rb b/app/components/projects/hover_card_component.rb
new file mode 100644
index 00000000000..231869f6d9a
--- /dev/null
+++ b/app/components/projects/hover_card_component.rb
@@ -0,0 +1,67 @@
+# 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.
+#++
+
+class Projects::HoverCardComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+
+ attr_reader :phase
+
+ def initialize(id:, gate: "start")
+ super
+
+ @id = id
+ @phase = Project::Phase.joins(:definition).includes(:definition).find(id)
+ @gate = gate.to_sym
+ end
+
+ def phase_gate_name
+ case @gate
+ when :start
+ @phase.definition.start_gate? ? @phase.definition.start_gate_name : nil
+ else
+ @phase.definition.finish_gate? ? @phase.definition.finish_gate_name : nil
+ end
+ end
+
+ def phase_gate_date
+ date = case @gate
+ when :start
+ @phase.start_date
+ else
+ @phase.finish_date
+ end
+
+ helpers.format_date(date)
+ end
+
+ def icon_color_class
+ Projects::PhaseComponent.icon_color_class(@phase.definition.id)
+ end
+end
diff --git a/app/components/projects/hover_card_component.sass b/app/components/projects/hover_card_component.sass
new file mode 100644
index 00000000000..1b09935dd0d
--- /dev/null
+++ b/app/components/projects/hover_card_component.sass
@@ -0,0 +1,19 @@
+.op-phase-gate-hover-card
+ display: grid
+ align-items: center
+ grid-template-columns: auto auto 1fr
+ grid-template-rows: max-content 1fr auto
+ grid-row-gap: calc(var(--stack-gap-condensed) / 2)
+ grid-column-gap: var(--stack-gap-condensed)
+ grid-template-areas: "info project project project" "subject subject subject subject" "assignee assignee dates dates"
+ overflow: hidden
+
+ &--project
+ @include text-shortener()
+
+ &--dates
+ justify-self: flex-end
+ white-space: nowrap
+
+ &--principal
+ max-width: 300px
diff --git a/app/components/projects/phase_component.html.erb b/app/components/projects/phase_component.html.erb
index 1079ff7a7af..511db0f8ea0 100644
--- a/app/components/projects/phase_component.html.erb
+++ b/app/components/projects/phase_component.html.erb
@@ -1,7 +1,7 @@
<%=
flex_layout(align_items: :center, classes: "gap-2") do |type_container|
if display_start_gate?
- type_container.with_column(classes: icon_color_class) do
+ type_container.with_column(classes: icon_color_class, data: hover_card_data_args) do
render Primer::Beta::Octicon.new(icon: gate_icon)
end
end
@@ -15,7 +15,7 @@
render(Primer::Beta::Text.new) { finish_date }
end
if display_finish_gate?
- type_container.with_column(classes: icon_color_class) do
+ type_container.with_column(classes: icon_color_class, data: hover_card_data_args(gate: "finish")) do
render Primer::Beta::Octicon.new(icon: gate_icon)
end
end
diff --git a/app/components/projects/phase_component.rb b/app/components/projects/phase_component.rb
index 93f56f23aa2..e6b80559920 100644
--- a/app/components/projects/phase_component.rb
+++ b/app/components/projects/phase_component.rb
@@ -61,12 +61,28 @@ module Projects
phase.finish_gate? && phase.finish_date.present?
end
- def gate_icon
+ 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
- helpers.hl_inline_class("project_phase_definition", phase.definition_id)
+ self.class.icon_color_class(phase.definition_id)
+ end
+
+ def hover_card_data_args(gate: "start")
+ raise ArgumentError, "gate must be either 'start' or 'finish'" unless %w[start finish].include?(gate.to_s)
+
+ {
+ hover_card_trigger_target: "trigger",
+ hover_card_url: "/projects/#{phase.id}/hover_card?gate=#{gate}"
+ }
end
private
diff --git a/app/controllers/projects/hover_card_controller.rb b/app/controllers/projects/hover_card_controller.rb
new file mode 100644
index 00000000000..fde1e24d3ca
--- /dev/null
+++ b/app/controllers/projects/hover_card_controller.rb
@@ -0,0 +1,56 @@
+# 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.
+#++
+class Projects::HoverCardController < ApplicationController
+ no_authorization_required! :show
+
+ def show
+ permitted_params = hover_card_params
+
+ unless valid_gate?(permitted_params[:gate])
+ render json: { error: "Invalid gate parameter" }, status: :unprocessable_entity
+ return
+ end
+
+ @id = permitted_params[:id]
+ @gate = permitted_params[:gate]
+
+ render layout: nil
+ end
+
+ private
+
+ def hover_card_params
+ params.permit(:id, :gate)
+ end
+
+ def valid_gate?(gate)
+ gate.present? && %w[start finish].include?(gate)
+ end
+end
diff --git a/app/views/projects/hover_card/show.html.erb b/app/views/projects/hover_card/show.html.erb
new file mode 100644
index 00000000000..9d25526fb5f
--- /dev/null
+++ b/app/views/projects/hover_card/show.html.erb
@@ -0,0 +1,3 @@
+<turbo-frame id="op-hover-card-body">
+ <%= render Projects::HoverCardComponent.new(id: @id, gate: @gate) %>
+</turbo-frame>
diff --git a/config/routes.rb b/config/routes.rb
index d2048905625..47dfb4e8f85 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -298,6 +298,8 @@ Rails.application.routes.draw do
patch :types
+ get "hover_card" => "projects/hover_card#show"
+
# Destroy uses a get request to prompt the user before the actual DELETE request
get :destroy_info, as: "confirm_destroy"
post :deactivate_work_package_attachments