helena_administration 0.0.2

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 (173) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rubocop.yml +18 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +44 -0
  6. data/Gemfile.lock +309 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.md +82 -0
  9. data/Rakefile +28 -0
  10. data/app/assets/images/helena_administration/.keep +0 -0
  11. data/app/assets/javascripts/helena_administration.js.coffee +20 -0
  12. data/app/assets/javascripts/polyfills.js +10 -0
  13. data/app/assets/stylesheets/_dashboard.sass +4 -0
  14. data/app/assets/stylesheets/_layout.sass +50 -0
  15. data/app/assets/stylesheets/_media_queries.scss +18 -0
  16. data/app/assets/stylesheets/_variables.sass +19 -0
  17. data/app/assets/stylesheets/helena_administration.css.sass +27 -0
  18. data/app/controllers/helena_administration/application_controller.rb +19 -0
  19. data/app/controllers/helena_administration/dashboard_controller.rb +11 -0
  20. data/app/controllers/helena_administration/import_surveys_controller.rb +40 -0
  21. data/app/controllers/helena_administration/question_groups_controller.rb +68 -0
  22. data/app/controllers/helena_administration/questions/checkbox_groups_controller.rb +15 -0
  23. data/app/controllers/helena_administration/questions/checkbox_matrix_controller.rb +7 -0
  24. data/app/controllers/helena_administration/questions/long_texts_controller.rb +11 -0
  25. data/app/controllers/helena_administration/questions/radio_groups_controller.rb +15 -0
  26. data/app/controllers/helena_administration/questions/radio_matrix_controller.rb +7 -0
  27. data/app/controllers/helena_administration/questions/short_texts_controller.rb +11 -0
  28. data/app/controllers/helena_administration/questions/static_texts_controller.rb +11 -0
  29. data/app/controllers/helena_administration/questions_controller.rb +96 -0
  30. data/app/controllers/helena_administration/sessions_controller.rb +60 -0
  31. data/app/controllers/helena_administration/surveys_controller.rb +71 -0
  32. data/app/controllers/helena_administration/versions_controller.rb +82 -0
  33. data/app/helpers/helena_administration/application_helper.rb +14 -0
  34. data/app/models/helena_administration/import_survey_form.rb +9 -0
  35. data/app/views/helena_administration/application/_chromeframe.html.slim +4 -0
  36. data/app/views/helena_administration/application/_flash_messages.html.haml +5 -0
  37. data/app/views/helena_administration/application/_head.html.slim +13 -0
  38. data/app/views/helena_administration/application/_header.html.slim +16 -0
  39. data/app/views/helena_administration/dashboard/index.html.slim +14 -0
  40. data/app/views/helena_administration/import_surveys/_form.html.slim +11 -0
  41. data/app/views/helena_administration/import_surveys/new.html.slim +1 -0
  42. data/app/views/helena_administration/kaminari/_first_page.html.slim +2 -0
  43. data/app/views/helena_administration/kaminari/_gap.html.slim +2 -0
  44. data/app/views/helena_administration/kaminari/_last_page.html.slim +2 -0
  45. data/app/views/helena_administration/kaminari/_next_page.html.slim +2 -0
  46. data/app/views/helena_administration/kaminari/_page.html.slim +2 -0
  47. data/app/views/helena_administration/kaminari/_paginator.html.slim +11 -0
  48. data/app/views/helena_administration/kaminari/_prev_page.html.slim +2 -0
  49. data/app/views/helena_administration/layouts/application.html.slim +13 -0
  50. data/app/views/helena_administration/question_groups/_form.html.slim +5 -0
  51. data/app/views/helena_administration/question_groups/edit.html.slim +1 -0
  52. data/app/views/helena_administration/question_groups/new.html.slim +1 -0
  53. data/app/views/helena_administration/question_groups/show.html.slim +60 -0
  54. data/app/views/helena_administration/questions/_form.html.slim +15 -0
  55. data/app/views/helena_administration/questions/_labels.html.slim +24 -0
  56. data/app/views/helena_administration/questions/_sub_questions.html.slim +32 -0
  57. data/app/views/helena_administration/questions/edit.html.slim +1 -0
  58. data/app/views/helena_administration/questions/new.html.slim +1 -0
  59. data/app/views/helena_administration/questions/show.html.slim +26 -0
  60. data/app/views/helena_administration/sessions/_form.html.slim +8 -0
  61. data/app/views/helena_administration/sessions/edit.html.slim +1 -0
  62. data/app/views/helena_administration/surveys/_form.html.slim +5 -0
  63. data/app/views/helena_administration/surveys/edit.html.slim +1 -0
  64. data/app/views/helena_administration/surveys/index.html.slim +34 -0
  65. data/app/views/helena_administration/surveys/new.html.slim +1 -0
  66. data/app/views/helena_administration/surveys/show.html.slim +120 -0
  67. data/app/views/helena_administration/versions/_form.html.slim +14 -0
  68. data/app/views/helena_administration/versions/edit.html.slim +1 -0
  69. data/app/views/helena_administration/versions/new.html.slim +1 -0
  70. data/app/views/helena_administration/versions/show.html.slim +68 -0
  71. data/app/views/layouts/helena_administration/application.html.slim +10 -0
  72. data/bin/rails +12 -0
  73. data/config/compass.rb +2 -0
  74. data/config/html5_rails.yml +26 -0
  75. data/config/locales/en.yml +21 -0
  76. data/config/locales/views/dashboard.en.yml +6 -0
  77. data/config/locales/views/import_surveys.en.yml +11 -0
  78. data/config/locales/views/question_groups.en.yml +5 -0
  79. data/config/locales/views/questions.en.yml +5 -0
  80. data/config/locales/views/surveys.en.yml +10 -0
  81. data/config/locales/views/versions.en.yml +11 -0
  82. data/config/routes.rb +24 -0
  83. data/coverage/.resultset.json.lock +0 -0
  84. data/coverage/assets/0.8.0/application.css +799 -0
  85. data/coverage/assets/0.8.0/application.js +1559 -0
  86. data/coverage/assets/0.8.0/colorbox/border.png +0 -0
  87. data/coverage/assets/0.8.0/colorbox/controls.png +0 -0
  88. data/coverage/assets/0.8.0/colorbox/loading.gif +0 -0
  89. data/coverage/assets/0.8.0/colorbox/loading_background.png +0 -0
  90. data/coverage/assets/0.8.0/favicon_green.png +0 -0
  91. data/coverage/assets/0.8.0/favicon_red.png +0 -0
  92. data/coverage/assets/0.8.0/favicon_yellow.png +0 -0
  93. data/coverage/assets/0.8.0/loading.gif +0 -0
  94. data/coverage/assets/0.8.0/magnify.png +0 -0
  95. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  96. data/coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  97. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  98. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  99. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  100. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  101. data/coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  102. data/coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  103. data/coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png +0 -0
  104. data/coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  105. data/coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png +0 -0
  106. data/coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png +0 -0
  107. data/coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  108. data/helena_administration.gemspec +37 -0
  109. data/lib/helena_administration/engine.rb +13 -0
  110. data/lib/helena_administration/version.rb +3 -0
  111. data/lib/helena_administration.rb +15 -0
  112. data/lib/tasks/helena_administration_tasks.rake +4 -0
  113. data/spec/controllers/dashboard_controller_spec.rb +11 -0
  114. data/spec/controllers/sessions_controller_spec.rb +102 -0
  115. data/spec/controllers/survey_controller_spec.rb +36 -0
  116. data/spec/dummy/README.rdoc +28 -0
  117. data/spec/dummy/Rakefile +6 -0
  118. data/spec/dummy/app/assets/images/.keep +0 -0
  119. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  120. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  121. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  122. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  123. data/spec/dummy/app/decorators/controllers/helena_administration/application_controller_decorator.rb +5 -0
  124. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  125. data/spec/dummy/app/mailers/.keep +0 -0
  126. data/spec/dummy/app/models/.keep +0 -0
  127. data/spec/dummy/app/models/concerns/.keep +0 -0
  128. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  129. data/spec/dummy/bin/bundle +3 -0
  130. data/spec/dummy/bin/rails +4 -0
  131. data/spec/dummy/bin/rake +4 -0
  132. data/spec/dummy/config/application.rb +27 -0
  133. data/spec/dummy/config/boot.rb +5 -0
  134. data/spec/dummy/config/environment.rb +5 -0
  135. data/spec/dummy/config/environments/development.rb +34 -0
  136. data/spec/dummy/config/environments/production.rb +78 -0
  137. data/spec/dummy/config/environments/test.rb +39 -0
  138. data/spec/dummy/config/initializers/assets.rb +9 -0
  139. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  140. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  141. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  142. data/spec/dummy/config/initializers/inflections.rb +16 -0
  143. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  144. data/spec/dummy/config/initializers/session_store.rb +3 -0
  145. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  146. data/spec/dummy/config/locales/en.yml +23 -0
  147. data/spec/dummy/config/mongoid.yml +13 -0
  148. data/spec/dummy/config/routes.rb +4 -0
  149. data/spec/dummy/config/secrets.yml +22 -0
  150. data/spec/dummy/config.ru +4 -0
  151. data/spec/dummy/lib/assets/.keep +0 -0
  152. data/spec/dummy/log/.keep +0 -0
  153. data/spec/dummy/public/404.html +67 -0
  154. data/spec/dummy/public/422.html +67 -0
  155. data/spec/dummy/public/500.html +66 -0
  156. data/spec/dummy/public/favicon.ico +0 -0
  157. data/spec/features/dashboard/index.html.slim_spec.rb +9 -0
  158. data/spec/features/question_groups/manage_question_groups_spec.rb +97 -0
  159. data/spec/features/questions/manage_questions_spec.rb +108 -0
  160. data/spec/features/questions/question_types/manage_checkbox_group_question_spec.rb +53 -0
  161. data/spec/features/questions/question_types/manage_long_text_question_spec.rb +22 -0
  162. data/spec/features/questions/question_types/manage_radio_group_question_spec.rb +57 -0
  163. data/spec/features/questions/question_types/manage_radio_matrix_question_spec.rb +78 -0
  164. data/spec/features/questions/question_types/manage_short_text_question_spec.rb +20 -0
  165. data/spec/features/questions/question_types/manage_static_text_question_spec.rb +18 -0
  166. data/spec/features/sessions/manage_sessions_spec.rb +51 -0
  167. data/spec/features/surveys/manage_survey_spec.rb +95 -0
  168. data/spec/features/versions/manage_version_spec.rb +113 -0
  169. data/spec/helpers/applicatin_helper_spec.rb +17 -0
  170. data/spec/rails_helper.rb +23 -0
  171. data/spec/spec_helper.rb +63 -0
  172. data/spec/support/.keep +0 -0
  173. metadata +455 -0
