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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add EmailUpdatesSwitchComponent
Mir Bhatiaa07251ddbe9c
diff --git a/app/components/op_primer/email_updates_switch_component.html.erb b/app/components/op_primer/email_updates_switch_component.html.erbnew file mode 100644index 00000000000..da18d22d098--- /dev/null+++ b/app/components/op_primer/email_updates_switch_component.html.erb@@ -0,0 +1,62 @@+<%#-- 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.++++#%>++<%=+ component_wrapper(data: { "test-selector": "email-updates-switch" }) do+ render(Primer::OpenProject::SidePanel::Section.new) do |section|+ section.with_title { @title }++ if @show_button+ section.with_footer_button(+ color: :accent,+ tag: :a,+ href: @path,+ classes: "hide-when-print",+ data: { "turbo-stream": true, "turbo-method": @method, "test-selector": "email-updates-switch-button" }+ ) do |button|+ button.with_leading_visual_icon(icon: button_icon)+ button_label+ end+ end++ flex_layout do |flex|+ flex.with_row do+ concat(render(Primer::Beta::Text.new(color: :subtle, font_weight: :semibold)) { "#{state} " })+ concat(render(Primer::Beta::Text.new(color: :subtle)) { description })+ end++ unless @show_button+ flex.with_row(mt: 2) do+ render(Primer::Beta::Text.new(color: :subtle)) { @alt_text }+ end+ end+ end+ end+ end+%>diff --git a/app/components/op_primer/email_updates_switch_component.rb b/app/components/op_primer/email_updates_switch_component.rbnew file mode 100644index 00000000000..d9ca572d476--- /dev/null+++ b/app/components/op_primer/email_updates_switch_component.rb@@ -0,0 +1,75 @@+# 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 OpPrimer+ class EmailUpdatesSwitchComponent < Primer::Component # rubocop:disable OpenProject/AddPreviewForViewComponent+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers++ def initialize(toggle:, path:, title:, enabled_description:, disabled_description:, alt_text: nil, show_button: true,+ method: :get)+ super++ if !show_button && alt_text.blank?+ raise NotImplementedError, "alt_text must be provided when the button is shown conditionally"++ end++ @toggle = toggle+ @path = path+ @title = title+ @enabled_description = enabled_description+ @disabled_description = disabled_description+ @alt_text = alt_text+ @show_button = show_button+ @method = method+ end++ private++ def button_icon+ @toggle ? :"bell-slash" : :bell+ end++ def button_label+ label_key = @toggle ? "disable" : "enable"+ I18n.t("meeting.notifications.sidepanel.button.#{label_key}")+ end++ def state+ key = @toggle ? "enabled" : "disabled"+ I18n.t("meeting.notifications.sidepanel.state.#{key}")+ end++ def description+ @toggle ? @enabled_description : @disabled_description+ end+ end+end