Class: Admin::ConfigsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/admin/configs_controller.rb

Instance Method Summary collapse

Instance Method Details

#get_tabsObject (protected)

Set configuration tab names as `@tabs`


32
33
34
35
36
37
38
# File 'app/controllers/admin/configs_controller.rb', line 32

def get_tabs
  @tabs = %w(foodcoop payment tasks messages layout language others)
  # allow engines to modify this list
  engines = Rails::Engine.subclasses.map(&:instance).select { |e| e.respond_to?(:configuration) }
  engines.each { |e| e.configuration(@tabs, self) }
  @tabs.uniq!
end

#listObject


10
11
12
13
14
15
# File 'app/controllers/admin/configs_controller.rb', line 10

def list
  @current_tab = 'list'
  @cfg = FoodsoftConfig
  @dfl = FoodsoftConfig.config
  @keys = FoodsoftConfig.keys.select {|k| FoodsoftConfig.allowed_key?(k)}.sort
end

#parse_recurring_selects!(config) ⇒ Object (protected)

turn recurring rules into something palatable


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/admin/configs_controller.rb', line 41

def parse_recurring_selects!(config)
  if config
    for k in [:pickup, :boxfill, :ends] do
      if config[k]
        # allow clearing it using dummy value '{}' ('' would break recurring_select)
        if config[k][:recurr].present? && config[k][:recurr] != '{}'
          config[k][:recurr] = ActiveSupport::JSON.decode(config[k][:recurr])
          config[k][:recurr] = FoodsoftDateUtil.rule_from(config[k][:recurr]).to_ical if config[k][:recurr]
        else
          config[k] = nil
        end
      end
    end
  end
end

#showObject


5
6
7
8
# File 'app/controllers/admin/configs_controller.rb', line 5

def show
  @current_tab = @tabs.include?(params[:tab]) ? params[:tab] : @tabs.first
  @cfg = FoodsoftConfig
end

#updateObject


17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/admin/configs_controller.rb', line 17

def update
  parse_recurring_selects! params[:config][:order_schedule]
  ActiveRecord::Base.transaction do
    # TODO support nested configuration keys
    params[:config].each do |key, val|
      FoodsoftConfig[key] = val
    end
  end
  flash[:notice] = I18n.t('admin.configs.update.notice')
  redirect_to action: 'show'
end