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

Make update_counter generic for all split view

Oliver Günther91bd0ac18c66
diff --git a/app/controllers/concerns/work_packages/with_split_view.rb b/app/controllers/concerns/work_packages/with_split_view.rb
index 158718129f5..0f9cfe74896 100644
--- a/app/controllers/concerns/work_packages/with_split_view.rb
+++ b/app/controllers/concerns/work_packages/with_split_view.rb
@@ -32,33 +32,12 @@ module WorkPackages
included do
helper_method :split_view_base_route
-
- before_action :find_work_package, only: %i[split_view update_counter]
- before_action :find_counter_menu, only: %i[update_counter]
end
def split_view_work_package_id
params[:work_package_id].to_i
end
- def update_counter
- respond_to do |format|
- format.turbo_stream do
- render turbo_stream: [
- turbo_stream.replace("wp-details-tab-#{@counter_menu.name}-counter") do
- count = @counter_menu.badge(work_package: @work_package).to_i
- Primer::Beta::Counter
- .new(count:,
- hide_if_zero: true,
- id: "wp-details-tab-#{@counter_menu.name}-counter",
- test_selector: "wp-details-tab-component--tab-counter")
- .render_in(view_context)
- end
- ]
- end
- end
- end
-
def close_split_view
respond_to do |format|
format.turbo_stream do
@@ -86,24 +65,5 @@ module WorkPackages
yield(format) if format_block
end
end
-
- private
-
- def find_work_package
- @work_package = WorkPackage.visible.find(params[:work_package_id])
- rescue ActiveRecord::RecordNotFound
- flash[:error] = I18n.t(:error_work_package_id_not_found)
- redirect_to split_view_base_route
- end
-
- def find_counter_menu
- @counter_menu = Redmine::MenuManager
- .items(:work_package_split_view, nil)
- .root
- .children
- .detect { |node| node.name.to_s == params[:counter] }
-
- render_400 if @counter_menu.nil?
- end
end
end
diff --git a/app/controllers/work_packages/split_view_controller.rb b/app/controllers/work_packages/split_view_controller.rb
new file mode 100644
index 00000000000..876478fcd57
--- /dev/null
+++ b/app/controllers/work_packages/split_view_controller.rb
@@ -0,0 +1,72 @@
+#-- 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.
+#++
+
+require "rack/utils"
+
+class WorkPackages::SplitViewController < ApplicationController
+ # Authorization is checked in the find_work_package action
+ no_authorization_required! :update_counter
+ before_action :find_work_package, only: %i[update_counter]
+ before_action :find_counter_menu, only: %i[update_counter]
+
+ def update_counter
+ respond_to do |format|
+ format.turbo_stream do
+ render turbo_stream: [
+ turbo_stream.replace("wp-details-tab-#{@counter_menu.name}-counter") do
+ count = @counter_menu.badge(work_package: @work_package).to_i
+ Primer::Beta::Counter
+ .new(count:,
+ hide_if_zero: true,
+ id: "wp-details-tab-#{@counter_menu.name}-counter",
+ test_selector: "wp-details-tab-component--tab-counter")
+ .render_in(view_context)
+ end
+ ]
+ end
+ end
+ end
+
+ private
+
+ def find_work_package
+ @work_package = WorkPackage.visible.find(params[:id])
+ rescue ActiveRecord::RecordNotFound
+ render_404 message: I18n.t(:error_work_package_id_not_found)
+ end
+
+ def find_counter_menu
+ @counter_menu = Redmine::MenuManager
+ .items(:work_package_split_view, nil)
+ .root
+ .children
+ .detect { |node| node.name.to_s == params[:counter] }
+
+ render_400 if @counter_menu.nil?
+ end
+end
diff --git a/config/routes.rb b/config/routes.rb
index 222c08b6abf..814193024c7 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -561,12 +561,15 @@ Rails.application.routes.draw do
as: :work_package_progress
end
+ get "/split_view/update_counter" => "work_packages/split_view#update_counter",
+ on: :member
+
# states managed by client-side (angular) routing on work_package#show
get "/" => "work_packages#index", on: :collection, as: "index"
get "/create_new" => "work_packages#index", on: :collection, as: "new_split"
get "/new" => "work_packages#index", on: :collection, as: "new", state: "new"
# We do not want to match the work package export routes
- get "(/*state)" => "work_packages#show", on: :member, as: "", constraints: { id: /\d+/, state: /(?!shares).+/ }
+ get "(/*state)" => "work_packages#show", on: :member, as: "", constraints: { id: /\d+/, state: /(?!(shares|split_view)).+/ }
get "/share_upsale" => "work_packages#index", on: :collection, as: "share_upsale"
get "/edit" => "work_packages#show", on: :member, as: "edit"
end
@@ -708,9 +711,6 @@ Rails.application.routes.draw do
get "/:work_package_id/close",
action: :close_split_view
-
- get "/:work_package_id/update_counter",
- action: :update_counter
end
resources :notifications, only: :index do
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/watchers-tab/watchers-tab.component.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/watchers-tab/watchers-tab.component.ts
index cebccd4eec5..cf6e8306999 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/watchers-tab/watchers-tab.component.ts
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/watchers-tab/watchers-tab.component.ts
@@ -182,7 +182,7 @@ export class WorkPackageWatchersTabComponent extends UntilDestroyedMixin impleme
}
public updateCounter() {
- const url = this.pathHelper.notificationsPath() + `/${this.workPackageId}/update_counter?counter=watchers`;
+ const url = `${this.pathHelper.workPackagePath(this.workPackageId)}/split_view/update_counter?counter=watchers`;
void this.turboRequests.request(url);
}
}