rubyforgood/casa

View on GitHub
app/views/layouts/_sidebar.html.erb

Summary

Maintainability
Test Coverage
<div class="sidebar-controller" data-controller="sidebar" data-sidebar-open-value="true" data-sidebar-sidebar-group-outlet=".group-item">
  <aside class="sidebar-nav-wrapper" data-sidebar-target="sidebar">
    <div class="container d-flex logo-div">
      <div class="d-flex flex-fill">
        <div>
          <button type="button" class="btn btn-sidebar" data-action="click->sidebar#click">
            <i class="lni lni-menu"></i>
          </button>
        </div>
        <div class="flex-grow-1 d-flex justify-content-center" data-sidebar-target="logo">
          <%= link_to "/", class: "d-flex" do %>
            <% if current_organization&.logo&.attached? %>
              <%= image_tag(current_organization.logo, alt: "CASA Logo", class: "img-fluid flex-fill") %>
            <% else %>
              <%= image_tag("default-logo.png", id: "casa-logo", alt: "CASA Logo", class: "img-fluid flex-fill align-text-bottom") %>
            <% end %>
          <% end %>
        </div>
      </div>
    </div>
    <nav class="sidebar-nav" data-action="mouseover->sidebar#hoverOn mouseout->sidebar#hoverOff">
      <nav class="sidebar-nav">
        <ul>
          <%= render(Sidebar::LinkComponent.new(title: "Supervisors", icon: "network", path: supervisors_path, render_check: policy(Supervisor).index?)) %>
          <%= render(Sidebar::LinkComponent.new(title: "Volunteers", icon: "heart-filled", path: volunteers_path, render_check: policy(Volunteer).index?)) %>
          <%= render(Sidebar::LinkComponent.new(title: "Other Duties", icon: "agenda", path: other_duties_path, render_check: policy(OtherDuty).index?)) %>
          <!-- Renders Cases for Volunteers -->
          <%= render(Sidebar::GroupComponent.new(title: cases_index_title, icon: "folder", render_check: current_user.volunteer?)) do |group| %>
            <% group.with_link(title: "All", path: casa_cases_path, nav_item: false) %>
            <% group.with_links(current_user.casa_cases.map { |cc| { title: cc.case_number, path: casa_case_path(cc), nav_item: false }}) %>
          <% end %>
          <!-- Renders Cases for Non-Volunteers -->
          <%= render(Sidebar::LinkComponent.new(title: cases_index_title, icon: "folder", path: casa_cases_path, render_check: !current_user.volunteer?)) %>

          <%= render(Sidebar::LinkComponent.new(title: "Admins", icon: "star-filled", path: casa_admins_path, render_check: policy(CasaAdmin).index?)) %>
          <%= render(Sidebar::LinkComponent.new(title: "Patch Notes", icon: "notepad", path: all_casa_admins_patch_notes_path, render_check: all_casa_admin_signed_in?)) %>
          <%= render(Sidebar::GroupComponent.new(title: "Case Contacts", icon: "users", render_check: current_user.volunteer?)) do |group| %>
            <%= group.with_link(title: "All", path: case_contacts_path, nav_item: false) %>
            <% group.with_links(current_user.casa_cases.map { |cc| { title: cc.case_number, path: case_contacts_path(casa_case_id: cc.id), nav_item: false } }) %>
          <% end %>
          <%= render(Sidebar::LinkComponent.new(title: "Learning Hours", icon: "timer", path: learning_hours_path, render_check: policy(LearningHour).index?)) %>
          <%= render(Sidebar::LinkComponent.new(title: "Emancipation Checklist(s)", icon: "list", path: emancipation_checklists_path, render_check: current_user.serving_transition_aged_youth?)) %>
          <%= render(Sidebar::LinkComponent.new(title: "Banners", icon: "flag", path: banners_path, render_check: policy(:application).see_banner_page?)) %>
          <%= render(Sidebar::LinkComponent.new(title: "Generate Court Reports", icon: "paperclip", path: case_court_reports_path, render_check: policy(:application).see_court_reports_page? && current_user.volunteer?)) %>
          <%= render(Sidebar::GroupComponent.new(title: "Group Actions", icon: "list", render_check: !current_user.volunteer?)) do |group| %>
            <% group.with_links([
              { title: "Generate Court Reports", icon: "paperclip", path: case_court_reports_path, render_check: policy(:application).see_court_reports_page? },
              { title: "Reimbursement Queue", icon: "money-location", path: reimbursements_path, render_check: policy(:reimbursement).index? },
              { title: "Export Data", icon: "folder", path: reports_path, render_check: policy(:application).see_reports_page? },
              { title: "System Imports", icon: "archive", path: imports_path, render_check: policy(:application).see_reports_page? },
              { title: "Mileage Rates", icon: "car", path: mileage_rates_path, render_check: policy(:application).see_mileage_rate? }
            ]) %>
          <% end %>
          <%= render(Sidebar::GroupComponent.new(title: "Edit Organization", icon: "list", render_check: !current_user.volunteer?)) do |group| %>
            <% group.with_links([
              { title: "Organization Details", icon: "briefcase", path: edit_casa_org_path(current_organization, anchor: 'organization-details'), render_check: policy(:application).modify_organization? },
              { title: "Contact Types", icon: "user", path: edit_casa_org_path(current_organization, anchor: 'contact-types'), render_check: policy(:application).modify_organization? },
              { title: "Court Details", icon: "library", path: edit_casa_org_path(current_organization, anchor: 'court-details'), render_check: policy(:application).modify_organization? },
              { title: "Learning Hours", icon: "timer", path: edit_casa_org_path(current_organization, anchor: 'learning-hours'), render_check: policy(:application).modify_organization? },
              { title: "Case Contact Topics", icon: "comments", path: edit_casa_org_path(current_organization, anchor: 'case-contact-topics'), render_check: policy(:application).modify_organization? }
            ]) %>
          <% end %>
        </ul>
      </nav>
    </nav>
  </aside>

  <div class="overlay" data-action="click->sidebar#click"></div>
</div>