decidim-surveys 0.10.1 → 0.11.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/app/assets/config/decidim_surveys_manifest.js +1 -0
  4. data/app/assets/javascripts/decidim/surveys/admin/auto_buttons_by_min_items.component.js.es6 +25 -0
  5. data/app/assets/javascripts/decidim/surveys/admin/auto_select_options_by_total_items.component.js.es6 +23 -0
  6. data/app/assets/javascripts/decidim/surveys/admin/surveys.js.es6 +146 -43
  7. data/app/assets/javascripts/decidim/surveys/autosortable_checkboxes.component.js.es6 +65 -0
  8. data/app/assets/javascripts/decidim/surveys/option_attached_inputs.component.js.es6 +32 -0
  9. data/app/assets/javascripts/decidim/surveys/surveys.js.es6 +20 -0
  10. data/app/assets/stylesheets/decidim/surveys/surveys.scss +20 -3
  11. data/app/commands/decidim/surveys/admin/update_survey.rb +36 -15
  12. data/app/commands/decidim/surveys/answer_survey.rb +12 -1
  13. data/app/commands/decidim/surveys/create_survey.rb +5 -5
  14. data/app/controllers/decidim/surveys/admin/application_controller.rb +2 -2
  15. data/app/controllers/decidim/surveys/admin/surveys_controller.rb +3 -3
  16. data/app/controllers/decidim/surveys/application_controller.rb +2 -2
  17. data/app/controllers/decidim/surveys/surveys_controller.rb +1 -1
  18. data/app/forms/decidim/surveys/admin/survey_answer_option_form.rb +23 -0
  19. data/app/forms/decidim/surveys/admin/survey_form.rb +7 -1
  20. data/app/forms/decidim/surveys/admin/survey_question_form.rb +12 -2
  21. data/app/forms/decidim/surveys/survey_answer_choice_form.rb +15 -0
  22. data/app/forms/decidim/surveys/survey_answer_form.rb +40 -6
  23. data/app/forms/decidim/surveys/survey_form.rb +1 -1
  24. data/app/helpers/decidim/surveys/admin/application_helper.rb +3 -19
  25. data/app/jobs/decidim/surveys/settings_change_job.rb +4 -4
  26. data/app/models/decidim/surveys/abilities/current_user_ability.rb +8 -8
  27. data/app/models/decidim/surveys/abilities/participatory_process_admin_ability.rb +1 -1
  28. data/app/models/decidim/surveys/survey.rb +2 -2
  29. data/app/models/decidim/surveys/survey_answer.rb +9 -1
  30. data/app/models/decidim/surveys/survey_answer_choice.rb +15 -0
  31. data/app/models/decidim/surveys/survey_answer_option.rb +9 -0
  32. data/app/models/decidim/surveys/survey_question.rb +21 -5
  33. data/app/views/decidim/surveys/admin/surveys/_answer_option.html.erb +28 -11
  34. data/app/views/decidim/surveys/admin/surveys/_form.html.erb +18 -14
  35. data/app/views/decidim/surveys/admin/surveys/_question.html.erb +74 -31
  36. data/app/views/decidim/surveys/admin/surveys/edit.html.erb +1 -1
  37. data/app/views/decidim/surveys/surveys/_answer.html.erb +94 -0
  38. data/app/views/decidim/surveys/surveys/show.html.erb +15 -42
  39. data/config/locales/ca.yml +33 -13
  40. data/config/locales/en.yml +33 -13
  41. data/config/locales/es.yml +33 -13
  42. data/config/locales/eu.yml +33 -13
  43. data/config/locales/fi.yml +33 -13
  44. data/config/locales/fr.yml +33 -13
  45. data/config/locales/gl.yml +33 -13
  46. data/config/locales/it.yml +33 -13
  47. data/config/locales/nl.yml +36 -16
  48. data/config/locales/pl.yml +33 -13
  49. data/config/locales/pt-BR.yml +33 -13
  50. data/config/locales/pt.yml +33 -13
  51. data/config/locales/ru.yml +0 -6
  52. data/config/locales/sv.yml +33 -13
  53. data/config/locales/uk.yml +0 -6
  54. data/db/migrate/20180305133837_rename_features_to_components_at_surveys.rb +11 -0
  55. data/db/migrate/20180314225829_add_max_choices_to_survey_questions.rb +7 -0
  56. data/db/migrate/20180321141024_add_description_to_decidim_survey_questions.rb +7 -0
  57. data/db/migrate/20180405014929_add_choices_to_decidim_survey_answers.rb +48 -0
  58. data/db/migrate/20180405015012_create_decidim_survey_answer_options.rb +43 -0
  59. data/db/migrate/20180405015147_create_decidim_survey_answer_choices.rb +61 -0
  60. data/db/migrate/20180405015258_add_free_text_to_survey_answer_options.rb +7 -0
  61. data/db/migrate/20180405015314_add_custom_body_to_survey_answer_choices.rb +7 -0
  62. data/db/migrate/20180406201818_add_position_to_decidim_survey_answer_choices.rb +7 -0
  63. data/lib/decidim/surveys.rb +1 -1
  64. data/lib/decidim/surveys/admin_engine.rb +0 -2
  65. data/lib/decidim/surveys/{feature.rb → component.rb} +38 -26
  66. data/lib/decidim/surveys/engine.rb +5 -1
  67. data/lib/decidim/surveys/test/factories.rb +22 -6
  68. data/lib/decidim/surveys/version.rb +1 -1
  69. metadata +33 -30
  70. data/app/assets/javascripts/decidim/surveys/admin/auto_label_by_position.component.js.es6 +0 -33
  71. data/app/assets/javascripts/decidim/surveys/admin/dynamic_fields.component.js.es6 +0 -95
  72. data/app/forms/decidim/surveys/admin/survey_question_answer_option_form.rb +0 -15
