Class: DatashiftJourney::JourneyPlansController
Instance Method Summary
collapse
#back_button_cache_buster, #back_button_param_list, #validate_state
Instance Method Details
#back_a_state ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 36
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
|
#create ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
|
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 24
def create
journey_plan = journey_plan_class.new
form_fields_to_data_nodes
move_next(journey_plan)
end
|
#edit ⇒ Object
56
57
58
59
|
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 56
def edit
logger.debug "Editing journey_plan [#{journey_plan.inspect}]"
render locals: { journey_plan: @journey_plan, form: @reform }
end
|
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 85
def form_fields_to_data_nodes
form_params = params.fetch(@reform.params_key, {})
data_nodes = form_params["data_nodes"]
if data_nodes.present?
fields = data_nodes["form_field"]
values = data_nodes["field_value"]
fields.each do |idx, name|
ff = Collector::FormField.where(name: name, form_definition: @reform.definition).first
next unless ff
Collector::DataNode.find_or_initialize_by(plan: journey_plan, form_field: ff).tap do |node|
node.field_value = values[idx]
node.save
end
end
end
end
|
#new ⇒ Object
17
18
19
20
21
22
|
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 17
def new
reform = FormObjectFactory.form_object_for(journey_plan)
render locals: { journey_plan: journey_plan, form: reform }
end
|
#update ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'app/controllers/datashift_journey/journey_plans_controller.rb', line 61
def update
form_fields_to_data_nodes
logger.debug("UPDATED Plan [#{journey_plan.inspect}] - Move to Next")
puts journey_plan.inspect
move_next(journey_plan) && return
end
|