Class: Admin::ConfigsController
- Inherits:
-
BaseController
- Object
- BaseController
- Admin::ConfigsController
- Defined in:
- app/controllers/admin/configs_controller.rb
Instance Method Summary collapse
- #convert_config_value(value) ⇒ Object protected
-
#get_tabs ⇒ Object
protected
Set configuration tab names as ‘@tabs`.
- #list ⇒ Object
-
#parse_recurring_selects!(config) ⇒ Object
protected
turn recurring rules into something palatable.
- #show ⇒ Object
- #update ⇒ Object
Instance Method Details
#convert_config_value(value) ⇒ Object (protected)
57 58 59 60 61 62 63 |
# File 'app/controllers/admin/configs_controller.rb', line 57 def convert_config_value(value) if value.is_a? ActionController::Parameters value.transform_values { |v| convert_config_value(v) }.to_hash else value end end |
#get_tabs ⇒ Object (protected)
Set configuration tab names as ‘@tabs`
31 32 33 34 35 36 37 |
# File 'app/controllers/admin/configs_controller.rb', line 31 def get_tabs @tabs = %w[foodcoop payment tasks messages layout language security 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 |
#list ⇒ Object
9 10 11 12 13 14 |
# File 'app/controllers/admin/configs_controller.rb', line 9 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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/admin/configs_controller.rb', line 40 def parse_recurring_selects!(config) return unless config for k in %i[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].nil? config[k][:recurr] = ActiveSupport::JSON.decode(config[k][:recurr]) date = FoodsoftDateUtil.rule_from(config[k][:recurr]) config[k][:recurr] = date.to_ical if date else config[k][:recurr] = '' end end end end |
#show ⇒ Object
4 5 6 7 |
# File 'app/controllers/admin/configs_controller.rb', line 4 def show @current_tab = @tabs.include?(params[:tab]) ? params[:tab] : @tabs.first @cfg = FoodsoftConfig end |
#update ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/admin/configs_controller.rb', line 16 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] = convert_config_value val end end flash[:notice] = I18n.t('admin.configs.update.notice') redirect_to action: 'show' end |