Extract admin menu to a component
This way adding new methods will be easier.
This commit is contained in:
@@ -408,101 +408,7 @@ code {
|
||||
// 02. Sidebar
|
||||
// -----------
|
||||
|
||||
.admin-sidebar {
|
||||
background: $sidebar;
|
||||
background: linear-gradient(to bottom, #245b80 0%, #488fb5 100%);
|
||||
border-right: 1px solid $border;
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
margin-bottom: 0;
|
||||
margin-left: 0;
|
||||
padding: 0;
|
||||
|
||||
[class^="icon-"] {
|
||||
color: #fff;
|
||||
display: inline-block;
|
||||
font-size: rem-calc(20);
|
||||
line-height: $line-height;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
width: $line-height * 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
li {
|
||||
margin: 0;
|
||||
outline: 0;
|
||||
|
||||
ul {
|
||||
margin-left: $line-height / 1.5;
|
||||
border-left: 1px solid $sidebar-hover;
|
||||
padding-left: $line-height / 2;
|
||||
}
|
||||
|
||||
&.is-active a {
|
||||
background: $sidebar-hover;
|
||||
border-left: 2px solid $sidebar-active;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
&[aria-expanded="true"] {
|
||||
|
||||
> a::after {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
li a {
|
||||
color: #fff;
|
||||
display: block;
|
||||
line-height: $line-height * 2;
|
||||
padding-left: $line-height / 4;
|
||||
vertical-align: top;
|
||||
|
||||
&:hover {
|
||||
background: $sidebar-hover;
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.is-accordion-submenu-parent {
|
||||
|
||||
> a::after {
|
||||
border: 0;
|
||||
content: "\f078";
|
||||
font-family: "Font Awesome 5 Free";
|
||||
font-weight: bold;
|
||||
height: auto;
|
||||
position: absolute;
|
||||
right: 24px;
|
||||
transition: 0.25s;
|
||||
}
|
||||
}
|
||||
|
||||
.submenu {
|
||||
border-bottom: 0;
|
||||
margin-left: $line-height;
|
||||
|
||||
li:first-child {
|
||||
padding-top: $line-height / 2;
|
||||
}
|
||||
|
||||
li:last-child {
|
||||
padding-bottom: $line-height / 2;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.is-active {
|
||||
border-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// See admin/menu.scss
|
||||
|
||||
// 03. List elements
|
||||
// -----------------
|
||||
|
||||
95
app/assets/stylesheets/admin/menu.scss
Normal file
95
app/assets/stylesheets/admin/menu.scss
Normal file
@@ -0,0 +1,95 @@
|
||||
.admin-sidebar {
|
||||
background: $sidebar;
|
||||
background: linear-gradient(to bottom, #245b80 0%, #488fb5 100%);
|
||||
border-right: 1px solid $border;
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
margin-bottom: 0;
|
||||
margin-left: 0;
|
||||
padding: 0;
|
||||
|
||||
[class^="icon-"] {
|
||||
color: #fff;
|
||||
display: inline-block;
|
||||
font-size: rem-calc(20);
|
||||
line-height: $line-height;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
width: $line-height * 1.5;
|
||||
}
|
||||
}
|
||||
|
||||
li {
|
||||
margin: 0;
|
||||
outline: 0;
|
||||
|
||||
ul {
|
||||
margin-left: $line-height / 1.5;
|
||||
border-left: 1px solid $sidebar-hover;
|
||||
padding-left: $line-height / 2;
|
||||
}
|
||||
|
||||
&.is-active a {
|
||||
background: $sidebar-hover;
|
||||
border-left: 2px solid $sidebar-active;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
&[aria-expanded="true"] {
|
||||
|
||||
> a::after {
|
||||
transform: rotate(180deg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
li a {
|
||||
color: #fff;
|
||||
display: block;
|
||||
line-height: $line-height * 2;
|
||||
padding-left: $line-height / 4;
|
||||
vertical-align: top;
|
||||
|
||||
&:hover {
|
||||
background: $sidebar-hover;
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.is-accordion-submenu-parent {
|
||||
|
||||
> a::after {
|
||||
border: 0;
|
||||
content: "\f078";
|
||||
font-family: "Font Awesome 5 Free";
|
||||
font-weight: bold;
|
||||
height: auto;
|
||||
position: absolute;
|
||||
right: 24px;
|
||||
transition: 0.25s;
|
||||
}
|
||||
}
|
||||
|
||||
.submenu {
|
||||
border-bottom: 0;
|
||||
margin-left: $line-height;
|
||||
|
||||
li:first-child {
|
||||
padding-top: $line-height / 2;
|
||||
}
|
||||
|
||||
li:last-child {
|
||||
padding-bottom: $line-height / 2;
|
||||
}
|
||||
|
||||
a {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
.is-active {
|
||||
border-bottom: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
60
app/components/admin/menu_component.rb
Normal file
60
app/components/admin/menu_component.rb
Normal file
@@ -0,0 +1,60 @@
|
||||
class Admin::MenuComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def menu_moderated_content?
|
||||
moderated_sections.include?(controller_name) && controller.class.parent != Admin::Legislation
|
||||
end
|
||||
|
||||
def moderated_sections
|
||||
["hidden_proposals", "hidden_debates", "hidden_comments", "hidden_users", "activity",
|
||||
"hidden_budget_investments", "hidden_proposal_notifications"]
|
||||
end
|
||||
|
||||
def menu_budgets?
|
||||
controller_name.starts_with?("budget")
|
||||
end
|
||||
|
||||
def menu_polls?
|
||||
controller.class.parent == Admin::Poll::Questions::Answers ||
|
||||
%w[polls active_polls recounts results questions answers].include?(controller_name) &&
|
||||
action_name != "booth_assignments"
|
||||
end
|
||||
|
||||
def menu_booths?
|
||||
%w[officers booths shifts booth_assignments officer_assignments].include?(controller_name) ||
|
||||
controller_name == "polls" && action_name == "booth_assignments"
|
||||
end
|
||||
|
||||
def menu_profiles?
|
||||
%w[administrators organizations officials moderators valuators managers users].include?(controller_name)
|
||||
end
|
||||
|
||||
def menu_settings?
|
||||
controllers_names = ["settings", "tags", "geozones", "images", "content_blocks",
|
||||
"local_census_records", "imports"]
|
||||
controllers_names.include?(controller_name) &&
|
||||
controller.class.parent != Admin::Poll::Questions::Answers
|
||||
end
|
||||
|
||||
def menu_customization?
|
||||
["pages", "banners", "information_texts", "documents"].include?(controller_name) ||
|
||||
menu_homepage? || menu_pages?
|
||||
end
|
||||
|
||||
def menu_homepage?
|
||||
["homepage", "cards"].include?(controller_name) && params[:page_id].nil?
|
||||
end
|
||||
|
||||
def menu_pages?
|
||||
["pages", "cards"].include?(controller_name) && params[:page_id].present?
|
||||
end
|
||||
|
||||
def menu_dashboard?
|
||||
["actions", "administrator_tasks"].include?(controller_name)
|
||||
end
|
||||
|
||||
def submenu_local_census_records?
|
||||
controller_name == "local_census_records" ||
|
||||
(controller_name == "imports" && controller.class.parent == Admin::LocalCensusRecords)
|
||||
end
|
||||
end
|
||||
@@ -1,2 +1,3 @@
|
||||
class ApplicationComponent < ViewComponent::Base
|
||||
include SettingsHelper
|
||||
end
|
||||
|
||||
@@ -11,63 +11,6 @@ module AdminHelper
|
||||
end
|
||||
end
|
||||
|
||||
def menu_moderated_content?
|
||||
moderated_sections.include?(controller_name) && controller.class.parent != Admin::Legislation
|
||||
end
|
||||
|
||||
def moderated_sections
|
||||
["hidden_proposals", "hidden_debates", "hidden_comments", "hidden_users", "activity",
|
||||
"hidden_budget_investments", "hidden_proposal_notifications"]
|
||||
end
|
||||
|
||||
def menu_budgets?
|
||||
controller_name.starts_with?("budget")
|
||||
end
|
||||
|
||||
def menu_polls?
|
||||
controller.class.parent == Admin::Poll::Questions::Answers ||
|
||||
%w[polls active_polls recounts results questions answers].include?(controller_name) &&
|
||||
action_name != "booth_assignments"
|
||||
end
|
||||
|
||||
def menu_booths?
|
||||
%w[officers booths shifts booth_assignments officer_assignments].include?(controller_name) ||
|
||||
controller_name == "polls" && action_name == "booth_assignments"
|
||||
end
|
||||
|
||||
def menu_profiles?
|
||||
%w[administrators organizations officials moderators valuators managers users].include?(controller_name)
|
||||
end
|
||||
|
||||
def menu_settings?
|
||||
controllers_names = ["settings", "tags", "geozones", "images", "content_blocks",
|
||||
"local_census_records", "imports"]
|
||||
controllers_names.include?(controller_name) &&
|
||||
controller.class.parent != Admin::Poll::Questions::Answers
|
||||
end
|
||||
|
||||
def menu_customization?
|
||||
["pages", "banners", "information_texts", "documents"].include?(controller_name) ||
|
||||
menu_homepage? || menu_pages?
|
||||
end
|
||||
|
||||
def menu_homepage?
|
||||
["homepage", "cards"].include?(controller_name) && params[:page_id].nil?
|
||||
end
|
||||
|
||||
def menu_pages?
|
||||
["pages", "cards"].include?(controller_name) && params[:page_id].present?
|
||||
end
|
||||
|
||||
def menu_dashboard?
|
||||
["actions", "administrator_tasks"].include?(controller_name)
|
||||
end
|
||||
|
||||
def submenu_local_census_records?
|
||||
controller_name == "local_census_records" ||
|
||||
(controller_name == "imports" && controller.class.parent == Admin::LocalCensusRecords)
|
||||
end
|
||||
|
||||
def official_level_options
|
||||
options = [["", 0]]
|
||||
(1..5).each do |i|
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
<%= check_box_tag :show_menu, nil, false, role: "switch" %>
|
||||
|
||||
<nav id="side_menu" class="admin-sidebar">
|
||||
<%= render "/#{namespace}/menu" %>
|
||||
<% if namespace == "admin" %>
|
||||
<%= render Admin::MenuComponent.new %>
|
||||
<% else %>
|
||||
<%= render "/#{namespace}/menu" %>
|
||||
<% end %>
|
||||
</nav>
|
||||
|
||||
<div class="admin-content">
|
||||
|
||||
Reference in New Issue
Block a user