Added a Maintenance Window flash (#758)

This commit is contained in:
farhatahmad 2019-08-22 12:15:01 -04:00 committed by Jesus Federico
parent 177bf4d595
commit 9ddc057589
6 changed files with 30 additions and 1 deletions

View File

@ -24,4 +24,11 @@ $(document).on('turbolinks:load', function(){
//hide the banner at the bottom //hide the banner at the bottom
$(".cookies-banner").attr("style","display:none !important") $(".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() + ";"
})
}) })

View File

@ -53,7 +53,7 @@ class ApplicationController < ActionController::Base
end end
def maintenance_mode? def maintenance_mode?
if ENV["MAINTENANCE_MODE"] == "true" if Rails.configuration.maintenance_mode
render "errors/greenlight_error", status: 503, formats: :html, render "errors/greenlight_error", status: 503, formats: :html,
locals: { locals: {
status_code: 503, status_code: 503,
@ -61,6 +61,11 @@ class ApplicationController < ActionController::Base
help: I18n.t("errors.maintenance.help"), help: I18n.t("errors.maintenance.help"),
} }
end 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 end
# Sets the appropriate locale. # Sets the appropriate locale.

View File

@ -24,6 +24,11 @@
<button type="button" class="close" data-dismiss="alert">&times</button> <button type="button" class="close" data-dismiss="alert">&times</button>
<%= value.html_safe %> <%= value.html_safe %>
</div> </div>
<% elsif key.eql? "maintenance" %>
<div class="alert alert-info alert-dismissible text-center mb-0">
<%= value.html_safe %>
<button id="maintenance-close" type="button" data-date="<%= Rails.configuration.maintenance_window %>" class="close" data-dismiss="alert">&times</button>
</div>
<% elsif key.eql? "info" %> <% elsif key.eql? "info" %>
<div class="alert alert-info alert-dismissible text-center mb-0"> <div class="alert alert-info alert-dismissible text-center mb-0">
<button type="button" class="close" data-dismiss="alert">&times</button> <button type="button" class="close" data-dismiss="alert">&times</button>

View File

@ -118,6 +118,10 @@ module Greenlight
config.google_analytics = ENV["GOOGLE_ANALYTICS_TRACKING_ID"].present? config.google_analytics = ENV["GOOGLE_ANALYTICS_TRACKING_ID"].present?
# MAINTENANCE
config.maintenance_window = ENV["MAINTENANCE_WINDOW"]
config.maintenance_mode = ENV["MAINTENANCE_MODE"] == "true"
# DEFAULTS # DEFAULTS
# Default branding image if the user does not specify one # Default branding image if the user does not specify one

View File

@ -285,6 +285,8 @@ en:
verify_text: 'To verify your account, just follow this link: %{url}' verify_text: 'To verify your account, just follow this link: %{url}'
verify_link: Verify Account verify_link: Verify Account
thanks: Thanks for joining and have a great day! 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! max_concurrent: The maximum number of concurrent sessions allowed has been reached!
modal: modal:
create_role: create_role:

View File

@ -156,6 +156,12 @@ ENABLE_GOOGLE_CALENDAR_BUTTON=
# false: Application runs normally # false: Application runs normally
MAINTENANCE_MODE=false 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 . # Comment this out to send logs to STDOUT in production instead of log/production.log .
# #
# RAILS_LOG_TO_STDOUT=true # RAILS_LOG_TO_STDOUT=true