@@ -15,6 +15,10 @@ module Decidim
15
15
  root to: "surveys#show"
16
16
  end
17
17
 
18
+ initializer "decidim_surveys.assets" do |app|
19
+ app.config.assets.precompile += %w(decidim_surveys_manifest.js)
20
+ end
21
+
18
22
  initializer "decidim_surveys.inject_abilities_to_user" do |_app|
19
23
  Decidim.configure do |config|
20
24
  config.abilities += ["Decidim::Surveys::Abilities::CurrentUserAbility"]
@@ -24,7 +28,7 @@ module Decidim
24
28
  initializer "decidim_changes" do
25
29
  Decidim::SettingsChange.subscribe "surveys" do |changes|
26
30
  Decidim::Surveys::SettingsChangeJob.perform_later(
27
- changes[:feature_id],
31
+ changes[:component_id],
28
32
  changes[:previous_settings],
29
33
  changes[:current_settings]
30
34
  )
@@ -4,8 +4,8 @@ require "decidim/core/test/factories"
4
4
  require "decidim/participatory_processes/test/factories"
5
5
 
6
6
  FactoryBot.define do
7
- factory :surveys_feature, parent: :feature do
8
- name { Decidim::Features::Namer.new(participatory_space.organization.available_locales, :surveys).i18n_name }
7
+ factory :surveys_component, parent: :component do
8
+ name { Decidim::Components::Namer.new(participatory_space.organization.available_locales, :surveys).i18n_name }
9
9
  manifest_name :surveys
10
10
  participatory_space { create(:participatory_process, :with_steps) }
11
11
  end
@@ -18,22 +18,38 @@ FactoryBot.define do
18
18
  end
19
19
  end
20
20
  tos { Decidim::Faker::Localized.sentence(4) }
21
- feature { build(:surveys_feature) }
21
+ component { build(:surveys_component) }
22
22
  end
23
23
 
24
24
  factory :survey_question, class: Decidim::Surveys::SurveyQuestion do
25
+ transient do
26
+ answer_options []
27
+ end
28
+
25
29
  body { Decidim::Faker::Localized.sentence }
26
30
  mandatory false
27
31
  position 0
28
- question_type Decidim::Surveys::SurveyQuestion::TYPES.first
29
- answer_options []
32
+ question_type { Decidim::Surveys::SurveyQuestion::TYPES.first }
30
33
  survey
34
+
35
+ before(:create) do |question, evaluator|
36
+ evaluator.answer_options.each do |answer_option|
37
+ question.answer_options.build(
38
+ body: answer_option["body"],
39
+ free_text: answer_option["free_text"]
40
+ )
41
+ end
42
+ end
31
43
  end
32
44
 
33
45
  factory :survey_answer, class: Decidim::Surveys::SurveyAnswer do
34
- body { Decidim::Faker::Localized.sentence }
46
+ body { "hola" }
35
47
  survey
36
48
  question { create(:survey_question, survey: survey) }
37
49
  user { create(:user, organization: survey.organization) }
38
50
  end
