decidim-surveys 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +24 -0
  3. data/Rakefile +3 -0
  4. data/app/assets/config/admin/decidim_surveys_manifest.js +1 -0
  5. data/app/assets/images/decidim/surveys/icon.svg +1 -0
  6. data/app/assets/javascripts/decidim/surveys/admin/auto_label_by_position.component.js.es6 +33 -0
  7. data/app/assets/javascripts/decidim/surveys/admin/dynamic_fields.component.js.es6 +95 -0
  8. data/app/assets/javascripts/decidim/surveys/admin/surveys.js.es6 +85 -0
  9. data/app/assets/stylesheets/decidim/surveys/surveys.scss +9 -0
  10. data/app/commands/decidim/surveys/admin/update_survey.rb +65 -0
  11. data/app/commands/decidim/surveys/answer_survey.rb +43 -0
  12. data/app/commands/decidim/surveys/create_survey.rb +19 -0
  13. data/app/controllers/decidim/surveys/admin/application_controller.rb +15 -0
  14. data/app/controllers/decidim/surveys/admin/surveys_controller.rb +55 -0
  15. data/app/controllers/decidim/surveys/application_controller.rb +13 -0
  16. data/app/controllers/decidim/surveys/surveys_controller.rb +39 -0
  17. data/app/forms/decidim/surveys/admin/survey_form.rb +19 -0
  18. data/app/forms/decidim/surveys/admin/survey_question_answer_option_form.rb +15 -0
  19. data/app/forms/decidim/surveys/admin/survey_question_form.rb +24 -0
  20. data/app/forms/decidim/surveys/survey_answer_form.rb +36 -0
  21. data/app/forms/decidim/surveys/survey_form.rb +22 -0
  22. data/app/helpers/decidim/surveys/admin/application_helper.rb +39 -0
  23. data/app/models/decidim/surveys/abilities/admin_user.rb +34 -0
  24. data/app/models/decidim/surveys/abilities/current_user.rb +47 -0
  25. data/app/models/decidim/surveys/abilities/process_admin_user.rb +44 -0
  26. data/app/models/decidim/surveys/application_record.rb +10 -0
  27. data/app/models/decidim/surveys/survey.rb +25 -0
  28. data/app/models/decidim/surveys/survey_answer.rb +27 -0
  29. data/app/models/decidim/surveys/survey_question.rb +18 -0
  30. data/app/queries/decidim/surveys/survey_user_answers.rb +28 -0
  31. data/app/views/decidim/surveys/admin/surveys/_answer_option.html.erb +23 -0
  32. data/app/views/decidim/surveys/admin/surveys/_form.html.erb +47 -0
  33. data/app/views/decidim/surveys/admin/surveys/_question.html.erb +57 -0
  34. data/app/views/decidim/surveys/admin/surveys/edit.html.erb +7 -0
  35. data/app/views/decidim/surveys/surveys/show.html.erb +102 -0
  36. data/config/i18n-tasks.yml +11 -0
  37. data/config/locales/ca.yml +69 -0
  38. data/config/locales/en.yml +73 -0
  39. data/config/locales/es.yml +69 -0
  40. data/config/locales/eu.yml +5 -0
  41. data/config/locales/fi.yml +5 -0
  42. data/config/locales/fr.yml +5 -0
  43. data/config/locales/it.yml +5 -0
  44. data/config/locales/nl.yml +5 -0
  45. data/db/migrate/20170511092231_create_decidim_surveys.rb +15 -0
  46. data/db/migrate/20170515090916_create_decidim_survey_questions.rb +12 -0
  47. data/db/migrate/20170515144119_create_decidim_survey_answers.rb +14 -0
  48. data/db/migrate/20170518085302_add_position_to_surveys_questions.rb +7 -0
  49. data/db/migrate/20170522075938_add_mandatory_to_surveys_questions.rb +7 -0
  50. data/db/migrate/20170524122229_add_question_type_to_surveys_questions.rb +7 -0
  51. data/db/migrate/20170525132233_add_answer_options_to_surveys_questions.rb +7 -0
  52. data/lib/decidim/surveys.rb +14 -0
  53. data/lib/decidim/surveys/admin.rb +10 -0
  54. data/lib/decidim/surveys/admin_engine.rb +34 -0
  55. data/lib/decidim/surveys/engine.rb +25 -0
  56. data/lib/decidim/surveys/feature.rb +85 -0
  57. data/lib/decidim/surveys/survey_user_answers_serializer.rb +23 -0
  58. data/lib/decidim/surveys/test/factories.rb +39 -0
  59. metadata +147 -0
