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

Extract `journal_sorting.{asc?,desc?}` inquiry

Kabiru Mwenjac1d070ab6f7c
diff --git a/app/components/concerns/work_packages/activities_tab/journal_sorting_inquirable.rb b/app/components/concerns/work_packages/activities_tab/journal_sorting_inquirable.rb
new file mode 100644
index 00000000000..9d5f90ae3ba
--- /dev/null
+++ b/app/components/concerns/work_packages/activities_tab/journal_sorting_inquirable.rb
@@ -0,0 +1,42 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 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 JournalSortingInquirable
+ extend ActiveSupport::Concern
+
+ def journal_sorting
+ ActiveSupport::StringInquirer
+ .new(User.current.preference&.comments_sorting || OpenProject::Configuration.default_comment_sort_order)
+ 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 dc05d390db3..7f2c2f97397 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
@@ -13,7 +13,7 @@
render(WorkPackages::ActivitiesTab::Journals::EmptyComponent.new)
end
else
- if journal_sorting_asc?
+ if journal_sorting.asc?
journals_index_container.with_row do
render(infinite_scroll_component)
end
@@ -23,7 +23,7 @@
render(page_component)
end
- if journal_sorting_desc?
+ if journal_sorting.desc?
journals_index_container.with_row do
render(infinite_scroll_component)
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 f0f6fad66b8..43c04764619 100644
--- a/app/components/work_packages/activities_tab/journals/index_component.rb
+++ b/app/components/work_packages/activities_tab/journals/index_component.rb
@@ -82,11 +82,7 @@ module WorkPackages
end
def inner_container_margin_bottom
- if journal_sorting_desc?
- 3
- else
- 0
- end
+ journal_sorting.desc? ? 3 : 0
end
end
end
diff --git a/app/components/work_packages/activities_tab/shared_helpers.rb b/app/components/work_packages/activities_tab/shared_helpers.rb
index b603fe4f610..0a935004560 100644
--- a/app/components/work_packages/activities_tab/shared_helpers.rb
+++ b/app/components/work_packages/activities_tab/shared_helpers.rb
@@ -31,6 +31,12 @@
module WorkPackages
module ActivitiesTab
module SharedHelpers
+ extend ActiveSupport::Concern
+
+ included do
+ include WorkPackages::ActivitiesTab::JournalSortingInquirable
+ end
+
def truncated_user_name(user, hover_card: false)
helpers.primer_link_to_user(user, scheme: :primary, font_weight: :bold, hover_card:)
end
@@ -61,18 +67,6 @@ module WorkPackages
end
end
- def journal_sorting_asc?
- journal_sorting == "asc"
- end
-
- def journal_sorting_desc?
- journal_sorting == "desc"
- end
-
- def journal_sorting
- User.current.preference&.comments_sorting || OpenProject::Configuration.default_comment_sort_order
- end
-
def activity_url(journal)
"#{project_work_package_url(journal.journable.project, journal.journable)}/activity#{activity_anchor(journal)}"
end
diff --git a/app/controllers/work_packages/activities_tab_controller.rb b/app/controllers/work_packages/activities_tab_controller.rb
index 5a2ac8ce24b..d9d6b908b1c 100644
--- a/app/controllers/work_packages/activities_tab_controller.rb
+++ b/app/controllers/work_packages/activities_tab_controller.rb
@@ -32,6 +32,7 @@ class WorkPackages::ActivitiesTabController < ApplicationController
include Pagy::Backend
include OpTurbo::ComponentStream
include FlashMessagesOutputSafetyHelper
+ include WorkPackages::ActivitiesTab::JournalSortingInquirable
include WorkPackages::ActivitiesTab::StimulusControllers
before_action :find_work_package
@@ -287,11 +288,6 @@ class WorkPackages::ActivitiesTabController < ApplicationController
@filter = (params[:filter] || params.dig(:journal, :filter))&.to_sym || :all
end
- def journal_sorting
- ActiveSupport::StringInquirer
- .new(User.current.preference&.comments_sorting || OpenProject::Configuration.default_comment_sort_order)
- end
-
def sanitized_journal_notes
WorkPackages::ActivitiesTab::InternalCommentMentionsSanitizer.sanitize(@work_package, journal_params[:notes])
end