Skip to content

Commit

Permalink
Merge 1106b0b into 6472173
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschilling committed Sep 11, 2014
2 parents 6472173 + 1106b0b commit 41c8366
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/assets/stylesheets/active_admin/_base.css.scss
Expand Up @@ -26,6 +26,7 @@
@import "active_admin/components/status_tags";
@import "active_admin/components/table_tools";
@import "active_admin/components/index_list";
@import "active_admin/components/unsupported_browser";
@import "active_admin/pages/logged_out";
@import "active_admin/structure/footer";
@import "active_admin/structure/main_structure";
Expand Down
@@ -0,0 +1,16 @@
.unsupported_browser {
padding: 10px 30px;
color: #211e14;
background-color: #fae692;
@include gradient(#feefae, #fae692);
border-bottom: 1px solid #b3a569;

h1 {
font-size: 13px;
font-weight: bold;
}

p {
margin-bottom: 0.5em;
}
}
4 changes: 4 additions & 0 deletions app/assets/stylesheets/active_admin/print.css.scss
Expand Up @@ -282,3 +282,7 @@ form {
}
}
}

.unsupported_browser {
display: none;
}
4 changes: 4 additions & 0 deletions config/locales/de-CH.yml
Expand Up @@ -93,6 +93,10 @@
sign_in: "Anmeldung"
forgot_your_password: "Passwort vergessen?"
sign_in_with_omniauth_provider: "Anmeldung mit %{provider}"
unsupported_browser:
headline: "ActiveAdmin unterstützt nicht länger den Internet Explorer in Version 8 oder niedriger."
recommendation: "Wir empfehlen die Nutzung von <a href=\"http://windows.microsoft.com/ie\">Internet Explorer</a>, <a href=\"https://chrome.google.com/\">Google Chrome</a>, oder <a href=\"https://mozilla.org/firefox/\">Firefox</a>."
turn_off_compatibility_view: "Wenn sie IE 9 oder neuer benutzen, stellen sie sicher das sie den <a href=\"http://windows.microsoft.com/en-US/windows7/webpages-look-incorrect-in-Internet-Explorer\">\"Kompatibilitätsansicht\" ausgeschaltet</a> haben."
activerecord:
attributes:
admin_user:
Expand Down
4 changes: 4 additions & 0 deletions config/locales/de.yml
Expand Up @@ -110,6 +110,10 @@ de:
sign_in: "Anmeldung"
forgot_your_password: "Passwort vergessen?"
sign_in_with_omniauth_provider: "Anmeldung mit %{provider}"
unsupported_browser:
headline: "ActiveAdmin unterstützt nicht länger den Internet Explorer in Version 8 oder niedriger."
recommendation: "Wir empfehlen die Nutzung von <a href=\"http://windows.microsoft.com/ie\">Internet Explorer</a>, <a href=\"https://chrome.google.com/\">Google Chrome</a>, oder <a href=\"https://mozilla.org/firefox/\">Firefox</a>."
turn_off_compatibility_view: "Wenn sie IE 9 oder neuer benutzen, stellen sie sicher das sie den <a href=\"http://windows.microsoft.com/en-US/windows7/webpages-look-incorrect-in-Internet-Explorer\">\"Kompatibilitätsansicht\" ausgeschaltet</a> haben."
access_denied:
message: "Sie haben nicht die Berechtigung um diese Aktion auszuführen."
activerecord:
Expand Down
4 changes: 4 additions & 0 deletions config/locales/en.yml
Expand Up @@ -114,6 +114,10 @@ en:
forgot_your_password: "Forgot your password?"
sign_in_with_omniauth_provider: "Sign in with %{provider}"
resend_unlock_instructions: "Re-send unlock instructions"
unsupported_browser:
headline: "Please note that ActiveAdmin no longer supports Internet Explorer versions 8 or less."
recommendation: "We recommend upgrading to the latest <a href=\"http://windows.microsoft.com/ie\">Internet Explorer</a>, <a href=\"https://chrome.google.com/\">Google Chrome</a>, or <a href=\"https://mozilla.org/firefox/\">Firefox</a>."
turn_off_compatibility_view: "If you are using IE 9 or later, make sure you <a href=\"http://windows.microsoft.com/en-US/windows7/webpages-look-incorrect-in-Internet-Explorer\">turn off \"Compatibility View\"</a>."
access_denied:
message: "You are not authorized to perform this action."
index_list:
Expand Down
3 changes: 3 additions & 0 deletions lib/active_admin/application.rb
Expand Up @@ -82,6 +82,9 @@ def initialize
# A proc to be used when a user is not authorized to view the current resource
inheritable_setting :on_unauthorized_access, :rescue_active_admin_access_denied

# A reqex to detect unsupported browser, set to false to disable
inheritable_setting :unsupported_browser_matcher, /MSIE [1-8]\.0/

