helena 0.3.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.
Files changed (202) hide show
  1. checksums.yaml +7 -0
  2. data/.coveralls.yml +2 -0
  3. data/.gitignore +15 -0
  4. data/.rubocop.yml +16 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +31 -0
  7. data/Gemfile.lock +290 -0
  8. data/LICENSE +16 -0
  9. data/README.md +90 -0
  10. data/Rakefile +29 -0
  11. data/app/assets/images/helena/.keep +0 -0
  12. data/app/assets/images/helena/helena_mobile_view.jpg +0 -0
  13. data/app/assets/images/helena/icons/export.svg +29 -0
  14. data/app/assets/images/helena/swissmadesoftware.png +0 -0
  15. data/app/assets/javascripts/helena/application.js +4 -0
  16. data/app/assets/javascripts/helena/survey.js +2 -0
  17. data/app/assets/stylesheets/helena/admin/labels.css.sass +7 -0
  18. data/app/assets/stylesheets/helena/admin/layout.css.sass +6 -0
  19. data/app/assets/stylesheets/helena/admin/question_groups.css.sass +7 -0
  20. data/app/assets/stylesheets/helena/admin/questions.css.sass +9 -0
  21. data/app/assets/stylesheets/helena/admin/sessions.css.sass +5 -0
  22. data/app/assets/stylesheets/helena/admin/subquestions.css.sass +7 -0
  23. data/app/assets/stylesheets/helena/admin/versions.css.sass +9 -0
  24. data/app/assets/stylesheets/helena/application.css.sass +21 -0
  25. data/app/assets/stylesheets/helena/forms.css.sass +13 -0
  26. data/app/assets/stylesheets/helena/layout.css.sass +3 -0
  27. data/app/assets/stylesheets/helena/question_groups.css.sass +4 -0
  28. data/app/controllers/helena/admin/application_controller.rb +31 -0
  29. data/app/controllers/helena/admin/question_groups_controller.rb +78 -0
  30. data/app/controllers/helena/admin/questions/checkbox_groups_controller.rb +17 -0
  31. data/app/controllers/helena/admin/questions/checkbox_matrix_controller.rb +9 -0
  32. data/app/controllers/helena/admin/questions/long_texts_controller.rb +13 -0
  33. data/app/controllers/helena/admin/questions/radio_groups_controller.rb +17 -0
  34. data/app/controllers/helena/admin/questions/radio_matrix_controller.rb +9 -0
  35. data/app/controllers/helena/admin/questions/short_texts_controller.rb +13 -0
  36. data/app/controllers/helena/admin/questions/static_texts_controller.rb +13 -0
  37. data/app/controllers/helena/admin/questions_controller.rb +105 -0
  38. data/app/controllers/helena/admin/sessions_controller.rb +35 -0
  39. data/app/controllers/helena/admin/surveys_controller.rb +78 -0
  40. data/app/controllers/helena/admin/versions_controller.rb +71 -0
  41. data/app/controllers/helena/application_controller.rb +15 -0
  42. data/app/controllers/helena/concerns/questions/matrix_questions.rb +24 -0
  43. data/app/controllers/helena/sessions_controller.rb +93 -0
  44. data/app/controllers/helena/surveys_controller.rb +11 -0
  45. data/app/helpers/helena/application_helper.rb +4 -0
  46. data/app/models/helena/answer.rb +48 -0
  47. data/app/models/helena/boolean_answer.rb +5 -0
  48. data/app/models/helena/concerns/application_model.rb +19 -0
  49. data/app/models/helena/concerns/questions/requirable.rb +19 -0
  50. data/app/models/helena/concerns/questions/validates_one_label.rb +22 -0
  51. data/app/models/helena/integer_answer.rb +5 -0
  52. data/app/models/helena/label.rb +18 -0
  53. data/app/models/helena/question.rb +63 -0
  54. data/app/models/helena/question_group.rb +18 -0
  55. data/app/models/helena/questions/checkbox_group.rb +17 -0
  56. data/app/models/helena/questions/long_text.rb +9 -0
  57. data/app/models/helena/questions/radio_group.rb +12 -0
  58. data/app/models/helena/questions/radio_matrix.rb +24 -0
  59. data/app/models/helena/questions/short_text.rb +9 -0
  60. data/app/models/helena/questions/static_text.rb +7 -0
  61. data/app/models/helena/session.rb +76 -0
  62. data/app/models/helena/string_answer.rb +5 -0
  63. data/app/models/helena/sub_question.rb +27 -0
  64. data/app/models/helena/survey.rb +29 -0
  65. data/app/models/helena/survey_detail.rb +10 -0
  66. data/app/models/helena/version.rb +33 -0
  67. data/app/views/helena/admin/question_groups/_form.html.haml +3 -0
  68. data/app/views/helena/admin/question_groups/edit.html.haml +3 -0
  69. data/app/views/helena/admin/question_groups/index.html.haml +41 -0
  70. data/app/views/helena/admin/question_groups/new.html.haml +3 -0
  71. data/app/views/helena/admin/questions/_form.html.haml +15 -0
  72. data/app/views/helena/admin/questions/_labels.html.haml +24 -0
  73. data/app/views/helena/admin/questions/_sub_questions.html.haml +32 -0
  74. data/app/views/helena/admin/questions/edit.html.haml +3 -0
  75. data/app/views/helena/admin/questions/index.html.haml +49 -0
  76. data/app/views/helena/admin/questions/new.html.haml +3 -0
  77. data/app/views/helena/admin/sessions/index.html.haml +46 -0
  78. data/app/views/helena/admin/surveys/_form.html.haml +10 -0
  79. data/app/views/helena/admin/surveys/edit.html.haml +5 -0
  80. data/app/views/helena/admin/surveys/index.html.haml +35 -0
  81. data/app/views/helena/admin/surveys/new.html.haml +3 -0
  82. data/app/views/helena/admin/versions/_form.html.haml +5 -0
  83. data/app/views/helena/admin/versions/default_session_report.html.haml +17 -0
  84. data/app/views/helena/admin/versions/edit.html.haml +3 -0
  85. data/app/views/helena/admin/versions/index.html.haml +35 -0
  86. data/app/views/helena/admin/versions/new.html.haml +3 -0
  87. data/app/views/helena/questions/_checkbox_group.html.haml +17 -0
  88. data/app/views/helena/questions/_long_text.html.haml +8 -0
  89. data/app/views/helena/questions/_radio_group.html.haml +13 -0
  90. data/app/views/helena/questions/_radio_matrix.html.haml +27 -0
  91. data/app/views/helena/questions/_short_text.html.haml +8 -0
  92. data/app/views/helena/sessions/edit.html.haml +16 -0
  93. data/app/views/helena/sessions/end_message.html.haml +5 -0
  94. data/app/views/helena/surveys/_survey.html.haml +3 -0
  95. data/app/views/helena/surveys/index.html.haml +2 -0
  96. data/bin/rails +8 -0
  97. data/config/i18n-tasks.yml +3 -0
  98. data/config/initializers/simple_form.rb +162 -0
  99. data/config/initializers/simple_form_bootstrap.rb +132 -0
  100. data/config/locales/en.yml +20 -0
  101. data/config/locales/models/label/en.yml +14 -0
  102. data/config/locales/models/question/en.yml +47 -0
  103. data/config/locales/models/question_group/en.yml +11 -0
  104. data/config/locales/models/session/en.yml +10 -0
  105. data/config/locales/models/sub_question/en.yml +14 -0
  106. data/config/locales/models/survey/en.yml +6 -0
  107. data/config/locales/models/version/en.yml +12 -0
  108. data/config/locales/simple_form.en.yml +26 -0
  109. data/config/locales/views/admin/question_groups/en.yml +12 -0
  110. data/config/locales/views/admin/questions/en.yml +16 -0
  111. data/config/locales/views/admin/sessions/en.yml +11 -0
  112. data/config/locales/views/admin/surveys/en.yml +10 -0
  113. data/config/locales/views/admin/versions/en.yml +8 -0
  114. data/config/locales/views/sessions/en.yml +9 -0
  115. data/config/routes.rb +28 -0
  116. data/db/seeds.rb +182 -0
  117. data/gpl-3.0.txt +674 -0
  118. data/helena.gemspec +40 -0
  119. data/lib/helena/engine.rb +6 -0
  120. data/lib/helena/version.rb +3 -0
  121. data/lib/helena/version_publisher.rb +16 -0
  122. data/lib/helena.rb +10 -0
  123. data/lib/tasks/helena_tasks.rake +4 -0
  124. data/lib/templates/erb/scaffold/_form.html.erb +13 -0
  125. data/spec/controllers/helena/admin/question_group_controller_spec.rb +59 -0
  126. data/spec/controllers/helena/admin/questions_controller_spec.rb +60 -0
  127. data/spec/controllers/helena/admin/sessions_controller_spec.rb +84 -0
  128. data/spec/controllers/helena/admin/survey_controller_spec.rb +89 -0
  129. data/spec/controllers/helena/admin/versions_controller_spec.rb +19 -0
  130. data/spec/controllers/helena/application_controller_spec.rb +15 -0
  131. data/spec/controllers/helena/sessions_controller_spec.rb +24 -0
  132. data/spec/dummy/README.rdoc +28 -0
  133. data/spec/dummy/Rakefile +6 -0
  134. data/spec/dummy/app/assets/images/.keep +0 -0
  135. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  136. data/spec/dummy/app/controllers/application_controller.rb +9 -0
  137. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  138. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  139. data/spec/dummy/app/mailers/.keep +0 -0
  140. data/spec/dummy/app/models/.keep +0 -0
  141. data/spec/dummy/app/models/concerns/.keep +0 -0
  142. data/spec/dummy/app/views/layouts/application.html.haml +24 -0
  143. data/spec/dummy/bin/bundle +3 -0
  144. data/spec/dummy/bin/rails +4 -0
  145. data/spec/dummy/bin/rake +4 -0
  146. data/spec/dummy/config/application.rb +27 -0
  147. data/spec/dummy/config/boot.rb +5 -0
  148. data/spec/dummy/config/environment.rb +5 -0
  149. data/spec/dummy/config/environments/development.rb +29 -0
  150. data/spec/dummy/config/environments/production.rb +80 -0
  151. data/spec/dummy/config/environments/test.rb +36 -0
  152. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  153. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  154. data/spec/dummy/config/initializers/session_store.rb +3 -0
  155. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  156. data/spec/dummy/config/locales/en.yml +23 -0
  157. data/spec/dummy/config/mongoid.yml +14 -0
  158. data/spec/dummy/config/routes.rb +4 -0
  159. data/spec/dummy/config.ru +4 -0
  160. data/spec/dummy/db/seeds.rb +1 -0
  161. data/spec/dummy/lib/assets/.keep +0 -0
  162. data/spec/dummy/log/.keep +0 -0
  163. data/spec/dummy/public/404.html +58 -0
  164. data/spec/dummy/public/422.html +58 -0
  165. data/spec/dummy/public/500.html +57 -0
  166. data/spec/dummy/public/favicon.ico +0 -0
  167. data/spec/factories/helena/answers.rb +24 -0
  168. data/spec/factories/helena/labels.rb +7 -0
  169. data/spec/factories/helena/question_groups.rb +6 -0
  170. data/spec/factories/helena/questions.rb +14 -0
  171. data/spec/factories/helena/sessions.rb +9 -0
  172. data/spec/factories/helena/sub_questions.rb +7 -0
  173. data/spec/factories/helena/survey_details.rb +6 -0
  174. data/spec/factories/helena/surveys.rb +7 -0
  175. data/spec/factories/helena/versions.rb +11 -0
  176. data/spec/features/helena/admin/manage_question_group_spec.rb +101 -0
  177. data/spec/features/helena/admin/manage_question_spec.rb +105 -0
  178. data/spec/features/helena/admin/manage_session_spec.rb +40 -0
  179. data/spec/features/helena/admin/manage_survey_spec.rb +141 -0
  180. data/spec/features/helena/admin/manage_version_spec.rb +74 -0
  181. data/spec/features/helena/admin/question_types/manage_checkbox_group_question_spec.rb +55 -0
  182. data/spec/features/helena/admin/question_types/manage_long_text_question_spec.rb +21 -0
  183. data/spec/features/helena/admin/question_types/manage_radio_group_question_spec.rb +59 -0
  184. data/spec/features/helena/admin/question_types/manage_radio_matrix_question_spec.rb +80 -0
  185. data/spec/features/helena/admin/question_types/manage_short_text_question_spec.rb +19 -0
  186. data/spec/features/helena/admin/question_types/manage_static_text_question_spec.rb +17 -0
  187. data/spec/features/helena/manage_session_spec.rb +284 -0
  188. data/spec/features/helena/manage_survey_spec.rb +24 -0
  189. data/spec/lib/version_publisher_spec.rb +26 -0
  190. data/spec/models/helena/answer_spec.rb +53 -0
  191. data/spec/models/helena/label_spec.rb +13 -0
  192. data/spec/models/helena/question_group_spec.rb +11 -0
  193. data/spec/models/helena/question_spec.rb +21 -0
  194. data/spec/models/helena/questions/radio_group_spec.rb +32 -0
  195. data/spec/models/helena/questions/radio_matrix_spec.rb +32 -0
  196. data/spec/models/helena/questions/short_text_spec.rb +10 -0
  197. data/spec/models/helena/session_spec.rb +20 -0
  198. data/spec/models/helena/sub_question_spec.rb +28 -0
  199. data/spec/models/helena/survey_spec.rb +14 -0
  200. data/spec/models/helena/version_spec.rb +15 -0
  201. data/spec/spec_helper.rb +43 -0
  202. metadata +485 -0
