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:
Javi Martín
2023-01-05 14:12:19 +01:00
parent d27bfb2afd
commit 86fd14f8f0
9 changed files with 153 additions and 142 deletions

View File

@@ -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;
}

View 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;
}
}

View File

@@ -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>

View 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

View File

@@ -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|

View File

@@ -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" %>

View File

@@ -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" %>