# Active Admin makes educated guesses when displaying objects, this is
# the list of methods it tries calling in order
setting :display_name_methods, [ :display_name,
Expand Down
1 change: 1 addition & 0 deletions lib/active_admin/base_controller.rb
Expand Up @@ -6,6 +6,7 @@ module ActiveAdmin
# It implements ActiveAdmin controllers core features.
class BaseController < ::InheritedResources::Base
helper ::ActiveAdmin::ViewHelpers
helper_method :env

layout :determine_active_admin_layout

Expand Down
1 change: 1 addition & 0 deletions lib/active_admin/view_factory.rb
Expand Up @@ -7,6 +7,7 @@ class ViewFactory < AbstractViewFactory
register global_navigation: ActiveAdmin::Views::TabbedNavigation,
utility_navigation: ActiveAdmin::Views::TabbedNavigation,
site_title: ActiveAdmin::Views::SiteTitle,
unsupported_browser: ActiveAdmin::Views::UnsupportedBrowser,
action_items: ActiveAdmin::Views::ActionItems,
title_bar: ActiveAdmin::Views::TitleBar,
header: ActiveAdmin::Views::Header,
Expand Down
13 changes: 13 additions & 0 deletions lib/active_admin/views/components/unsupported_browser.rb
@@ -0,0 +1,13 @@
module ActiveAdmin
module Views
class UnsupportedBrowser < Component
def build
super()

h1 I18n.t("active_admin.unsupported_browser.headline").html_safe
para I18n.t("active_admin.unsupported_browser.recommendation").html_safe
para I18n.t("active_admin.unsupported_browser.turn_off_compatibility_view").html_safe
end
end
end
end
5 changes: 5 additions & 0 deletions lib/active_admin/views/pages/base.rb
Expand Up @@ -42,6 +42,7 @@ def build_active_admin_head
def build_page
within @body do
div id: "wrapper" do
build_unsupported_browser
build_header
build_title_bar
build_page_content
Expand All @@ -50,6 +51,10 @@ def build_page
end
end

def build_unsupported_browser
insert_tag view_factory.unsupported_browser if active_admin_namespace.unsupported_browser_matcher =~ env["HTTP_USER_AGENT"]
end

def build_header
insert_tag view_factory.header, active_admin_namespace, current_menu
end
Expand Down
48 changes: 48 additions & 0 deletions spec/unit/views/components/unsupported_browser_spec.rb
@@ -0,0 +1,48 @@
require 'rails_helper'

describe ActiveAdmin::Views::UnsupportedBrowser do

let(:helpers){ mock_action_view }
let(:namespace) { double :namespace, unsupported_browser_matcher: /MSIE [1-8]\.0/ }
let(:component) { double :unsupported_browser_component }
let(:view_factory) { double :view_factory, unsupported_browser: component }
let(:base) { ActiveAdmin::Views::Pages::Base.new }

def build_panel
render_arbre_component({}, helpers) do
insert_tag ActiveAdmin::Views::UnsupportedBrowser
end
end

it "should render the panel", focus: true do
expect(ActiveAdmin::Views::UnsupportedBrowser::I18n).to receive(:t).and_return("headline", "recommendation" ,"turn_off_compatibility_view")

expect(build_panel.content.gsub(/\s+/, "")).to eq "<h1>headline</h1><p>recommendation</p><p>turn_off_compatibility_view</p>"
end

describe "ActiveAdmin::Views::Pages::Base behavior" do
context "when the reqex match" do

it "should build the unsupported browser panel" do
expect(base).to receive(:active_admin_namespace).and_return(namespace)
expect(base).to receive(:env).and_return({ "HTTP_USER_AGENT" => "Mozilla/5.0 (compatible; MSIE 7.0; Windows NT 6.2; Trident/6.0)" })
expect(base).to receive(:view_factory).and_return(view_factory)
expect(base).to receive(:insert_tag).with(component)
base.send(:build_unsupported_browser)
end

end

context "when the reqex not match", focus: true do

it "should not build the unsupported browser panel" do
expect(base).to receive(:active_admin_namespace).and_return(namespace)
expect(base).to receive(:env).and_return({ "HTTP_USER_AGENT" => "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0)" })
expect(base).to receive(:insert_tag).never
base.send(:build_unsupported_browser)
end

end
end

end
3 changes: 2 additions & 1 deletion spec/unit/views/pages/layout_spec.rb
Expand Up @@ -13,7 +13,8 @@
current_active_admin_user: nil,
current_active_admin_user?: false,
current_menu: double('Menu', items: []),
params: {controller: 'UsersController', action: 'edit'}
params: {controller: 'UsersController', action: 'edit'},
env: {}
}.each do |method, returns|
allow(helpers).to receive(method).and_return returns
end
Expand Down

0 comments on commit 41c8366

Please sign in to comment.