51
+
52
+ factory :survey_answer_option, class: Decidim::Surveys::SurveyAnswerOption do
53
+ body { Decidim::Faker::Localized.sentence }
54
+ end
39
55
  end
@@ -4,7 +4,7 @@ module Decidim
4
4
  # This holds the decidim-surveys version.
5
5
  module Surveys
6
6
  def self.version
7
- "0.10.1"
7
+ "0.11.0.pre1"
8
8
  end
9
9
  end
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: decidim-surveys
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.1
4
+ version: 0.11.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josep Jaume Rey Peroy
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-04-17 00:00:00.000000000 Z
13
+ date: 2018-04-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: decidim-core
@@ -18,70 +18,56 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.10.1
21
+ version: 0.11.0.pre1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.10.1
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'
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'
28
+ version: 0.11.0.pre1
43
29
  - !ruby/object:Gem::Dependency
44
30
  name: decidim-admin
45
31
  requirement: !ruby/object:Gem::Requirement
46
32
  requirements:
47
33
  - - '='
48
34
  - !ruby/object:Gem::Version
49
- version: 0.10.1
35
+ version: 0.11.0.pre1
50
36
  type: :development
51
37
  prerelease: false
52
38
  version_requirements: !ruby/object:Gem::Requirement
53
39
  requirements:
54
40
  - - '='
55
41
  - !ruby/object:Gem::Version
56
- version: 0.10.1
42
+ version: 0.11.0.pre1
57
43
  - !ruby/object:Gem::Dependency
58
44
  name: decidim-dev
59
45
  requirement: !ruby/object:Gem::Requirement
60
46
  requirements:
61
47
  - - '='
62
48
  - !ruby/object:Gem::Version
63
- version: 0.10.1
49
+ version: 0.11.0.pre1
64
50
  type: :development
65
51
  prerelease: false
66
52
  version_requirements: !ruby/object:Gem::Requirement
67
53
  requirements:
68
54
  - - '='
69
55
  - !ruby/object:Gem::Version
70
- version: 0.10.1
56
+ version: 0.11.0.pre1
71
57
  - !ruby/object:Gem::Dependency
72
58
  name: decidim-participatory_processes
73
59
  requirement: !ruby/object:Gem::Requirement
74
60
  requirements:
75
61
  - - '='
76
62
  - !ruby/object:Gem::Version
77
- version: 0.10.1
63
+ version: 0.11.0.pre1
78
64
  type: :development
79
65
  prerelease: false
80
66
  version_requirements: !ruby/object:Gem::Requirement
81
67
  requirements:
82
68
  - - '='
83
69
  - !ruby/object:Gem::Version
84
- version: 0.10.1
70
+ version: 0.11.0.pre1
85
71
  description: A surveys component for decidim's participatory spaces.
86
72
  email:
87
73
  - josepjaume@gmail.com
@@ -94,10 +80,14 @@ files:
94
80
  - README.md
95
81
  - Rakefile
96
82
  - app/assets/config/admin/decidim_surveys_manifest.js
83
+ - app/assets/config/decidim_surveys_manifest.js
97
84
  - app/assets/images/decidim/surveys/icon.svg
98
- - app/assets/javascripts/decidim/surveys/admin/auto_label_by_position.component.js.es6
99
- - app/assets/javascripts/decidim/surveys/admin/dynamic_fields.component.js.es6
85
+ - app/assets/javascripts/decidim/surveys/admin/auto_buttons_by_min_items.component.js.es6
86
+ - app/assets/javascripts/decidim/surveys/admin/auto_select_options_by_total_items.component.js.es6
100
87
  - app/assets/javascripts/decidim/surveys/admin/surveys.js.es6
88
+ - app/assets/javascripts/decidim/surveys/autosortable_checkboxes.component.js.es6
89
+ - app/assets/javascripts/decidim/surveys/option_attached_inputs.component.js.es6
90
+ - app/assets/javascripts/decidim/surveys/surveys.js.es6
101
91
  - app/assets/stylesheets/decidim/surveys/surveys.scss
102
92
  - app/commands/decidim/surveys/admin/update_survey.rb
103
93
  - app/commands/decidim/surveys/answer_survey.rb
@@ -108,9 +98,10 @@ files:
108
98
  - app/controllers/decidim/surveys/surveys_controller.rb
109
99
  - app/events/decidim/surveys/closed_survey_event.rb
110
100
  - app/events/decidim/surveys/opened_survey_event.rb
