diff --git a/app/assets/stylesheets/admin.scss b/app/assets/stylesheets/admin.scss index fad0f439a..e6bab74a3 100644 --- a/app/assets/stylesheets/admin.scss +++ b/app/assets/stylesheets/admin.scss @@ -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 // ----------------- diff --git a/app/assets/stylesheets/admin/menu.scss b/app/assets/stylesheets/admin/menu.scss new file mode 100644 index 000000000..482d2db91 --- /dev/null +++ b/app/assets/stylesheets/admin/menu.scss @@ -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; + } + } +} diff --git a/app/views/admin/_menu.html.erb b/app/components/admin/menu_component.html.erb similarity index 100% rename from app/views/admin/_menu.html.erb rename to app/components/admin/menu_component.html.erb diff --git a/app/components/admin/menu_component.rb b/app/components/admin/menu_component.rb new file mode 100644 index 000000000..bb4f6ab92 --- /dev/null +++ b/app/components/admin/menu_component.rb @@ -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 diff --git a/app/components/application_component.rb b/app/components/application_component.rb index 3db4d0451..3c5f3e47a 100644 --- a/app/components/application_component.rb +++ b/app/components/application_component.rb @@ -1,2 +1,3 @@ class ApplicationComponent < ViewComponent::Base + include SettingsHelper end diff --git a/app/helpers/admin_helper.rb b/app/helpers/admin_helper.rb index 44a878bf1..b531bf82a 100644 --- a/app/helpers/admin_helper.rb +++ b/app/helpers/admin_helper.rb @@ -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| diff --git a/app/views/layouts/admin.html.erb b/app/views/layouts/admin.html.erb index 32dd1c045..ff29aa5d5 100644 --- a/app/views/layouts/admin.html.erb +++ b/app/views/layouts/admin.html.erb @@ -13,7 +13,11 @@ <%= check_box_tag :show_menu, nil, false, role: "switch" %>