Class: Vario::LevelsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/vario/levels_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#add_breadcrumbs, #breadcrumb_settings_path

Instance Method Details

#createObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/vario/levels_controller.rb', line 10

def create
  @level = Level.new(@setting, level_params)
  @setting.levels.unshift @level
  @level.conditions = normalize_booleans(level_params[:conditions].to_h)
  @level.conditions = normalize_booleans(level_params[:conditions].to_h)
  if @setting.save
    if request.referer.present? && URI.parse(request.referer).path != setting_path(@setting)
      redirect_to request.referer
    else
      respond_with @setting, collection_location: -> { setting_path(@setting) }
    end
  else
     Signum.error(current_user, text:  @setting.errors.full_messages.join(","))
    redirect_to setting_path(@setting)
  end  
end

#destroyObject



48
49
50
51
52
53
54
55
56
# File 'app/controllers/vario/levels_controller.rb', line 48

def destroy
  @setting.levels.reject! { |level| level.id == params[:id] }
  @setting.save
  if request.referer.present? && URI.parse(request.referer).path != setting_path(@setting)
    redirect_to request.referer
  else
    respond_with @setting, collection_location: -> { setting_path(@setting) }
  end
end

#indexObject



67
# File 'app/controllers/vario/levels_controller.rb', line 67

def index; end

#moveObject



58
59
60
61
62
63
64
65
# File 'app/controllers/vario/levels_controller.rb', line 58

def move
  oldIndex = @setting.levels.find_index { |level| level.id == params[:id] }
  newIndex = params[:index]
  @level = @setting.levels[oldIndex]
  @level.move(oldIndex - newIndex)

  render json: { old: oldIndex, new: newIndex }
end

#showObject



69
# File 'app/controllers/vario/levels_controller.rb', line 69

def show; end

#updateObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/vario/levels_controller.rb', line 27

def update
  if params[:commit] == 'delete'
    self.action_name = 'destroy'
    return destroy
  end

  @level = @setting.levels.find { |level| level.id == params[:id] }
  @level.value = level_params[:value]
  @level.conditions = normalize_booleans(level_params[:conditions].to_h)
  if @setting.save
    if request.referer.present? && URI.parse(request.referer).path != setting_path(@setting)
      redirect_to request.referer
    else
      respond_with @setting, collection_location: -> { setting_path(@setting) }
    end
  else
    Signum.error(current_user, text:  @setting.errors.full_messages.join(","))
    redirect_to setting_path(@setting)
  end  
end