Class: Decidim::DecidimAwesome::Menu

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/decidim_awesome/menu.rb

Class Method Summary collapse

Class Method Details

.config_enabled?(*vars) ⇒ Boolean

ensure boolean value

Returns:

  • (Boolean)


245
246
247
# File 'lib/decidim/decidim_awesome/menu.rb', line 245

def config_enabled?(*vars)
  DecidimAwesome.enabled?(*vars)
end

.first_enabled(*vars) ⇒ Object



237
238
239
240
241
242
# File 'lib/decidim/decidim_awesome/menu.rb', line 237

def first_enabled(*vars)
  vars.each do |var|
    return var if config_enabled?(var)
  end
  nil
end

.main_path_for(config_var) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/decidim/decidim_awesome/menu.rb', line 32

def main_path_for(config_var)
  case config_var.to_sym
  when :styles
    [:config_path, [menus[:styles]]]
  when :custom_fields
    [:config_path, [menus[:custom_fields]]]
  when :menu_hacks
    [:menu_hacks_path, [menus[:menu_hacks]]]
  when :custom_redirects
    [:custom_redirects_path, []]
  when :cookie_management
    [:cookie_categories_path, []]
  when :verifications
    if menus[:force_authorizations]
      [:config_path, [config_var]]
    else
      [:awesome_authorizations_path, []]
    end
  when :maintenance
    [:checks_path, []]
  else
    [:config_path, [config_var]]
  end
end


205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/decidim/decidim_awesome/menu.rb', line 205

def menus
  @menus ||= {
    editors: config_enabled?(:allow_images_in_editors, :allow_videos_in_editors),
    proposals: config_enabled?(
      :allow_images_in_proposals,
      :validate_title_min_length, :validate_title_max_caps_percent,
      :validate_title_max_marks_together, :validate_title_start_with_caps,
      :validate_body_min_length, :validate_body_max_caps_percent,
      :validate_body_max_marks_together, :validate_body_start_with_caps
    ),
    surveys: config_enabled?(:auto_save_forms, :user_timezone, :hashcash_signup, :hashcash_login),
    styles: first_enabled(:scoped_styles, :scoped_admin_styles),
    scoped_styles: config_enabled?(:scoped_styles),
    scoped_admin_styles: config_enabled?(:scoped_admin_styles),
    custom_fields: first_enabled(:proposal_custom_fields, :proposal_private_custom_fields),
    proposal_custom_fields: config_enabled?(:proposal_custom_fields),
    proposal_private_custom_fields: config_enabled?(:proposal_private_custom_fields),
    admins: config_enabled?(:scoped_admins),
    menu_hacks: first_enabled(:menu, :mobile_menu, :home_content_block_menu),
    menu_hacks_menu: config_enabled?(:menu),
    menu_hacks_mobile_menu: config_enabled?(:mobile_menu),
    menu_hacks_home_content_block_menu: config_enabled?(:home_content_block_menu),
    custom_redirects: config_enabled?(:custom_redirects),
    livechat: config_enabled?(:intergram_for_admins, :intergram_for_public),
    verifications: config_enabled?(:force_authorizations, :awesome_authorization_handler),
    force_authorizations: config_enabled?(:force_authorizations),
    awesome_authorization_handler: config_enabled?(:awesome_authorization_handler),
    cookie_management: config_enabled?(:cookie_management),
    maintenance: true
  }
end

.register_awesome_admin_menu!Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/decidim/decidim_awesome/menu.rb', line 57

