From 9ddc05758923169433a4344c7f576f450f0558cf Mon Sep 17 00:00:00 2001 From: farhatahmad <35435341+farhatahmad@users.noreply.github.com> Date: Thu, 22 Aug 2019 12:15:01 -0400 Subject: [PATCH] Added a Maintenance Window flash (#758) --- app/assets/javascripts/cookies.js | 7 +++++++ app/controllers/application_controller.rb | 7 ++++++- app/views/shared/_flash_messages.html.erb | 5 +++++ config/application.rb | 4 ++++ config/locales/en.yml | 2 ++ sample.env | 6 ++++++ 6 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/cookies.js b/app/assets/javascripts/cookies.js index efd9d69f..be2c0560 100644 --- a/app/assets/javascripts/cookies.js +++ b/app/assets/javascripts/cookies.js @@ -24,4 +24,11 @@ $(document).on('turbolinks:load', function(){ //hide the banner at the bottom $(".cookies-banner").attr("style","display:none !important") }) + + $("#maintenance-close").click(function(event) { + //create a cookie that lasts 1 year + var cookieDate = new Date(); + cookieDate.setFullYear(cookieDate.getFullYear() + 1); //1 year from now + document.cookie = "maintenance_window=" + $(event.target).data("date") + "; path=/; expires=" + cookieDate.toUTCString() + ";" + }) }) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 833ac5b7..7202898a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base end def maintenance_mode? - if ENV["MAINTENANCE_MODE"] == "true" + if Rails.configuration.maintenance_mode render "errors/greenlight_error", status: 503, formats: :html, locals: { status_code: 503, @@ -61,6 +61,11 @@ class ApplicationController < ActionController::Base help: I18n.t("errors.maintenance.help"), } end + if Rails.configuration.maintenance_window.present? + unless cookies[:maintenance_window] == Rails.configuration.maintenance_window + flash.now[:maintenance] = I18n.t("maintenance.window_alert", date: Rails.configuration.maintenance_window) + end + end end # Sets the appropriate locale. diff --git a/app/views/shared/_flash_messages.html.erb b/app/views/shared/_flash_messages.html.erb index 6e863608..cd03782d 100644 --- a/app/views/shared/_flash_messages.html.erb +++ b/app/views/shared/_flash_messages.html.erb @@ -24,6 +24,11 @@ <%= value.html_safe %> + <% elsif key.eql? "maintenance" %> +
+ <%= value.html_safe %> + +
<% elsif key.eql? "info" %>
diff --git a/config/application.rb b/config/application.rb index b9ae60fe..467bf900 100644 --- a/config/application.rb +++ b/config/application.rb @@ -118,6 +118,10 @@ module Greenlight config.google_analytics = ENV["GOOGLE_ANALYTICS_TRACKING_ID"].present? + # MAINTENANCE + config.maintenance_window = ENV["MAINTENANCE_WINDOW"] + config.maintenance_mode = ENV["MAINTENANCE_MODE"] == "true" + # DEFAULTS # Default branding image if the user does not specify one diff --git a/config/locales/en.yml b/config/locales/en.yml index ce9dee19..6bca4ec9 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -285,6 +285,8 @@ en: verify_text: 'To verify your account, just follow this link: %{url}' verify_link: Verify Account thanks: Thanks for joining and have a great day! + maintenance: + window_alert: Maintenance window scheduled for %{date} max_concurrent: The maximum number of concurrent sessions allowed has been reached! modal: create_role: diff --git a/sample.env b/sample.env index e11137d9..7039efee 100644 --- a/sample.env +++ b/sample.env @@ -156,6 +156,12 @@ ENABLE_GOOGLE_CALENDAR_BUTTON= # false: Application runs normally MAINTENANCE_MODE=false +# Displays a flash that appears to inform the user of a scheduled maintenance window +# This variable should contain ONLY the date and time of the scheduled maintenance +# +# Ex: MAINTENANCE_WINDOW=Friday August 18 6pm-10pm EST +MAINTENANCE_WINDOW= + # Comment this out to send logs to STDOUT in production instead of log/production.log . # # RAILS_LOG_TO_STDOUT=true