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
Reusable banner
Oliver Günthercf98215083e5
diff --git a/app/controllers/my_controller.rb b/app/controllers/my_controller.rbindex f0d6ccdba04..f3faf5b83ae 100644--- a/app/controllers/my_controller.rb+++ b/app/controllers/my_controller.rb@@ -238,7 +238,7 @@ class MyController < ApplicationControllerdef handle_email_changes# If mail changed, expire all other sessions- if @user.previous_changes['mail']+ if @user.previous_changes["mail"]Users::DropTokensService.new(current_user: @user).call!Sessions::DropOtherSessionsService.call!(@user, session)diff --git a/app/helpers/banner_messages_helper.rb b/app/helpers/banner_messages_helper.rbnew file mode 100644index 00000000000..4e6aa0e3545--- /dev/null+++ b/app/helpers/banner_messages_helper.rb@@ -0,0 +1,43 @@+#-- 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 BannerMessagesHelper+ extend ActiveSupport::Concern++ def render_primer_banner_message+ return if flash[:primer_banner].blank?++ system_arguments = flash[:primer_banner]+ message = system_arguments.delete(:message)++ render(OpPrimer::BannerMessageComponent.new(**system_arguments)) do+ message+ end+ end+enddiff --git a/app/helpers/flash_messages_helper.rb b/app/helpers/flash_messages_helper.rbindex c3f426ac1fa..71c86c969b6 100644--- a/app/helpers/flash_messages_helper.rb+++ b/app/helpers/flash_messages_helper.rb@@ -34,21 +34,10 @@ module FlashMessagesHelperinclude FlashMessagesOutputSafetyHelperend- def render_primer_banner_message?- flash[:primer_banner].present?- end-- def render_primer_banner_message- return unless render_primer_banner_message?-- render(BannerMessageComponent.new(**flash[:primer_banner].to_hash))- end-# Renders flash messagesdef render_flash_messages- return if render_primer_banner_message?-messages = flash+ .reject { |k, _| k.to_s == "primer_banner" }.reject { |k, _| k.start_with? "_" }.map do |k, v|if k.to_sym == :modaldiff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erbindex 4de4854fbb0..19c1006cd18 100644--- a/app/views/layouts/base.html.erb+++ b/app/views/layouts/base.html.erb@@ -117,13 +117,13 @@ See COPYRIGHT and LICENSE files for more details.<% end %><div class="content-overlay"></div><main id="content-wrapper" class="<%= initial_classes %>">- <div id="flash-container">- <div id="narrow" class="op-toast--wrapper"></div>+ <%# Banner messages are being rendered using primer %>+ <div id="banner-messages" class="op-primer-banner">+ <%= render_primer_banner_message %></div>- <%= render_primer_banner_message %>- <%= render_streameable_primer_banner_message %><%# Banner messages are being rendered using primer %><div id="banner-messages" class="op-primer-banner"></div>+ <%# Flash messages are being rendered using the old op-flash style %><turbo-frame id="flash-messages"><%= render_flash_messages %></turbo-frame>diff --git a/modules/meeting/app/components/banner_message_component.html.erb b/modules/meeting/app/components/banner_message_component.html.erbindex 8df5a04db49..0f7373dba3c 100644--- a/modules/meeting/app/components/banner_message_component.html.erb+++ b/modules/meeting/app/components/banner_message_component.html.erb@@ -27,13 +27,6 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<%=- render(Primer::Alpha::Banner.new(full:,- full_when_narrow:,- dismiss_scheme:,- dismiss_label:,- icon:,- scheme:,- test_selector:,- )) { message.html_safe }-%>+<div class="op-primer-banner--item">+ <%= render_parent %>+</div>diff --git a/modules/meeting/app/components/banner_message_component.rb b/modules/meeting/app/components/banner_message_component.rbindex dfe94b69898..d4d61a53cf0 100644--- a/modules/meeting/app/components/banner_message_component.rb+++ b/modules/meeting/app/components/banner_message_component.rb@@ -26,26 +26,16 @@# See COPYRIGHT and LICENSE files for more details.#++-class BannerMessageComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent- def initialize(message: nil,- full: true,- full_when_narrow: false,- dismiss_scheme: :hide,- dismiss_label: I18n.t("button_close"),- icon: false,- scheme: :default,- test_selector: "primer-banner-message-component")- super+class BannerMessageComponent < Primer::Alpha::Banner+ include ApplicationHelper+ include OpTurbo::Streamable+ include OpPrimer::ComponentHelpers- @message = message- @full = full- @full_when_narrow = full_when_narrow- @dismiss_scheme = dismiss_scheme- @dismiss_label = dismiss_label- @icon = icon- @scheme = scheme- @test_selector = test_selector- end+ def initialize(**system_arguments)+ system_arguments[:test_selector] ||= "primer-banner-message-component"+ system_arguments[:dismiss_scheme] ||= :remove+ system_arguments[:dismiss_label] ||= I18n.t(:button_close)- attr_reader :message, :full, :full_when_narrow, :dismiss_scheme, :dismiss_label, :icon, :scheme, :test_selector+ super+ endenddiff --git a/modules/meeting/app/components/meetings/update_flash_component.rb b/modules/meeting/app/components/meetings/update_flash_component.rbindex ea6b1eadf5f..0bcc39bba27 100644--- a/modules/meeting/app/components/meetings/update_flash_component.rb+++ b/modules/meeting/app/components/meetings/update_flash_component.rb@@ -28,22 +28,21 @@module Meetingsclass UpdateFlashComponent < ApplicationComponent- include ApplicationHelperinclude OpTurbo::Streamable- include OpPrimer::ComponentHelpers- def initialize(message:, full: false, icon: "info", scheme: :default, dismiss_scheme: :none, button: false,- button_message: nil, button_path_object: nil)- super+ alias_method :meeting, :model- @message = message- @full = full- @icon = icon- @scheme = scheme- @button = button- @button_message = button_message- @dismiss_scheme = dismiss_scheme- @button_path_object = button_path_object+ def call+ render(::OpPrimer::BannerMessageComponent.new(icon: :info)) do |banner|+ banner.with_action_button(+ tag: :a,+ href: helpers.meeting_path(meeting),+ data: { turbo: false },+ size: :medium+ ) { I18n.t("label_meeting_reload") }++ I18n.t("notice_meeting_updated")+ endendendend