def register_awesome_admin_menu!
  register_simple_entry(:awesome_admin_menu, :editors, 1, "editors-text")
  register_simple_entry(:awesome_admin_menu, :proposals, 2, "documents")
  register_simple_entry(:awesome_admin_menu, :surveys, 3, "surveys")
  register_simple_entry(:awesome_admin_menu, :styles, 4, "brush",
                        submenu: { target_menu: :custom_styles_submenu },
                        active: [[:config_path, :scoped_styles], [:config_path, :scoped_admin_styles]])

  register_simple_entry(:awesome_admin_menu, :custom_fields, 5, "layers",
                        i18n_key: "menu.proposal_custom_fields",
                        submenu: { target_menu: :custom_fields_submenu },
                        active: [[:config_path, :proposal_custom_fields], [:config_path, :proposal_private_custom_fields]])

  register_simple_entry(:awesome_admin_menu, :admins, 6, "group-line")

  register_simple_entry(:awesome_admin_menu, :menu_hacks, 7, "menu-line",
                        submenu: { target_menu: :menu_hacks_submenu },
                        active: [[:menu_hacks_path, :menu], [:menu_hacks_path, :mobile_menu], [:menu_hacks_path, :home_content_block_menu]])

  register_simple_entry(:awesome_admin_menu, :custom_redirects, 8, "external-link-line")
  register_simple_entry(:awesome_admin_menu, :livechat, 9, "chat-1-line")

  register_simple_entry(:awesome_admin_menu, :verifications, 10, "fingerprint-line",
                        i18n_key: "menu.verifications.verifications",
                        submenu: { target_menu: :awesome_authorization_submenu },
                        active: [[:awesome_authorizations_path]])

  register_simple_entry(:awesome_admin_menu, :cookie_management, 11, "shield-check-line")

  register_simple_entry(:awesome_admin_menu, :maintenance, 12, "tools-line",
                        i18n_key: "menu.maintenance.maintenance",
                        submenu: { target_menu: :maintenance_submenu },
                        active: [[:private_data_path], [:hashcashes_path], [:checks_path]])
end

.register_awesome_authorization_submenu!Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/decidim/decidim_awesome/menu.rb', line 186

def register_awesome_authorization_submenu!
  Decidim.menu :awesome_authorization_submenu do |menu|
    if config_enabled?(:force_authorizations)
      menu.add_item :verifications,
                    I18n.t("force_authorizations", scope: "decidim.decidim_awesome.admin.menu.verifications"),
                    decidim_admin_decidim_awesome.config_path(:verifications),
                    position: 1,
                    icon_name: "lock-line"
    end
    if config_enabled?(:awesome_authorization_handler)
      menu.add_item :awesome_authorizations,
                    I18n.t("awesome_authorizations", scope: "decidim.decidim_awesome.admin.menu.verifications"),
                    decidim_admin_decidim_awesome.awesome_authorizations_path,
                    position: 2,
                    icon_name: "bubble-chart-line"
    end
  end
end

.register_custom_fields_submenu!Object



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/decidim/decidim_awesome/menu.rb', line 92

def register_custom_fields_submenu!
  Decidim.menu :custom_fields_submenu do |menu|
    if menus[:proposal_custom_fields].present?
      menu.add_item :proposal_custom_fields,
                    I18n.t("menu.title", scope: "decidim.decidim_awesome.admin.proposal_custom_fields"),
                    decidim_admin_decidim_awesome.config_path(:proposal_custom_fields),
                    position: 5.1,
                    icon_name: "draft-line"
    end

    if menus[:proposal_private_custom_fields].present?
      menu.add_item :proposal_private_custom_fields,
                    I18n.t("proposal_private_custom_fields", scope: "decidim.decidim_awesome.admin.proposal_custom_fields"),
                    decidim_admin_decidim_awesome.config_path(:proposal_private_custom_fields),
                    position: 5.2,
                    icon_name: "spy"
    end
  end
end

.register_custom_styles_submenu!Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/decidim/decidim_awesome/menu.rb', line 112