@@ -0,0 +1,5 @@
1
+ eu:
2
+ activemodel:
3
+ attributes:
4
+ survey_answer:
5
+ body: Erantzuna
@@ -0,0 +1,5 @@
1
+ fi:
2
+ decidim:
3
+ features:
4
+ surveys:
5
+ name: Tutkimus
@@ -0,0 +1,5 @@
1
+ fr:
2
+ decidim:
3
+ features:
4
+ surveys:
5
+ name: Enquête
@@ -0,0 +1,5 @@
1
+ it:
2
+ activemodel:
3
+ attributes:
4
+ survey_answer:
5
+ body: Risposta
@@ -0,0 +1,5 @@
1
+ nl:
2
+ activemodel:
3
+ attributes:
4
+ survey_answer:
5
+ body: Antwoord
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDecidimSurveys < ActiveRecord::Migration[5.0]
4
+ def change
5
+ create_table :decidim_surveys_surveys do |t|
6
+ t.jsonb :title
7
+ t.jsonb :description
8
+ t.jsonb :tos
9
+ t.references :decidim_feature, index: true
10
+ t.datetime :published_at
11
+
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDecidimSurveyQuestions < ActiveRecord::Migration[5.0]
4
+ def change
5
+ create_table :decidim_surveys_survey_questions do |t|
6
+ t.jsonb :body
7
+ t.references :decidim_survey, index: true
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDecidimSurveyAnswers < ActiveRecord::Migration[5.0]
4
+ def change
5
+ create_table :decidim_surveys_survey_answers do |t|
6
+ t.jsonb :body, default: []
7
+ t.references :decidim_user, index: true
8
+ t.references :decidim_survey, index: true
9
+ t.references :decidim_survey_question, index: { name: "index_decidim_surveys_answers_question_id" }
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddPositionToSurveysQuestions < ActiveRecord::Migration[5.0]
4
+ def change
5
+ add_column :decidim_surveys_survey_questions, :position, :integer, index: true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddMandatoryToSurveysQuestions < ActiveRecord::Migration[5.0]
4
+ def change
5
+ add_column :decidim_surveys_survey_questions, :mandatory, :boolean
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddQuestionTypeToSurveysQuestions < ActiveRecord::Migration[5.0]
4
+ def change
5
+ add_column :decidim_surveys_survey_questions, :question_type, :string
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddAnswerOptionsToSurveysQuestions < ActiveRecord::Migration[5.0]
4
+ def change
5
+ add_column :decidim_surveys_survey_questions, :answer_options, :jsonb, default: []
6
+ end
7
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/surveys/admin"
4
+ require "decidim/surveys/engine"
5
+ require "decidim/surveys/admin_engine"
6
+ require "decidim/surveys/feature"
7
+
8
+ module Decidim
9
+ # This namespace holds the logic of the `Surveys` component. This component
10
+ # allows users to create surveys in a participatory process.
11
+ module Surveys
12
+ autoload :SurveyUserAnswersSerializer, "decidim/surveys/survey_user_answers_serializer"
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Surveys
5
+ # This module contains all the domain logic associated to Decidim's Surveys
6
+ # component admin panel.
7
+ module Admin
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "jquery-tmpl-rails"
4
+
5
+ module Decidim
6
+ module Surveys
7
+ # This is the engine that runs on the public interface of `Surveys`.
8
+ class AdminEngine < ::Rails::Engine
9
+ isolate_namespace Decidim::Surveys::Admin
10
+
11
+ paths["db/migrate"] = nil
12
+
13
+ routes do
14
+ post "/", to: "surveys#update", as: :survey
15
+ root to: "surveys#edit"
16
+ end
17
+
18
+ initializer "decidim_surveys.assets" do |app|
19
+ app.config.assets.precompile += %w(admin/decidim_surveys_manifest.js)
20
+ end
21
+
22
+ initializer "decidim_surveys.inject_abilities_to_user" do |_app|
23
+ Decidim.configure do |config|
24
+ config.admin_abilities += ["Decidim::Surveys::Abilities::AdminUser"]
25
+ config.admin_abilities += ["Decidim::Surveys::Abilities::ProcessAdminUser"]
26
+ end
27
+ end
28
+
29
+ def load_seed
30
+ nil
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Surveys
5
+ # This is the engine that runs on the public interface of `decidim-surveys`.
6
+ class Engine < ::Rails::Engine
7
+ isolate_namespace Decidim::Surveys
8
+
9
+ routes do
10
+ resources :surveys, only: [:show] do
11
+ member do
12
+ post :answer
13
+ end
14
+ end
15
+ root to: "surveys#show"
16
+ end
17
+
18
+ initializer "decidim_surveys.inject_abilities_to_user" do |_app|
19
+ Decidim.configure do |config|
20
+ config.abilities += ["Decidim::Surveys::Abilities::CurrentUser"]
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_dependency "decidim/features/namer"
4
+
5
+ Decidim.register_feature(:surveys) do |feature|
6
+ feature.engine = Decidim::Surveys::Engine
7
+ feature.admin_engine = Decidim::Surveys::AdminEngine
8
+ feature.icon = "decidim/surveys/icon.svg"
9
+ feature.stylesheet = "decidim/surveys/surveys"
10
+
11
+ feature.on(:create) do |instance|
12
+ Decidim::Surveys::CreateSurvey.call(instance) do
13
+ on(:invalid) { raise "Can't create survey" }
14
+ end
15
+ end
16
+
17
+ feature.on(:before_destroy) do |instance|
18
+ if Decidim::Surveys::Survey.where(feature: instance).any?
19
+ raise "Can't destroy this feature when there are surveys"
20
+ end
21
+ end
22
+
23
+ # These actions permissions can be configured in the admin panel
24
+ feature.actions = %w(answer)
25
+
26
+ # feature.settings(:global) do |settings|
27
+ # # Add your global settings
28
+ # # Available types: :integer, :boolean
29
+ # # settings.attribute :vote_limit, type: :integer, default: 0
30
+ # end
31
+
32
+ feature.settings(:step) do |settings|
33
+ settings.attribute :allow_answers, type: :boolean, default: false
34
+ end
35
+
36
+ # feature.register_resource do |resource|
37
+ # # Register a optional resource that can be references from other resources.
38
+ # resource.model_class_name = "Decidim::Surveys::SomeResource"
39
+ # resource.template = "decidim/surveys/some_resources/linked_some_resources"
40
+ # end
41
+
42
+ # feature.register_stat :some_stat do |context, start_at, end_at|
43
+ # # Register some stat number to the application
44
+ # end
45
+
46
+ feature.exports :survey_user_answers do |exports|
47
+ exports.collection do |f|
48
+ survey = Decidim::Surveys::Survey.where(feature: f).first
49
+ Decidim::Surveys::SurveyUserAnswers.for(survey)
50
+ end
51
+
52
+ exports.serializer Decidim::Surveys::SurveyUserAnswersSerializer
53
+ end
54
+
55
+ feature.seeds do
56
+ Decidim::ParticipatoryProcess.all.each do |process|
57
+ next unless process.steps.any?
58
+
59
+ feature = Decidim::Feature.create!(
60
+ name: Decidim::Features::Namer.new(process.organization.available_locales, :surveys).i18n_name,
61
+ manifest_name: :surveys,
62
+ published_at: Time.current,
63
+ participatory_process: process
64
+ )
65
+
66
+ survey = Decidim::Surveys::Survey.create!(
67
+ feature: feature,
68
+ title: Decidim::Faker::Localized.paragraph,
69
+ description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
70
+ Decidim::Faker::Localized.paragraph(3)
71
+ end,
72
+ tos: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
73
+ Decidim::Faker::Localized.paragraph(2)
74
+ end
75
+ )
76
+
77
+ 3.times do
78
+ Decidim::Surveys::SurveyQuestion.create!(
79
+ survey: survey,
80
+ body: Decidim::Faker::Localized.paragraph
81
+ )
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Surveys
5
+ # This class serializes the answers given by a User for survey so can be
6
+ # exported to CSV, JSON or other formats.
7
+ class SurveyUserAnswersSerializer < Decidim::Exporters::Serializer
8
+ include Decidim::TranslationsHelper
9
+
10
+ # Public: Initializes the serializer with a collection of SurveyAnswers.
11
+ def initialize(survey_answers)
12
+ @survey_answers = survey_answers
13
+ end
14
+
15
+ # Public: Exports a hash with the serialized data for the user answers.
16
+ def serialize
17
+ @survey_answers.each_with_index.inject({}) do |serialized, (answer, idx)|
18
+ serialized.update("#{idx + 1}. #{translated_attribute(answer.question.body)}" => answer.body)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/core/test/factories"
4
+ require "decidim/admin/test/factories"
5
+
6
+ FactoryGirl.define do
7
+ factory :surveys_feature, parent: :feature do
8
+ name { Decidim::Features::Namer.new(participatory_process.organization.available_locales, :surveys).i18n_name }
9
+ manifest_name :surveys
10
+ participatory_process { create(:participatory_process, :with_steps) }
11
+ end
12
+
13
+ factory :survey, class: Decidim::Surveys::Survey do
14
+ title { Decidim::Faker::Localized.sentence }
15
+ description do
16
+ Decidim::Faker::Localized.wrapped("<p>", "</p>") do
17
+ Decidim::Faker::Localized.sentence(4)
18
+ end
19
+ end
20
+ tos { Decidim::Faker::Localized.sentence(4) }
21
+ feature { build(:surveys_feature) }
22
+ end
23
+
24
+ factory :survey_question, class: Decidim::Surveys::SurveyQuestion do
25
+ body { Decidim::Faker::Localized.sentence }
26
+ mandatory false
27
+ position 0
28
+ question_type Decidim::Surveys::SurveyQuestion::TYPES.first
29
+ answer_options []
30
+ survey
31
+ end
32
+
33
+ factory :survey_answer, class: Decidim::Surveys::SurveyAnswer do
34
+ body { Decidim::Faker::Localized.sentence }
35
+ survey
36
+ question { create(:survey_question, survey: survey) }
37
+ user { create(:user, organization: survey.organization) }
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: decidim-surveys
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Josep Jaume Rey Peroy
8
+ - Marc Riera Casals
9
+ - Oriol Gual Oliva
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2017-06-16 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: decidim-core
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - '='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.3.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - '='
27
+ - !ruby/object:Gem::Version
28
+ version: 0.3.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: jquery-tmpl-rails
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: 1.1.0
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: 1.1.0
43
+ - !ruby/object:Gem::Dependency
44
+ name: decidim-dev
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '='
48
+ - !ruby/object:Gem::Version
49
+ version: 0.3.0
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '='
55
+ - !ruby/object:Gem::Version
56
+ version: 0.3.0
57
+ description: A component for decidim's participatory processes.
58
+ email:
59
+ - josepjaume@gmail.com
60
+ - mrc2407@gmail.com
61
+ - oriolgual@gmail.com
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - README.md
67
+ - Rakefile
68
+ - app/assets/config/admin/decidim_surveys_manifest.js
69
+ - app/assets/images/decidim/surveys/icon.svg
70
+ - app/assets/javascripts/decidim/surveys/admin/auto_label_by_position.component.js.es6
71
+ - app/assets/javascripts/decidim/surveys/admin/dynamic_fields.component.js.es6
72
+ - app/assets/javascripts/decidim/surveys/admin/surveys.js.es6
73
+ - app/assets/stylesheets/decidim/surveys/surveys.scss
74
+ - app/commands/decidim/surveys/admin/update_survey.rb
75
+ - app/commands/decidim/surveys/answer_survey.rb
76
+ - app/commands/decidim/surveys/create_survey.rb
77
+ - app/controllers/decidim/surveys/admin/application_controller.rb
78
+ - app/controllers/decidim/surveys/admin/surveys_controller.rb
79
+ - app/controllers/decidim/surveys/application_controller.rb
80
+ - app/controllers/decidim/surveys/surveys_controller.rb
81
+ - app/forms/decidim/surveys/admin/survey_form.rb
82
+ - app/forms/decidim/surveys/admin/survey_question_answer_option_form.rb
83
+ - app/forms/decidim/surveys/admin/survey_question_form.rb
84
+ - app/forms/decidim/surveys/survey_answer_form.rb
85
+ - app/forms/decidim/surveys/survey_form.rb
86
+ - app/helpers/decidim/surveys/admin/application_helper.rb
87
+ - app/models/decidim/surveys/abilities/admin_user.rb
88
+ - app/models/decidim/surveys/abilities/current_user.rb
89
+ - app/models/decidim/surveys/abilities/process_admin_user.rb
90
+ - app/models/decidim/surveys/application_record.rb
91
+ - app/models/decidim/surveys/survey.rb
92
+ - app/models/decidim/surveys/survey_answer.rb
93
+ - app/models/decidim/surveys/survey_question.rb
94
+ - app/queries/decidim/surveys/survey_user_answers.rb
95
+ - app/views/decidim/surveys/admin/surveys/_answer_option.html.erb
96
+ - app/views/decidim/surveys/admin/surveys/_form.html.erb
97
+ - app/views/decidim/surveys/admin/surveys/_question.html.erb
98
+ - app/views/decidim/surveys/admin/surveys/edit.html.erb
99
+ - app/views/decidim/surveys/surveys/show.html.erb
100
+ - config/i18n-tasks.yml
101
+ - config/locales/ca.yml
102
+ - config/locales/en.yml
103
+ - config/locales/es.yml
104
+ - config/locales/eu.yml
105
+ - config/locales/fi.yml
106
+ - config/locales/fr.yml
107
+ - config/locales/it.yml
108
+ - config/locales/nl.yml
109
+ - db/migrate/20170511092231_create_decidim_surveys.rb
110
+ - db/migrate/20170515090916_create_decidim_survey_questions.rb
111
+ - db/migrate/20170515144119_create_decidim_survey_answers.rb
112
+ - db/migrate/20170518085302_add_position_to_surveys_questions.rb
113
+ - db/migrate/20170522075938_add_mandatory_to_surveys_questions.rb
114
+ - db/migrate/20170524122229_add_question_type_to_surveys_questions.rb
115
+ - db/migrate/20170525132233_add_answer_options_to_surveys_questions.rb
116
+ - lib/decidim/surveys.rb
117
+ - lib/decidim/surveys/admin.rb
118
+ - lib/decidim/surveys/admin_engine.rb
119
+ - lib/decidim/surveys/engine.rb
120
+ - lib/decidim/surveys/feature.rb
121
+ - lib/decidim/surveys/survey_user_answers_serializer.rb
122
+ - lib/decidim/surveys/test/factories.rb
123
+ homepage: https://github.com/decidim/decidim
124
+ licenses:
125
+ - AGPLv3
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 2.3.1
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.11
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A component for decidim's participatory processes.
147
+ test_files: []