surveyor_gui 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +32 -0
- data/README.md +22 -2
- data/app/controllers/surveyor_gui/answers_controller.rb +3 -0
- data/app/controllers/surveyor_gui/application_controller.rb +3 -0
- data/app/controllers/{dependencys_controller.rb → surveyor_gui/dependencys_controller.rb} +5 -5
- data/app/controllers/{question_groups_controller.rb → surveyor_gui/question_groups_controller.rb} +13 -7
- data/app/controllers/{questions_controller.rb → surveyor_gui/questions_controller.rb} +6 -6
- data/app/controllers/surveyor_gui/reports_controller.rb +6 -6
- data/app/controllers/surveyor_gui/responses_controller.rb +3 -1
- data/app/controllers/surveyor_gui/survey_controller.rb +1 -1
- data/app/controllers/{survey_sections_controller.rb → surveyor_gui/survey_sections_controller.rb} +5 -5
- data/app/controllers/{surveyforms_controller.rb → surveyor_gui/surveyforms_controller.rb} +1 -1
- data/app/controllers/{surveyor_controller.rb → surveyor_gui/surveyor_controller.rb} +2 -2
- data/app/helpers/surveyor_gui/application_helper.rb +2 -0
- data/app/helpers/{dependency_helper.rb → surveyor_gui/dependencys_helper.rb} +1 -1
- data/app/helpers/surveyor_gui/question_groups_helper.rb +3 -0
- data/app/helpers/{question_helper.rb → surveyor_gui/questions_helper.rb} +1 -1
- data/app/helpers/surveyor_gui/{report_helper.rb → reports_helper.rb} +1 -1
- data/app/helpers/surveyor_gui/surveyforms_helper.rb +160 -0
- data/app/helpers/{surveyor_helper.rb → surveyor_gui/surveyor_helper.rb} +1 -1
- data/app/models/question_group_tracker.rb +19 -0
- data/app/views/layouts/{application.html.erb → surveyor_gui/application.html.erb} +0 -0
- data/app/views/layouts/{surveyor_gui_blank.html.erb → surveyor_gui/surveyor_gui_blank.html.erb} +1 -0
- data/app/views/layouts/{surveyor_gui_default.html.erb → surveyor_gui/surveyor_gui_default.html.erb} +1 -0
- data/app/views/layouts/{surveyor_modified.html.erb → surveyor_gui/surveyor_modified.html.erb} +0 -0
- data/app/views/{dependencys → surveyor_gui/dependencys}/_column.html.erb +0 -0
- data/app/views/{dependencys → surveyor_gui/dependencys}/_dependency.html.erb +0 -0
- data/app/views/{dependencys → surveyor_gui/dependencys}/_dependency_condition_fields.html.erb +0 -0
- data/app/views/{dependencys → surveyor_gui/dependencys}/_form.html.erb +0 -0
- data/app/views/{dependencys → surveyor_gui/dependencys}/blank.html.erb +0 -0
- data/app/views/{dependencys → surveyor_gui/dependencys}/edit.html.erb +0 -0
- data/app/views/{dependencys → surveyor_gui/dependencys}/new.html.erb +0 -0
- data/app/views/{partials → surveyor_gui/partials}/_answer.html.haml +0 -0
- data/app/views/{partials → surveyor_gui/partials}/_question.html.haml +0 -0
- data/app/views/{partials → surveyor_gui/partials}/_question_group.html.haml +0 -0
- data/app/views/{partials → surveyor_gui/partials}/_section.html.haml +0 -0
- data/app/views/surveyor_gui/partials/_url_helpers.html.erb +5 -0
- data/app/views/{question_groups → surveyor_gui/question_groups}/_form.html.erb +2 -1
- data/app/views/{question_groups → surveyor_gui/question_groups}/_group_inline_field.html.erb +0 -0
- data/app/views/{question_groups → surveyor_gui/question_groups}/_group_inline_fields.html.erb +0 -0
- data/app/views/{question_groups → surveyor_gui/question_groups}/blank.html.erb +0 -0
- data/app/views/{question_groups → surveyor_gui/question_groups}/edit.html.erb +0 -0
- data/app/views/{question_groups → surveyor_gui/question_groups}/new.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/_answer_fields.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/_answer_options.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/_form.html.erb +2 -1
- data/app/views/{questions → surveyor_gui/questions}/_grid_dropdown_columns.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/_grid_dropdown_fields.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/_grid_fields.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/_no_picks.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/_pick.html +0 -0
- data/app/views/{questions → surveyor_gui/questions}/_picks.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/blank.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/edit.html.erb +0 -0
- data/app/views/{questions → surveyor_gui/questions}/new.html.erb +0 -0
- data/app/views/surveyor_gui/responses/_survey_results.html.haml +1 -1
- data/app/views/surveyor_gui/responses/index.html.haml +1 -1
- data/app/views/surveyor_gui/shared/_report_data.html.haml +17 -14
- data/app/views/{survey_sections → surveyor_gui/survey_sections}/_form.html.erb +0 -0
- data/app/views/{survey_sections → surveyor_gui/survey_sections}/blank.html.erb +0 -0
- data/app/views/{survey_sections → surveyor_gui/survey_sections}/edit.html.erb +0 -0
- data/app/views/{survey_sections → surveyor_gui/survey_sections}/new.html.erb +0 -0
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/_form.html.erb +4 -4
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/_question_field.html.erb +0 -0
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/_question_group.html.erb +14 -14
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/_question_group_fields.html.erb +0 -0
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/_question_name_and_number.html.erb +0 -0
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/_question_section.html.erb +0 -0
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/_question_wrapper.html.erb +14 -15
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/_survey_section_fields.html.erb +11 -12
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/clone_survey.html.erb +0 -0
- data/app/views/surveyor_gui/surveyforms/edit.html.erb +5 -0
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/index.html.erb +2 -2
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/new.html.erb +0 -0
- data/app/views/{surveyforms → surveyor_gui/surveyforms}/show.html.erb +0 -0
- data/config/routes.rb +20 -22
- data/lib/assets/javascripts/surveyor_gui/surveyor_gui.js +25 -14
- data/lib/assets/stylesheets/surveyor_gui/surveyor_gui.sass +2 -0
- data/lib/generators/surveyor_gui/install_generator.rb +1 -1
- data/lib/generators/surveyor_gui/templates/app/views/layouts/{surveyor_gui_default.html.erb → surveyor_gui/surveyor_gui_default.html.erb} +1 -0
- data/lib/surveyor_gui/engine.rb +2 -1
- data/lib/surveyor_gui/models/response_set_methods.rb +2 -1
- data/lib/surveyor_gui/surveyforms_controller_methods.rb +1 -1
- data/lib/surveyor_gui/version.rb +1 -1
- data/spec/controllers/surveyforms_controller_spec.rb +10 -9
- data/spec/features/create_survey_spec.rb +2 -3
- data/spec/features/dependencies_spec.rb +1 -1
- data/spec/support/surveyforms_creation_helpers.rb +4 -4
- data/spec/views/questions/edit.html.erb_spec.rb +4 -3
- data/spec/views/surveyforms/edit.html.erb_spec.rb +1 -1
- metadata +71 -67
- data/app/controllers/answers_controller.rb +0 -3
- data/app/controllers/application_controller.rb +0 -3
- data/app/helpers/application_helper.rb +0 -2
- data/app/helpers/surveyform_helper.rb +0 -179
- data/app/views/surveyforms/edit.html.erb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 289785dc295cf459338fa764ccab75b77eb5a5f5
|
4
|
+
data.tar.gz: 856577a30296bc7a4db424363578859d95667e64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2fcbec126c907ee557bcca03d509f218631c185aa5bfecfeb778203f15051eff8432cf0bf23b6dbd87fdf3d68dee88d262519eac27dd8f2cb9ef90ae666e7163
|
7
|
+
data.tar.gz: 213a50cc096022c92529a88e6f50e00e1d1dc85a843f066330dd793955e1b1e4008b711cb1c5746b7d6ffe2176e5b0efbe4ee0765444f974c7215c01f7547d20
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
History for Surveyor
|
2
|
+
====================
|
3
|
+
|
4
|
+
0.1.0
|
5
|
+
------
|
6
|
+
|
7
|
+
### Features
|
8
|
+
|
9
|
+
- This gem is now a mountable engine and uses isolate_namespace.
|
10
|
+
|
11
|
+
### Fixes
|
12
|
+
|
13
|
+
- Fixes error on preview report in which no users are shown and report data is empty. Will now show fake user names.
|
14
|
+
- Fixes error on preview response and show response when dependencies are set. Also shows correct user name on reponse
|
15
|
+
index.
|
16
|
+
|
17
|
+
0.0.3
|
18
|
+
------
|
19
|
+
|
20
|
+
### Features
|
21
|
+
|
22
|
+
- Official support for Rails 4.0. Will work generally work with 4.1 but, Surveyor, a critical dependency, is not officially supported on 4.1.
|
23
|
+
|
24
|
+
- Supports survey creation and reporting.
|
25
|
+
|
26
|
+
- Provides preview of how surveys and reports will look as you are building a survey.
|
27
|
+
|
28
|
+
### Fixes
|
29
|
+
|
30
|
+
|
31
|
+
### Infrastructure
|
32
|
+
|
data/README.md
CHANGED
@@ -11,7 +11,9 @@ Surveyor_gui meets this need by providing a gui to create surveys from scratch.
|
|
11
11
|
|
12
12
|
Surveyor is feature-rich and can create very complex surveys. Surveyor-gui supports most of the features in Surveyor.
|
13
13
|
|
14
|
-
This gem
|
14
|
+
This gem also provides a reporting capability for Surveyor.
|
15
|
+
|
16
|
+
Surveyor_gui is a mountable engine.
|
15
17
|
|
16
18
|
## Requirements
|
17
19
|
|
@@ -86,6 +88,9 @@ This gem enforces locking on surveys. A survey may be modified up until a user
|
|
86
88
|
can no longer be edited for structural changes (i.e., /surveyform/edit will not permit any changes). This protects the
|
87
89
|
data integrity of the survey response data.
|
88
90
|
|
91
|
+
If you want to unlock a survey, you will need to manually delete all of the child ResponseSet records (e.g.,
|
92
|
+
Survey.find(1).response_set.all.each{|r| r.destroy} ). Use appropriate caution!
|
93
|
+
|
89
94
|
## Templates
|
90
95
|
|
91
96
|
Surveys may be saved as templates. This allows them to be cloned when creating a new survey (cloning is a pending feature). It is
|
@@ -156,4 +161,19 @@ If you wanted the users full name, you could add something like this:
|
|
156
161
|
|
157
162
|
@user ? @user.last_name + ', ' + @user.first_name : nil
|
158
163
|
|
159
|
-
Note that SurveyorGui controllers expect to use surveyor_gui's own layout view, surveyor_gui_default.rb. A copy will be placed in your application's app/views/layouts directory. You may need edit it for various reasons, such as adding a Devise login/logout link.
|
164
|
+
Note that SurveyorGui controllers expect to use surveyor_gui's own layout view, surveyor_gui_default.rb. A copy will be placed in your application's app/views/layouts directory. You may need edit it for various reasons, such as adding a Devise login/logout link. Keep in mind that surveyor_gui works in an isolated namespace, so devise helpers need to be namespaced to the main app. That means that any view local to surveyor_gui would need to refer to Devise's new_user_registration_path as main_app.new_user_registration_path. If you wanted to add a login/logout link to the surveyor_gui_default layout, you might add something like this:
|
165
|
+
|
166
|
+
<% if user_signed_in? %>
|
167
|
+
Logged in as <strong><%= current_user.email %></strong>.
|
168
|
+
<%= link_to 'Edit profile', main_app.edit_user_registration_path %> |
|
169
|
+
<%= link_to "Logout", main_app.destroy_user_session_path, method: :delete %>
|
170
|
+
<% else %>
|
171
|
+
<%= link_to "Sign up", main_app.new_user_registration_path %> |
|
172
|
+
<%= link_to "Login", main_app.new_user_session_path %>
|
173
|
+
<% end %>
|
174
|
+
|
175
|
+
|
176
|
+
## Surveyor
|
177
|
+
|
178
|
+
Please take a look at the NUBIC/surveyor on github. The README.doc file will help you to understand how the surveyor engine works. Also, the wiki has a very useful data diagram that will help you to grasp the data
|
179
|
+
structure of the surveys and responses.
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class DependencysController < ApplicationController
|
2
|
-
layout 'surveyor_gui_blank'
|
1
|
+
class SurveyorGui::DependencysController < ApplicationController
|
2
|
+
layout 'surveyor_gui/surveyor_gui_blank'
|
3
3
|
|
4
4
|
def new
|
5
5
|
prep_variables
|
@@ -21,7 +21,7 @@ class DependencysController < ApplicationController
|
|
21
21
|
if @question.save
|
22
22
|
redirect_to :back
|
23
23
|
else
|
24
|
-
render :action => 'new', :layout => 'surveyor_gui_blank'
|
24
|
+
render :action => 'new', :layout => 'surveyor_gui/surveyor_gui_blank'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -37,10 +37,10 @@ class DependencysController < ApplicationController
|
|
37
37
|
end
|
38
38
|
if update_object.update_attributes(update_params)
|
39
39
|
update_object.dependency.destroy if update_object.dependency.dependency_conditions.blank?
|
40
|
-
render :blank, :layout => 'surveyor_gui_blank'
|
40
|
+
render :blank, :layout => 'surveyor_gui/surveyor_gui_blank'
|
41
41
|
else
|
42
42
|
prep_variables
|
43
|
-
render :action => 'edit', :layout => 'surveyor_gui_blank'
|
43
|
+
render :action => 'edit', :layout => 'surveyor_gui/surveyor_gui_blank'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
data/app/controllers/{question_groups_controller.rb → surveyor_gui/question_groups_controller.rb}
RENAMED
@@ -1,8 +1,9 @@
|
|
1
|
-
class QuestionGroupsController < ApplicationController
|
1
|
+
class SurveyorGui::QuestionGroupsController < ApplicationController
|
2
|
+
layout 'surveyor_gui/surveyor_gui_blank'
|
2
3
|
|
3
4
|
def new
|
4
5
|
@title = "Add Question"
|
5
|
-
@survey_section_id =
|
6
|
+
@survey_section_id = question_params[:survey_section_id]
|
6
7
|
@question_group = QuestionGroup.new(
|
7
8
|
text: params[:text],
|
8
9
|
question_type_id: params[:question_type_id])
|
@@ -25,7 +26,8 @@ class QuestionGroupsController < ApplicationController
|
|
25
26
|
@title = "Edit Question Group"
|
26
27
|
@question_group = QuestionGroup.includes(:questions).find(params[:id])
|
27
28
|
@question_group.question_type_id = params[:question_type_id]
|
28
|
-
@survey_section_id =
|
29
|
+
@survey_section_id = question_params[:survey_section_id]
|
30
|
+
p "edit survey sect id #{@survey_section_id}"
|
29
31
|
end
|
30
32
|
|
31
33
|
def create
|
@@ -34,11 +36,11 @@ class QuestionGroupsController < ApplicationController
|
|
34
36
|
#@question_group.questions.update_attributes(survey_section_id: question_group_params[])
|
35
37
|
original_question = Question.find(question_group_params[:question_id]) if !question_group_params[:question_id].blank?
|
36
38
|
original_question.destroy if original_question
|
37
|
-
render :inline => '<div id="cboxQuestionId">'+@question_group.questions.first.id.to_s+'</div>', :layout => 'surveyor_gui_blank'
|
39
|
+
render :inline => '<div id="cboxQuestionId">'+@question_group.questions.first.id.to_s+'</div>', :layout => 'surveyor_gui/surveyor_gui_blank'
|
38
40
|
else
|
39
41
|
@title = "Add Question"
|
40
42
|
survey_section_id = question_group_params[:survey_section_id]
|
41
|
-
redirect_to :action => 'new', :controller => 'questions', :layout => 'surveyor_gui_blank', :survey_section_id => survey_section_id
|
43
|
+
redirect_to :action => 'new', :controller => 'questions', :layout => 'surveyor_gui/surveyor_gui_blank', :survey_section_id => survey_section_id
|
42
44
|
end
|
43
45
|
end
|
44
46
|
|
@@ -46,7 +48,7 @@ class QuestionGroupsController < ApplicationController
|
|
46
48
|
@title = "Update Question"
|
47
49
|
@question_group = QuestionGroup.includes(:questions).find(params[:id])
|
48
50
|
if @question_group.update_attributes(question_group_params)
|
49
|
-
render :blank, :layout => 'surveyor_gui_blank'
|
51
|
+
render :blank, :layout => 'surveyor_gui/surveyor_gui_blank'
|
50
52
|
#If a nested question is destroyed, the Question model performs a cascade delete
|
51
53
|
#on the parent QuestionGroup (stuck with this behaviour as it is a Surveyor default).
|
52
54
|
#Need to check for this and restore question group.
|
@@ -58,7 +60,7 @@ class QuestionGroupsController < ApplicationController
|
|
58
60
|
QuestionGroup.create!(scrubbed_params)
|
59
61
|
end
|
60
62
|
else
|
61
|
-
render :action => 'edit', :layout => 'surveyor_gui_blank'
|
63
|
+
render :action => 'edit', :layout => 'surveyor_gui/surveyor_gui_blank'
|
62
64
|
end
|
63
65
|
end
|
64
66
|
|
@@ -81,4 +83,8 @@ class QuestionGroupsController < ApplicationController
|
|
81
83
|
def question_group_params
|
82
84
|
::PermittedParams.new(params[:question_group]).question_group
|
83
85
|
end
|
86
|
+
def question_params
|
87
|
+
params.permit(:survey_section_id, :id, :text, :question_id, :question_type_id, :display_order, :pick, :display_type)
|
88
|
+
end
|
89
|
+
|
84
90
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
class QuestionsController < ApplicationController
|
2
|
-
layout 'surveyor_gui_blank'
|
1
|
+
class SurveyorGui::QuestionsController < ApplicationController
|
2
|
+
layout 'surveyor_gui/surveyor_gui_blank'
|
3
3
|
|
4
4
|
def new
|
5
5
|
@title = "Add Question"
|
@@ -49,10 +49,10 @@ class QuestionsController < ApplicationController
|
|
49
49
|
if @question.save
|
50
50
|
@question.answers.each_with_index {|a, index| a.destroy if index > 0} if @question.pick == 'none'
|
51
51
|
#load any page - if it has no flash errors, the colorbox that contains it will be closed immediately after the page loads
|
52
|
-
render :inline => '<div id="cboxQuestionId">'+@question.id.to_s+'</div>', :layout => 'surveyor_gui_blank'
|
52
|
+
render :inline => '<div id="cboxQuestionId">'+@question.id.to_s+'</div>', :layout => 'surveyor_gui/surveyor_gui_blank'
|
53
53
|
else
|
54
54
|
@title = "Add Question"
|
55
|
-
render :action => 'new', :layout => 'surveyor_gui_blank'
|
55
|
+
render :action => 'new', :layout => 'surveyor_gui/surveyor_gui_blank'
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -62,9 +62,9 @@ class QuestionsController < ApplicationController
|
|
62
62
|
if @question.update_attributes(question_params)
|
63
63
|
@question.answers.each_with_index {|a, index| a.destroy if index > 0} if @question.pick == 'none'
|
64
64
|
#load any page - if it has no flash errors, the colorbox that contains it will be closed immediately after the page loads
|
65
|
-
render :blank, :layout => 'surveyor_gui_blank'
|
65
|
+
render :blank, :layout => 'surveyor_gui/surveyor_gui_blank'
|
66
66
|
else
|
67
|
-
render :action => 'edit', :layout => 'surveyor_gui_blank'
|
67
|
+
render :action => 'edit', :layout => 'surveyor_gui/surveyor_gui_blank'
|
68
68
|
end
|
69
69
|
end
|
70
70
|
|
@@ -6,19 +6,19 @@ class SurveyorGui::ReportsController < ApplicationController
|
|
6
6
|
|
7
7
|
# ReportPreviewWrapper wraps preview in a database transaction so test data is not permanently saved.
|
8
8
|
around_action :wrap_in_transaction, only: :preview
|
9
|
-
layout 'surveyor_gui_default'
|
9
|
+
layout 'surveyor_gui/surveyor_gui_default'
|
10
10
|
|
11
11
|
def preview
|
12
12
|
response_qty = 5
|
13
|
+
user_ids = response_qty.times.map{|i| -1*i}
|
13
14
|
@title = "Preview Report for "+response_qty.to_s+" randomized responses"
|
14
15
|
@survey = Survey.find(params[:survey_id])
|
15
|
-
|
16
|
-
response_qty.times.each {
|
16
|
+
user_ids.each do |user_id|
|
17
17
|
@response_set = ResponseSet.create(survey: @survey, user_id: user_id, test_data: true)
|
18
18
|
ReportResponseGenerator.new(@survey).generate_1_result_set(@response_set)
|
19
|
-
|
20
|
-
@response_sets = ResponseSet.where(survey_id: @survey.id, test_data: true
|
21
|
-
@responses = Response.joins(:response_set, :answer).where('user_id
|
19
|
+
end
|
20
|
+
@response_sets = ResponseSet.where(survey_id: @survey.id, test_data: true).where('user_id in (?)', user_ids)
|
21
|
+
@responses = Response.joins(:response_set, :answer).where('user_id in (?) and survey_id = ? and test_data = ? and answers.is_comment = ?',user_ids,params[:survey_id],true, false)
|
22
22
|
if (!@survey)
|
23
23
|
flash[:notice] = "Survey/Questionnnaire not found."
|
24
24
|
redirect_to :back
|
@@ -2,7 +2,7 @@ class SurveyorGui::ResponsesController < ApplicationController
|
|
2
2
|
include ReportPreviewWrapper
|
3
3
|
# ReportPreviewWrapper wraps preview in a database transaction so test data is not permanently saved.
|
4
4
|
around_action :wrap_in_transaction, only: :preview
|
5
|
-
layout 'surveyor_gui_default'
|
5
|
+
layout 'surveyor_gui/surveyor_gui_default'
|
6
6
|
|
7
7
|
def index
|
8
8
|
@title = "Survey Responses"
|
@@ -16,6 +16,7 @@ class SurveyorGui::ResponsesController < ApplicationController
|
|
16
16
|
@response_set = ResponseSet.create(:survey => @survey, :user_id => user_id, :test_data => true)
|
17
17
|
ReportResponseGenerator.new(@survey).generate_1_result_set(@response_set)
|
18
18
|
@responses = @response_set.responses
|
19
|
+
@response_sets = [@response_set]
|
19
20
|
if (!@survey)
|
20
21
|
flash[:notice] = "Survey/Questionnnaire not found."
|
21
22
|
redirect_to :back
|
@@ -28,6 +29,7 @@ class SurveyorGui::ResponsesController < ApplicationController
|
|
28
29
|
@response_set = ResponseSet.find(params[:id])
|
29
30
|
@survey = @response_set.survey
|
30
31
|
@responses = @response_set.responses
|
32
|
+
@response_sets = [@response_set]
|
31
33
|
if (!@response_set)
|
32
34
|
flash[:error] = "Response not found"
|
33
35
|
redirect_to :back
|
@@ -2,7 +2,7 @@ class SurveyorGui::SurveyController < ApplicationController
|
|
2
2
|
def show
|
3
3
|
@title = "User Will See this Survey"
|
4
4
|
@survey = Survey.find(params[:survey_id])
|
5
|
-
user_id = defined?(current_user) ? current_user.id : 1
|
5
|
+
user_id = defined?(current_user) && current_user ? current_user.id : 1
|
6
6
|
ResponseSet.where('survey_id = ? and test_data = ? and user_id = ?',params[:survey_id],true, user_id).each {|r| r.destroy}
|
7
7
|
@response_set = ResponseSet.create(:survey => @survey, :user_id => user_id, :test_data => true)
|
8
8
|
if (@survey)
|
data/app/controllers/{survey_sections_controller.rb → surveyor_gui/survey_sections_controller.rb}
RENAMED
@@ -1,5 +1,5 @@
|
|
1
|
-
class SurveySectionsController < ApplicationController
|
2
|
-
layout 'surveyor_gui_blank'
|
1
|
+
class SurveyorGui::SurveySectionsController < ApplicationController
|
2
|
+
layout 'surveyor_gui/surveyor_gui_blank'
|
3
3
|
|
4
4
|
def new
|
5
5
|
@title = "Add Survey Section"
|
@@ -28,7 +28,7 @@ class SurveySectionsController < ApplicationController
|
|
28
28
|
if @survey_section.save
|
29
29
|
redirect_to :back
|
30
30
|
else
|
31
|
-
render :action => 'new', :layout => 'surveyor_gui_blank'
|
31
|
+
render :action => 'new', :layout => 'surveyor_gui/surveyor_gui_blank'
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -36,9 +36,9 @@ class SurveySectionsController < ApplicationController
|
|
36
36
|
@title = "Update Survey Section"
|
37
37
|
@survey_section = SurveySection.find(params[:id])
|
38
38
|
if @survey_section.update_attributes(survey_section_params)
|
39
|
-
render :blank, :layout => 'surveyor_gui_blank'
|
39
|
+
render :blank, :layout => 'surveyor_gui/surveyor_gui_blank'
|
40
40
|
else
|
41
|
-
render :action => 'edit', :layout => 'surveyor_gui_blank'
|
41
|
+
render :action => 'edit', :layout => 'surveyor_gui/surveyor_gui_blank'
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module SurveyorControllerCustomMethods
|
2
2
|
def self.included(base)
|
3
|
-
base.send :layout, 'surveyor_modified'
|
3
|
+
base.send :layout, 'surveyor_gui/surveyor_modified'
|
4
4
|
end
|
5
5
|
|
6
6
|
def edit
|
@@ -83,7 +83,7 @@ module SurveyorControllerCustomMethods
|
|
83
83
|
|
84
84
|
end
|
85
85
|
end
|
86
|
-
class SurveyorController < ApplicationController
|
86
|
+
class SurveyorGui::SurveyorController < ApplicationController
|
87
87
|
include Surveyor::SurveyorControllerMethods
|
88
88
|
include SurveyorControllerCustomMethods
|
89
89
|
end
|
@@ -0,0 +1,160 @@
|
|
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
|
+
{dependency: :dependency_conditions},
|
140
|
+
{question_group: :columns}
|
141
|
+
]
|
142
|
+
}
|
143
|
+
},
|
144
|
+
use_dictionary: true
|
145
|
+
end
|
146
|
+
|
147
|
+
def _set_api_keys(cloned_survey)
|
148
|
+
cloned_survey.sections.each do |section|
|
149
|
+
section.questions.each do |question|
|
150
|
+
question.api_id = Surveyor::Common.generate_api_id
|
151
|
+
question.question_group.api_id = Surveyor::Common.generate_api_id if question.part_of_group?
|
152
|
+
question.answers.each do |answer|
|
153
|
+
answer.api_id = Surveyor::Common.generate_api_id
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|