101
+ - app/forms/decidim/surveys/admin/survey_answer_option_form.rb
111
102
  - app/forms/decidim/surveys/admin/survey_form.rb
112
- - app/forms/decidim/surveys/admin/survey_question_answer_option_form.rb
113
103
  - app/forms/decidim/surveys/admin/survey_question_form.rb
104
+ - app/forms/decidim/surveys/survey_answer_choice_form.rb
114
105
  - app/forms/decidim/surveys/survey_answer_form.rb
115
106
  - app/forms/decidim/surveys/survey_form.rb
116
107
  - app/helpers/decidim/surveys/admin/application_helper.rb
@@ -121,12 +112,15 @@ files:
121
112
  - app/models/decidim/surveys/application_record.rb
122
113
  - app/models/decidim/surveys/survey.rb
123
114
  - app/models/decidim/surveys/survey_answer.rb
115
+ - app/models/decidim/surveys/survey_answer_choice.rb
116
+ - app/models/decidim/surveys/survey_answer_option.rb
124
117
  - app/models/decidim/surveys/survey_question.rb
125
118
  - app/queries/decidim/surveys/survey_user_answers.rb
126
119
  - app/views/decidim/surveys/admin/surveys/_answer_option.html.erb
127
120
  - app/views/decidim/surveys/admin/surveys/_form.html.erb
128
121
  - app/views/decidim/surveys/admin/surveys/_question.html.erb
129
122
  - app/views/decidim/surveys/admin/surveys/edit.html.erb
123
+ - app/views/decidim/surveys/surveys/_answer.html.erb
130
124
  - app/views/decidim/surveys/surveys/show.html.erb
131
125
  - config/locales/ca.yml
132
126
  - config/locales/en.yml
@@ -150,11 +144,20 @@ files:
150
144
  - db/migrate/20170522075938_add_mandatory_to_surveys_questions.rb
151
145
  - db/migrate/20170524122229_add_question_type_to_surveys_questions.rb
152
146
  - db/migrate/20170525132233_add_answer_options_to_surveys_questions.rb
147
+ - db/migrate/20180305133837_rename_features_to_components_at_surveys.rb
148
+ - db/migrate/20180314225829_add_max_choices_to_survey_questions.rb
149
+ - db/migrate/20180321141024_add_description_to_decidim_survey_questions.rb
150
+ - db/migrate/20180405014929_add_choices_to_decidim_survey_answers.rb
151
+ - db/migrate/20180405015012_create_decidim_survey_answer_options.rb
152
+ - db/migrate/20180405015147_create_decidim_survey_answer_choices.rb
153
+ - db/migrate/20180405015258_add_free_text_to_survey_answer_options.rb
154
+ - db/migrate/20180405015314_add_custom_body_to_survey_answer_choices.rb
155
+ - db/migrate/20180406201818_add_position_to_decidim_survey_answer_choices.rb
153
156
  - lib/decidim/surveys.rb
154
157
  - lib/decidim/surveys/admin.rb
155
158
  - lib/decidim/surveys/admin_engine.rb
159
+ - lib/decidim/surveys/component.rb
156
160
  - lib/decidim/surveys/engine.rb
157
- - lib/decidim/surveys/feature.rb
158
161
  - lib/decidim/surveys/survey_user_answers_serializer.rb
159
162
  - lib/decidim/surveys/test/factories.rb
160
163
  - lib/decidim/surveys/version.rb
@@ -173,9 +176,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
176
  version: '2.3'
174
177
  required_rubygems_version: !ruby/object:Gem::Requirement
175
178
  requirements:
176
- - - ">="
179
+ - - ">"
177
180
  - !ruby/object:Gem::Version
178
- version: '0'
181
+ version: 1.3.1
179
182
  requirements: []
180
183
  rubyforge_project:
181
184
  rubygems_version: 2.7.3