data/Rakefile ADDED
@@ -0,0 +1,28 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'HelenaAdministration'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rspec/core'
23
+ require 'rspec/core/rake_task'
24
+
25
+ desc 'Run all specs in spec directory (excluding plugin specs)'
26
+ RSpec::Core::RakeTask.new(spec: 'app:db:test:prepare')
27
+
28
+ task default: :spec
File without changes
@@ -0,0 +1,20 @@
1
+ #= require jquery
2
+ #= require jquery_ujs
3
+ #= require polyfills
4
+ #= require bootstrap
5
+ #= require codemirror
6
+ #= require codemirror/modes/xml
7
+ #= require codemirror/modes/htmlembedded
8
+ #= require codemirror/modes/htmlmixed
9
+ #= require codemirror/modes/coffeescript
10
+ #= require codemirror/modes/javascript
11
+ #= require codemirror/modes/ruby
12
+ #= require codemirror/modes/markdown
13
+ #= require codemirror/modes/slim
14
+ #= require codemirror/modes/yaml
15
+ $ ->
16
+ $('textarea.slim_lang').each ->
17
+ CodeMirror.fromTextArea(@, { mode: 'application/x-slim', lineNumbers: true, tabSize: 2, insertSoftTab: true })
18
+
19
+ $('textarea.yaml_lang').each ->
20
+ CodeMirror.fromTextArea(@, { mode: 'yaml', lineNumbers: true, tabSize: 2, insertSoftTab: true })
@@ -0,0 +1,10 @@
1
+ // This file was generated by html5-rails
2
+ // https://github.com/sporkd/html5-rails
3
+ // Upgrade with: $ rails generate html5:install
4
+ //
5
+ // This is a manifest for javascript polyfills that will be included
6
+ // in the head section of your layouts.
7
+ //
8
+ // polyfill (n): a JavaScript shim that replicates the standard API for older browsers.
9
+ //
10
+ //= require modernizr.min
@@ -0,0 +1,4 @@
1
+ body.dashboard
2
+ .decision
3
+ svg
4
+ width: 70px
@@ -0,0 +1,50 @@
1
+ // This file was generated by html5-rails
2
+ // https://github.com/sporkd/html5-rails
3
+ // Upgrade with: $ rails generate html5:install
4
+
5
+ //-----------------------------------------
6
+ // Layout styles
7
+ //-----------------------------------------
8
+
9
+ body
10
+ font-weight: 300
11
+
12
+ .decision
13
+ a
14
+ font-size: 2em
15
+ font-weight: 100
16
+
17
+ svg
18
+ fill: $brand-primary
19
+
20
+ nav.navbar
21
+ ul.breadcrumbs
22
+ li:before
23
+ content: '»'
24
+ padding-right: 5px
25
+
26
+ li
27
+ margin: 15px 5px
28
+
29
+ a
30
+ padding: 0px
31
+ display: inline
32
+
33
+ a.btn
34
+ margin: 3px
35
+
36
+ i.fa
37
+ padding-right: 1ex
38
+
39
+ &.disabled,
40
+ @include opacity(.2)
41
+
42
+ hr
43
+ border-color: #EEE
44
+
45
+ .hide-text
46
+ visibility: hidden
47
+
48
+ .CodeMirror
49
+ border: 1px solid #ccc
50
+ border-radius: 4px
@@ -0,0 +1,18 @@
1
+ // This file was generated by html5-rails
2
+ // https://github.com/sporkd/html5-rails
3
+ // Upgrade with: $ rails generate html5:install
4
+ //
5
+ // EXAMPLE Media Query for Responsive Design.
6
+ // This example overrides the primary ('mobile first') styles
7
+ // Modify as content requires.
8
+
9
+ @media only screen and (min-width: 35em) {
10
+ // Style adjustments for viewports that meet the condition
11
+ }
12
+
13
+ @media print,
14
+ (-o-min-device-pixel-ratio: 5/4),
15
+ (-webkit-min-device-pixel-ratio: 1.25),
16
+ (min-resolution: 120dpi) {
17
+ // Style adjustments for high resolution devices
18
+ }
@@ -0,0 +1,19 @@
1
+ // color palette: http://www.colourlovers.com/palette/3477680/ANA
2
+ $brand-primary: #00A0B0
3
+ $brand-danger: #BD1550
4
+ $brand-success: #00C176
5
+ $state-success-bg: #00C176
6
+ $state-success-text: #FFF
7
+
8
+ $line-height: 1.4
9
+ $font-color: #222
10
+ $font-family: sans-serif
11
+ $font-size: 1em
12
+ $link-color: $brand-primary
13
+ $link-hover-color: $brand-primary
14
+ $link-visited-color: $brand-primary
15
+ $selected-font-color: #fff
16
+ $selected-background-color: #ff5e99
17
+ $invalid-background-color: #f0dddd
18
+ $well-bg: #FFF
19
+ $navbar-default-bg: #FFF
@@ -0,0 +1,27 @@
1
+ // This file was generated by html5-rails
2
+ // https://github.com/sporkd/html5-rails
3
+ // Upgrade with: $ rails generate html5:install
4
+ //
5
+ // application styles
6
+
7
+ //-----------------------------------------
8
+ // Variables
9
+ //-----------------------------------------
10
+ @import '_variables'
11
+
12
+ //-----------------------------------------
13
+ // Vendor imports
14
+ //-----------------------------------------
15
+ // @import 'compass/css3';
16
+ @import 'bootstrap-sprockets'
17
+ @import 'bootstrap'
18
+ @import 'font-awesome.css'
19
+
20
+
21
+ //-----------------------------------------
22
+ // Custom imports
23
+ //-----------------------------------------
24
+ @import 'layout'
25
+ @import media_queries
26
+ @import 'dashboard'
27
+ @import 'codemirror.css'
@@ -0,0 +1,19 @@
1
+ module HelenaAdministration
2
+ class ApplicationController < ActionController::Base
3
+ before_action :set_locale, :authenticate_administrator
4
+
5
+ def add_breadcrumb(name, path = nil, options = {})
6
+ super(name.presence || t('shared.untitled'), path, options)
7
+ end
8
+
9
+ def set_locale
10
+ I18n.locale = params[:locale] || I18n.default_locale
11
+ end
12
+
13
+ helper_method :can_administer?
14
+
15
+ def authenticate_administrator
16
+ fail(ActionController::RoutingError, 'Access Denied') unless can_administer?
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ module HelenaAdministration
2
+ class DashboardController < ApplicationController
3
+ before_action :add_breadcrumbs
4
+
5
+ private
6
+
7
+ def add_breadcrumbs
8
+ add_breadcrumb t('shared.navigation.dashboard'), dashboard_index_path
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ module HelenaAdministration
2
+ class ImportSurveysController < ApplicationController
3
+ before_action :add_breadcrumbs
4
+
5
+ def new
6
+ add_breadcrumb t('.import')
7
+ @import_survey_form = ImportSurveyForm.new
8
+ end
9
+
10
+ # rubocop:disable Metrics/MethodLength
11
+ def create
12
+ @import_survey_form = ImportSurveyForm.new import_survey_form_params
13
+ if @import_survey_form.valid?
14
+ begin
15
+ Helena::SurveyImporter.new @import_survey_form.script
16
+ flash[:success] = t('shared.actions.created')
17
+ redirect_to surveys_path
18
+ rescue => e
19
+ @error = e
20
+
21
+ render 'new'
22
+ end
23
+ else
24
+ flash.now[:danger] = t('shared.actions.error')
25
+ render 'new'
26
+ end
27
+ end
28
+ # rubocop:enable Metrics/MethodLength
29
+
30
+ private
31
+
32
+ def import_survey_form_params
33
+ params.require(:import_survey_form).permit(:script)
34
+ end
35
+
36
+ def add_breadcrumbs
37
+ add_breadcrumb t('shared.navigation.dashboard'), dashboard_index_path
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,68 @@
1
+ module HelenaAdministration
2
+ class QuestionGroupsController < ApplicationController
3
+ respond_to :html
4
+
5
+ before_action :load_version, :add_breadcrumbs
6
+ before_action :load_question_group, only: [:destroy, :edit, :update, :show]
7
+
8
+ def show
9
+ add_breadcrumb @question_group.title
10
+ end
11
+
12
+ def new
13
+ @question_group = @version.question_groups.build
14
+ add_breadcrumb t('.new')
15
+ end
16
+
17
+ def create
18
+ @question_group = @version.question_groups.build question_group_params
19
+ if @question_group.save
20
+ flash[:success] = t 'shared.actions.created'
21
+ else
22
+ flash.now[:danger] = t 'shared.actions.error'
23
+ end
24
+ respond_with [@survey, @version, @question_group]
25
+ end
26
+
27
+ def edit
28
+ add_breadcrumb @question_group.title
29
+ end
30
+
31
+ def update
32
+ if @question_group.update_attributes(question_group_params)
33
+ flash[:success] = t 'shared.actions.updated'
34
+ else
35
+ flash.now[:danger] = t 'shared.actions.error'
36
+ add_breadcrumb @question_group.title_was
37
+ end
38
+ respond_with [@survey, @version, @question_group]
39
+ end
40
+
41
+ def destroy
42
+ flash[:success] = t 'shared.actions.deleted' if @question_group.destroy
43
+ respond_with @question_group, location: [@survey, @version]
44
+ end
45
+
46
+ private
47
+
48
+ def add_breadcrumbs
49
+ add_breadcrumb t('shared.navigation.dashboard'), dashboard_index_path
50
+ add_breadcrumb Helena::Survey.model_name.human(count: 2), surveys_path
51
+ add_breadcrumb @survey.name, @survey
52
+ add_breadcrumb t('helena_administration.versions.version', version: @version.version), [@survey, @version]
53
+ end
54
+
55
+ def load_version
56
+ @survey = Helena::Survey.find params[:survey_id]
57
+ @version = @survey.versions.find params[:version_id]
58
+ end
59
+
60
+ def load_question_group
61
+ @question_group = @version.question_groups.find params[:id]
62
+ end
63
+
64
+ def question_group_params
65
+ params.require(:question_group).permit(:position, :title, :allow_to_go_back)
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,15 @@
1
+ module HelenaAdministration
2
+ module Questions
3
+ class CheckboxGroupsController < QuestionsController
4
+ private
5
+
6
+ def add_ressources
7
+ @question.sub_questions.build
8
+ end
9
+
10
+ def permited_params
11
+ [:required, sub_questions_attributes: sub_questions_attributes]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module HelenaAdministration
2
+ module Questions
3
+ class CheckboxMatrixController < QuestionsController
4
+ include Helena::Concerns::Questions::MatrixQuestions
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module HelenaAdministration
2
+ module Questions
3
+ class LongTextsController < QuestionsController
4
+ private
5
+
6
+ def permited_params
7
+ [:default_value, :required]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module HelenaAdministration
2
+ module Questions
3
+ class RadioGroupsController < QuestionsController
4
+ private
5
+
6
+ def add_ressources
7
+ @question.labels.build
8
+ end
9
+
10
+ def permited_params
11
+ [:required, labels_attributes: labels_attributes]
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,7 @@
1
+ module HelenaAdministration
2
+ module Questions
3
+ class RadioMatrixController < QuestionsController
4
+ include Helena::Concerns::Questions::MatrixQuestions
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ module HelenaAdministration
2
+ module Questions
3
+ class ShortTextsController < QuestionsController
4
+ private
5
+
6
+ def permited_params
7
+ [:default_value, :required]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module HelenaAdministration
2
+ module Questions
3
+ class StaticTextsController < QuestionsController
4
+ private
5
+
6
+ def permited_params
7
+ [:default_value, :required]
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,96 @@
1
+ module HelenaAdministration
2
+ class QuestionsController < ApplicationController
3
+ respond_to :html
4
+
5
+ before_action :load_question_group, :add_breadcrumbs
6
+ before_action :load_question, only: [:destroy, :edit, :update, :show]
7
+
8
+ def show
9
+ add_breadcrumb @question.code
10
+ end
11
+
12
+ def new
13
+ @question = @question_group.questions.build
14
+ add_breadcrumb t('.new')
15
+ end
16
+
17
+ def create
18
+ @question = @question_group.questions.build question_params
19
+ if @question.save
20
+ flash[:success] = t 'shared.actions.created'
21
+ else
22
+ flash.now[:danger] = t 'shared.actions.error'
23
+ end
24
+ respond_with [@survey, @version, @question_group, @question]
25
+ end
26
+
27
+ def edit
28
+ add_ressources
29
+ add_breadcrumb @question.code
30
+ end
31
+
32
+ def update
33
+ if @question.update_attributes(question_params)
34
+ flash[:success] = t 'shared.actions.updated'
35
+ else
36
+ flash[:danger] = t 'shared.actions.error'
37
+ add_breadcrumb @question.code_was
38
+ end
39
+ add_ressources
40
+ respond_with @question, location: [@survey, @version, @question_group, @question]
41
+ end
42
+
43
+ def destroy
44
+ flash[:success] = t 'shared.actions.deleted' if @question.destroy
45
+ respond_with @question_group, location: [@survey, @version, @question_group]
46
+ end
47
+
48
+ private
49
+
50
+ def add_breadcrumbs
51
+ add_breadcrumb t('shared.navigation.dashboard'), dashboard_index_path
52
+ add_breadcrumb Helena::Survey.model_name.human(count: 2), surveys_path
53
+ add_breadcrumb @survey.name, @survey
54
+ add_breadcrumb t('helena_administration.versions.version', version: @version.version), [@survey, @version]
55
+ add_breadcrumb @question_group.title, [@survey, @version, @question_group]
56
+ end
57
+
58
+ def load_question_group
59
+ @survey = Helena::Survey.find params[:survey_id]
60
+ @version = @survey.versions.find params[:version_id]
61
+ @question_group = @version.question_groups.find params[:question_group_id]
62
+ end
63
+
64
+ def load_question
65
+ @question = @question_group.questions.find params[:id]
66
+ end
67
+
68
+ def question_group_params
69
+ params.require(:question).permit(:position, :title)
70
+ end
71
+
72
+ def labels_attributes
73
+ [:id, :position, :text, :value, :preselected, :_destroy]
74
+ end
75
+
76
+ def sub_questions_attributes
77
+ [:id, :position, :code, :text, :value, :preselected, :_destroy]
78
+ end
79
+
80
+ def question_params
81
+ required_param.permit(permited_params + [:question_text, :code, :_type])
82
+ end
83
+
84
+ def permited_params
85
+ []
86
+ end
87
+
88
+ def add_ressources
89
+ end
90
+
91
+ def required_param
92
+ param_name = self.class == QuestionsController ? :question : "questions_#{controller_name.singularize}"
93
+ params.require(param_name)
94
+ end
95
+ end
96
+ end