Class: Backend::GolumnsController

Inherits:
BaseController show all
Defined in:
app/controllers/backend/golumns_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


30
31
32
33
34
35
# File 'app/controllers/backend/golumns_controller.rb', line 30

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

#showObject


25
26
27
28
# File 'app/controllers/backend/golumns_controller.rb', line 25

def show
  preference = current_user.preference("golumn.#{params[:id]}", {}.to_yaml)
  render json: YAML.load(preference.value)
end

#updateObject

Save golumn config in preferences


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/backend/golumns_controller.rb', line 4

def update
  unless params['positions'].nil?
    positions = params['positions'].sort do |a, b|
      a[0] <=> b[0]
    end.map do |group|
      next unless group.second['id'] && !group.second['id'].to_i.zero?
      g = { id: group.second['id'].to_i }
      if group.second['containers']
        g[:containers] = group.second['containers'].map(&:to_i)
      end
      g
    end.compact
    begin
      current_user.prefer!("golumn.#{params[:id]}", { positions: positions }.deep_stringify_keys.to_yaml)
      head :ok
    rescue ActiveRecord::StaleObjectError
      head :locked
    end
  end
end