Class: SolidusAdmin::Configuration

Inherits:
Spree::Preferences::Configuration
  • Object
show all
Defined in:
lib/solidus_admin/configuration.rb

Overview

Configuration for the admin interface.

Ensure requiring this file after the Rails application has been created, as some defaults depend on the application context.

Constant Summary collapse

ComponentNotFoundError =
Class.new(NameError)
ENGINE_ROOT =
File.expand_path("#{__dir__}/../..")

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dark_themeString

Returns Default admin theme name.

Returns:

  • Default admin theme name



235
# File 'lib/solidus_admin/configuration.rb', line 235

preference :dark_theme, :string, default: 'solidus_dark'

#enable_alpha_features?Boolean

Returns Determines whether alpha features are enabled or disabled in the application. Setting this to ‘true` enables access to alpha stage features that might still be in testing or development. Use with caution, as these features may not be fully stable or complete. Default: false.

Returns:

  • Determines whether alpha features are enabled or disabled in the application. Setting this to ‘true` enables access to alpha stage features that might still be in testing or development. Use with caution, as these features may not be fully stable or complete. Default: false



47
# File 'lib/solidus_admin/configuration.rb', line 47

preference :enable_alpha_features?, :boolean, default: false

#low_stock_valueInteger

Returns The low stock value determines the threshold at which products are considered low in stock. Products with a count_on_hand less than or equal to this value will be considered low in stock. Default: 10.

Returns:

  • The low stock value determines the threshold at which products are considered low in stock. Products with a count_on_hand less than or equal to this value will be considered low in stock. Default: 10



40
# File 'lib/solidus_admin/configuration.rb', line 40

preference :low_stock_value, :integer, default: 10

#themeString

Returns Default admin theme name.

Returns:

  • Default admin theme name



231
# File 'lib/solidus_admin/configuration.rb', line 231

preference :theme, :string, default: 'solidus'

#themesHash

Returns A hash containing the themes that are available for the admin panel.

Returns:

  • A hash containing the themes that are available for the admin panel



223
224
225
226
227
# File 'lib/solidus_admin/configuration.rb', line 223

preference :themes, :hash, default: {
  solidus: 'solidus_admin/application',
  solidus_dark: 'solidus_admin/dark',
  solidus_dimmed: 'solidus_admin/dimmed',
}

Instance Method Details

#componentsObject



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/solidus_admin/configuration.rb', line 187

def components
  @components ||= Hash.new do |_h, k|
    const_name = "solidus_admin/#{k}/component".classify

    unless Object.const_defined?(const_name)
      prefix = "#{ENGINE_ROOT}/app/components/solidus_admin/"
      suffix = "/component.rb"
      dictionary = Dir["#{prefix}**#{suffix}"].map { _1.delete_prefix(prefix).delete_suffix(suffix) }
      corrections = DidYouMean::SpellChecker.new(dictionary: dictionary).correct(k.to_s)

      raise ComponentNotFoundError.new(
        "Unknown component #{k}#{DidYouMean.formatter.message_for(corrections)}",
        k.classify,
        receiver: ::SolidusAdmin
      )
    end

    const_name.constantize
  end
end

#import_menu_items_from_backend!Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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
185
# File 'lib/solidus_admin/configuration.rb', line 142

def import_menu_items_from_backend!
  menu_item_to_hash = ->(item, index) do
    route =
      if item.url.is_a?(Symbol)
        -> { solidus_admin.public_send(item.url) }
      elsif item.url.is_a?(String)
        -> { item.url }
      elsif item.url.is_a?(Proc)
        item.url
      elsif item.url.nil?
        -> { spree.public_send(:"admin_#{item.label}_path") }
      else
        raise ArgumentError, "Unknown url type #{item.url.class}"
      end

    match_path =
      case item.match_path
      when Regexp then -> { _1 =~ item.match_path }
      when Proc then item.match_path
      when String then -> { _1.start_with?("/admin#{item.match_path}") }
      when nil then -> { _1.start_with?(route.call) }
      else raise ArgumentError, "Unknown match_path type #{item.match_path.class}"
      end

    icon =
      case item.icon
      when /^ri-/
        item.icon.delete_prefix("ri-")
      when String
        'record-circle-line' # fallback on a generic icon
      end

    {
      position: index,
      key: item.label,
      icon: icon,
      route: route,
      children: item.children.map.with_index(&menu_item_to_hash),
      match_path: match_path,
    }
  end

  @menu_items = Spree::Backend::Config.menu_items.map.with_index(&menu_item_to_hash)
end

Gives access to the main navigation configuration

Examples:

SolidusAdmin::Config.menu_items << {
  key: :my_custom_link,
  route: :products_path,
  icon: "solidus_admin/price-tag-3-line.svg",
  position: 80
}

Returns:

API:

  • public



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/solidus_admin/configuration.rb', line 69

def menu_items
  @menu_items ||= [
    {
      key: "orders",
      route: -> { spree.admin_orders_path },
      icon: "inbox-line",
      position: 10
    },
    {
      key: "products",
      route: :products_path,
      icon: "price-tag-3-line",
      position: 20,
      children: [
        {
          key: "products",
          route: -> { solidus_admin.products_path },
          match_path: -> { _1.start_with?("/admin/products/") },
          position: 0
        },
        {
          key: "option_types",
          route: -> { spree.admin_option_types_path },
          position: 10
        },
        {
          key: "property_types",
          route: -> { spree.admin_properties_path },
          position: 20
        },
        {
          key: "taxonomies",
          route: -> { spree.admin_taxonomies_path },
          position: 30
        },
        {
          key: "taxons",
          route: -> { spree.admin_taxons_path },
          position: 40
        }
      ]
    },

    {
      key: "promotions",
      route: -> { spree.admin_promotions_path },
      icon: "megaphone-line",
      position: 30,
    },

    {
      key: "stock",
      route: -> { spree.admin_stock_items_path },
      icon: "stack-line",
      position: 40
    },

    {
      key: "users",
      route: -> { spree.admin_users_path },
      icon: "user-line",
      position: 50
    },

    {
      key: "settings",
      route: -> { spree.admin_stores_path },
      icon: "settings-line",
      position: 60,
    }
  ]
end

#storefront_product_path(product) ⇒ Object



53
54
55
# File 'lib/solidus_admin/configuration.rb', line 53

def storefront_product_path(product)
  storefront_product_path_proc.call(product)
end

#theme_path(user_theme) ⇒ Object



237
238
239
# File 'lib/solidus_admin/configuration.rb', line 237

def theme_path(user_theme)
  themes.fetch(user_theme&.to_sym, themes[theme.to_sym])
end