def register_custom_styles_submenu!
  Decidim.menu :custom_styles_submenu do |menu|
    if menus[:scoped_styles].present?
      menu.add_item :scoped_styles,
                    I18n.t("menu.title", scope: "decidim.decidim_awesome.admin.scoped_styles"),
                    decidim_admin_decidim_awesome.config_path(:scoped_styles),
                    position: 4.1,
                    icon_name: "computer-line"
    end

    if menus[:scoped_admin_styles].present?
      menu.add_item :scoped_admin_styles,
                    I18n.t("menu.title", scope: "decidim.decidim_awesome.admin.scoped_admin_styles"),
                    decidim_admin_decidim_awesome.config_path(:scoped_admin_styles),
                    position: 4.2,
                    icon_name: "file-settings-line"
    end
  end
end

.register_maintenance_admin_menu!Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/decidim/decidim_awesome/menu.rb', line 160

def register_maintenance_admin_menu!
  Decidim.menu :maintenance_submenu do |menu|
    if config_enabled?(:proposal_private_custom_fields)
      menu.add_item :private_data,
                    I18n.t("private_data", scope: "decidim.decidim_awesome.admin.menu.maintenance"),
                    decidim_admin_decidim_awesome.private_data_path,
                    position: 10.1,
                    icon_name: "spy-line"
    end

    if config_enabled?(:hashcash_signup, :hashcash_login)
      menu.add_item :hashcash,
                    I18n.t("hashcash", scope: "decidim.decidim_awesome.admin.menu.maintenance"),
                    decidim_admin_decidim_awesome.hashcashes_path,
                    position: 10.2,
                    icon_name: "hashtag"
    end

    menu.add_item :checks,
                  I18n.t("checks", scope: "decidim.decidim_awesome.admin.menu.maintenance"),
                  decidim_admin_decidim_awesome.checks_path,
                  position: 10.3,
                  icon_name: "pulse"
  end
end

.register_menu_hacks_submenu!Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/decidim/decidim_awesome/menu.rb', line 132

def register_menu_hacks_submenu!
  Decidim.menu :menu_hacks_submenu do |menu|
    if menus[:menu_hacks_menu].present?
      menu.add_item :main_menu,
                    I18n.t("menu.title", scope: "decidim.decidim_awesome.admin.menu_hacks.index"),
                    decidim_admin_decidim_awesome.menu_hacks_path(:menu),
                    position: 7.1,
                    icon_name: "global-line"
    end

    if menus[:menu_hacks_mobile_menu].present?
      menu.add_item :mobile_menu,
                    I18n.t("mobile_menu.title", scope: "decidim.decidim_awesome.admin.menu_hacks.index"),
                    decidim_admin_decidim_awesome.menu_hacks_path(:mobile_menu),
                    position: 7.2,
                    icon_name: "smartphone"
    end

    if menus[:menu_hacks_home_content_block_menu].present?
      menu.add_item :content_block_main_menu,
                    I18n.t("home_content_block_menu.title", scope: "decidim.decidim_awesome.admin.menu_hacks.index"),
                    decidim_admin_decidim_awesome.menu_hacks_path(:home_content_block_menu),
                    position: 7.3,
                    icon_name: "layout-masonry-line"
    end
  end
end

.register_simple_entry(menu_registry, name, position, icon, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/decidim/decidim_awesome/menu.rb', line 7

def register_simple_entry(menu_registry, name, position, icon, options = {})
  return if menus[name].blank?

  path = main_path_for(name)

  Decidim.menu menu_registry do |menu|
    i18n_key = options[:i18n_key].presence || "menu.#{name}"
    extra = {}.tap do |hash|
      hash[:submenu] = options[:submenu] if options[:submenu].present?
      if options[:active].present?
        hash[:active] = false
        options[:active].each do |active_path|
          hash[:active] ||= is_active_link?(decidim_admin_decidim_awesome.send(active_path[0], *active_path[1..]))
        end
      end
    end
    menu.add_item name,
                  I18n.t(i18n_key, scope: "decidim.decidim_awesome.admin"),
                  decidim_admin_decidim_awesome.send(path[0], path[1]),
                  position:,
                  icon_name: icon,
                  **extra
  end
end