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

Add HighlightedDate to WorkPackage HoverCard

Henriette Dargefdcfa07b888c
diff --git a/app/components/work_packages/highlighted_date_component.html.erb b/app/components/work_packages/highlighted_date_component.html.erb
new file mode 100644
index 00000000000..5611b5bef81
--- /dev/null
+++ b/app/components/work_packages/highlighted_date_component.html.erb
@@ -0,0 +1,11 @@
+<%=
+ if @start_date == @due_date
+ render(Primer::Beta::Text.new(**text_arguments, classes: date_classes(@start_date))) { parsed_date(@start_date) }
+ else
+ component_wrapper do
+ concat(render(Primer::Beta::Text.new(**text_arguments)) { parsed_date(@start_date) })
+ concat(render(Primer::Beta::Text.new(**text_arguments)) { " - " }) if @due_date.present?
+ concat(render(Primer::Beta::Text.new(**text_arguments, classes: date_classes(@due_date))) { parsed_date(@due_date) })
+ end
+ end
+%>
diff --git a/app/components/work_packages/highlighted_date_component.rb b/app/components/work_packages/highlighted_date_component.rb
new file mode 100644
index 00000000000..8c59ef70e81
--- /dev/null
+++ b/app/components/work_packages/highlighted_date_component.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+class WorkPackages::HighlightedDateComponent < ApplicationComponent
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(work_package:)
+ super
+
+ @work_package = work_package
+ @start_date = work_package.start_date
+ @due_date = work_package.due_date
+ end
+
+ def parsed_date(date)
+ return if date.nil?
+
+ date.strftime(I18n.t("date.formats.default"))
+ end
+
+ def date_classes(date)
+ return if date.nil?
+
+ diff = (date - Time.zone.today).to_i
+ if diff === 0
+ return "__hl_date_due_today"
+ elsif diff <= -1
+ return "__hl_date_overdue"
+ end
+
+ "__hl_date_not_overdue"
+ end
+
+ def text_arguments
+ {
+ font_size: :small,
+ color: :muted
+ }
+ end
+end
diff --git a/app/components/work_packages/highlighted_type_component.rb b/app/components/work_packages/highlighted_type_component.rb
index 7a5ba448281..a13e528adf1 100644
--- a/app/components/work_packages/highlighted_type_component.rb
+++ b/app/components/work_packages/highlighted_type_component.rb
@@ -7,10 +7,10 @@ class WorkPackages::HighlightedTypeComponent < ApplicationComponent
super
@type = work_package.type
- @system_arguments = system_arguments
+ @system_arguments = system_arguments.merge({ classes: "__hl_inline_type_#{@type.id}" })
end
def call
- render(Primer::Beta::Text.new(classes: "__hl_inline_type_#{@type.id}"), **@system_arguments) { @type.name.upcase }
+ render(Primer::Beta::Text.new(**@system_arguments)) { @type.name.upcase }
end
end
diff --git a/app/components/work_packages/hover_card_component.html.erb b/app/components/work_packages/hover_card_component.html.erb
index abb9f1003d8..8bdd2f075ef 100644
--- a/app/components/work_packages/hover_card_component.html.erb
+++ b/app/components/work_packages/hover_card_component.html.erb
@@ -1,39 +1,40 @@
-<%= if @work_package.present?
- grid_layout('op-wp-hover-card', tag: :div) do |grid|
- grid.with_area(:status, tag: :div, color: :muted) do
- render WorkPackages::StatusButtonComponent.new(work_package: @work_package,
- user: helpers.current_user,
- readonly: true,
- button_arguments: { size: :small })
- end
+<%=
+ if @work_package.present?
+ grid_layout('op-wp-hover-card', tag: :div) do |grid|
+ grid.with_area(:status, tag: :div, color: :muted) do
+ render WorkPackages::StatusButtonComponent.new(work_package: @work_package,
+ user: helpers.current_user,
+ readonly: true,
+ button_arguments: { size: :small })
+ end
- grid.with_area(:id, tag: :div, color: :muted) do
- render(Primer::Beta::Text.new(font_size: :small)) { "##{@work_package.id}" }
- end
+ grid.with_area(:id, tag: :div, color: :muted) do
+ render(Primer::Beta::Text.new(font_size: :small)) { "##{@work_package.id}" }
+ end
- grid.with_area(:project, tag: :div, color: :muted) do
- render(Primer::Beta::Text.new(font_size: :small)) { "- #{@work_package.project.name}" }
- end
+ grid.with_area(:project, tag: :div, color: :muted) do
+ render(Primer::Beta::Text.new(font_size: :small)) { "- #{@work_package.project.name}" }
+ end
- grid.with_area(:type, tag: :div) do
- render(WorkPackages::HighlightedTypeComponent.new(work_package: @work_package))
- end
+ grid.with_area(:middleRow, tag: :div) do
+ concat(render(WorkPackages::HighlightedTypeComponent.new(work_package: @work_package, mr: 1)))
+ concat(render(Primer::Beta::Text.new(font_weight: :semibold)) { @work_package.subject })
+ end
- grid.with_area(:subject, tag: :div) do
- render(Primer::Beta::Text.new(font_weight: :semibold)) { @work_package.subject }
- end
+ if @assignee.present?
+ grid.with_area(:assignee, tag: :div) do
+ render(Users::AvatarComponent.new(user: @assignee, show_name: false, size: :medium))
+ end
+ end
- if @assignee.present?
- grid.with_area(:assignee, tag: :div) do
- render(Users::AvatarComponent.new(user: @assignee, show_name: false, size: :medium))
+ grid.with_area(:dates, tag: :div) do
+ render(WorkPackages::HighlightedDateComponent.new(work_package: @work_package))
+ end
+ end
+ else
+ render Primer::Beta::Blankslate.new(border: false, narrow: true) do |component|
+ component.with_visual_icon(icon: "x-circle")
+ component.with_heading(tag: :h3).with_content(I18n.t("api_v3.errors.not_found.work_package"))
end
end
- end
- else
-
- render Primer::Beta::Blankslate.new(border: false, narrow: true) do |component|
- component.with_visual_icon(icon: "x-circle")
- component.with_heading(tag: :h3).with_content(I18n.t("api_v3.errors.not_found.work_package"))
- end
-
-end %>
+%>
diff --git a/app/components/work_packages/hover_card_component.sass b/app/components/work_packages/hover_card_component.sass
index 4f22ecb3dac..af7a019e17b 100644
--- a/app/components/work_packages/hover_card_component.sass
+++ b/app/components/work_packages/hover_card_component.sass
@@ -1,13 +1,15 @@
.op-wp-hover-card
display: grid
align-items: center
- grid-template-columns: max-content max-content max-content auto auto 1fr
+ grid-template-columns: max-content max-content max-content auto 1fr
grid-template-rows: max-content 1fr auto
grid-row-gap: 5px
grid-column-gap: 5px
- grid-template-areas: "status status id project project project" "type subject subject subject subject subject" "assignee assignee . . . ."
+ grid-template-areas: "status status id project project" "middleRow middleRow middleRow middleRow middleRow" "assignee assignee dates dates dates"
overflow: hidden
- &--type,
- &--subject
+ &--middleRow
align-self: flex-start
+
+ &--dates
+ justify-self: flex-end