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
Primerize all backend flashes
Oliver Günther7ef79e487342
diff --git a/app/helpers/flash_messages_helper.rb b/app/helpers/flash_messages_helper.rbindex 0e8b668c935..8015199aaaf 100644--- a/app/helpers/flash_messages_helper.rb+++ b/app/helpers/flash_messages_helper.rb@@ -37,44 +37,46 @@ module FlashMessagesHelper# Renders flash messagesdef render_flash_messagesmessages = flash- .reject { |k, _| k.to_s == "op_primer_flash" }.reject { |k, _| k.start_with? "_" }- .map do |k, v|- if k.to_sym == :modal- component = v[:type].constantize- component.new(**v.fetch(:parameters, {})).render_in(self)- else- render_flash_message(k, v)- end- end+ .reject { |k, _| k.to_s == "modal" }+ .map { |k, v| render_flash_content(k.to_sym, v) }safe_join messages, "\n"end- def render_flash_message(type, message, html_options = {}) # rubocop:disable Metrics/AbcSize- if type.to_s == "notice"- type = "success"+ def render_flash_content(key, content)+ case key+ when :op_primer_flash+ render_flash_message(content[:scheme] || :default, content[:message])+ else+ render_flash_message(key, content)end+ end- toast_css_classes = ["op-toast -#{type}", html_options.delete(:class)]+ def render_flash_modal+ content = flash[:modal]+ return if content.blank?- # Add autohide class to notice flashes if configured- if type.to_s == "success" && User.current.pref.auto_hide_popups?- toast_css_classes << "autohide-toaster"+ component = content[:type].constantize+ component.new(**content.fetch(:parameters, {})).render_in(self)+ end++ def mapped_flash_type(type)+ case type+ when :error+ :danger+ when :warning+ :warning+ when :notice+ :success+ else+ :defaultend+ end- html_options = { class: toast_css_classes.join(" "), role: "alert" }.merge(html_options)- close_button = content_tag :a, "", class: "op-toast--close icon-context icon-close",- title: I18n.t("js.close_popup_title"),- tabindex: "0"- toast = content_tag(:div, join_flash_messages(message), class: "op-toast--content")- content_tag :div, "", class: "op-toast--wrapper" do- content_tag :div, "", class: "op-toast--casing" do- content_tag :div, html_options do- concat(close_button)- concat(toast)- end- end+ def render_flash_message(type, message)+ render(OpPrimer::FlashComponent.new(scheme: mapped_flash_type(type))) do+ join_flash_messages(message)endendenddiff --git a/app/helpers/primerized_flash_helper.rb b/app/helpers/primerized_flash_helper.rbdeleted file mode 100644index ffe46356ab3..00000000000--- a/app/helpers/primerized_flash_helper.rb+++ /dev/null@@ -1,43 +0,0 @@-#-- 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 PrimerizedFlashHelper- extend ActiveSupport::Concern-- def render_primerized_flash- return if flash[:op_primer_flash].blank?-- system_arguments = flash[:op_primer_flash]- message = system_arguments.delete(:message)-- render(OpPrimer::FlashComponent.new(**system_arguments)) do- message- end- end-enddiff --git a/app/views/layouts/base.html.erb b/app/views/layouts/base.html.erbindex b30d04035b0..5d1855a998b 100644--- a/app/views/layouts/base.html.erb+++ b/app/views/layouts/base.html.erb@@ -118,13 +118,14 @@ See COPYRIGHT and LICENSE files for more details.<div class="content-overlay"></div><%= content_tag :main, id: "content-wrapper", class: initial_classes, data: stimulus_content_data do %><%# Primerized flash messages are being rendered separately %>- <div id="primerized-flash-messages" class="op-primer-flash">- <%= render_primerized_flash %>- </div>- <%# Flash messages are being rendered using the old op-flash style %>- <turbo-frame id="flash-messages">+ <div id="primerized-flash-messages"+ class="op-primer-flash"+ data-controller="flash"+ data-flash-autohide-value="<%= User.current.pref.auto_hide_popups? %>"><%= render_flash_messages %>- </turbo-frame>+ </div>+ <%# Flash modals render modal components %>+ <%= render_flash_modal %><% if show_onboarding_modal? %><section data-augmented-model-wrapperdata-modal-initialize-now="true"