@@ -0,0 +1,31 @@
1
+ module Helena
2
+ module Admin
3
+ class ApplicationController < Helena::ApplicationController
4
+ before_filter :authenticate_administrator
5
+
6
+ def notify_successful_create_for(resource_name)
7
+ flash[:notice] = t('actions.created', resource: resource_name)
8
+ end
9
+
10
+ def notify_successful_update_for(resource_name)
11
+ flash[:notice] = t('actions.updated', resource: resource_name)
12
+ end
13
+
14
+ def notify_successful_delete_for(resource_name)
15
+ flash[:notice] = t('actions.deleted', resource: resource_name)
16
+ end
17
+
18
+ def notify_error(resource = nil)
19
+ flash[:error] = []
20
+ if resource
21
+
22
+ resource.errors.full_messages.each do |message|
23
+ flash[:error] << message
24
+ end
25
+ else
26
+ flash[:error] << t('actions.error')
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,78 @@
1
+ module Helena
2
+ module Admin
3
+ class QuestionGroupsController < Admin::ApplicationController
4
+ respond_to :html
5
+
6
+ before_filter :load_resources, :add_breadcrumbs
7
+ before_filter :find_question_group, only: [:edit, :destroy, :move_up, :move_down]
8
+
9
+ def index
10
+ @question_groups = @version.question_groups.asc(:position)
11
+ end
12
+
13
+ def new
14
+ add_breadcrumb t('helena.admin.question_groups.new.new')
15
+ @question_group = @version.question_groups.new
16
+ end
17
+
18
+ def create
19
+ add_breadcrumb t('helena.admin.question_groups.create.new')
20
+
21
+ @question_group = @version.question_groups.new question_group_params
22
+
23
+ if @question_group.save
24
+ notify_successful_create_for(@question_group.title)
25
+ end
26
+ respond_with @question_group, location: admin_survey_question_groups_path(@survey)
27
+ end
28
+
29
+ def edit
30
+ add_breadcrumb @question_group.title
31
+ end
32
+
33
+ def update
34
+ @question_group = @version.question_groups.find(params[:id])
35
+
36
+ if @question_group.update_attributes question_group_params
37
+ notify_successful_update_for(@question_group.title)
38
+ end
39
+ respond_with @question_group, location: admin_survey_question_groups_path(@survey)
40
+ end
41
+
42
+ def destroy
43
+ notify_successful_delete_for(@question_group.title) if @question_group.destroy
44
+ respond_with @question_group, location: admin_survey_question_groups_path(@survey)
45
+ end
46
+
47
+ def move_up
48
+ @question_group.move_to! :higher
49
+ respond_with @survey, location: admin_survey_question_groups_path(@survey)
50
+ end
51
+
52
+ def move_down
53
+ @question_group.move_to! :lower
54
+ respond_with @survey, location: admin_survey_question_groups_path(@survey)
55
+ end
56
+
57
+ private
58
+
59
+ def load_resources
60
+ @survey = Helena::Survey.find params['survey_id']
61
+ @version = @survey.versions.find_by(version: 0)
62
+ end
63
+
64
+ def find_question_group
65
+ @question_group = @version.question_groups.find(params[:id])
66
+ end
67
+
68
+ def add_breadcrumbs
69
+ add_breadcrumb Helena::Survey.model_name.human(count: 2), :admin_surveys_path
70
+ add_breadcrumb @survey.name, admin_survey_question_groups_path(@survey)
71
+ end
72
+
73
+ def question_group_params
74
+ params.require(:question_group).permit(:title)
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,17 @@
1
+ module Helena
2
+ module Admin
3
+ module Questions
4
+ class CheckboxGroupsController < Admin::QuestionsController
5
+ private
6
+
7
+ def add_ressources
8
+ @question.sub_questions.build
9
+ end
10
+
11
+ def permited_params
12
+ [:required, sub_questions_attributes: sub_questions_attributes]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Helena
2
+ module Admin
3
+ module Questions
4
+ class CheckboxMatrixController < Admin::QuestionsController
5
+ include Helena::Concerns::Questions::MatrixQuestions
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Helena
2
+ module Admin
3
+ module Questions
4
+ class LongTextsController < Admin::QuestionsController
5
+ private
6
+
7
+ def permited_params
8
+ [:default_value, :required]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ module Helena
2
+ module Admin
3
+ module Questions
4
+ class RadioGroupsController < Admin::QuestionsController
5
+ private
6
+
7
+ def add_ressources
8
+ @question.labels.build
9
+ end
10
+
11
+ def permited_params
12
+ [:required, labels_attributes: labels_attributes]
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Helena
2
+ module Admin
3
+ module Questions
4
+ class RadioMatrixController < Admin::QuestionsController
5
+ include Helena::Concerns::Questions::MatrixQuestions
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Helena
2
+ module Admin
3
+ module Questions
4
+ class ShortTextsController < Admin::QuestionsController
5
+ private
6
+
7
+ def permited_params
8
+ [:default_value, :required]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module Helena
2
+ module Admin
3
+ module Questions
4
+ class StaticTextsController < Admin::QuestionsController
5
+ private
6
+
7
+ def permited_params
8
+ [:default_value, :required]
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,105 @@
1
+ module Helena
2
+ module Admin
3
+ class QuestionsController < Admin::ApplicationController
4
+ respond_to :html
5
+
6
+ before_filter :load_resources, :add_breadcrumbs
7
+ before_filter :load_question, only: [:edit, :update, :destroy, :move_up, :move_down]
8
+
9
+ def index
10
+ @questions = @question_group.questions.asc :position
11
+ end
12
+
13
+ def new
14
+ @question = @question_group.questions.new
15
+ end
16
+
17
+ def create
18
+ @question = @question_group.questions.new question_params
19
+
20
+ if @question.save
21
+ notify_successful_create_for(@question.code)
22
+ location = [:admin, @survey, @question_group, :questions]
23
+ else
24
+ notify_error(@question)
25
+ location = [:new, :admin, @survey, @question_group, @question]
26
+ end
27
+ respond_with @question, location: location
28
+ end
29
+
30
+ def edit
31
+ add_ressources
32
+ end
33
+
34
+ def update
35
+ if @question.update_attributes question_params
36
+ notify_successful_update_for(@question.code)
37
+ else
38
+ notify_error @question
39
+ add_breadcrumb @question.code_was
40
+ end
41
+ add_ressources
42
+ respond_with @question, location: [:edit, :admin, @survey, @question_group, @question]
43
+ end
44
+
45
+ def destroy
46
+ notify_successful_delete_for(@question.code) if @question.destroy
47
+ respond_with @question, location: admin_survey_question_group_questions_path(@survey, @question_group)
48
+ end
49
+
50
+ def move_up
51
+ @question.move_to! :higher
52
+ respond_with @question, location: admin_survey_question_group_questions_path(@survey, @question_group)
53
+ end
54
+
55
+ def move_down
56
+ @question.move_to! :lower
57
+ respond_with @question, location: admin_survey_question_group_questions_path(@survey, @question_group)
58
+ end
59
+
60
+ private
61
+
62
+ def load_resources
63
+ @survey = Helena::Survey.find params['survey_id']
64
+ @version = @survey.versions.find_by(version: 0)
65
+ @question_group = @version.question_groups.find params[:question_group_id]
66
+ end
67
+
68
+ def add_breadcrumbs
69
+ add_breadcrumb Helena::Survey.model_name.human(count: 2), :admin_surveys_path
70
+ add_breadcrumb @survey.name, admin_survey_question_groups_path(@survey)
71
+ add_breadcrumb @question_group.title, admin_survey_question_group_questions_path(@survey, @question_group)
72
+ add_breadcrumb t('helena.admin.questions.new') if action_name == 'new' || action_name == 'create'
73
+ end
74
+
75
+ def question_params
76
+ required_param.permit(permited_params + [:question_text, :code, :_type])
77
+ end
78
+
79
+ def required_param
80
+ param_name = self.class == Helena::Admin::QuestionsController ? :question : "questions_#{controller_name.singularize}"
81
+ params.require(param_name)
82
+ end
83
+
84
+ def permited_params
85
+ []
86
+ end
87
+
88
+ def load_question
89
+ @question = @question_group.questions.find(params[:id])
90
+ add_breadcrumb @question.code
91
+ end
92
+
93
+ def add_ressources
94
+ end
95
+
96
+ def labels_attributes
97
+ [:id, :position, :text, :value, :preselected, :_destroy]
98
+ end
99
+
100
+ def sub_questions_attributes
101
+ [:id, :position, :code, :text, :value, :preselected, :_destroy]
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,35 @@
1
+ module Helena
2
+ module Admin
3
+ class SessionsController < Admin::ApplicationController
4
+ respond_to :html
5
+
6
+ before_filter :load_survey, :add_breadcrumbs
7
+
8
+ def index
9
+ respond_to do |format|
10
+ @sessions = @survey.sessions.desc(:created_at)
11
+ format.html
12
+ format.json { render json: @sessions }
13
+ format.csv { render text: @sessions.to_csv }
14
+ end
15
+ end
16
+
17
+ def destroy
18
+ @session = @survey.sessions.find_by id: params[:id]
19
+ notify_successful_delete_for(@session.token) if @session.destroy
20
+ respond_with @session, location: admin_survey_sessions_path(@survey)
21
+ end
22
+
23
+ private
24
+
25
+ def load_survey
26
+ @survey = Helena::Survey.find params['survey_id']
27
+ end
28
+
29
+ def add_breadcrumbs
30
+ add_breadcrumb Helena::Survey.model_name.human(count: 2), :admin_surveys_path
31
+ add_breadcrumb @survey.name, admin_survey_sessions_path(@survey)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,78 @@
1
+ require_dependency 'helena/application_controller'
2
+
3
+ module Helena
4
+ module Admin
5
+ class SurveysController < Admin::ApplicationController
6
+ respond_to :html
7
+
8
+ before_filter :add_breadcrumbs
9
+ before_filter :load_survey, only: [:edit, :update, :move_up, :move_down, :destroy]
10
+
11
+ def index
12
+ @surveys = Helena::Survey.asc :position
13
+ end
14
+
15
+ def new
16
+ add_breadcrumb t('helena.admin.surveys.new')
17
+ @survey = Helena::Survey.new
18
+ @survey.versions.build version: 0, survey_detail: Helena::SurveyDetail.new
19
+ end
20
+
21
+ def create
22
+ add_breadcrumb t('helena.admin.surveys.new')
23
+
24
+ @survey = Helena::Survey.new survey_params
25
+
26
+ if @survey.save
27
+ notify_successful_create_for(@survey.name)
28
+ else
29
+ notify_error
30
+ end
31
+ respond_with @survey, location: admin_surveys_path
32
+ end
33
+
34
+ def edit
35
+ add_breadcrumb @survey.name
36
+ end
37
+
38
+ def update
39
+ if @survey.update_attributes survey_params
40
+ notify_successful_update_for(@survey.name)
41
+ else
42
+ notify_error @survey
43
+ add_breadcrumb @survey.name_was
44
+ end
45
+ respond_with @survey, location: admin_surveys_path
46
+ end
47
+
48
+ def move_up
49
+ @survey.move_to! :higher
50
+ respond_with @survey, location: admin_surveys_path
51
+ end
52
+
53
+ def move_down
54
+ @survey.move_to! :lower
55
+ respond_with @survey, location: admin_surveys_path
56
+ end
57
+
58
+ def destroy
59
+ notify_successful_delete_for(@survey.name) if @survey.destroy
60
+ respond_with @survey, location: admin_surveys_path
61
+ end
62
+
63
+ private
64
+
65
+ def add_breadcrumbs
66
+ add_breadcrumb Helena::Survey.model_name.human(count: 2), :admin_surveys_path
67
+ end
68
+
69
+ def survey_params
70
+ params.require(:survey).permit(:name, :tag_list, :language, versions_attributes: [:version, :id, survey_detail_attributes: [:title, :description]])
71
+ end
72
+
73
+ def load_survey
74
+ @survey = Helena::Survey.find params[:id]
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,71 @@
1
+ require_dependency 'helena/application_controller'
2
+
3
+ module Helena
4
+ module Admin
5
+ class VersionsController < Admin::ApplicationController
6
+ respond_to :html
7
+
8
+ before_filter :load_survey, :add_breadcrumbs
9
+ before_filter :build_version, only: [:new, :create]
10
+ before_filter :load_version, only: [:edit, :update]
11
+
12
+ def index
13
+ @versions = @survey.versions.without_base
14
+ end
15
+
16
+ def new
17
+ end
18
+
19
+ def create
20
+ @version.update_attributes(version_params)
21
+ @version.save
22
+ notify_successful_create_for(@version.version)
23
+ respond_with @version, location: admin_survey_versions_path(@survey)
24
+ end
25
+
26
+ def edit
27
+ end
28
+
29
+ def update
30
+ @version.update_attributes version_params
31
+ notify_successful_update_for(@version.version)
32
+ respond_with @version, location: admin_survey_versions_path(@survey)
33
+ end
34
+
35
+ def destroy
36
+ @version = @survey.versions.find_by id: params[:id]
37
+ notify_successful_delete_for(@version.version) if @version.destroy && Helena::Session.where(version: @version).destroy
38
+ respond_with @version, location: admin_survey_versions_path(@survey)
39
+ end
40
+
41
+ private
42
+
43
+ def load_survey
44
+ @survey = Helena::Survey.find(params[:survey_id])
45
+ end
46
+
47
+ def load_version
48
+ @version = @survey.versions.find(params[:id])
49
+ end
50
+
51
+ def add_breadcrumbs
52
+ add_breadcrumb Helena::Survey.model_name.human(count: 2), :admin_surveys_path
53
+ add_breadcrumb @survey.name, admin_survey_versions_path(@survey)
54
+ end
55
+
56
+ def version_params
57
+ params.require(:version).permit(:notes, :session_report)
58
+ end
59
+
60
+ def default_session_report
61
+ render_to_string 'default_session_report', layout: false
62
+ end
63
+
64
+ def build_version
65
+ base_version = @survey.versions.find_by(version: 0)
66
+ @version = Helena::VersionPublisher.publish(base_version)
67
+ @version.session_report = @survey.reload.versions.last.session_report || default_session_report
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,15 @@
1
+ module Helena
2
+ class ApplicationController < ::ApplicationController
3
+ helper Helena::Engine.helpers
4
+
5
+ helper_method :can_administer?
6
+
7
+ def authenticate_administrator
8
+ fail(ActionController::RoutingError, 'Access Denied') unless can_administer?
9
+ end
10
+
11
+ def add_breadcrumb(name, path = nil, options = {})
12
+ super(name.presence || t('shared.untitled'), path, options)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,24 @@
1
+ module Helena
2
+ module Concerns
3
+ module Questions
4
+ module MatrixQuestions
5
+ extend ActiveSupport::Concern
6
+
7
+ def includes_labels?
8
+ true
9
+ end
10
+
11
+ private
12
+
13
+ def add_ressources
14
+ @question.labels.build
15
+ @question.sub_questions.build
16
+ end
17
+
18
+ def permited_params
19
+ [:required, labels_attributes: labels_attributes, sub_questions_attributes: sub_questions_attributes]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,93 @@
1
+ module Helena
2
+ class SessionsController < ApplicationController
3
+ respond_to :html
4
+
5
+ before_filter :load_session, only: [:edit, :update]
6
+
7
+ def show
8
+ @session = Helena::Session.find_by view_token: params[:token]
9
+ @survey = @session.survey
10
+ @version = @survey.versions.find @session.version_id
11
+ @question_group = question_group
12
+
13
+ respond_to do |format|
14
+ format.html { render html: @version.session_report.html_safe, layout: true }
15
+ format.json { render json: @session }
16
+ end
17
+ end
18
+
19
+ def edit
20
+ @questions = question_group_questions
21
+ @answers = session_answers
22
+ @errors = {}
23
+ end
24
+
25
+ def update
26
+ @answers = update_answers
27
+ @errors = answer_errors
28
+
29
+ if @question_group.last? && @errors.blank?
30
+ @session.update_attribute :completed, true
31
+ render 'end_message'
32
+ else
33
+ @question_group = @question_group.next_item if @errors.blank?
34
+ @questions = question_group_questions
35
+ render 'edit'
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def load_session
42
+ @session = Helena::Session.find_by token: params[:token]
43
+ @survey = @session.survey
44
+ @version = @survey.versions.find @session.version_id
45
+ @question_group = question_group
46
+ end
47
+
48
+ def question_group
49
+ if params[:question_group]
50
+ @version.question_groups.find params[:question_group]
51
+ else
52
+ @version.question_groups.asc(:position).first
53
+ end
54
+ end
55
+
56
+ def session_answers
57
+ Hash[@session.answers.map { |answer| [answer.code, answer.value] }]
58
+ end
59
+
60
+ def session_params
61
+ return unless params[:session]
62
+ params.require(:session).permit(answers: @question_group.question_codes, question_types: @question_group.question_codes)
63
+ end
64
+
65
+ def question_group_questions
66
+ @question_group.questions.asc(:position)
67
+ end
68
+
69
+ def update_answers
70
+ @question_group.question_codes.each do |question_code|
71
+ @session.answers.where(code: question_code).delete
72
+
73
+ value = session_params[:answers][question_code] if session_params
74
+
75
+ next if value.blank?
76
+
77
+ answer = Helena::Answer.build_generic(question_code, value, request.remote_ip)
78
+ @session.answers << answer
79
+ end
80
+ session_answers
81
+ end
82
+
83
+ def answer_errors
84
+ errors = {}
85
+ @question_group.questions.where(required: true).each do |question|
86
+ question.validate_answers_in(session_answers).each do |question_code, error_message|
87
+ errors[question_code] = t("errors.messages.#{error_message}")
88
+ end
89
+ end
90
+ errors
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,11 @@
1
+ require_dependency 'helena/application_controller'
2
+
3
+ module Helena
4
+ class SurveysController < ApplicationController
5
+ respond_to :html, :json
6
+
7
+ def index
8
+ @surveys = Helena::Survey.all
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,4 @@
1
+ module Helena
2
+ module ApplicationHelper
3
+ end
4
+ end