upgrade_surveyor_gui 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +44 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +46 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/MIT-LICENSE +20 -0
- data/README.md +244 -0
- data/Rakefile +66 -0
- data/app/controllers/surveyor_controller.rb +89 -0
- data/app/controllers/surveyor_gui/answers_controller.rb +3 -0
- data/app/controllers/surveyor_gui/application_controller.rb +3 -0
- data/app/controllers/surveyor_gui/dependencys_controller.rb +286 -0
- data/app/controllers/surveyor_gui/question_groups_controller.rb +90 -0
- data/app/controllers/surveyor_gui/questions_controller.rb +187 -0
- data/app/controllers/surveyor_gui/reports_controller.rb +339 -0
- data/app/controllers/surveyor_gui/responses_controller.rb +41 -0
- data/app/controllers/surveyor_gui/survey_controller.rb +16 -0
- data/app/controllers/surveyor_gui/survey_sections_controller.rb +80 -0
- data/app/controllers/surveyor_gui/surveyforms_controller.rb +4 -0
- data/app/facades/report_formatter.rb +46 -0
- data/app/facades/report_preview_wrapper.rb +11 -0
- data/app/facades/report_response_generator.rb +147 -0
- data/app/helpers/surveyor_gui/application_helper.rb +2 -0
- data/app/helpers/surveyor_gui/dependencys_helper.rb +5 -0
- data/app/helpers/surveyor_gui/question_groups_helper.rb +3 -0
- data/app/helpers/surveyor_gui/questions_helper.rb +22 -0
- data/app/helpers/surveyor_gui/reports_helper.rb +19 -0
- data/app/helpers/surveyor_gui/surveyforms_helper.rb +164 -0
- data/app/helpers/surveyor_helper.rb +4 -0
- data/app/inputs/currency_input.rb +5 -0
- data/app/inputs/date_picker_input.rb +7 -0
- data/app/inputs/datetime_picker_input.rb +5 -0
- data/app/inputs/percent_input.rb +5 -0
- data/app/inputs/time_picker_input.rb +5 -0
- data/app/mailers/.gitkeep +0 -0
- data/app/models/.gitkeep +0 -0
- data/app/models/answer.rb +4 -0
- data/app/models/column.rb +3 -0
- data/app/models/dependency.rb +4 -0
- data/app/models/dependency_condition.rb +4 -0
- data/app/models/permitted_params_decorator.rb +80 -0
- data/app/models/question.rb +4 -0
- data/app/models/question_group.rb +4 -0
- data/app/models/question_group_tracker.rb +19 -0
- data/app/models/question_type.rb +7 -0
- data/app/models/response.rb +4 -0
- data/app/models/response_set.rb +4 -0
- data/app/models/row.rb +3 -0
- data/app/models/survey.rb +4 -0
- data/app/models/survey_section.rb +4 -0
- data/app/models/surveyform.rb +103 -0
- data/app/uploaders/blob_uploader.rb +48 -0
- data/app/views/layouts/surveyor_gui/application.html.erb +14 -0
- data/app/views/layouts/surveyor_gui/surveyor_gui_blank.html.erb +13 -0
- data/app/views/layouts/surveyor_gui/surveyor_gui_default.html.erb +17 -0
- data/app/views/layouts/surveyor_gui/surveyor_modified.html.erb +14 -0
- data/app/views/partials/_answer.html.haml +33 -0
- data/app/views/partials/_question.html.haml +33 -0
- data/app/views/partials/_question_group.html.haml +73 -0
- data/app/views/partials/_section.html.haml +13 -0
- data/app/views/surveyor/edit.html.haml +21 -0
- data/app/views/surveyor_gui/dependencys/_column.html.erb +1 -0
- data/app/views/surveyor_gui/dependencys/_dependency.html.erb +22 -0
- data/app/views/surveyor_gui/dependencys/_dependency_condition_fields.html.erb +48 -0
- data/app/views/surveyor_gui/dependencys/_form.html.erb +20 -0
- data/app/views/surveyor_gui/dependencys/blank.html.erb +0 -0
- data/app/views/surveyor_gui/dependencys/edit.html.erb +1 -0
- data/app/views/surveyor_gui/dependencys/new.html.erb +1 -0
- data/app/views/surveyor_gui/partials/_url_helpers.html.erb +5 -0
- data/app/views/surveyor_gui/question_groups/_form.html.erb +57 -0
- data/app/views/surveyor_gui/question_groups/_group_inline_field.html.erb +21 -0
- data/app/views/surveyor_gui/question_groups/_group_inline_fields.html.erb +25 -0
- data/app/views/surveyor_gui/question_groups/blank.html.erb +0 -0
- data/app/views/surveyor_gui/question_groups/edit.html.erb +1 -0
- data/app/views/surveyor_gui/question_groups/new.html.erb +1 -0
- data/app/views/surveyor_gui/questions/_answer_fields.html.erb +23 -0
- data/app/views/surveyor_gui/questions/_answer_options.html.erb +28 -0
- data/app/views/surveyor_gui/questions/_form.html.erb +66 -0
- data/app/views/surveyor_gui/questions/_grid_dropdown_columns.html.erb +10 -0
- data/app/views/surveyor_gui/questions/_grid_dropdown_fields.html.erb +42 -0
- data/app/views/surveyor_gui/questions/_grid_fields.html.erb +9 -0
- data/app/views/surveyor_gui/questions/_no_picks.html.erb +29 -0
- data/app/views/surveyor_gui/questions/_pick.html +21 -0
- data/app/views/surveyor_gui/questions/_picks.html.erb +12 -0
- data/app/views/surveyor_gui/questions/blank.html.erb +0 -0
- data/app/views/surveyor_gui/questions/edit.html.erb +1 -0
- data/app/views/surveyor_gui/questions/new.html.erb +1 -0
- data/app/views/surveyor_gui/reports/_graphs.html.haml +21 -0
- data/app/views/surveyor_gui/reports/_grid.html.haml +42 -0
- data/app/views/surveyor_gui/reports/_grid_dropdown.html.haml +56 -0
- data/app/views/surveyor_gui/reports/_repeater.html.haml +27 -0
- data/app/views/surveyor_gui/reports/_show_report.html.haml +33 -0
- data/app/views/surveyor_gui/reports/_single_question.html.haml +70 -0
- data/app/views/surveyor_gui/reports/show.html.erb +14 -0
- data/app/views/surveyor_gui/responses/_grid.html.haml +20 -0
- data/app/views/surveyor_gui/responses/_grid_dropdown.html.haml +20 -0
- data/app/views/surveyor_gui/responses/_repeater.html.haml +22 -0
- data/app/views/surveyor_gui/responses/_survey_results.html.haml +40 -0
- data/app/views/surveyor_gui/responses/index.html.haml +24 -0
- data/app/views/surveyor_gui/responses/show.html.haml +42 -0
- data/app/views/surveyor_gui/shared/_grid_comments.html.haml +10 -0
- data/app/views/surveyor_gui/shared/_new_line.html.haml +2 -0
- data/app/views/surveyor_gui/shared/_pick_comments.html.haml +15 -0
- data/app/views/surveyor_gui/shared/_question_number.html.haml +11 -0
- data/app/views/surveyor_gui/shared/_report_data.html.haml +27 -0
- data/app/views/surveyor_gui/shared/_stars_report_data.html.haml +14 -0
- data/app/views/surveyor_gui/survey_sections/_form.html.erb +13 -0
- data/app/views/surveyor_gui/survey_sections/blank.html.erb +0 -0
- data/app/views/surveyor_gui/survey_sections/edit.html.erb +1 -0
- data/app/views/surveyor_gui/survey_sections/new.html.erb +1 -0
- data/app/views/surveyor_gui/surveyforms/_form.html.erb +50 -0
- data/app/views/surveyor_gui/surveyforms/_question_field.html.erb +148 -0
- data/app/views/surveyor_gui/surveyforms/_question_group.html.erb +116 -0
- data/app/views/surveyor_gui/surveyforms/_question_group_fields.html.erb +3 -0
- data/app/views/surveyor_gui/surveyforms/_question_name_and_number.html.erb +6 -0
- data/app/views/surveyor_gui/surveyforms/_question_section.html.erb +15 -0
- data/app/views/surveyor_gui/surveyforms/_question_wrapper.html.erb +108 -0
- data/app/views/surveyor_gui/surveyforms/_survey_section_fields.html.erb +137 -0
- data/app/views/surveyor_gui/surveyforms/clone_survey.html.erb +13 -0
- data/app/views/surveyor_gui/surveyforms/edit.html.erb +5 -0
- data/app/views/surveyor_gui/surveyforms/index.html.erb +40 -0
- data/app/views/surveyor_gui/surveyforms/new.html.erb +1 -0
- data/app/views/surveyor_gui/surveyforms/show.html.erb +5 -0
- data/config/environment.rb +0 -0
- data/config/routes.rb +71 -0
- data/config.ru +4 -0
- data/db/migrate/20140307204049_add_template_to_surveys.rb +5 -0
- data/db/migrate/20140307235607_add_test_data_to_response_sets.rb +5 -0
- data/db/migrate/20140308171947_add_original_choice_to_answers.rb +5 -0
- data/db/migrate/20140308172118_add_blob_to_responses.rb +5 -0
- data/db/migrate/20140308172417_add_modifiable_to_survey_section.rb +5 -0
- data/db/migrate/20140308174532_add_modifiable_to_question.rb +5 -0
- data/db/migrate/20140308175305_add_dynamically_generate_to_questions.rb +5 -0
- data/db/migrate/20140311032923_add_dummy_blob_to_questions.rb +5 -0
- data/db/migrate/20140311160609_add_dynamic_source_to_questions.rb +5 -0
- data/db/migrate/20140311161714_add_report_code_to_questions.rb +5 -0
- data/db/migrate/20140530181134_add_is_comment_to_questions.rb +5 -0
- data/db/migrate/20140531012006_add_is_comment_to_answers.rb +5 -0
- data/db/migrate/20140531225529_create_rows.rb +9 -0
- data/db/migrate/20140601011151_create_columns.rb +11 -0
- data/db/migrate/20140602030330_add_column_id_to_answers.rb +5 -0
- data/db/migrate/20140603155606_add_column_id_to_responses.rb +5 -0
- data/db/migrate/20140606023527_add_column_id_to_dependency_conditions.rb +5 -0
- data/db/migrate/20140815165307_add_user_id_to_survey.rb +5 -0
- data/lib/assets/.gitkeep +0 -0
- data/lib/assets/images/addicon.png +0 -0
- data/lib/assets/images/datepicker.gif +0 -0
- data/lib/assets/images/delete.gif +0 -0
- data/lib/assets/images/delete.png +0 -0
- data/lib/assets/images/images/border.png +0 -0
- data/lib/assets/images/images/controls.png +0 -0
- data/lib/assets/images/images/loading.gif +0 -0
- data/lib/assets/images/images/loading_background.png +0 -0
- data/lib/assets/images/images/overlay.png +0 -0
- data/lib/assets/images/rails.png +0 -0
- data/lib/assets/images/star.gif +0 -0
- data/lib/assets/javascripts/.gitkeep +0 -0
- data/lib/assets/javascripts/surveyor_gui/jquery.MetaData.js +121 -0
- data/lib/assets/javascripts/surveyor_gui/jquery.blockUI.js +619 -0
- data/lib/assets/javascripts/surveyor_gui/jquery.rating.js +377 -0
- data/lib/assets/javascripts/surveyor_gui/jquery.validate.js +1188 -0
- data/lib/assets/javascripts/surveyor_gui/surveyor_add_ons.js +10 -0
- data/lib/assets/javascripts/surveyor_gui/surveyor_gui.js +1428 -0
- data/lib/assets/stylesheets/.gitkeep +0 -0
- data/lib/assets/stylesheets/surveyor_gui/jquery.rating.css +12 -0
- data/lib/assets/stylesheets/surveyor_gui/surveyor_add_ons.css +3 -0
- data/lib/assets/stylesheets/surveyor_gui/surveyor_gui.sass +652 -0
- data/lib/enumerable_extenders.rb +31 -0
- data/lib/generators/surveyor_gui/install_generator.rb +57 -0
- data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_add_ons.js +2 -0
- data/lib/generators/surveyor_gui/templates/app/assets/javascripts/surveyor_gui_all.js +24 -0
- data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_add_ons.css.sass +1 -0
- data/lib/generators/surveyor_gui/templates/app/assets/stylesheets/surveyor_gui_all.css.sass +8 -0
- data/lib/generators/surveyor_gui/templates/app/helpers/surveyor_helper.rb +4 -0
- data/lib/generators/surveyor_gui/templates/app/models/response_set_user.rb +13 -0
- data/lib/generators/surveyor_gui/templates/app/views/layouts/surveyor_gui/surveyor_gui_default.html.erb +17 -0
- data/lib/generators/surveyor_gui/templates/config/initializers/simple_form.rb +140 -0
- data/lib/generators/surveyor_gui/templates/config/locales/en.yml +5 -0
- data/lib/surveyor_gui/engine.rb +31 -0
- data/lib/surveyor_gui/helpers/surveyor_helper_methods.rb +19 -0
- data/lib/surveyor_gui/models/answer_methods.rb +24 -0
- data/lib/surveyor_gui/models/column_methods.rb +43 -0
- data/lib/surveyor_gui/models/dependency_condition_methods.rb +53 -0
- data/lib/surveyor_gui/models/dependency_methods.rb +83 -0
- data/lib/surveyor_gui/models/question_and_group_shared_methods.rb +11 -0
- data/lib/surveyor_gui/models/question_group_methods.rb +55 -0
- data/lib/surveyor_gui/models/question_methods.rb +435 -0
- data/lib/surveyor_gui/models/question_type_methods.rb +493 -0
- data/lib/surveyor_gui/models/response_methods.rb +71 -0
- data/lib/surveyor_gui/models/response_set_methods.rb +56 -0
- data/lib/surveyor_gui/models/row_methods.rb +11 -0
- data/lib/surveyor_gui/models/survey_methods.rb +32 -0
- data/lib/surveyor_gui/models/survey_section_methods.rb +32 -0
- data/lib/surveyor_gui/surveyforms_controller_methods.rb +258 -0
- data/lib/surveyor_gui/version.rb +3 -0
- data/lib/surveyor_gui.rb +17 -0
- data/lib/tasks/.gitkeep +0 -0
- data/lib/tasks/surveyor_gui_tasks.rake +4 -0
- data/lib/templates/erb/scaffold/_form.html.erb +13 -0
- data/spec/controllers/surveyforms_controller_spec.rb +362 -0
- data/spec/controllers/surveyor_controller_spec.rb +303 -0
- data/spec/factories.rb +181 -0
- data/spec/features/create_survey_spec.rb +417 -0
- data/spec/features/dependencies_spec.rb +65 -0
- data/spec/features/make_and_take_spec.rb +187 -0
- data/spec/features/rearrange_survey_spec.rb +118 -0
- data/spec/features/ui_spec.rb +469 -0
- data/spec/fixtures/REDCapDemoDatabase_DataDictionary.csv +127 -0
- data/spec/fixtures/chinese_survey.rb +14 -0
- data/spec/fixtures/everything.rb +215 -0
- data/spec/fixtures/favorites-ish.rb +22 -0
- data/spec/fixtures/favorites.rb +22 -0
- data/spec/fixtures/feelings.rb +38 -0
- data/spec/fixtures/lifestyle.rb +55 -0
- data/spec/fixtures/numbers.rb +21 -0
- data/spec/fixtures/redcap_new_headers.csv +1 -0
- data/spec/fixtures/redcap_siblings.csv +1 -0
- data/spec/fixtures/redcap_whitespace.csv +1 -0
- data/spec/helpers/formtastic_custom_input_spec.rb +15 -0
- data/spec/helpers/surveyor_helper_spec.rb +116 -0
- data/spec/lib/common_spec.rb +37 -0
- data/spec/lib/parser_spec.rb +393 -0
- data/spec/lib/rake_kitchen_sink.rb +42 -0
- data/spec/lib/redcap_parser_spec.rb +129 -0
- data/spec/lib/unparser_spec.rb +126 -0
- data/spec/models/answer_spec.rb +144 -0
- data/spec/models/dependency_condition_spec.rb +428 -0
- data/spec/models/dependency_spec.rb +90 -0
- data/spec/models/question_group_spec.rb +66 -0
- data/spec/models/question_spec.rb +176 -0
- data/spec/models/response_set_spec.rb +452 -0
- data/spec/models/response_spec.rb +208 -0
- data/spec/models/survey_section_spec.rb +58 -0
- data/spec/models/survey_spec.rb +155 -0
- data/spec/models/surveyor_gui/question_spec.rb +60 -0
- data/spec/models/surveyor_gui/question_type_spec.rb +268 -0
- data/spec/models/validation_condition_spec.rb +98 -0
- data/spec/models/validation_spec.rb +64 -0
- data/spec/spec.opts +4 -0
- data/spec/spec_helper.rb +119 -0
- data/spec/support/scenario_outline_helper.rb +39 -0
- data/spec/support/shared.rb +10 -0
- data/spec/support/surveyforms_creation_helpers.rb +313 -0
- data/spec/support/surveyforms_rearrangement_helpers.rb +170 -0
- data/spec/support/surveyor_api_helpers.rb +15 -0
- data/spec/support/surveyor_ui_helpers.rb +108 -0
- data/spec/support/wait_for_ajax.rb +11 -0
- data/spec/views/questions/edit.html.erb_spec.rb +74 -0
- data/spec/views/surveyforms/edit.html.erb_spec.rb +126 -0
- data/surveyor_gui.gemspec +52 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/surveyor-gui_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- data/tmp/cache/assets/CF0/DA0/sprockets%2Fd7d5b37686831d37c4dd75e645f5e016 +0 -0
- data/tmp/cache/assets/E25/4C0/sprockets%2Fde2fd9fd11c04a582cdbbe3d84a35ae6 +0 -0
- data/vendor/assets/stylesheets/.gitkeep +0 -0
- data/vendor/assets/stylesheets/custom.sass +5 -0
- data/vendor/plugins/.gitkeep +0 -0
- metadata +600 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
class SurveyorGui::ResponsesController < ApplicationController
|
2
|
+
include ReportPreviewWrapper
|
3
|
+
# ReportPreviewWrapper wraps preview in a database transaction so test data is not permanently saved.
|
4
|
+
around_action :wrap_in_transaction, only: :preview
|
5
|
+
layout 'surveyor_gui/surveyor_gui_default'
|
6
|
+
|
7
|
+
def index
|
8
|
+
@title = "Survey Responses"
|
9
|
+
@response_sets = Survey.find_by_id(params[:id]).response_sets
|
10
|
+
end
|
11
|
+
|
12
|
+
def preview
|
13
|
+
user_id = defined?(current_user) && current_user ? current_user.id : nil
|
14
|
+
@title = "Show Response"
|
15
|
+
@survey = Survey.find(params[:survey_id])
|
16
|
+
@response_set = ResponseSet.create(:survey => @survey, :user_id => user_id, :test_data => true)
|
17
|
+
ReportResponseGenerator.new(@survey).generate_1_result_set(@response_set)
|
18
|
+
@responses = @response_set.responses
|
19
|
+
@response_sets = [@response_set]
|
20
|
+
if (!@survey)
|
21
|
+
flash[:notice] = "Survey/Questionnnaire not found."
|
22
|
+
redirect_to :back
|
23
|
+
end
|
24
|
+
render :show
|
25
|
+
end
|
26
|
+
|
27
|
+
def show
|
28
|
+
@title = "Show Response"
|
29
|
+
@response_set = ResponseSet.find(params[:id])
|
30
|
+
@survey = @response_set.survey
|
31
|
+
@responses = @response_set.responses
|
32
|
+
@response_sets = [@response_set]
|
33
|
+
if (!@response_set)
|
34
|
+
flash[:error] = "Response not found"
|
35
|
+
redirect_to :back
|
36
|
+
elsif (!@survey)
|
37
|
+
flash[:error] = "Survey/Questionnnaire not found."
|
38
|
+
redirect_to :back
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class SurveyorGui::SurveyController < ApplicationController
|
2
|
+
def show
|
3
|
+
@title = "User Will See this Survey"
|
4
|
+
@survey = Survey.find(params[:survey_id])
|
5
|
+
user_id = defined?(current_user) && current_user ? current_user.id : 1
|
6
|
+
ResponseSet.where('survey_id = ? and test_data = ? and user_id = ?',params[:survey_id],true, user_id).each {|r| r.destroy}
|
7
|
+
@response_set = ResponseSet.create(:survey => @survey, :user_id => user_id, :test_data => true)
|
8
|
+
if (@survey)
|
9
|
+
flash[:notice] = t('surveyor.survey_started_success')
|
10
|
+
redirect_to surveyor.edit_my_survey_path @survey.access_code, @response_set.access_code
|
11
|
+
else
|
12
|
+
flash[:notice] = "Survey not found."
|
13
|
+
redirect :back
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
class SurveyorGui::SurveySectionsController < ApplicationController
|
2
|
+
layout 'surveyor_gui/surveyor_gui_blank'
|
3
|
+
|
4
|
+
def new
|
5
|
+
@title = "Add Survey Section"
|
6
|
+
survey = Survey.find(params[:survey_id])
|
7
|
+
prev_section = SurveySection.find(params[:prev_section_id])
|
8
|
+
@last_survey_section = survey.survey_sections.last
|
9
|
+
@survey_section = survey.survey_sections
|
10
|
+
.build(:title => 'New Section',
|
11
|
+
:display_order => prev_section.display_order + 1,
|
12
|
+
:modifiable => true)
|
13
|
+
end
|
14
|
+
|
15
|
+
def edit
|
16
|
+
@title = "Edit Survey Section"
|
17
|
+
@survey_section = SurveySection.find(params[:id])
|
18
|
+
end
|
19
|
+
|
20
|
+
def create
|
21
|
+
survey = Survey.find(params[:survey_section][:survey_id])
|
22
|
+
SurveySection.where(:survey_id => survey.id)
|
23
|
+
.where("display_order >= ?", params[:survey_section][:display_order])
|
24
|
+
.update_all("display_order = display_order+1")
|
25
|
+
@survey_section = survey.survey_sections.build(survey_section_params)
|
26
|
+
@survey_section.display_order = params[:survey_section][:display_order].to_i
|
27
|
+
#@survey_section.questions.build(:text=>'New question',:pick=>'none',:display_order=>0,:display_type=>'default').answers.build(:text=>'string', :response_class=>'string', :display_order=>1, :template=>true)
|
28
|
+
if @survey_section.save
|
29
|
+
redirect_to :back
|
30
|
+
else
|
31
|
+
render :action => 'new', :layout => 'surveyor_gui/surveyor_gui_blank'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
@title = "Update Survey Section"
|
37
|
+
@survey_section = SurveySection.find(params[:id])
|
38
|
+
if @survey_section.update_attributes(survey_section_params)
|
39
|
+
render :blank, :layout => 'surveyor_gui/surveyor_gui_blank'
|
40
|
+
else
|
41
|
+
render :action => 'edit', :layout => 'surveyor_gui/surveyor_gui_blank'
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def destroy
|
46
|
+
@survey_section = SurveySection.find(params[:id])
|
47
|
+
if !@survey_section.survey.template && @survey_section.survey.response_sets.count > 0
|
48
|
+
render :text => "Reponses have already been collected for this survey, therefore it cannot be modified. Please create a new survey instead."
|
49
|
+
return false
|
50
|
+
end
|
51
|
+
if !@survey_section.modifiable
|
52
|
+
render :text => "This section cannot be removed."
|
53
|
+
return false
|
54
|
+
end
|
55
|
+
if !@survey_section.questions.map{|q| q.dependency_conditions}.flatten.blank?
|
56
|
+
render :text => "The following questions have logic that depend on questions in this section: \n\n"+@survey_section.questions.map{|q| q.dependency_conditions.map{|d| " - "+d.dependency.question.text}}.flatten.join('\n')+"\n\nPlease delete logic before deleting this section.".html_safe
|
57
|
+
return
|
58
|
+
end
|
59
|
+
@survey_section.destroy
|
60
|
+
render :text => ""
|
61
|
+
end
|
62
|
+
|
63
|
+
def sort
|
64
|
+
survey = Survey.find(params[:survey_id])
|
65
|
+
satts = { :id => params[:survey_id], :survey_sections_attributes=>{} }
|
66
|
+
sections = params[:survey_section]
|
67
|
+
sections.each_with_index do |sid, index|
|
68
|
+
satts[:survey_sections_attributes][index.to_s] = { :id => sid, :display_order => index }
|
69
|
+
end
|
70
|
+
puts satts
|
71
|
+
survey.update_attributes!(satts)
|
72
|
+
render :nothing => true
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
def survey_section_params
|
77
|
+
::PermittedParams.new(params[:survey_section]).survey_section
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class ReportFormatter
|
2
|
+
|
3
|
+
STAT_FUNCTIONS = {
|
4
|
+
sum: ->(arr){arr.sum},
|
5
|
+
min: ->(arr){arr.min},
|
6
|
+
max: ->(arr){arr.max},
|
7
|
+
average: ->(arr){arr.average}
|
8
|
+
}
|
9
|
+
|
10
|
+
STAT_FORMATS = {
|
11
|
+
number: "%g",
|
12
|
+
date: "%m-%d-%y",
|
13
|
+
time: "%I:%M:%S %P",
|
14
|
+
datetime: "%m-%d-%y %I:%M:%S %P"
|
15
|
+
}
|
16
|
+
|
17
|
+
def initialize(question, responses)
|
18
|
+
@question = question
|
19
|
+
@responses = responses
|
20
|
+
end
|
21
|
+
|
22
|
+
def stats(stat_function)
|
23
|
+
stat = calculate_stats(stat_function)
|
24
|
+
format_stats(stat)
|
25
|
+
end
|
26
|
+
|
27
|
+
def calculate_stats(stat_function)
|
28
|
+
arr = @responses.where(:question_id => @question.id).map{|r| r.response_value.to_f}
|
29
|
+
STAT_FUNCTIONS[stat_function].call(arr)
|
30
|
+
end
|
31
|
+
|
32
|
+
def format_stats(stat)
|
33
|
+
if @question.question_type_id == :number
|
34
|
+
STAT_FORMATS[@question.question_type_id] % stat.to_f
|
35
|
+
elsif [:date, :datetime, :time].include? @question.question_type_id
|
36
|
+
format_time_stat(stat.to_f)
|
37
|
+
else
|
38
|
+
stat
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def format_time_stat(stat)
|
43
|
+
stat = Time.zone.at(stat)
|
44
|
+
stat.strftime(STAT_FORMATS[@question.question_type_id])
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,147 @@
|
|
1
|
+
class ReportResponseGenerator
|
2
|
+
RESPONSE_GENERATOR = {
|
3
|
+
pick_one: pick_one = ->(response, response_set, q, context){ context.send(:make_pick_one, response_set, q) },
|
4
|
+
pick_any: pick_any = ->(response, response_set, q, context){ context.send(:random_anys, response, response_set, q) },
|
5
|
+
dropdown: pick_one,
|
6
|
+
slider: pick_one,
|
7
|
+
number: ->(response, response_set, q, context){ response.integer_value = rand(100); response.save },
|
8
|
+
string: ->(response, response_set, q, context){ response.string_value = context.send(:random_string); response.save },
|
9
|
+
box: ->(response, response_set, q, context){ response.text_value = context.send(:random_string); response.save },
|
10
|
+
date: ->(response, response_set, q, context){ response.datetime_value = context.send(:random_date); response.save },
|
11
|
+
datetime: ->(response, response_set, q, context){ response.datetime_value = context.send(:random_date); response.save },
|
12
|
+
time: ->(response, response_set, q, context){ response.datetime_value = context.send(:random_date); response.save },
|
13
|
+
file: ->(response, response_set, q, context){ context.send(:make_blob, response, false) },
|
14
|
+
stars: ->(response, response_set, q, context){ response_set.responses.create(:question_id => q.id, :integer_value => rand(5)+1, :answer_id => q.answers.first.id)},
|
15
|
+
grid_one: pick_one,
|
16
|
+
grid_any: pick_any,
|
17
|
+
grid_dropdown: ->(response, response_set, q, context){ context.send(:grid_dropdown, response, response_set, q) }
|
18
|
+
}
|
19
|
+
|
20
|
+
def initialize(survey)
|
21
|
+
@survey = survey
|
22
|
+
end
|
23
|
+
|
24
|
+
def generate_1_result_set(response_set)
|
25
|
+
@survey.survey_sections.each do |ss|
|
26
|
+
ss.questions.each do |q|
|
27
|
+
response = response_set.responses.build(:question_id => q.id, :answer_id => q.answers.first ? q.answers.first.id : nil)
|
28
|
+
if q.repeater?
|
29
|
+
rand(5).times.each do
|
30
|
+
response = response_set.responses.build(:question_id => q.id, :answer_id => q.answers.first.id)
|
31
|
+
RESPONSE_GENERATOR[q.question_type_id].call(response, response_set, q, self)
|
32
|
+
end
|
33
|
+
elsif q.question_type_id != :label
|
34
|
+
RESPONSE_GENERATOR[q.question_type_id].call(response, response_set, q, self)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def random_string
|
41
|
+
whichone = rand(5)
|
42
|
+
case whichone
|
43
|
+
when 0
|
44
|
+
'An answer.'
|
45
|
+
when 1
|
46
|
+
'A different answer.'
|
47
|
+
when 2
|
48
|
+
'Any answer here.'
|
49
|
+
when 3
|
50
|
+
'Some response.'
|
51
|
+
when 4
|
52
|
+
'A random response.'
|
53
|
+
when 5
|
54
|
+
'A random answer.'
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def random_date
|
59
|
+
Time.now + (rand(100)-50).days
|
60
|
+
end
|
61
|
+
|
62
|
+
def random_pick(question, avoid=[])
|
63
|
+
answer = nil
|
64
|
+
answers = question.answers.is_not_comment
|
65
|
+
while !answer && avoid.count < answers.count
|
66
|
+
pick = rand(answers.count)
|
67
|
+
if !avoid.include?(answers[pick].id)
|
68
|
+
answer=answers[pick].id
|
69
|
+
end
|
70
|
+
end
|
71
|
+
return answer
|
72
|
+
end
|
73
|
+
|
74
|
+
def make_pick_comment(response_set, q)
|
75
|
+
comment = q.answers.is_comment
|
76
|
+
if comment && !comment.empty?
|
77
|
+
response_set.responses.create(question_id: q.id, answer_id: comment.first.id, string_value: "User added a comment here.")
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def make_pick_one(response_set, q)
|
82
|
+
if q.is_comment?
|
83
|
+
response_set.responses.create(question_id: q.id, answer_id: q.answers.first.id, string_value: "User added a comment here.")
|
84
|
+
else
|
85
|
+
response_set.responses.create(question_id: q.id, answer_id: random_pick(q))
|
86
|
+
make_pick_comment(response_set, q)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
def random_pick_count(question)
|
91
|
+
answers = question.answers
|
92
|
+
return rand(answers.count)+1
|
93
|
+
end
|
94
|
+
|
95
|
+
def make_blob(response, show_blob)
|
96
|
+
response.save!
|
97
|
+
response.blob.store!(File.new(Rails.public_path+'/images/regulations.jpg')) if show_blob
|
98
|
+
end
|
99
|
+
|
100
|
+
def random_any(response, response_set, q)
|
101
|
+
if !q.answers.empty?
|
102
|
+
how_many = random_pick_count(q)
|
103
|
+
how_many.times {
|
104
|
+
already_checked = response_set.responses.where('question_id=?',q.id).collect(&:answer_id)
|
105
|
+
response = response_set.responses.build(:question_id => q.id, :answer_id => random_pick(q,already_checked))
|
106
|
+
response.save
|
107
|
+
}
|
108
|
+
else
|
109
|
+
response = nil
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def random_anys(response, response_set, q)
|
114
|
+
if q.is_comment?
|
115
|
+
response_set.responses.create(question_id: q.id, answer_id: q.answers.first.id, string_value: "User added a comment here.")
|
116
|
+
else
|
117
|
+
random_any(response, response_set, q)
|
118
|
+
make_pick_comment(response_set, q)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
def grid_one(response, response_set, q)
|
123
|
+
q.question_group.questions.each do |question|
|
124
|
+
response = response_set.responses.build(question_id: question.id, answer_id: random_pick(question))
|
125
|
+
response.save
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def random_pick_with_column(question, column)
|
130
|
+
answers = Answer.where(question_id: question.id, column_id: column.id)
|
131
|
+
pick = rand(answers.count)
|
132
|
+
answer=answers[pick].id
|
133
|
+
end
|
134
|
+
|
135
|
+
def grid_dropdown(response, response_set, q)
|
136
|
+
q.question_group.questions.is_not_comment.each do |question|
|
137
|
+
q.question_group.columns.each do |column|
|
138
|
+
response = response_set.responses.build(question_id: q.id, answer_id: random_pick_with_column(question, column), column_id: column.id )
|
139
|
+
response.save
|
140
|
+
end
|
141
|
+
end
|
142
|
+
if question = q.question_group.questions.is_comment.first && question && !question.empty?
|
143
|
+
response_set.responses.create(question_id: question.id, answer_id: question.answers.first.id, column_id: column.id, string_value: "User added comment here")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module SurveyorGui::QuestionsHelper
|
2
|
+
def link_to_remove_fields (name, f, dom_to_hide=nil)
|
3
|
+
f.hidden_field(:_destroy) + link_to(image_tag("delete.png",:border => 0, :margin=>'-1em'), "#", onclick: "remove_fields(this, \"#{dom_to_hide}\");")
|
4
|
+
end
|
5
|
+
|
6
|
+
def adjusted_text
|
7
|
+
if @question.part_of_group?
|
8
|
+
@question.question_group.text
|
9
|
+
else
|
10
|
+
@question.text
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def question_type_subset(args)
|
15
|
+
question_types = QuestionType.all.map{|t|[t.text, t.id]}[0..19].uniq
|
16
|
+
ordered_types = []
|
17
|
+
args.each do |id|
|
18
|
+
ordered_types << question_types.select{|t| id == t[1]}.flatten
|
19
|
+
end
|
20
|
+
ordered_types
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module SurveyorGui::ReportsHelper
|
2
|
+
|
3
|
+
def question_should_display(q)
|
4
|
+
display=true
|
5
|
+
if q.dependency
|
6
|
+
q.dependency.dependency_conditions.each do |dc|
|
7
|
+
if Response.where(:question_id => dc.question_id).first && dc.answer_id != Response.where(:question_id => dc.question_id).first.answer_id
|
8
|
+
display=false
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
return display
|
13
|
+
end
|
14
|
+
|
15
|
+
def star_average(responses,q)
|
16
|
+
(responses.where(:question_id => q.id).where('integer_value > ?',0).collect(&:integer_value).average * 2).round
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
module SurveyorGui
|
2
|
+
module SurveyformsHelper
|
3
|
+
require 'deep_cloneable'
|
4
|
+
|
5
|
+
def list_dependencies(o)
|
6
|
+
controlling_questions = o.controlling_questions
|
7
|
+
|
8
|
+
controlling_question_ids = controlling_questions.map{|q| q.question_number.to_s+')'}.uniq
|
9
|
+
count = controlling_question_ids.count
|
10
|
+
retstr ='This question is shown depending on the '
|
11
|
+
retstr += 'answer'.pluralize(count)
|
12
|
+
retstr += ' to '
|
13
|
+
retstr += 'question'.pluralize(count) + ' '
|
14
|
+
retstr + list_phrase(controlling_question_ids)
|
15
|
+
end
|
16
|
+
|
17
|
+
def list_phrase(args)
|
18
|
+
## given a list of word parameters, return a syntactically correct phrase
|
19
|
+
## [dog] = "dog"
|
20
|
+
## [dog, cat] = "dog and cat"
|
21
|
+
## [dog, cat, bird] = "dog, cat and bird"
|
22
|
+
case args.count
|
23
|
+
when 0
|
24
|
+
''
|
25
|
+
when 1
|
26
|
+
args[0]
|
27
|
+
when 2
|
28
|
+
args[0] + ' and ' + args[1]
|
29
|
+
else
|
30
|
+
last = args.count
|
31
|
+
args.take(last - 2).join(', ') + ', ' + args[last - 2] + ' and ' + args[last - 1]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_questions_and_groups_helper(q, ss)
|
36
|
+
#this method will render either a question or a complete question group.
|
37
|
+
#we always iterate through questions, and if we happen to notice a question
|
38
|
+
#belongs to a group, we process the group at that time.
|
39
|
+
#note that questions carry a question_group_id, and this is how we know
|
40
|
+
#that a question is part of a group, and that it should not be rendered individually,
|
41
|
+
#but as part of a group.
|
42
|
+
if q.object.part_of_group?
|
43
|
+
_render_initial_group(q, ss) || _respond_to_a_change_in_group_id(q, ss)
|
44
|
+
else
|
45
|
+
render "question_wrapper", f: q
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def render_one_group(qg)
|
50
|
+
qg.simple_fields_for :questions, @current_group.questions do |f|
|
51
|
+
if f.object.is_comment != true
|
52
|
+
render "question_group_fields", f: f
|
53
|
+
elsif f.object.is_comment == true
|
54
|
+
"</div>".html_safe+(render "question_field", f: f)+"<div>".html_safe
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def question_group_heading(f)
|
60
|
+
if f.object.question_type_id == :grid_dropdown
|
61
|
+
heading = f.object.question_group.columns
|
62
|
+
elsif f.object.question_group.display_type == "grid"
|
63
|
+
heading = f.object.answers
|
64
|
+
else
|
65
|
+
heading = []
|
66
|
+
end
|
67
|
+
heading.map {|a| "<span class=\"question_group_heading #{f.object.question_type_id.to_s}\" >#{a.text}<\/span>"}.join().html_safe
|
68
|
+
end
|
69
|
+
|
70
|
+
def row_label_if_question_group(question)
|
71
|
+
if question.part_of_group?
|
72
|
+
"<span class=\"row_name\">#{question.text}: </span>".html_safe
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def question_group_class(question)
|
77
|
+
if @current_group.question_group.display_type == "inline"
|
78
|
+
"inline"
|
79
|
+
elsif @current_group.question_group.display_type == "default"
|
80
|
+
"default"
|
81
|
+
else
|
82
|
+
if question.question_type_id == :grid_dropdown
|
83
|
+
"dropdown"
|
84
|
+
else
|
85
|
+
"grid"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
def _render_initial_group(q, ss)
|
92
|
+
if @current_group.nil?
|
93
|
+
@current_group = QuestionGroupTracker.new(q.object.question_group_id)
|
94
|
+
render "question_group", :ss => ss, :f => q
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def _respond_to_a_change_in_group_id(q, ss)
|
99
|
+
if @current_group.question_group_id != q.object.question_group_id
|
100
|
+
@current_group = QuestionGroupTracker.new(q.object.question_group_id)
|
101
|
+
render "question_group", :ss => ss, :f => q
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
class SurveyCloneFactory
|
108
|
+
def initialize(id, as_template=false)
|
109
|
+
@survey = Surveyform.find(id.to_i)
|
110
|
+
@as_template = as_template
|
111
|
+
end
|
112
|
+
|
113
|
+
def clone
|
114
|
+
cloned_survey = _deep_clone
|
115
|
+
_set_api_keys(cloned_survey)
|
116
|
+
if cloned_survey.save!
|
117
|
+
return cloned_survey
|
118
|
+
else
|
119
|
+
raise cloned_survey.errors.messages.map{|m| m}.join(',')
|
120
|
+
return nil
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
private
|
125
|
+
|
126
|
+
def _initial_clone
|
127
|
+
initial_clone = @survey
|
128
|
+
initial_clone.api_id = Surveyor::Common.generate_api_id
|
129
|
+
initial_clone.survey_version = Survey.where(access_code: @survey.access_code).maximum(:survey_version) + 1
|
130
|
+
return initial_clone
|
131
|
+
end
|
132
|
+
|
133
|
+
def _deep_clone
|
134
|
+
_initial_clone.deep_clone include: {
|
135
|
+
sections:
|
136
|
+
{
|
137
|
+
questions: [
|
138
|
+
:answers,
|
139
|
+
{
|
140
|
+
dependency: {
|
141
|
+
dependency_conditions: [:question, :answer]
|
142
|
+
}
|
143
|
+
},
|
144
|
+
{question_group: :columns}
|
145
|
+
]
|
146
|
+
}
|
147
|
+
},
|
148
|
+
use_dictionary: true
|
149
|
+
end
|
150
|
+
|
151
|
+
def _set_api_keys(cloned_survey)
|
152
|
+
cloned_survey.sections.each do |section|
|
153
|
+
section.questions.each do |question|
|
154
|
+
question.api_id = Surveyor::Common.generate_api_id
|
155
|
+
question.question_group.api_id = Surveyor::Common.generate_api_id if question.part_of_group?
|
156
|
+
question.answers.each do |answer|
|
157
|
+
answer.api_id = Surveyor::Common.generate_api_id
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|