@@ -1,33 +0,0 @@
1
- ((exports) => {
2
- class AutoLabelByPositionComponent {
3
- constructor(options = {}) {
4
- this.listSelector = options.listSelector;
5
- this.labelSelector = options.labelSelector;
6
- this.onPositionComputed = options.onPositionComputed;
7
-
8
- this.run();
9
- }
10
-
11
- run() {
12
- const $list = $(this.listSelector);
13
-
14
- $list.each((idx, el) => {
15
- const $label = $(el).find(this.labelSelector);
16
- const labelContent = $label.html();
17
-
18
- if (labelContent.match(/#(\d+)/)) {
19
- $label.html(labelContent.replace(/#(\d+)/, `#${idx + 1}`));
20
- } else {
21
- $label.html(`${labelContent} #${idx + 1}`);
22
- }
23
-
24
- if (this.onPositionComputed) {
25
- this.onPositionComputed(el, idx);
26
- }
27
- });
28
- }
29
- }
30
-
31
- exports.DecidimAdmin = exports.DecidimAdmin || {};
32
- exports.DecidimAdmin.AutoLabelByPositionComponent = AutoLabelByPositionComponent;
33
- })(window);
@@ -1,95 +0,0 @@
1
- ((exports) => {
2
- class DynamicFieldsComponent {
3
- constructor(options = {}) {
4
- this.templateId = options.templateId;
5
- this.wrapperSelector = options.wrapperSelector;
6
- this.containerSelector = options.containerSelector;
7
- this.fieldSelector = options.fieldSelector;
8
- this.addFieldButtonSelector = options.addFieldButtonSelector;
9
- this.removeFieldButtonSelector = options.removeFieldButtonSelector;
10
- this.onAddField = options.onAddField;
11
- this.onRemoveField = options.onRemoveField;
12
- this.tabsPrefix = options.tabsPrefix;
13
- this._compileTemplate();
14
- this._bindEvents();
15
- }
16
-
17
- _compileTemplate() {
18
- $.template(this.templateId, $(`#${this.templateId}`).html());
19
- }
20
-
21
- _bindEvents() {
22
- $(this.wrapperSelector).on('click', this.addFieldButtonSelector, (event) =>
23
- this._bindSafeEvent(event, () => this._addField())
24
- );
25
-
26
- $(this.wrapperSelector).on('click', this.removeFieldButtonSelector, (event) =>
27
- this._bindSafeEvent(event, (target) => this._removeField(target))
28
- );
29
- }
30
-
31
- _bindSafeEvent(event, cb) {
32
- event.preventDefault();
33
- event.stopPropagation();
34
-
35
- try {
36
- return cb(event.target);
37
- } catch (error) {
38
- console.error(error); // eslint-disable-line no-console
39
- return error;
40
- }
41
- }
42
-
43
- _addField() {
44
- const $container = $(this.wrapperSelector).find(this.containerSelector);
45
- const uid = this._getUID();
46
- const tabsId = `${this.tabsPrefix}-${uid}`;
47
-
48
- const $newField = $.tmpl(this.templateId, { tabsId });
49
-
50
- $newField.attr('id', `${tabsId}-field`);
51
- $newField.find('[disabled]').attr('disabled', false);
52
- $newField.find('ul.tabs').attr('data-tabs', true);
53
-
54
- $newField.appendTo($container);
55
- $newField.foundation();
56
-
57
- if (this.onAddField) {
58
- this.onAddField($newField);
59
- }
60
- }
61
-
62
- _removeField(target) {
63
- const $target = $(target);
64
- const $removedField = $target.parents(this.fieldSelector);
65
- const idInput = $removedField.find('input').filter((idx, input) => input.name.match(/id/));
66
-
67
- if (idInput.length > 0) {
68
- const deletedInput = $removedField.find('input').filter((idx, input) => input.name.match(/delete/));
69
-
70
- if (deletedInput.length > 0) {
71
- $(deletedInput[0]).val(true);
72
- }
73
-
74
- $removedField.addClass('hidden');
75
- $removedField.hide();
76
- } else {
77
- $removedField.remove();
78
- }
79
-
80
- if (this.onRemoveField) {
81
- this.onRemoveField($removedField);
82
- }
83
- }
84
-
85
- _getUID() {
86
- return `${new Date().getTime()}-${Math.floor(Math.random() * 1000000)}`;
87
- }
88
- }
89
-
90
- exports.DecidimAdmin = exports.DecidimAdmin || {};
91
- exports.DecidimAdmin.DynamicFieldsComponent = DynamicFieldsComponent;
92
- exports.DecidimAdmin.createDynamicFields = (options) => {
93
- return new DynamicFieldsComponent(options);
94
- };
95
- })(window);
@@ -1,15 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Decidim
4
- module Surveys
5
- module Admin
6
- # This class holds a Form to update survey question answer options
7
- class SurveyQuestionAnswerOptionForm < Decidim::Form
8
- include TranslatableAttributes
9
-
10
- attribute :body, String
11
- translatable_attribute :body, String
12
- end
13
- end
14
- end
15
- end