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

reapplied refactoring previously reverted

Jonas Jabari990c4bdd56c6
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index 6aec4724d5f..48929162060 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -96,13 +96,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
def edit
if allowed_to_edit?(@journal)
- update_via_turbo_stream(
- component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
- journal: @journal,
- state: :edit,
- filter: @filter
- )
- )
+ update_item_component(journal: @journal, state: :edit)
else
@turbo_status = :forbidden
end
@@ -112,13 +106,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
def cancel_edit
if allowed_to_edit?(@journal)
- update_via_turbo_stream(
- component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
- journal: @journal,
- state: :show,
- filter: @filter
- )
- )
+ update_item_component(journal: @journal, state: :show)
else
@turbo_status = :forbidden
end
@@ -145,7 +133,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
)
if call.success? && call.result
- update_item_component(call.result, state: :show)
+ update_item_component(journal: call.result, state: :show)
else
handle_failed_update_call(call)
end
@@ -282,38 +270,28 @@ class WorkPackages::ActivitiesTabController < ApplicationController
###
end
- def update_item_component(journal, state: :show)
+ def update_item_component(journal:, filter: @filter, state: :show)
update_via_turbo_stream(
component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
journal:,
state:,
- filter: @filter
+ filter:
)
)
end
def generate_time_based_update_streams(last_update_timestamp)
- # TODO: prototypical implementation
journals = @work_package.journals
if @filter == :only_comments
journals = journals.where.not(notes: "")
end
- journals.where("updated_at > ?", last_update_timestamp).find_each do |journal|
- update_via_turbo_stream(
- # we need to update the whole component as the show part is not rendered for journals which originally have no notes
- component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
- journal:,
- filter: @filter
- )
- )
- # TODO: is it possible to loose an edit state this way?
- end
+ rerender_updated_journals(journals, last_update_timestamp)
- journals.where("created_at > ?", last_update_timestamp).find_each do |journal|
- append_or_prepend_latest_journal_via_turbo_stream(journal)
- end
+ rerender_journals_with_updated_notification(journals, last_update_timestamp)
+
+ append_or_prepend_journals(journals, last_update_timestamp)
if journals.any?
remove_potential_empty_state
@@ -321,6 +299,28 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
end
+ def rerender_updated_journals(journals, last_update_timestamp)
+ journals.where("updated_at > ?", last_update_timestamp).find_each do |journal|
+ update_item_component(journal:)
+ end
+ end
+
+ def rerender_journals_with_updated_notification(journals, last_update_timestamp)
+ # Case: the user marked the journal as read somewhere else and expects the bubble to disappear
+ journals
+ .joins(:notifications)
+ .where("notifications.updated_at > ?", last_update_timestamp)
+ .find_each do |journal|
+ update_item_component(journal:)
+ end
+ end
+
+ def append_or_prepend_journals(journals, last_update_timestamp)
+ journals.where("created_at > ?", last_update_timestamp).find_each do |journal|
+ append_or_prepend_latest_journal_via_turbo_stream(journal)
+ end
+ end
+
def append_or_prepend_latest_journal_via_turbo_stream(journal)
target_component = WorkPackages::ActivitiesTab::Journals::IndexComponent.new(
work_package: @work_package,