Class: Backend::BeehivesController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/beehives_controller.rb

Instance Attribute Summary

Attributes inherited from ApplicationController

#current_theme

Instance Method Summary collapse

Methods inherited from BaseController

accounts_range_crit, crit_params, journal_entries_states_crit, journal_period_crit, journals_crit, search_conditions

Methods inherited from ApplicationController

#after_sign_in_path_for, #authorized?, human_action_name, #human_action_name

Instance Method Details

#resetObject


47
48
49
50
51
52
# File 'app/controllers/backend/beehives_controller.rb', line 47

def reset
  if preference = current_user.preferences.find_by(name: "beehive.#{params[:id]}")
    preference.destroy!
  end
  head :ok
end

#updateObject

Save beehive config in preferences


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/backend/beehives_controller.rb', line 22

def update
  params['boxes'] ||= []
  boxes = params['boxes'].sort do |a, b|
    a[0] <=> b[0]
  end.map do |box|
    next unless box.second['cells']
    cells = box.second['cells'].symbolize_keys.sort do |a, b|
      a[0] <=> b[0]
    end.map do |cell|
      cell.second.symbolize_keys
    end.compact
    cells.any? ? { cells: cells } : nil
  end.compact
  begin
    current_user.reload
    current_user.prefer!("beehive.#{params[:id]}", {
      version: Backend::BeehiveHelper::FORMAT_VERSION,
      boxes: boxes
    }.deep_stringify_keys.to_yaml)
    head :ok
  rescue ActiveRecord::StaleObjectError
    head :locked
  end
end