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

group journals by day

Jonas Jabari83a4948802bc
diff --git a/app/components/work_packages/activities_tab/journals/day_component.html.erb b/app/components/work_packages/activities_tab/journals/day_component.html.erb
new file mode 100644
index 00000000000..b0e44ce2c33
--- /dev/null
+++ b/app/components/work_packages/activities_tab/journals/day_component.html.erb
@@ -0,0 +1,20 @@
+<%=
+ component_wrapper do
+ flex_layout do |day_container|
+ day_container.with_row(my:2) do
+ render(Primer::Beta::Text.new(color: :muted)) { format_activity_day(day_as_date) }
+ end
+ day_container.with_row do
+ flex_layout(id: insert_target_modifier_id) do |journals_of_day_container|
+ journals.each do |journal|
+ journals_of_day_container.with_row do
+ render(
+ WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:)
+ )
+ end
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/work_packages/activities_tab/journals/day_component.rb b/app/components/work_packages/activities_tab/journals/day_component.rb
new file mode 100644
index 00000000000..2b72d553e33
--- /dev/null
+++ b/app/components/work_packages/activities_tab/journals/day_component.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 WorkPackages
+ module ActivitiesTab
+ module Journals
+ class DayComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(day_as_date:, journals:, work_package:)
+ super
+
+ @work_package = work_package
+ @day_as_date = day_as_date
+ @journals = journals
+ end
+
+ private
+
+ attr_reader :work_package, :day_as_date, :journals
+
+ def insert_target_modified?
+ true
+ end
+
+ def insert_target_modifier_id
+ "work-package-journals-day-#{day_as_date}"
+ end
+ end
+ end
+ end
+end
diff --git a/app/components/work_packages/activities_tab/journals/index_component.html.erb b/app/components/work_packages/activities_tab/journals/index_component.html.erb
index 65ace85f92a..fdac77e9d30 100644
--- a/app/components/work_packages/activities_tab/journals/index_component.html.erb
+++ b/app/components/work_packages/activities_tab/journals/index_component.html.erb
@@ -1,11 +1,11 @@
<%=
component_wrapper do
flex_layout(id: insert_target_modifier_id) do |journals_index_container|
- if journals.any?
- journals.each do |journal|
+ if journals_grouped_by_day.any?
+ journals_grouped_by_day.each do |day, journals|
journals_index_container.with_row do
render(
- WorkPackages::ActivitiesTab::Journals::ItemComponent.new(journal:)
+ WorkPackages::ActivitiesTab::Journals::DayComponent.new(day_as_date: day, journals:, work_package:)
)
end
end
diff --git a/app/components/work_packages/activities_tab/journals/index_component.rb b/app/components/work_packages/activities_tab/journals/index_component.rb
index 3cff987bdde..5dc61aedbf5 100644
--- a/app/components/work_packages/activities_tab/journals/index_component.rb
+++ b/app/components/work_packages/activities_tab/journals/index_component.rb
@@ -52,20 +52,20 @@ module WorkPackages
end
def insert_target_modifier_id
- "work-package-journals"
+ "work-package-journal-days"
end
def journal_sorting
User.current.preference&.comments_sorting || "desc"
end
- def journals
+ def journals_grouped_by_day
result = work_package.journals.includes(:user, :notifications).reorder(version: journal_sorting)
result = result.where.not(notes: "") if filter == :only_comments
result = result.where(notes: "") if filter == :only_changes
- result
+ result.group_by { |journal| journal.created_at.in_time_zone(User.current.time_zone).to_date }
end
end
end
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index 99e0df6d706..d7526eca62f 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -86,8 +86,10 @@ class WorkPackages::ActivitiesTabController < ApplicationController
)
end
+ latest_journal_visible_for_user = journals.where(created_at: ..params[:last_update_timestamp]).last
+
journals.where("created_at > ?", params[:last_update_timestamp]).find_each do |journal|
- append_or_prepend_latest_journal_via_turbo_stream(journal)
+ append_or_prepend_latest_journal_via_turbo_stream(journal, latest_journal_visible_for_user)
end
respond_with_turbo_streams
@@ -117,14 +119,14 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
def create
- latest_journal_version = @work_package.journals.last.try(:version) || 0
+ latest_journal = @work_package.journals.last
call = Journals::CreateService.new(@work_package, User.current).call(
notes: journal_params[:notes]
)
if call.success? && call.result
- after_create_turbo_stream(call, latest_journal_version)
+ after_create_turbo_stream(call, latest_journal)
end
clear_form_via_turbo_stream
@@ -200,24 +202,39 @@ class WorkPackages::ActivitiesTabController < ApplicationController
params.require(:journal).permit(:notes)
end
- def after_create_turbo_stream(call, latest_journal_version)
+ def after_create_turbo_stream(call, latest_journal)
# journals might get merged in some cases,
# thus we need to check if the journal is already present and update it rather then ap/prepending it
- if latest_journal_version < call.result.version
- append_or_prepend_latest_journal_via_turbo_stream(call.result)
+ if latest_journal.nil? || (latest_journal.present? && latest_journal.version < call.result.version)
+ append_or_prepend_latest_journal_via_turbo_stream(call.result, latest_journal)
else
update_journal_via_turbo_stream(call.result)
end
end
- def append_or_prepend_latest_journal_via_turbo_stream(journal)
- stream_config = {
- target_component: WorkPackages::ActivitiesTab::Journals::IndexComponent.new(
- work_package: @work_package
- ),
- component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
+ def append_or_prepend_latest_journal_via_turbo_stream(journal, latest_journal)
+ if latest_journal.created_at.to_date == journal.created_at.to_date
+ target_component = WorkPackages::ActivitiesTab::Journals::DayComponent.new(
+ work_package: @work_package,
+ day_as_date: journal.created_at.to_date,
+ journals: [journal] # we don't need to pass all actual journals of this day as we do not really render this component
+ )
+ component = WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
journal:
)
+ else
+ target_component = WorkPackages::ActivitiesTab::Journals::IndexComponent.new(
+ work_package: @work_package
+ )
+ component = WorkPackages::ActivitiesTab::Journals::DayComponent.new(
+ work_package: @work_package,
+ day_as_date: journal.created_at.to_date,
+ journals: [journal]
+ )
+ end
+ stream_config = {
+ target_component:,
+ component:
}
# Append or prepend the new journal depending on the sorting