From 6a1534386f1cccb0beee9e31bbe9f327238561bd Mon Sep 17 00:00:00 2001 From: barnden Date: Fri, 16 Feb 2024 16:37:45 -0600 Subject: [PATCH 1/4] Survey: Add radio buttons and programmatic generation --- .../survey_responses_controller.rb | 12 ++++ .../app/views/survey_responses/_form.html.erb | 67 +++++++------------ .../app/views/survey_responses/new.html.erb | 2 +- 3 files changed, 36 insertions(+), 45 deletions(-) diff --git a/rails_root/app/controllers/survey_responses_controller.rb b/rails_root/app/controllers/survey_responses_controller.rb index 3c1bdcf..7a76932 100644 --- a/rails_root/app/controllers/survey_responses_controller.rb +++ b/rails_root/app/controllers/survey_responses_controller.rb @@ -14,6 +14,18 @@ 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 diff --git a/rails_root/app/views/survey_responses/_form.html.erb b/rails_root/app/views/survey_responses/_form.html.erb index 03f68c7..74b53f7 100644 --- a/rails_root/app/views/survey_responses/_form.html.erb +++ b/rails_root/app/views/survey_responses/_form.html.erb @@ -14,50 +14,29 @@ <%= form.number_field :user_id %>
-

Part 1: Leadership Behavior - Interpersonal

-

To what extent do you agree the following behaviors reflect your personal leadership behaviors?

-
    - <%# IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! %> - <%# FORM INPUTS NEED TO BE TURNED INTO RADIO OPTIONS %> -
  1. - <%= form.label :leads_by_example, style: "display: block" %> - <%= form.number_field :leads_by_example %> -
  2. -
  3. - <%= form.label :ability_to_juggle, style: "display: block" %> - <%= form.number_field :ability_to_juggle %> -
  4. -
  5. - <%= form.label :communicator, style: "display: block" %> - <%= form.number_field :communicator %> -
  6. -
-
-
-

Part 2: Leadership Behavior - Interpersonal

-

To what extent do you agree the following behaviors reflect your personal leadership behaviors?

-
    -
  1. - <%= form.label :lifelong_learner, style: "display: block" %> - <%= form.number_field :lifelong_learner %> -
  2. -
  3. - <%= form.label :high_expectations, style: "display: block" %> - <%= form.number_field :high_expectations %> -
  4. -
  5. - <%= form.label :cooperative, style: "display: block" %> - <%= form.number_field :cooperative %> -
  6. -
  7. - <%= form.label :empathetic, style: "display: block" %> - <%= form.number_field :empathetic %> -
  8. -
  9. - <%= form.label :people_oriented, style: "display: block" %> - <%= form.number_field :people_oriented %> -
  10. -
+ <% survey_sections.each do |section| %> +

<%= section[:title] %>

+

<%= section[:prompt] %>

+ + + + + + + + + + <% section[:questions].each do |question| %> + + + + + + + + <% end %> +
Strongly DisagreeDisagreeAgreeStrongly Agree
<%= form.label question %><%= form.radio_button question, 1 %><%= form.radio_button question, 2 %><%= form.radio_button question, 3 %><%= form.radio_button question, 4 %>
+ <% end %>
<%= form.submit %> diff --git a/rails_root/app/views/survey_responses/new.html.erb b/rails_root/app/views/survey_responses/new.html.erb index af7c319..91238e2 100644 --- a/rails_root/app/views/survey_responses/new.html.erb +++ b/rails_root/app/views/survey_responses/new.html.erb @@ -1,5 +1,5 @@

ORGANIZATIONAL AND LEADERSHIP EFFECTIVENESS INVENTORY

-<%= render "form", survey_response: @survey_response %> +<%= render "form", survey_response: @survey_response, survey_sections: @survey_sections%> <%#
%> <%# <%= link_to "Back to survey responses", survey_responses_path %> <%#
%> From bebd26835f941a157f9fe69af162573db5ecc1a3 Mon Sep 17 00:00:00 2001 From: barnden Date: Fri, 16 Feb 2024 17:12:25 -0600 Subject: [PATCH 2/4] Survey: Enable loading survey responses in form --- rails_root/app/views/survey_responses/_form.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/rails_root/app/views/survey_responses/_form.html.erb b/rails_root/app/views/survey_responses/_form.html.erb index 74b53f7..619145b 100644 --- a/rails_root/app/views/survey_responses/_form.html.erb +++ b/rails_root/app/views/survey_responses/_form.html.erb @@ -26,13 +26,13 @@ Agree Strongly Agree - <% section[:questions].each do |question| %> + <% section[:questions].each_with_index do |question, i| %> <%= form.label question %> - <%= form.radio_button question, 1 %> - <%= form.radio_button question, 2 %> - <%= form.radio_button question, 3 %> - <%= form.radio_button question, 4 %> + + <% 4.times do |i| %> + <%= form.radio_button question, i, {checked: (i == survey_response[question]) ? 'checked': ''} %> + <% end %> <% end %> From 5956f37168624b3d6bc3850ee9c2afc0081504bc Mon Sep 17 00:00:00 2001 From: barnden Date: Fri, 16 Feb 2024 17:12:51 -0600 Subject: [PATCH 3/4] Survey: Update edit controller --- .../controllers/survey_responses_controller.rb | 16 +++++++++++++++- .../app/views/survey_responses/edit.html.erb | 4 ++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/rails_root/app/controllers/survey_responses_controller.rb b/rails_root/app/controllers/survey_responses_controller.rb index 7a76932..d651d6e 100644 --- a/rails_root/app/controllers/survey_responses_controller.rb +++ b/rails_root/app/controllers/survey_responses_controller.rb @@ -29,7 +29,21 @@ def new 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 diff --git a/rails_root/app/views/survey_responses/edit.html.erb b/rails_root/app/views/survey_responses/edit.html.erb index 40deed1..40ef521 100644 --- a/rails_root/app/views/survey_responses/edit.html.erb +++ b/rails_root/app/views/survey_responses/edit.html.erb @@ -1,7 +1,7 @@

Editing survey response

-<%= render "form", survey_response: @survey_response %> - +
+<%= render "form", survey_response: @survey_response, survey_sections: @survey_sections %>
From 47eeb6667eb48da286eb77a13e08c01e866b1734 Mon Sep 17 00:00:00 2001 From: barnden Date: Fri, 16 Feb 2024 17:31:44 -0600 Subject: [PATCH 4/4] Tests/Survey: Update cucumber scenarios to handle radio inputs --- rails_root/features/step_definitions/stepdefs.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rails_root/features/step_definitions/stepdefs.rb b/rails_root/features/step_definitions/stepdefs.rb index 7359593..9d773b0 100644 --- a/rails_root/features/step_definitions/stepdefs.rb +++ b/rails_root/features/step_definitions/stepdefs.rb @@ -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