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 `CounterComponent` as delegator for different Counters

Aaron Contreras86f5171b627b
diff --git a/app/components/work_packages/share/bulk_selection_counter_component.html.erb b/app/components/work_packages/share/bulk_selection_counter_component.html.erb
new file mode 100644
index 00000000000..6b2d2383afc
--- /dev/null
+++ b/app/components/work_packages/share/bulk_selection_counter_component.html.erb
@@ -0,0 +1,21 @@
+<%
+ concat(
+ render(Primer::Alpha::CheckBox.new(name: 'toggle_all',
+ value: nil,
+ label: I18n.t('work_package.sharing.label_toggle_all'),
+ visually_hide_label: true,
+ data: { 'work-packages--share--bulk-selection-target': 'toggleAll',
+ action: 'work-packages--share--bulk-selection#toggle' }))
+ )
+
+ concat(
+ render(Primer::Beta::Text.new(pl: 2, data: { 'work-packages--share--bulk-selection-target': 'sharedCounter' })) do
+ I18n.t('work_package.sharing.count', count:)
+ end
+ )
+
+ # Text contents managed by Stimulus controller
+ concat(
+ render(Primer::Beta::Text.new(pl: 2, data: { 'work-packages--share--bulk-selection-target': 'selectedCounter' }))
+ )
+%>
diff --git a/app/components/work_packages/share/bulk_selection_counter_component.rb b/app/components/work_packages/share/bulk_selection_counter_component.rb
new file mode 100644
index 00000000000..6dc141ba6e8
--- /dev/null
+++ b/app/components/work_packages/share/bulk_selection_counter_component.rb
@@ -0,0 +1,45 @@
+# 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 Share
+ class BulkSelectionCounterComponent < ApplicationComponent
+ def initialize(count:)
+ super
+
+ @count = count
+ end
+
+ private
+
+ attr_reader :count
+ end
+ end
+end
diff --git a/app/components/work_packages/share/counter_component.html.erb b/app/components/work_packages/share/counter_component.html.erb
new file mode 100644
index 00000000000..b2a11e6b01d
--- /dev/null
+++ b/app/components/work_packages/share/counter_component.html.erb
@@ -0,0 +1,10 @@
+<%=
+ component_wrapper(class: 'op-share-wp-modal-body--header--counter--container',
+ data: { test_selector: 'op-share-wp-active-count'}) do
+ if sharing_manageable?
+ render(WorkPackages::Share::BulkSelectionCounterComponent.new(count:))
+ else
+ render(WorkPackages::Share::ShareCounterComponent.new(count:))
+ end
+ end
+%>
diff --git a/app/components/work_packages/share/counter_component.rb b/app/components/work_packages/share/counter_component.rb
new file mode 100644
index 00000000000..8fcb33b1d3a
--- /dev/null
+++ b/app/components/work_packages/share/counter_component.rb
@@ -0,0 +1,51 @@
+# 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 Share
+ class CounterComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpTurbo::Streamable
+ include OpPrimer::ComponentHelpers
+ include WorkPackages::Share::Concerns::Authorization
+
+ def initialize(work_package:, count:)
+ super
+
+ @work_package = work_package
+ @count = count
+ end
+
+ private
+
+ attr_reader :work_package, :count
+ end
+ end
+end
diff --git a/app/components/work_packages/share/share_counter_component.html.erb b/app/components/work_packages/share/share_counter_component.html.erb
index b31a9a99ad3..18639ad4a76 100644
--- a/app/components/work_packages/share/share_counter_component.html.erb
+++ b/app/components/work_packages/share/share_counter_component.html.erb
@@ -1,5 +1,5 @@
-<%=
- component_wrapper do
- I18n.t('work_package.sharing.count', count:)
- end
+<%
+ concat(render(Primer::Beta::Octicon.new(icon: 'person')))
+
+ concat(render(Primer::Beta::Text.new(pl: 2)) { I18n.t('work_package.sharing.count', count:) })
%>
diff --git a/app/components/work_packages/share/share_counter_component.rb b/app/components/work_packages/share/share_counter_component.rb
index 417a325534c..0b882c56d5d 100644
--- a/app/components/work_packages/share/share_counter_component.rb
+++ b/app/components/work_packages/share/share_counter_component.rb
@@ -31,9 +31,6 @@
module WorkPackages
module Share
class ShareCounterComponent < ApplicationComponent
- include ApplicationHelper
- include OpTurbo::Streamable
-
def initialize(count:)
super
diff --git a/app/controllers/work_packages/shares_controller.rb b/app/controllers/work_packages/shares_controller.rb
index 2866ab107fe..bc406bcea44 100644
--- a/app/controllers/work_packages/shares_controller.rb
+++ b/app/controllers/work_packages/shares_controller.rb
@@ -89,7 +89,7 @@ class WorkPackages::SharesController < ApplicationController
)
update_via_turbo_stream(
- component: WorkPackages::Share::ShareCounterComponent.new(count: current_visible_member_count)
+ component: WorkPackages::Share::CounterComponent.new(work_package: @work_package, count: current_visible_member_count)
)
prepend_via_turbo_stream(
@@ -106,7 +106,7 @@ class WorkPackages::SharesController < ApplicationController
)
update_via_turbo_stream(
- component: WorkPackages::Share::ShareCounterComponent.new(count: current_visible_member_count)
+ component: WorkPackages::Share::CounterComponent.new(work_package: @work_package, count: current_visible_member_count)
)
respond_with_turbo_streams