Skip to content

Commit

Permalink
Merge pull request #18 from tamu-edu-students/form
Browse files Browse the repository at this point in the history
Survey: Add radio buttons and programmatic generation
  • Loading branch information
jacobtoddmathes authored Feb 16, 2024
2 parents 6ba90a5 + 47eeb66 commit 0614509
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 51 deletions.
28 changes: 27 additions & 1 deletion rails_root/app/controllers/survey_responses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,36 @@ def show; end
# GET /survey_responses/new
def new
@survey_response = SurveyResponse.new
@survey_sections = [
{
:title => "Part 1: Leadership Behavior - Management",
:prompt => "To what extent do you agree the following behaviors reflect your personal leadership behaviors?",
:questions => [:leads_by_example, :ability_to_juggle, :communicator]
},
{
:title => "Part 2: Leadership Behavior - Interpersonal",
:prompt => "To what extent do you agree the following behaviors reflect your personal leadership behaviors?",
:questions => [:lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented]
}
]
end

# GET /survey_responses/1/edit
def edit; end
def edit
# FIXME: DRY
@survey_sections = [
{
:title => "Part 1: Leadership Behavior - Management",
:prompt => "To what extent do you agree the following behaviors reflect your personal leadership behaviors?",
:questions => [:leads_by_example, :ability_to_juggle, :communicator]
},
{
:title => "Part 2: Leadership Behavior - Interpersonal",
:prompt => "To what extent do you agree the following behaviors reflect your personal leadership behaviors?",
:questions => [:lifelong_learner, :high_expectations, :cooperative, :empathetic, :people_oriented]
}
]
end

# POST /survey_responses or /survey_responses.json
def create
Expand Down
67 changes: 23 additions & 44 deletions rails_root/app/views/survey_responses/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,29 @@
<%= form.number_field :user_id %>
</div>
<div>
<h2>Part 1: Leadership Behavior - Interpersonal</h2>
<p>To what extent do you agree the following behaviors reflect your personal leadership behaviors?</p>
<ol>
<%# IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! %>
<%# FORM INPUTS NEED TO BE TURNED INTO RADIO OPTIONS %>
<li>
<%= form.label :leads_by_example, style: "display: block" %>
<%= form.number_field :leads_by_example %>
</li>
<li>
<%= form.label :ability_to_juggle, style: "display: block" %>
<%= form.number_field :ability_to_juggle %>
</li>
<li>
<%= form.label :communicator, style: "display: block" %>
<%= form.number_field :communicator %>
</li>
</ol>
</div>
<div>
<h2>Part 2: Leadership Behavior - Interpersonal</h2>
<p>To what extent do you agree the following behaviors reflect your personal leadership behaviors?</p>
<ol>
<li>
<%= form.label :lifelong_learner, style: "display: block" %>
<%= form.number_field :lifelong_learner %>
</li>
<li>
<%= form.label :high_expectations, style: "display: block" %>
<%= form.number_field :high_expectations %>
</li>
<li>
<%= form.label :cooperative, style: "display: block" %>
<%= form.number_field :cooperative %>
</li>
<li>
<%= form.label :empathetic, style: "display: block" %>
<%= form.number_field :empathetic %>
</li>
<li>
<%= form.label :people_oriented, style: "display: block" %>
<%= form.number_field :people_oriented %>
</li>
</ol>
<% survey_sections.each do |section| %>
<h2><%= section[:title] %></h2>
<p><%= section[:prompt] %></p>

<table>
<tr>
<th></th>
<th>Strongly Disagree</th>
<th>Disagree</th>
<th>Agree</th>
<th>Strongly Agree</th>
</tr>
<% section[:questions].each_with_index do |question, i| %>
<tr>
<td><%= form.label question %></td>

<% 4.times do |i| %>
<td><%= form.radio_button question, i, {checked: (i == survey_response[question]) ? 'checked': ''} %></td>
<% end %>
</tr>
<% end %>
</table>
<% end %>
</div>
<div>
<%= form.submit %>
Expand Down
4 changes: 2 additions & 2 deletions rails_root/app/views/survey_responses/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<h1>Editing survey response</h1>

<%= render "form", survey_response: @survey_response %>

<br>
<%= render "form", survey_response: @survey_response, survey_sections: @survey_sections %>
<br>

<div>
Expand Down
2 changes: 1 addition & 1 deletion rails_root/app/views/survey_responses/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1>ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY</h1>
<%= render "form", survey_response: @survey_response %>
<%= render "form", survey_response: @survey_response, survey_sections: @survey_sections%>
<%# <div> %>
<%# <%= link_to "Back to survey responses", survey_responses_path %>
<%# </div> %>
9 changes: 6 additions & 3 deletions rails_root/features/step_definitions/stepdefs.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
# Analysis Result Presentation Steps
Given('I have completed the survey with invalid inputs') do
@user_id = nil
@attributes = {}
SurveyResponse.column_names.each do |name|
@attributes[name] = nil if name != 'id' && name != 'created_at' && name != 'updated_at'
@attributes[name] = nil if not ['id', 'created_at', 'updated_at', 'user_id'].include? name
end
end

Given('I have completed the survey with valid inputs') do
@user_id = 1
@attributes = {}
SurveyResponse.column_names.each do |name|
@attributes[name] = 1 if name != 'id' && name != 'created_at' && name != 'updated_at'
@attributes[name] = nil if not ['id', 'created_at', 'updated_at', 'user_id'].include? name
end
end

When('I try to submit the form') do
visit new_survey_response_path
fill_in "survey_response_user_id", with: @user_id
@attributes.each do |key, value|
fill_in 'survey_response_' + key.to_s, with: value
choose "survey_response_#{key.to_s}_0"
end
click_button 'commit'
end
Expand Down

0 comments on commit 0614509

Please sign in to comment.