Move admin header partial to a component
This way it's easier to refactor it. Note we're using `with_request_url` in the tests because the component renders the locale switcher, which needs a URL in order to work. This doesn't affect whether we're in the management section or not.
This commit is contained in:
@@ -31,14 +31,6 @@ $table-header: #ecf1f6;
|
||||
.admin {
|
||||
@include admin-layout;
|
||||
|
||||
> header {
|
||||
border-bottom: 1px solid #eee;
|
||||
|
||||
> * {
|
||||
@include full-width-background($adjust-margin: false, $adjust-padding: true);
|
||||
}
|
||||
}
|
||||
|
||||
h2 {
|
||||
font-weight: 100;
|
||||
margin-bottom: $line-height;
|
||||
@@ -60,86 +52,6 @@ $table-header: #ecf1f6;
|
||||
float: none;
|
||||
}
|
||||
|
||||
.top-links {
|
||||
|
||||
a {
|
||||
line-height: rem-calc($line-height * 1.5);
|
||||
}
|
||||
}
|
||||
|
||||
.top-bar {
|
||||
height: auto;
|
||||
padding-top: $line-height / 2;
|
||||
|
||||
@include breakpoint(small only) {
|
||||
|
||||
.top-bar-left ul {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.top-bar-right {
|
||||
|
||||
> ul {
|
||||
border-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.submenu {
|
||||
position: initial;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: normal;
|
||||
}
|
||||
}
|
||||
|
||||
[class^="icon-"] {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
[class^="icon-"] {
|
||||
font-size: $base-font-size;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: $line-height / 2;
|
||||
margin-bottom: 0;
|
||||
|
||||
@include breakpoint(medium) {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
small {
|
||||
color: inherit;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
display: inline-block;
|
||||
font-family: "Lato" !important;
|
||||
font-size: rem-calc(24);
|
||||
font-weight: lighter;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.top-bar .menu > li {
|
||||
|
||||
@include breakpoint(medium) {
|
||||
height: auto !important;
|
||||
}
|
||||
}
|
||||
|
||||
.title-bar {
|
||||
color: inherit;
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
}
|
||||
|
||||
.notifications.unread-notifications::after {
|
||||
color: $admin-color;
|
||||
}
|
||||
|
||||
89
app/assets/stylesheets/layout/admin_header.scss
Normal file
89
app/assets/stylesheets/layout/admin_header.scss
Normal file
@@ -0,0 +1,89 @@
|
||||
.admin {
|
||||
> header {
|
||||
border-bottom: 1px solid #eee;
|
||||
|
||||
> * {
|
||||
@include full-width-background($adjust-margin: false, $adjust-padding: true);
|
||||
}
|
||||
}
|
||||
|
||||
.top-links {
|
||||
|
||||
a {
|
||||
line-height: rem-calc($line-height * 1.5);
|
||||
}
|
||||
}
|
||||
|
||||
.top-bar {
|
||||
height: auto;
|
||||
padding-top: $line-height / 2;
|
||||
|
||||
@include breakpoint(small only) {
|
||||
|
||||
.top-bar-left ul {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.top-bar-right {
|
||||
|
||||
> ul {
|
||||
border-bottom: 0;
|
||||
padding-bottom: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.submenu {
|
||||
position: initial;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: normal;
|
||||
}
|
||||
}
|
||||
|
||||
[class^="icon-"] {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
[class^="icon-"] {
|
||||
font-size: $base-font-size;
|
||||
}
|
||||
|
||||
h1 {
|
||||
margin-top: $line-height / 2;
|
||||
margin-bottom: 0;
|
||||
|
||||
@include breakpoint(medium) {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
small {
|
||||
color: inherit;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
a {
|
||||
color: inherit;
|
||||
display: inline-block;
|
||||
font-family: "Lato" !important;
|
||||
font-size: rem-calc(24);
|
||||
font-weight: lighter;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.top-bar .menu > li {
|
||||
|
||||
@include breakpoint(medium) {
|
||||
height: auto !important;
|
||||
}
|
||||
}
|
||||
|
||||
.title-bar {
|
||||
color: inherit;
|
||||
position: absolute;
|
||||
right: 12px;
|
||||
}
|
||||
}
|
||||
@@ -34,13 +34,13 @@
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% if show_admin_menu?(current_user) || namespace != "management" %>
|
||||
<% if show_admin_menu?(user) || namespace != "management" %>
|
||||
<div id="responsive_menu">
|
||||
<div class="top-bar-right">
|
||||
<ul class="menu" data-responsive-menu="medium-dropdown">
|
||||
<%= render "shared/admin_login_items", current_user: current_user %>
|
||||
<%= render "layouts/notification_item", current_user: current_user %>
|
||||
<%= render "devise/menu/login_items", current_user: current_user %>
|
||||
<%= render "shared/admin_login_items", current_user: user %>
|
||||
<%= render "layouts/notification_item", current_user: user %>
|
||||
<%= render "devise/menu/login_items", current_user: user %>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
20
app/components/layout/admin_header_component.rb
Normal file
20
app/components/layout/admin_header_component.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class Layout::AdminHeaderComponent < ApplicationComponent
|
||||
attr_reader :user
|
||||
delegate :namespace, :namespaced_root_path, :show_admin_menu?, to: :helpers
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def namespaced_header_title
|
||||
if namespace == "moderation/budgets"
|
||||
t("moderation.header.title")
|
||||
elsif namespace == "management"
|
||||
t("management.dashboard.index.title")
|
||||
else
|
||||
t("#{namespace}.header.title")
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -3,16 +3,6 @@ module AdminHelper
|
||||
"/#{namespace}"
|
||||
end
|
||||
|
||||
def namespaced_header_title
|
||||
if namespace == "moderation/budgets"
|
||||
t("moderation.header.title")
|
||||
elsif namespace == "management"
|
||||
t("management.dashboard.index.title")
|
||||
else
|
||||
t("#{namespace}.header.title")
|
||||
end
|
||||
end
|
||||
|
||||
def official_level_options
|
||||
options = [["", 0]]
|
||||
(1..5).each do |i|
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</head>
|
||||
|
||||
<body class="admin">
|
||||
<%= render "layouts/admin_header" %>
|
||||
<%= render Layout::AdminHeaderComponent.new(current_user) %>
|
||||
|
||||
<div class="menu-and-content">
|
||||
<%= check_box_tag :show_menu, nil, false, role: "switch" %>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</head>
|
||||
|
||||
<body class="admin">
|
||||
<%= render "layouts/admin_header", current_user: manager_logged_in %>
|
||||
<%= render Layout::AdminHeaderComponent.new(manager_logged_in) %>
|
||||
|
||||
<div class="menu-and-content">
|
||||
<%= check_box_tag :show_menu, nil, false, role: "switch" %>
|
||||
|
||||
38
spec/components/layout/admin_header_component_spec.rb
Normal file
38
spec/components/layout/admin_header_component_spec.rb
Normal file
@@ -0,0 +1,38 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Layout::AdminHeaderComponent do
|
||||
let(:user) { create(:user) }
|
||||
before { Setting["org_name"] = "CONSUL" }
|
||||
|
||||
around do |example|
|
||||
with_request_url("/") { example.run }
|
||||
end
|
||||
|
||||
context "management section", controller: Management::BaseController do
|
||||
it "shows the menu for administrators" do
|
||||
create(:administrator, user: user)
|
||||
sign_in(user)
|
||||
|
||||
render_inline Layout::AdminHeaderComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Go back to CONSUL"
|
||||
expect(page).to have_link "You don't have new notifications"
|
||||
expect(page).to have_link "My content"
|
||||
expect(page).to have_link "My account"
|
||||
expect(page).to have_link "Sign out"
|
||||
end
|
||||
|
||||
it "does not show the menu managers" do
|
||||
create(:manager, user: user)
|
||||
sign_in(user)
|
||||
|
||||
render_inline Layout::AdminHeaderComponent.new(user)
|
||||
|
||||
expect(page).to have_link "Go back to CONSUL"
|
||||
expect(page).not_to have_content "You don't have new notifications"
|
||||
expect(page).not_to have_content "My content"
|
||||
expect(page).not_to have_content "My account"
|
||||
expect(page).not_to have_content "Sign out"
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,38 +0,0 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe "Management" do
|
||||
let(:user) { create(:user) }
|
||||
before { Setting["org_name"] = "CONSUL" }
|
||||
|
||||
scenario "Should show admin menu if logged user is admin" do
|
||||
create(:administrator, user: user)
|
||||
login_as(user)
|
||||
|
||||
visit root_path
|
||||
click_link "Menu"
|
||||
click_link "Management"
|
||||
|
||||
expect(page).to have_link "Go back to CONSUL"
|
||||
|
||||
expect(page).to have_link "You don't have new notifications"
|
||||
expect(page).to have_link "My content"
|
||||
expect(page).to have_link "My account"
|
||||
expect(page).to have_link "Sign out"
|
||||
end
|
||||
|
||||
scenario "Should not show admin menu if logged user is manager" do
|
||||
create(:manager, user: user)
|
||||
login_as(user)
|
||||
visit root_path
|
||||
|
||||
click_link "Menu"
|
||||
click_link "Management"
|
||||
|
||||
expect(page).to have_link "Go back to CONSUL"
|
||||
|
||||
expect(page).not_to have_content "You don't have new notifications"
|
||||
expect(page).not_to have_content "My content"
|
||||
expect(page).not_to have_content "My account"
|
||||
expect(page).not_to have_content "Sign out"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user