From dbe40d36ce70c5dcf4d27db4453a16310a695bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Tue, 28 Nov 2023 13:50:10 +0100 Subject: [PATCH 1/2] Render dots in meeting subheader --- .../meetings/header_component.html.erb | 36 +--------------- .../components/meetings/header_component.rb | 14 ------ .../header_infoline_component.html.erb | 7 +++ .../meetings/header_infoline_component.rb | 43 +++++++++++++++++++ 4 files changed, 52 insertions(+), 48 deletions(-) create mode 100644 modules/meeting/app/components/meetings/header_infoline_component.html.erb create mode 100644 modules/meeting/app/components/meetings/header_infoline_component.rb diff --git a/modules/meeting/app/components/meetings/header_component.html.erb b/modules/meeting/app/components/meetings/header_component.html.erb index 7b1374d8592b..94203ba3ebfe 100644 --- a/modules/meeting/app/components/meetings/header_component.html.erb +++ b/modules/meeting/app/components/meetings/header_component.html.erb @@ -57,23 +57,7 @@ end show_header.with_row do - flex_layout(align_items: :center) do |meta_info| - meta_info.with_column(mr: 1) do - render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) { t("label_meeting_created_by") } - end - - meta_info.with_column(mr: 1) do - render_author_link - end - - meta_info.with_column(mr: 1) do - render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) { t("label_meeting_last_updated") } - end - - meta_info.with_column do - render(Primer::Beta::RelativeTime.new(font_size: :small, color: :subtle, datetime: last_updated_at)) - end - end + render(Meetings::HeaderInfolineComponent.new(@meeting)) end end @@ -110,23 +94,7 @@ end edit_header.with_row do - flex_layout(align_items: :center) do |meta_info| - meta_info.with_column(mr: 1) do - render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) { t("label_meeting_created_by") } - end - - meta_info.with_column(mr: 1) do - render_author_link - end - - meta_info.with_column(mr: 1) do - render(Primer::Beta::Text.new(font_size: :small, color: :subtle)) { t("label_meeting_last_updated") } - end - - meta_info.with_column do - render(Primer::Beta::RelativeTime.new(font_size: :small, color: :subtle, datetime: last_updated_at)) - end - end + render(Meetings::HeaderInfolineComponent.new(@meeting)) end end end diff --git a/modules/meeting/app/components/meetings/header_component.rb b/modules/meeting/app/components/meetings/header_component.rb index 967c2a8d006c..69d2bbdca109 100644 --- a/modules/meeting/app/components/meetings/header_component.rb +++ b/modules/meeting/app/components/meetings/header_component.rb @@ -41,22 +41,8 @@ def initialize(meeting:, state: :show) private - def render_author_link - render(Primer::Beta::Link.new(font_size: :small, href: user_path(@meeting.author), underline: false, - target: "_blank")) do - "#{@meeting.author.name}" - end - end - def delete_enabled? User.current.allowed_in_project?(:delete_meetings, @meeting.project) end - - def last_updated_at - latest_agenda_update = @meeting.agenda_items.maximum(:updated_at) || @meeting.updated_at - latest_meeting_update = @meeting.updated_at - - [latest_agenda_update, latest_meeting_update].max - end end end diff --git a/modules/meeting/app/components/meetings/header_infoline_component.html.erb b/modules/meeting/app/components/meetings/header_infoline_component.html.erb new file mode 100644 index 000000000000..efa0827c4462 --- /dev/null +++ b/modules/meeting/app/components/meetings/header_infoline_component.html.erb @@ -0,0 +1,7 @@ +<%= render(Primer::BaseComponent.new(tag: :div, color: :subtle, font_size: :small)) do %> + <%= t("label_meeting_created_by") %> + <%= render(Primer::Beta::Link.new(href: user_path(@meeting.author), underline: false, + target: "_blank")) { @meeting.author.name } %>. + <%= t("label_meeting_last_updated") %> + <%= render(Primer::Beta::RelativeTime.new(font_size: :small, datetime: last_updated_at, prefix: I18n.t(:label_on))) %>. +<% end %> diff --git a/modules/meeting/app/components/meetings/header_infoline_component.rb b/modules/meeting/app/components/meetings/header_infoline_component.rb new file mode 100644 index 000000000000..4d2a81553e16 --- /dev/null +++ b/modules/meeting/app/components/meetings/header_infoline_component.rb @@ -0,0 +1,43 @@ +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2012-2023 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 Meetings + class HeaderInfolineComponent < ApplicationComponent + def initialize(meeting) + super + @meeting = meeting + end + + def last_updated_at + latest_agenda_update = @meeting.agenda_items.maximum(:updated_at) || @meeting.updated_at + latest_meeting_update = @meeting.updated_at + + [latest_agenda_update, latest_meeting_update].max + end + end +end From 570d7658780f22758debe37e23092d00ddef6b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20G=C3=BCnther?= Date: Wed, 29 Nov 2023 11:48:12 +0100 Subject: [PATCH 2/2] Use our own relative time component for fixed prefix --- .../op_primer/relative_time_component.rb | 46 +++++++++++++++++++ .../relative_time_component_preview.rb | 13 ++++++ .../header_infoline_component.html.erb | 2 +- 3 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 app/components/op_primer/relative_time_component.rb create mode 100644 lookbook/previews/op_primer/relative_time_component_preview.rb diff --git a/app/components/op_primer/relative_time_component.rb b/app/components/op_primer/relative_time_component.rb new file mode 100644 index 000000000000..c49ab4758ca0 --- /dev/null +++ b/app/components/op_primer/relative_time_component.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true + +#-- copyright +# OpenProject is an open source project management software. +# Copyright (C) 2012-2023 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 OpPrimer + class RelativeTimeComponent < Primer::Component + def initialize(datetime:, **system_arguments) + super() + @system_arguments = deny_tag_argument(**system_arguments) + + @system_arguments[:datetime] = datetime + @system_arguments[:lang] ||= I18n.locale + @system_arguments[:prefix] ||= I18n.t(:label_on) + end + + def call + render(Primer::Beta::RelativeTime.new(**@system_arguments)) + end + end +end diff --git a/lookbook/previews/op_primer/relative_time_component_preview.rb b/lookbook/previews/op_primer/relative_time_component_preview.rb new file mode 100644 index 000000000000..6908a0d06a30 --- /dev/null +++ b/lookbook/previews/op_primer/relative_time_component_preview.rb @@ -0,0 +1,13 @@ +module OpPrimer + class RelativeTimeComponentPreview < Lookbook::Preview + def default(datetime: (Time.now - 123456.seconds)) + render OpPrimer::RelativeTimeComponent.new(datetime:) + end + + def german_locale(datetime: Time.parse('2023-10-25T09:06:03Z')) + I18n.with_locale(:de) do + render OpPrimer::RelativeTimeComponent.new(datetime:) + end + end + end +end diff --git a/modules/meeting/app/components/meetings/header_infoline_component.html.erb b/modules/meeting/app/components/meetings/header_infoline_component.html.erb index efa0827c4462..d6e0169dc7db 100644 --- a/modules/meeting/app/components/meetings/header_infoline_component.html.erb +++ b/modules/meeting/app/components/meetings/header_infoline_component.html.erb @@ -3,5 +3,5 @@ <%= render(Primer::Beta::Link.new(href: user_path(@meeting.author), underline: false, target: "_blank")) { @meeting.author.name } %>. <%= t("label_meeting_last_updated") %> - <%= render(Primer::Beta::RelativeTime.new(font_size: :small, datetime: last_updated_at, prefix: I18n.t(:label_on))) %>. + <%= render(OpPrimer::RelativeTimeComponent.new(font_size: :small, datetime: last_updated_at, prefix: I18n.t(:label_on))) %>. <% end %>