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:

  • opts (Hash)

    options to generate content



11
12
13
14
# File 'app/components/layout/navbar_component.rb', line 11

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

Instance Method Details

#admin_submenuObject



84
85
86
87
88
89
90
91
# File 'app/components/layout/navbar_component.rb', line 84

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")
  ]
end

#callString

Generate an html safe string with full ispra top menu

Returns:

  • (String)

    html string menu



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

def call
  tag.div tag.div(navbar, class: "container"), id: "nav3", class: "has-background-primary-dark"
end

#editor_submenuObject



94
95
96
97
98
99
100
101
102
103
# File 'app/components/layout/navbar_component.rb', line 94

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



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

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



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

def navbar
  render Bulmacomp::NavbarComponent.new(brand: navbar_title, navbar_start:, navbar_end:,
                                        class: "navbar has-background-primary-dark")
end

Generate the navbar-end html block



45
46
47
48
49
50
51
52
53
54
# File 'app/components/layout/navbar_component.rb', line 45

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: false },
                                                                                               class: "navbar-item")
  end
  safe_join(ret)
end

Gerate the navbar-start html block



34
35
36
37
38
39
40
41
42
# File 'app/components/layout/navbar_component.rb', line 34

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, class: "navbar-item")
  ]
end

Generate the navbar-title html block



29
30
31
# File 'app/components/layout/navbar_component.rb', line 29

def navbar_title
  safe_join([ icon_text("fas fa-signature", "P"), "artecipo" ])
end


65
66
67
68
# File 'app/components/layout/navbar_component.rb', line 65

def submenu(title:, sub:)
  style = "navbar-item has-dropdown is-hoverable has-background-primary-dark"
  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



71
72
73
74
75
76
77
78
79
80
81
# File 'app/components/layout/navbar_component.rb', line 71

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"),
                    link_to(t(".sign_out"), destroy_user_session_path, data: { turbo_method: :delete },
                                                                       class: "navbar-item")
                  ])
  submenu title:, sub:
end