Class: DatashiftJourney::JourneyPlansController

Inherits:
ApplicationController show all
Includes:
ValidateState
Defined in:
app/controllers/datashift_journey/journey_plans_controller.rb

Instance Method Summary collapse

Methods included from ValidateState

#back_button_cache_buster, #back_button_param_list, #validate_state

Instance Method Details

#back_a_stateObject

UPDATE



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 62

def back_a_state
  respond_to do |format|
    logger.debug("BACK Requested - current [#{journey_plan.state}] - previous [#{journey_plan.previous_state_name}]")

    journey_plan.back!

    if journey_plan.save

      logger.debug("Successfully back a step - state now [#{journey_plan.state}]")

      format.html do
        redirect_to(datashift_journey.journey_plan_state_path(journey_plan.state, journey_plan)) && return
      end

    else
      format.html { render :edit }
    end
  end
end

#createObject



24
25
26
27
28
29
30
31
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 24

def create
  set_journey_plan_class
  @reform = FormObjectFactory.form_object_for(journey_plan_class.create!)

  @reform.save(params)

  move_next(@reform.journey_plan)
end

#editObject



33
34
35
36
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 33

def edit
  logger.debug "Editing journey_plan [#{journey_plan.inspect}]"
  render locals: { journey_plan: @journey_plan, form: @reform }
end

#newObject



17
18
19
20
21
22
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 17

def new
  # Find and create the form object, backing the current states view
  reform = FormObjectFactory.form_object_for(journey_plan)

  render locals: { journey_plan: journey_plan, form: reform }
end

#updateObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 38

def update

  # result = form.validate(params)
  #
  # redirect_to(form.redirection_url) && return if form.redirect?
  #
  # if result && form.save
  #   logger.debug("SUCCESS - Updated #{journey_plan.inspect}")
  #
  #   move_next(journey_plan)
  # else
  #   logger.debug("FAILED - Form Errors [#{form.errors.inspect}]")
  #
  #   render :edit, locals: { journey_plan: journey_plan, form: form }
  # end

  @reform.save(params)

  logger.debug("UPDATED Plan [#{journey_plan.inspect}] - Move to Next")
  puts journey_plan.inspect

  move_next(journey_plan) && return
end