surveyor_gui 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +44 -0
- data/.travis.yml +17 -0
- data/Gemfile +7 -0
- data/LICENSE +21 -0
- data/MIT-LICENSE +20 -0
- data/README.md +159 -0
- data/Rakefile +66 -0
- data/app/controllers/answers_controller.rb +3 -0
- data/app/controllers/application_controller.rb +3 -0
- data/app/controllers/dependencys_controller.rb +286 -0
- data/app/controllers/question_groups_controller.rb +84 -0
- data/app/controllers/questions_controller.rb +187 -0
- data/app/controllers/survey_sections_controller.rb +80 -0
- data/app/controllers/surveyforms_controller.rb +4 -0
- data/app/controllers/surveyor_controller.rb +89 -0
- data/app/controllers/surveyor_gui/reports_controller.rb +339 -0
- data/app/controllers/surveyor_gui/responses_controller.rb +39 -0
- data/app/controllers/surveyor_gui/survey_controller.rb +16 -0
- data/app/facades/report_formatter.rb +44 -0
- data/app/facades/report_preview_wrapper.rb +11 -0
- data/app/facades/report_response_generator.rb +147 -0
- data/app/helpers/application_helper.rb +2 -0
- data/app/helpers/dependency_helper.rb +5 -0
- data/app/helpers/question_helper.rb +22 -0
- data/app/helpers/surveyform_helper.rb +179 -0
- data/app/helpers/surveyor_gui/report_helper.rb +19 -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_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/dependencys/_column.html.erb +1 -0
- data/app/views/dependencys/_dependency.html.erb +22 -0
- data/app/views/dependencys/_dependency_condition_fields.html.erb +48 -0
- data/app/views/dependencys/_form.html.erb +20 -0
- data/app/views/dependencys/blank.html.erb +0 -0
- data/app/views/dependencys/edit.html.erb +1 -0
- data/app/views/dependencys/new.html.erb +1 -0
- data/app/views/layouts/application.html.erb +14 -0
- data/app/views/layouts/surveyor_gui_blank.html.erb +12 -0
- data/app/views/layouts/surveyor_gui_default.html.erb +16 -0
- data/app/views/layouts/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/question_groups/_form.html.erb +56 -0
- data/app/views/question_groups/_group_inline_field.html.erb +21 -0
- data/app/views/question_groups/_group_inline_fields.html.erb +25 -0
- data/app/views/question_groups/blank.html.erb +0 -0
- data/app/views/question_groups/edit.html.erb +1 -0
- data/app/views/question_groups/new.html.erb +1 -0
- data/app/views/questions/_answer_fields.html.erb +23 -0
- data/app/views/questions/_answer_options.html.erb +28 -0
- data/app/views/questions/_form.html.erb +65 -0
- data/app/views/questions/_grid_dropdown_columns.html.erb +10 -0
- data/app/views/questions/_grid_dropdown_fields.html.erb +42 -0
- data/app/views/questions/_grid_fields.html.erb +9 -0
- data/app/views/questions/_no_picks.html.erb +29 -0
- data/app/views/questions/_pick.html +21 -0
- data/app/views/questions/_picks.html.erb +12 -0
- data/app/views/questions/blank.html.erb +0 -0
- data/app/views/questions/edit.html.erb +1 -0
- data/app/views/questions/new.html.erb +1 -0
- data/app/views/survey_sections/_form.html.erb +13 -0
- data/app/views/survey_sections/blank.html.erb +0 -0
- data/app/views/survey_sections/edit.html.erb +1 -0
- data/app/views/survey_sections/new.html.erb +1 -0
- data/app/views/surveyforms/_form.html.erb +50 -0
- data/app/views/surveyforms/_question_field.html.erb +148 -0
- data/app/views/surveyforms/_question_group.html.erb +116 -0
- data/app/views/surveyforms/_question_group_fields.html.erb +3 -0
- data/app/views/surveyforms/_question_name_and_number.html.erb +6 -0
- data/app/views/surveyforms/_question_section.html.erb +15 -0
- data/app/views/surveyforms/_question_wrapper.html.erb +109 -0
- data/app/views/surveyforms/_survey_section_fields.html.erb +138 -0
- data/app/views/surveyforms/clone_survey.html.erb +13 -0
- data/app/views/surveyforms/edit.html.erb +5 -0
- data/app/views/surveyforms/index.html.erb +40 -0
- data/app/views/surveyforms/new.html.erb +1 -0
- data/app/views/surveyforms/show.html.erb +5 -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 +28 -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 +9 -0
- data/app/views/surveyor_gui/shared/_report_data.html.haml +24 -0
- data/app/views/surveyor_gui/shared/_stars_report_data.html.haml +14 -0
- data/config.ru +4 -0
- data/config/environment.rb +0 -0
- data/config/routes.rb +71 -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 +1417 -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 +650 -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_default.html.erb +16 -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.rb +17 -0
- data/lib/surveyor_gui/engine.rb +30 -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 +67 -0
- data/lib/surveyor_gui/models/response_set_methods.rb +54 -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/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 +361 -0
- data/spec/controllers/surveyor_controller_spec.rb +303 -0
- data/spec/factories.rb +181 -0
- data/spec/features/create_survey_spec.rb +418 -0
- data/spec/features/dependencies_spec.rb +61 -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 +312 -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 +73 -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.ru +4 -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/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/vendor/assets/stylesheets/.gitkeep +0 -0
- data/vendor/assets/stylesheets/custom.sass +5 -0
- data/vendor/plugins/.gitkeep +0 -0
- metadata +664 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
module SurveyorGui
|
2
|
+
module Models
|
3
|
+
module ResponseMethods
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send :has_many, :answers, :primary_key => :answer_id, :foreign_key => :id
|
7
|
+
base.send :has_many, :questions
|
8
|
+
base.send :belongs_to, :column
|
9
|
+
base.send :attr_accessible, :response_set, :question, :answer, :date_value, :time_value,
|
10
|
+
:response_set_id, :question_id, :answer_id, :datetime_value, :integer_value, :float_value,
|
11
|
+
:unit, :text_value, :string_value, :response_other, :response_group,
|
12
|
+
:survey_section_id, :blob, :column if defined? ActiveModel::MassAssignmentSecurity
|
13
|
+
#belongs_to :user
|
14
|
+
|
15
|
+
# after_destroy :delete_blobs!
|
16
|
+
# after_destroy :delete_empty_dir
|
17
|
+
|
18
|
+
#extends response to allow file uploads.
|
19
|
+
base.send :mount_uploader, :blob, BlobUploader
|
20
|
+
end
|
21
|
+
|
22
|
+
VALUE_TYPE = ['float', 'integer', 'string', 'datetime', 'text']
|
23
|
+
|
24
|
+
def response_value
|
25
|
+
response_class = self.answer.response_class
|
26
|
+
if self.question.pick=='none'
|
27
|
+
_no_pick_value(response_class)
|
28
|
+
else
|
29
|
+
return self.answer.text
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def is_comment?
|
34
|
+
if self.answer
|
35
|
+
self.answer.is_comment?
|
36
|
+
else
|
37
|
+
false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def delete_blobs!
|
44
|
+
self.remove_blob!
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def delete_empty_dir
|
49
|
+
FileUtils.rm_rf(File.join(Rails.root.to_s,'public',BlobUploader.store_dir))
|
50
|
+
end
|
51
|
+
|
52
|
+
def _no_pick_value(response_class)
|
53
|
+
VALUE_TYPE.each do |value_type|
|
54
|
+
value_attribute = value_type+'_value'
|
55
|
+
if instance_eval(value_attribute)
|
56
|
+
if response_class == "time"
|
57
|
+
return self.datetime_value - self.datetime_value.beginning_of_day
|
58
|
+
else
|
59
|
+
return instance_eval(value_attribute)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
nil
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module SurveyorGui
|
2
|
+
module Models
|
3
|
+
module ResponseSetMethods
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send :has_many, :responses, :dependent=>:destroy
|
7
|
+
base.send :attr_accessible, :survey, :responses_attributes, :user_id, :survey_id, :test_data if defined? ActiveModel::MassAssignmentSecurity
|
8
|
+
end
|
9
|
+
|
10
|
+
#determine whether a mandatory question is missing a response. Only applicable if the question is not dependent on other questions,
|
11
|
+
#or if it is dependent, but has been triggered for inclusion by a previous answer.
|
12
|
+
def triggered_mandatory_missing
|
13
|
+
qs = survey.sections.map(&:questions).flatten
|
14
|
+
ds = Dependency.all(:include => :dependency_conditions, :conditions => {:dependency_conditions => {:question_id => qs.map(&:id) || responses.map(&:question_id)}})
|
15
|
+
triggered = qs - ds.select{|d| !d.is_met?(self)}.map(&:question)
|
16
|
+
triggered_mandatory = triggered.select{|q| q.mandatory?}
|
17
|
+
triggered_mandatory_completed = triggered.select{|q| q.mandatory? and is_answered?(q)}
|
18
|
+
triggered_mandatory_missing = triggered_mandatory - triggered_mandatory_completed
|
19
|
+
return triggered_mandatory_missing
|
20
|
+
end
|
21
|
+
|
22
|
+
#return a hash of dependent questions.
|
23
|
+
def all_dependencies(question_ids = nil)
|
24
|
+
arr = dependencies(question_ids).partition{|d| d.is_met?(self) }
|
25
|
+
{:show => arr[0].map{|d| d.question_group_id.nil? ? (d.question.is_mandatory? ? nil : "q_#{d.question_id}") : "g_#{d.question_group_id}"},
|
26
|
+
:show_mandatory => arr[0].map{|d| d.question_group_id.nil? ? (d.question.is_mandatory? ? "q_#{d.question_id}" : nil) : "g_#{d.question_group_id}"},
|
27
|
+
:hide => arr[1].map{|d| d.question_group_id.nil? ? "q_#{d.question_id}" : "g_#{d.question_group_id}"}}
|
28
|
+
end
|
29
|
+
def correctness_hash
|
30
|
+
{ :questions => Survey.where(id: self.survey_id).includes(sections: :questions).first.sections.map(&:questions).flatten.compact.size,
|
31
|
+
:responses => responses.to_a.compact.size,
|
32
|
+
:correct => responses.find_all(&:correct?).compact.size
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
def report_user_name
|
37
|
+
user_name = nil
|
38
|
+
if class_exists?('ResponseSetUser')
|
39
|
+
user_name = ResponseSetUser.new(self.user_id).report_user_name
|
40
|
+
end
|
41
|
+
user_name || self.user_id || self.id
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def class_exists?(class_name)
|
47
|
+
klass = Module.const_get(class_name)
|
48
|
+
return klass.is_a?(Class)
|
49
|
+
rescue NameError
|
50
|
+
return false
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SurveyorGui
|
2
|
+
module Models
|
3
|
+
module SurveyMethods
|
4
|
+
def self.included(base)
|
5
|
+
base.extend Surveyor::Models::SurveyMethods
|
6
|
+
base.send :attr_accessible, :title, :access_code, :template,
|
7
|
+
:survey_sections_attributes if defined? ActiveModel::MassAssignmentSecurity
|
8
|
+
base.send :has_many, :survey_sections, :dependent => :destroy
|
9
|
+
base.send :accepts_nested_attributes_for, :survey_sections, :allow_destroy => true
|
10
|
+
|
11
|
+
base.send :validate, :no_responses
|
12
|
+
base.send :before_destroy, :no_responses
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
#don't let a survey be deleted or changed if responses have been submitted
|
18
|
+
#to ensure data integrity
|
19
|
+
def no_responses
|
20
|
+
if self.id
|
21
|
+
#this will be a problem if two people are editing the survey at the same time and do a survey preview - highly unlikely though.
|
22
|
+
self.response_sets.where('test_data = ?',true).each {|r| r.destroy}
|
23
|
+
end
|
24
|
+
if !template && response_sets.count>0
|
25
|
+
errors.add(:base,"Reponses have already been collected for this survey, therefore it cannot be modified. Please create a new survey instead.")
|
26
|
+
return false
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SurveyorGui
|
2
|
+
module Models
|
3
|
+
module SurveySectionMethods
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
|
7
|
+
base.send :attr_accessible, :title, :display_order,
|
8
|
+
:questions_attributes, :survey_id, :modifiable if defined? ActiveModel::MassAssignmentSecurity
|
9
|
+
base.send :belongs_to, :surveyform, :foreign_key=>:survey_id
|
10
|
+
base.send :has_many, :questions, :dependent => :destroy
|
11
|
+
base.send :accepts_nested_attributes_for, :questions
|
12
|
+
base.send :default_scope, lambda{ base.order('display_order') }
|
13
|
+
|
14
|
+
base.send :validate, :no_responses
|
15
|
+
base.send :before_destroy, :no_responses
|
16
|
+
end
|
17
|
+
|
18
|
+
#don't let a survey be deleted or changed if responses have been submitted
|
19
|
+
#to ensure data integrity
|
20
|
+
def no_responses
|
21
|
+
if self.id && self.survey
|
22
|
+
#this will be a problem if two people are editing the survey at the same time and do a survey preview - highly unlikely though.
|
23
|
+
self.survey.response_sets.where('test_data = ?',true).each {|r| r.destroy}
|
24
|
+
end
|
25
|
+
if self.survey && !survey.template && survey.response_sets.count>0
|
26
|
+
errors.add(:base,"Reponses have already been collected for this survey, therefore it cannot be modified. Please create a new survey instead.")
|
27
|
+
return false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,258 @@
|
|
1
|
+
module SurveyorGui
|
2
|
+
module SurveyformsControllerMethods
|
3
|
+
|
4
|
+
def self.included(base)
|
5
|
+
base.send :layout, 'surveyor_gui_default'
|
6
|
+
end
|
7
|
+
|
8
|
+
def index
|
9
|
+
if params[:template]=='false'
|
10
|
+
template=false
|
11
|
+
elsif params[:template]=='true'
|
12
|
+
template=true
|
13
|
+
else
|
14
|
+
template=false
|
15
|
+
end
|
16
|
+
@title = "Manage " + (template ? "Templates" : "Surveys")
|
17
|
+
@surveyforms = Surveyform.where('template = ?',template).search(params[:search]).order(:title).paginate(:page => params[:page])
|
18
|
+
end
|
19
|
+
|
20
|
+
def new
|
21
|
+
@title = "Create New "+ (params[:template] == 'template'? 'Template' : 'Survey')
|
22
|
+
@hide_survey_type = params[:hide_survey_type]
|
23
|
+
template = params[:template] == 'template'? true : false
|
24
|
+
@surveyform = Surveyform.new(:template=>template)
|
25
|
+
@surveyform.survey_sections.build(:title=>'Section 1', :display_order=>0, :modifiable=>true)#.questions.build(:text=>'New question',:pick=>'none',:display_order=>0,:display_type=>'default', :modifiable=>modifiable).answers.build(:text=>'string', :response_class=>'string', :display_order=>1, :template=>true)
|
26
|
+
@question_no = 0
|
27
|
+
end
|
28
|
+
|
29
|
+
def edit
|
30
|
+
@surveyform = Surveyform.where(:id=>params[:id]).includes(:survey_sections).first
|
31
|
+
@survey_locked=false
|
32
|
+
#unfortunately, request.referrer does not seem to capture parameters. Need to add explicitly.
|
33
|
+
#don't edit the format of a non template survey that has responses. could cause unpredictable results
|
34
|
+
@surveyform.response_sets.where('test_data=?',true).map{|r| r.destroy}
|
35
|
+
if !@surveyform.template && @surveyform.response_sets.count>0
|
36
|
+
@survey_locked=true
|
37
|
+
flash.now[:error] = "Reponses have already been collected for this survey, therefore modifications are not permitted."
|
38
|
+
end
|
39
|
+
@title = "Edit "+ (@surveyform.template ? 'Template' : 'Survey')
|
40
|
+
@surveyform.survey_sections.build if @surveyform.survey_sections.blank?
|
41
|
+
@question_no = 0
|
42
|
+
@url = "update"
|
43
|
+
end
|
44
|
+
|
45
|
+
def create
|
46
|
+
@surveyform = Surveyform.new(surveyforms_params.merge(user_id: @current_user.nil? ? @current_user : @current_user.id))
|
47
|
+
if @surveyform.save
|
48
|
+
flash[:notice] = "Successfully created survey."
|
49
|
+
@title = "Edit Survey"
|
50
|
+
@question_no = 0
|
51
|
+
redirect_to edit_surveyform_path(@surveyform.id)
|
52
|
+
else
|
53
|
+
render :action => 'new'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def update
|
58
|
+
@title = "Update Survey"
|
59
|
+
@surveyform = Surveyform.includes(:survey_sections).find(params[:surveyform][:id])
|
60
|
+
if @surveyform.update_attributes(surveyforms_params)
|
61
|
+
flash[:notice] = "Successfully updated surveyform."
|
62
|
+
redirect_to :action=>:index
|
63
|
+
else
|
64
|
+
flash[:error] = "Changes not saved."
|
65
|
+
@question_no = 0
|
66
|
+
render :action => 'edit'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def show
|
71
|
+
@title = "Show Survey"
|
72
|
+
@survey_locked = true
|
73
|
+
@surveyform = Surveyform.find(params[:id])
|
74
|
+
@question_no = 0
|
75
|
+
end
|
76
|
+
|
77
|
+
def destroy
|
78
|
+
@surveyform = Surveyform.find(params[:id])
|
79
|
+
@surveyform.destroy
|
80
|
+
if !@surveyform
|
81
|
+
flash[:notice] = "Successfully destroyed survey."
|
82
|
+
redirect_to surveyforms_url
|
83
|
+
else
|
84
|
+
if @surveyform.response_sets.count > 0
|
85
|
+
flash[:error] = 'This survey has responses and can not be deleted'
|
86
|
+
else
|
87
|
+
flash[:error] = 'Survey could not be deleted.'
|
88
|
+
end
|
89
|
+
redirect_to surveyforms_url
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def replace_form
|
94
|
+
@surveyform = SurveySection.find(params[:survey_section_id]).surveyform
|
95
|
+
@question_no = 0
|
96
|
+
render :new, :layout => false
|
97
|
+
end
|
98
|
+
|
99
|
+
def insert_survey_section
|
100
|
+
survey_id = params[:id]
|
101
|
+
@survey_section = Survey.find(survey_id).survey_sections.reorder('survey_sections.id').last
|
102
|
+
if @survey_section
|
103
|
+
@question_no = 0
|
104
|
+
render "_survey_section_fields" , :layout=> false
|
105
|
+
else
|
106
|
+
render :nothing=> true
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def replace_survey_section
|
111
|
+
survey_section_id = params[:survey_section_id]
|
112
|
+
@survey_section = SurveySection.find(survey_section_id)
|
113
|
+
@question_no = 0
|
114
|
+
render "_survey_section_fields" , :layout=> false
|
115
|
+
end
|
116
|
+
|
117
|
+
def insert_new_question
|
118
|
+
question_id = params[:question_id]
|
119
|
+
@question = Question.find(question_id)
|
120
|
+
@question_no = 0
|
121
|
+
@surveyform = @question.survey_section.surveyform
|
122
|
+
render :new, :layout=>false
|
123
|
+
end
|
124
|
+
|
125
|
+
def cut_section
|
126
|
+
session[:cut_section]=params[:survey_section_id]
|
127
|
+
if ss=SurveySection.find(params[:survey_section_id])
|
128
|
+
@surveyform=ss.surveyform
|
129
|
+
ss.update_attribute(:survey_id,nil)
|
130
|
+
@question_no = 0
|
131
|
+
render :new, :layout=>false
|
132
|
+
return true
|
133
|
+
end
|
134
|
+
render :nothing=>true
|
135
|
+
return false
|
136
|
+
end
|
137
|
+
|
138
|
+
def paste_section
|
139
|
+
@title="Edit Survey"
|
140
|
+
@question_no = 0
|
141
|
+
if session[:cut_section]
|
142
|
+
_continue_paste_section
|
143
|
+
else
|
144
|
+
render :nothing=>true
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def _continue_paste_section
|
149
|
+
survey_section = SurveySection.find(session[:cut_section])
|
150
|
+
place_at_section = SurveySection.find(params[:survey_section_id])
|
151
|
+
survey_section.survey_id = place_at_section.survey_id
|
152
|
+
survey_section.display_order = _paste_to(params[:position], place_at_section.survey, place_at_section)
|
153
|
+
@surveyform = place_at_section.surveyform
|
154
|
+
_save_pasted_object(survey_section, @surveyform, :cut_section)
|
155
|
+
end
|
156
|
+
|
157
|
+
def _paste_to(position, object_parent, object)
|
158
|
+
paste_position = object.display_order + _display_order_offset(position)
|
159
|
+
_make_room(paste_position, object_parent, object)
|
160
|
+
paste_position
|
161
|
+
end
|
162
|
+
|
163
|
+
def _display_order_offset(position)
|
164
|
+
position == "over" ? 0 : 1
|
165
|
+
end
|
166
|
+
|
167
|
+
def _make_room(paste_at, object_parent, object)
|
168
|
+
statement = "object_parent."+object.class.to_s.underscore.pluralize
|
169
|
+
collection = eval(statement)
|
170
|
+
collection.where('display_order >= ?',paste_at).update_all('display_order=display_order+1')
|
171
|
+
end
|
172
|
+
|
173
|
+
def _save_pasted_object(object, surveyform, session_id)
|
174
|
+
if object.save
|
175
|
+
surveyform.reload
|
176
|
+
session[session_id]=nil
|
177
|
+
render :new, :layout=>false
|
178
|
+
else
|
179
|
+
render :nothing=>true
|
180
|
+
return false
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def cut_question
|
185
|
+
session[:cut_question]=params[:question_id]
|
186
|
+
if q=Question.find(params[:question_id])
|
187
|
+
@surveyform=q.survey_section.surveyform
|
188
|
+
q.update_attribute(:survey_section_id,nil)
|
189
|
+
q.question_group.questions.map{|q| q.update_attribute(:survey_section_id,nil)} if q.part_of_group?
|
190
|
+
@question_no = 0
|
191
|
+
render :new, :layout=>false
|
192
|
+
return true
|
193
|
+
end
|
194
|
+
render :nothing=>true
|
195
|
+
return false
|
196
|
+
end
|
197
|
+
|
198
|
+
def paste_question
|
199
|
+
@title="Edit Survey"
|
200
|
+
if session[:cut_question]
|
201
|
+
@question = Question.find(session[:cut_question])
|
202
|
+
@question_no = 0
|
203
|
+
if params[:question_id]
|
204
|
+
place_under_question = Question.find(params[:question_id])
|
205
|
+
survey_section = place_under_question.survey_section
|
206
|
+
survey_section_id = survey_section.id
|
207
|
+
survey_section.questions.where('display_order>?',place_under_question.display_order).update_all('display_order=display_order+1')
|
208
|
+
@question.display_order = place_under_question.display_order+1
|
209
|
+
@surveyform = survey_section.surveyform
|
210
|
+
else
|
211
|
+
survey_section_id = params[:survey_section_id]
|
212
|
+
@question.display_order = 0
|
213
|
+
SurveySection.find(survey_section_id).questions.update_all('display_order = display_order+1')
|
214
|
+
@surveyform = SurveySection.find(survey_section_id).surveyform
|
215
|
+
end
|
216
|
+
@question.survey_section_id = survey_section_id
|
217
|
+
|
218
|
+
if @question.save
|
219
|
+
@surveyform.reload
|
220
|
+
session[:cut_question]=nil
|
221
|
+
render :new, :layout=>false
|
222
|
+
else
|
223
|
+
render :nothing=>true
|
224
|
+
return false
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
def replace_question
|
230
|
+
question_id = params[:question_id]
|
231
|
+
begin
|
232
|
+
@question = Question.find(question_id)
|
233
|
+
@question_no = 0
|
234
|
+
render "_question_section" , :layout=> false
|
235
|
+
rescue
|
236
|
+
render inline: "not found"
|
237
|
+
end
|
238
|
+
end
|
239
|
+
|
240
|
+
def clone_survey
|
241
|
+
@title = "Clone Survey"
|
242
|
+
@surveyform = SurveyCloneFactory.new(params[:id]).clone
|
243
|
+
if @surveyform.save
|
244
|
+
flash[:notice] = "Successfully created survey, questionnaire, or form."
|
245
|
+
redirect_to edit_surveyform_path(@surveyform)
|
246
|
+
else
|
247
|
+
flash[:error] = "Could not clone the survey, questionnaire, or form."
|
248
|
+
render :action => 'new'
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
private
|
253
|
+
def surveyforms_params
|
254
|
+
::PermittedParams.new(params[:surveyform]).survey
|
255
|
+
end
|
256
|
+
|
257
|
+
end
|
258
|
+
end
|