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

refactored to resolve rubocop issues

Jonas Jabari87ec0dab32ff
diff --git a/app/components/work_packages/activities_tab/index_component.rb b/app/components/work_packages/activities_tab/index_component.rb
index e957fcb19f4..b6db9d8bf16 100644
--- a/app/components/work_packages/activities_tab/index_component.rb
+++ b/app/components/work_packages/activities_tab/index_component.rb
@@ -51,7 +51,9 @@ module WorkPackages
test_selector: "op-wp-activity-tab",
controller: "work-packages--activities-tab--index",
"application-target": "dynamic",
- "work-packages--activities-tab--index-update-streams-url-value": update_streams_work_package_activities_url(work_package),
+ "work-packages--activities-tab--index-update-streams-url-value": update_streams_work_package_activities_url(
+ work_package
+ ),
"work-packages--activities-tab--index-sorting-value": journal_sorting,
"work-packages--activities-tab--index-filter-value": filter,
"work-packages--activities-tab--index-user-id-value": User.current.id,
diff --git a/app/components/work_packages/activities_tab/journals/empty_component.rb b/app/components/work_packages/activities_tab/journals/empty_component.rb
index 65e96f34c83..dc3c28904ba 100644
--- a/app/components/work_packages/activities_tab/journals/empty_component.rb
+++ b/app/components/work_packages/activities_tab/journals/empty_component.rb
@@ -35,10 +35,6 @@ module WorkPackages
include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
-
- def initialize
- super
- end
end
end
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component.rb b/app/components/work_packages/activities_tab/journals/item_component.rb
index 91ee523f9f1..b134ae47264 100644
--- a/app/components/work_packages/activities_tab/journals/item_component.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component.rb
@@ -145,7 +145,7 @@ module WorkPackages
class=\"comments-number--bubble op-bubble op-bubble_mini\"
data-test-selector=\"user-activity-bubble\"
></span>
- ".html_safe
+ ".html_safe # rubocop:disable Rails/OutputSafety
end
end
end
diff --git a/app/components/work_packages/activities_tab/journals/item_component/details.rb b/app/components/work_packages/activities_tab/journals/item_component/details.rb
index ca2bca1fb97..f6ae6bfd4ec 100644
--- a/app/components/work_packages/activities_tab/journals/item_component/details.rb
+++ b/app/components/work_packages/activities_tab/journals/item_component/details.rb
@@ -58,81 +58,126 @@ module WorkPackages
justify_content: :space_between,
classes: "journal-details-header-container",
id: "activity-#{journal.version}") do |header_container|
- header_container.with_column(flex_layout: true,
- classes: "journal-details-header") do |header_start_container|
- header_start_container.with_column(mr: 2, classes: "timeline-icon") do
- if journal.initial?
- render Primer::Beta::Octicon.new(icon: "diff-added", size: :small, "aria-label": "Add", color: :subtle)
- else
- render Primer::Beta::Octicon.new(icon: "diff-modified", size: :small, "aria-label": "Change", color: :subtle)
- end
- end
- header_start_container.with_column(mr: 2) do
- render Users::AvatarComponent.new(user: journal.user, show_name: false, size: :mini)
- end
- header_start_container.with_column(mr: 1, flex_layout: true) do |user_name_container|
- user_name_container.with_row do
- truncated_user_name(journal.user)
- end
- user_name_container.with_row(classes: "hidden-for-desktop") do
- render(Primer::Beta::Text.new(font_size: :small, color: :subtle, mt: 1)) { format_time(journal.created_at) }
- end
- end
- header_start_container.with_column(mr: 1, classes: "hidden-for-mobile") do
- if journal.initial?
- render(Primer::Beta::Text.new(font_size: :small, color: :subtle, mt: 1)) do
- t("activities.work_packages.activity_tab.created_on")
- end
- else
- render(Primer::Beta::Text.new(font_size: :small, color: :subtle, mt: 1)) do
- t("activities.work_packages.activity_tab.changed_on")
- end
- end
- end
- header_start_container.with_column(mr: 1, classes: "hidden-for-mobile") do
- render(Primer::Beta::Text.new(font_size: :small, color: :subtle, mt: 1)) { format_time(journal.updated_at) }
- end
+ render_header_start(header_container)
+ render_header_end(header_container)
+ end
+ end
+
+ def render_header_start(header_container)
+ header_container.with_column(flex_layout: true, classes: "journal-details-header") do |header_start_container|
+ render_timeline_icon(header_start_container)
+ render_user_avatar(header_start_container)
+ render_user_name_and_time(header_start_container)
+ render_created_or_changed_on_text(header_start_container)
+ render_updated_time(header_start_container)
+ end
+ end
+
+ def render_timeline_icon(container)
+ container.with_column(mr: 2, classes: "timeline-icon") do
+ icon_name = journal.initial? ? "diff-added" : "diff-modified"
+ render Primer::Beta::Octicon.new(icon: icon_name, size: :small, "aria-label": icon_aria_label, color: :subtle)
+ end
+ end
+
+ def render_user_avatar(container)
+ container.with_column(mr: 2) do
+ render Users::AvatarComponent.new(user: journal.user, show_name: false, size: :mini)
+ end
+ end
+
+ def render_user_name_and_time(container)
+ container.with_column(mr: 1, flex_layout: true) do |user_name_container|
+ user_name_container.with_row { truncated_user_name(journal.user) }
+ user_name_container.with_row(classes: "hidden-for-desktop") do
+ render(Primer::Beta::Text.new(font_size: :small, color: :subtle, mt: 1)) { format_time(journal.created_at) }
end
- header_container.with_column(flex_layout: true) do |header_end_container|
- if has_unread_notifications
- header_end_container.with_column(mr: 2, classes: "bubble-container") do
- bubble_html
- end
- end
- header_end_container.with_column(pr: 3) do
- render(Primer::Beta::Link.new(
- href: activity_anchor,
- scheme: :secondary,
- underline: false,
- font_size: :small,
- data: { turbo: false }
- )) do
- "##{journal.version}"
- end
- end
+ end
+ end
+
+ def render_created_or_changed_on_text(container)
+ container.with_column(mr: 1, classes: "hidden-for-mobile") do
+ text_key = journal.initial? ? "activities.work_packages.activity_tab.created_on" : "activities.work_packages.activity_tab.changed_on"
+ render(Primer::Beta::Text.new(font_size: :small, color: :subtle, mt: 1)) { t(text_key) }
+ end
+ end
+
+ def render_updated_time(container)
+ container.with_column(mr: 1, classes: "hidden-for-mobile") do
+ render(Primer::Beta::Text.new(font_size: :small, color: :subtle, mt: 1)) { format_time(journal.updated_at) }
+ end
+ end
+
+ def render_header_end(header_container)
+ header_container.with_column(flex_layout: true) do |header_end_container|
+ render_notification_bubble(header_end_container) if has_unread_notifications
+ render_activity_link(header_end_container)
+ end
+ end
+
+ def render_notification_bubble(container)
+ container.with_column(mr: 2, classes: "bubble-container") do
+ bubble_html
+ end
+ end
+
+ def render_activity_link(container)
+ container.with_column(pr: 3) do
+ render(Primer::Beta::Link.new(
+ href: activity_anchor,
+ scheme: :secondary,
+ underline: false,
+ font_size: :small,
+ data: { turbo: false }
+ )) do
+ "##{journal.version}"
end
end
end
+ def icon_aria_label
+ journal.initial? ? "Add" : "Change"
+ end
+
def render_details(details_container)
- return if journal.initial? && journal_sorting == "desc"
+ return if skip_rendering_details?
details_container.with_row(flex_layout: true, pt: 1, pb: 3) do |details_container_inner|
if journal.initial?
render_empty_line(details_container_inner)
else
- journal.details.each do |detail|
- details_container_inner.with_row(flex_layout: true, my: 1, align_items: :flex_start) do |detail_container|
- detail_container.with_column(classes: "journal-detail-stem-line")
- detail_container.with_column(pl: 1, font_size: :small) do
- render(Primer::Beta::Text.new(classes: "journal-detail-description")) { journal.render_detail(detail) }
- end
- end
- end
+ render_journal_details(details_container_inner)
end
end
end
+ def skip_rendering_details?
+ journal.initial? && journal_sorting == "desc"
+ end
+
+ def render_journal_details(details_container_inner)
+ journal.details.each do |detail|
+ render_single_detail(details_container_inner, detail)
+ end
+ end
+
+ def render_single_detail(container, detail)
+ container.with_row(flex_layout: true, my: 1, align_items: :flex_start) do |detail_container|
+ render_stem_line(detail_container)
+ render_detail_description(detail_container, detail)
+ end
+ end
+
+ def render_stem_line(container)
+ container.with_column(classes: "journal-detail-stem-line")
+ end
+
+ def render_detail_description(container, detail)
+ container.with_column(pl: 1, font_size: :small) do
+ render(Primer::Beta::Text.new(classes: "journal-detail-description")) { journal.render_detail(detail) }
+ end
+ end
+
def render_empty_line(details_container)
details_container.with_row(my: 1, font_size: :small, classes: "empty-line")
end
@@ -143,7 +188,7 @@ module WorkPackages
class=\"comments-number--bubble op-bubble op-bubble_mini\"
data-test-selector=\"user-activity-bubble\"
></span>
- ".html_safe
+ ".html_safe # rubocop:disable Rails/OutputSafety
end
def activity_anchor
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index d435bdddbb0..ca135be1a8f 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -97,26 +97,14 @@ class WorkPackages::ActivitiesTabController < ApplicationController
end
def create
- ### taken from ActivitiesByWorkPackageAPI
- call = AddWorkPackageNoteService
- .new(user: User.current,
- work_package: @work_package)
- .call(journal_params[:notes],
- send_notifications: !(params.has_key?(:notify) && params[:notify] == "false"))
- ###
+ call = create_notification_service_call
if call.success? && call.result
if call.result.initial?
# we need to update the whole item component for an initial journal entry
# and not just the show part as happens in the time based update
# as this part is not rendered for initial journal
- update_via_turbo_stream(
- component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
- journal: call.result,
- state: :show,
- filter: params[:filter]&.to_sym || :all
- )
- )
+ update_item_component(call.result, state: :show, filter: params[:filter]&.to_sym || :all)
end
generate_time_based_update_streams(params[:last_update_timestamp], params[:filter])
end
@@ -130,13 +118,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
)
if call.success? && call.result
- update_via_turbo_stream(
- component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
- journal: call.result,
- state: :show,
- filter: params[:filter]&.to_sym || :all
- )
- )
+ update_item_component(call.result, state: :show, filter: params[:filter]&.to_sym || :all)
end
# TODO: handle errors
@@ -186,6 +168,26 @@ class WorkPackages::ActivitiesTabController < ApplicationController
params.require(:journal).permit(:notes)
end
+ def create_notification_service_call
+ ### taken from ActivitiesByWorkPackageAPI
+ call = AddWorkPackageNoteService
+ .new(user: User.current,
+ work_package: @work_package)
+ .call(journal_params[:notes],
+ send_notifications: !(params.has_key?(:notify) && params[:notify] == "false"))
+ ###
+ end
+
+ def update_item_component(journal, state: :show, filter: :all)
+ update_via_turbo_stream(
+ component: WorkPackages::ActivitiesTab::Journals::ItemComponent.new(
+ journal:,
+ state:,
+ filter:
+ )
+ )
+ end
+
def generate_time_based_update_streams(last_update_timestamp, filter)
filter = filter&.to_sym || :all
# TODO: prototypical implementation