Class: Layout::NavbarComponent

Inherits:
CommonComponent show all
Defined in:
app/components/layout/navbar_component.rb

Overview

This class manage the site navbar generation (id: nav3)

Instance Method Summary collapse

Methods inherited from CommonComponent

#icon, #icon_text, #level, #level_item, #pagy, #turbo_yield

Methods included from ApplicationHelper

#fas_icon, #icon, #icon_text, #l_date, #l_long, #l_time, #notifications, #notify, #notify_status, #t_enum

Constructor Details

#initialize(user: nil) ⇒ NavbarComponent

Returns a new instance of NavbarComponent.

Parameters:

  • user (Hash) (defaults to: nil)

    (nil) used for define current_user in this component



7
8
9
10
# File 'app/components/layout/navbar_component.rb', line 7

def initialize(user: nil)
  super
  @user = user
end

Instance Method Details

#admin_submenuArray

Returns admin menu entries.

Returns:

  • (Array)

    admin menu entries



76
77
78
79
80
81
82
83
84
# File 'app/components/layout/navbar_component.rb', line 76

def admin_submenu
  return unless @user.admin?

  [
    link_to(t(".admin.groups"), admin_groups_path, data: { turbo: { frame: "yield" } }, class: "navbar-item"),
    link_to(t(".admin.users"), admin_users_path, data: { turbo: { frame: "yield" } }, class: "navbar-item"),
    link_to(t(".admin.templates"), admin_templates_path, data: { turbo: { frame: "yield" } }, class: "navbar-item")
  ]
end

#callString

Generate an html safe string with full ispra top menu

Returns:

  • (String)

    html string menu



14
15
16
# File 'app/components/layout/navbar_component.rb', line 14

def call
  tag.div tag.div(navbar, class: "container"), id: "nav3"
end

#editor_submenuArray

Returns admin menu entries.

Returns:

  • (Array)

    admin menu entries



87
88
89
90
91
92
93
94
95
# File 'app/components/layout/navbar_component.rb', line 87

def editor_submenu
  return unless @user.editor?

  [
    link_to(t(".editor.events"), editor_events_path, data: { turbo: { frame: "yield" } }, class: "navbar-item"),
    link_to(t(".editor.happenings"), editor_happenings_path, data: { turbo: { frame: "yield" } }, class: "navbar-item"),
    link_to(t(".editor.users"), editor_users_path, data: { turbo: { frame: "yield" } }, class: "navbar-item")
  ]
end

#lang_submenuObject

Generate the ‘select language’ submenu html block



50
51
52
53
54
55
56
# File 'app/components/layout/navbar_component.rb', line 50

def lang_submenu
  title = icon("fas fa-globe")
  sub = link_to("IT", events_path(locale: "it"),
                class: "navbar-item") + link_to("EN", events_path(locale: "en"), class: "navbar-item")
  submenu title:, sub:
  # tag.div lang_title + lang_dropdown, class: 'navbar-item has-dropdown is-hoverable has-background-primary-dark'
end

render Bulmacomp::NavbarComponent with the options



19
20
21
# File 'app/components/layout/navbar_component.rb', line 19

def navbar
  render Bulmacomp::NavbarComponent.new(brand: navbar_title, navbar_start:, navbar_end:)
end

Generate the navbar-end html block



39
40
41
42
43
44
45
46
47
# File 'app/components/layout/navbar_component.rb', line 39

def navbar_end
  ret = [ lang_submenu ]
  if @user.present?
    ret << user_submenu
  else
    ret << link_to(icon_text("fas fa-right-to-bracket", t(".sign_in")), new_user_session_path, data: { turbo_frame: "yield" }, class: "navbar-item")
  end
  safe_join(ret)
end

Gerate the navbar-start html block



30
31
32
33
34
35
36
# File 'app/components/layout/navbar_component.rb', line 30

def navbar_start
  safe_join [
    link_to(icon_text("fas fa-calendar", t(".events")), events_path, data: { turbo_frame: "yield" }, class: "navbar-item"),
    link_to(icon_text("fas fa-calendar-day", t(".happenings")), happenings_path, data: { turbo_frame: "yield" }, class: "navbar-item"),
    link_to(icon_text("fas fa-ticket-alt", t(".tickets")), tickets_path, data: { turbo_frame: "yield" }, class: "navbar-item")
  ]
end

Generate the navbar-title html block



24
25
26
27
# File 'app/components/layout/navbar_component.rb', line 24

def navbar_title
  title = ENV.fetch("RAILS_TITLE", "Partecipo")
  safe_join([ icon(ENV.fetch("RAILS_ICON", "fas fa-signature")), tag.span(title.first), title[1..] ])
end


58
59
60
61
# File 'app/components/layout/navbar_component.rb', line 58

def submenu(title:, sub:)
  style = "navbar-item has-dropdown is-hoverable"
  tag.div link_to(title, "", class: "navbar-link") + tag.div(sub, class: "navbar-dropdown"), class: style
end

#user_submenuObject

Generate the user submenu html block



64
65
66
67
68
69
70
71
72
73
# File 'app/components/layout/navbar_component.rb', line 64

def user_submenu
  title = icon_text("fas fa-user", @user.email)
  sub = safe_join([
                    editor_submenu,
                    admin_submenu,
                    (link_to(t(".user_edit"), edit_user_registration_path, class: "navbar-item") if RAILS_DEVISE_DATABASE_AUTHENTICATABLE),
                    link_to(t(".sign_out"), destroy_user_session_path, data: { turbo_method: :delete }, class: "navbar-item")
                  ])
  submenu title:, sub:
end