decidim-consultations 0.11.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +51 -0
  3. data/Rakefile +3 -0
  4. data/app/assets/config/decidim_consultations_manifest.js +5 -0
  5. data/app/assets/config/decidim_consultations_manifest.scss +3 -0
  6. data/app/assets/images/decidim/consultations/icon.svg +70 -0
  7. data/app/assets/images/decidim/consultations/icon2.svg +88 -0
  8. data/app/assets/javascripts/decidim/consultations/show_more.js.es6 +12 -0
  9. data/app/assets/javascripts/decidim/consultations/social_share.js +2 -0
  10. data/app/assets/javascripts/decidim/consultations/utils.js.es6 +19 -0
  11. data/app/assets/javascripts/decidim/consultations/vote_dialog.js +36 -0
  12. data/app/assets/stylesheets/decidim/consultations/_question.scss +46 -0
  13. data/app/assets/stylesheets/decidim/consultations/_stats.scss +22 -0
  14. data/app/assets/stylesheets/decidim/consultations/_video_wrapper.scss +14 -0
  15. data/app/assets/stylesheets/decidim/consultations/banners/_block-banner.scss +39 -0
  16. data/app/assets/stylesheets/decidim/consultations/consultations.scss +6 -0
  17. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-banner.scss +13 -0
  18. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-card.scss +17 -0
  19. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-header.scss +115 -0
  20. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-home-banner.scss +15 -0
  21. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-home-intro.scss +30 -0
  22. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-intro.scss +11 -0
  23. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations-title.scss +26 -0
  24. data/app/assets/stylesheets/decidim/consultations/consultations/_consultations_nav.scss +7 -0
  25. data/app/assets/stylesheets/decidim/consultations/consultations/introductory_image.scss +3 -0
  26. data/app/assets/stylesheets/decidim/consultations/highlighted-content-banner.css.scss +42 -0
  27. data/app/assets/stylesheets/decidim/consultations/social_share.css.scss +18 -0
  28. data/app/commands/decidim/consultations/admin/create_consultation.rb +61 -0
  29. data/app/commands/decidim/consultations/admin/create_question.rb +68 -0
  30. data/app/commands/decidim/consultations/admin/create_response.rb +39 -0
  31. data/app/commands/decidim/consultations/admin/publish_consultation.rb +34 -0
  32. data/app/commands/decidim/consultations/admin/publish_consultation_results.rb +34 -0
  33. data/app/commands/decidim/consultations/admin/publish_question.rb +34 -0
  34. data/app/commands/decidim/consultations/admin/unpublish_consultation.rb +34 -0
  35. data/app/commands/decidim/consultations/admin/unpublish_consultation_results.rb +34 -0
  36. data/app/commands/decidim/consultations/admin/unpublish_question.rb +34 -0
  37. data/app/commands/decidim/consultations/admin/update_consultation.rb +64 -0
  38. data/app/commands/decidim/consultations/admin/update_question.rb +72 -0
  39. data/app/commands/decidim/consultations/admin/update_response.rb +46 -0
  40. data/app/commands/decidim/consultations/unvote_question.rb +37 -0
  41. data/app/commands/decidim/consultations/vote_question.rb +42 -0
  42. data/app/constraints/decidim/consultations/current_component.rb +28 -0
  43. data/app/constraints/decidim/consultations/current_question.rb +36 -0
  44. data/app/controllers/concerns/decidim/consultations/action_authorization.rb +38 -0
  45. data/app/controllers/concerns/decidim/consultations/admin/consultation_admin.rb +24 -0
  46. data/app/controllers/concerns/decidim/consultations/admin/question_admin.rb +28 -0
  47. data/app/controllers/concerns/decidim/consultations/needs_consultation.rb +54 -0
  48. data/app/controllers/concerns/decidim/consultations/needs_question.rb +79 -0
  49. data/app/controllers/concerns/decidim/consultations/orderable.rb +52 -0
  50. data/app/controllers/decidim/consultations/admin/application_controller.rb +14 -0
  51. data/app/controllers/decidim/consultations/admin/categories_controller.rb +13 -0
  52. data/app/controllers/decidim/consultations/admin/component_permissions_controller.rb +13 -0
  53. data/app/controllers/decidim/consultations/admin/components_controller.rb +13 -0
  54. data/app/controllers/decidim/consultations/admin/consultation_publications_controller.rb +44 -0
  55. data/app/controllers/decidim/consultations/admin/consultation_results_publications_controller.rb +44 -0
  56. data/app/controllers/decidim/consultations/admin/consultations_controller.rb +100 -0
  57. data/app/controllers/decidim/consultations/admin/question_attachments_controller.rb +25 -0
  58. data/app/controllers/decidim/consultations/admin/question_publications_controller.rb +44 -0
  59. data/app/controllers/decidim/consultations/admin/questions_controller.rb +88 -0
  60. data/app/controllers/decidim/consultations/admin/responses_controller.rb +85 -0
  61. data/app/controllers/decidim/consultations/consultation_widgets_controller.rb +25 -0
  62. data/app/controllers/decidim/consultations/consultations_controller.rb +75 -0
  63. data/app/controllers/decidim/consultations/question_votes_controller.rb +40 -0
  64. data/app/controllers/decidim/consultations/question_widgets_controller.rb +26 -0
  65. data/app/controllers/decidim/consultations/questions_controller.rb +23 -0
  66. data/app/forms/decidim/consultations/admin/consultation_form.rb +56 -0
  67. data/app/forms/decidim/consultations/admin/question_form.rb +74 -0
  68. data/app/forms/decidim/consultations/admin/response_form.rb +18 -0
  69. data/app/forms/decidim/consultations/vote_form.rb +28 -0
  70. data/app/helpers/decidim/consultations/admin/consultations_helper.rb +14 -0
  71. data/app/helpers/decidim/consultations/admin/questions_helper.rb +14 -0
  72. data/app/helpers/decidim/consultations/consultations_helper.rb +17 -0
  73. data/app/models/concerns/decidim/consultations/override_categorization.rb +21 -0
  74. data/app/models/concerns/decidim/consultations/publicable_results.rb +51 -0
  75. data/app/models/decidim/consultation.rb +79 -0
  76. data/app/models/decidim/consultations/abilities/admin/consultation_admin_ability.rb +34 -0
  77. data/app/models/decidim/consultations/abilities/admin/question_admin_ability.rb +30 -0
  78. data/app/models/decidim/consultations/abilities/admin/response_admin_ability.rb +26 -0
  79. data/app/models/decidim/consultations/abilities/current_user_ability.rb +45 -0
  80. data/app/models/decidim/consultations/abilities/everyone_ability.rb +23 -0
  81. data/app/models/decidim/consultations/application_record.rb +9 -0
  82. data/app/models/decidim/consultations/question.rb +127 -0
  83. data/app/models/decidim/consultations/response.rb +19 -0
  84. data/app/models/decidim/consultations/vote.rb +26 -0
  85. data/app/presenters/decidim/consultations/question_stats_presenter.rb +52 -0
  86. data/app/queries/decidim/consultations/admin/admin_users.rb +40 -0
  87. data/app/queries/decidim/consultations/organization_active_consultations.rb +20 -0
  88. data/app/queries/decidim/consultations/organization_consultations.rb +20 -0
  89. data/app/queries/decidim/consultations/organization_questions.rb +20 -0
  90. data/app/services/decidim/consultations/consultation_search.rb +51 -0
  91. data/app/views/decidim/consultations/_consultation.html.erb +32 -0
  92. data/app/views/decidim/consultations/admin/consultations/_form.html.erb +58 -0
  93. data/app/views/decidim/consultations/admin/consultations/edit.html.erb +42 -0
  94. data/app/views/decidim/consultations/admin/consultations/index.html.erb +74 -0
  95. data/app/views/decidim/consultations/admin/consultations/new.html.erb +11 -0
  96. data/app/views/decidim/consultations/admin/questions/_form.html.erb +84 -0
  97. data/app/views/decidim/consultations/admin/questions/edit.html.erb +32 -0
  98. data/app/views/decidim/consultations/admin/questions/index.html.erb +74 -0
  99. data/app/views/decidim/consultations/admin/questions/new.html.erb +13 -0
  100. data/app/views/decidim/consultations/admin/responses/_form.html.erb +11 -0
  101. data/app/views/decidim/consultations/admin/responses/edit.html.erb +18 -0
  102. data/app/views/decidim/consultations/admin/responses/index.html.erb +48 -0
  103. data/app/views/decidim/consultations/admin/responses/new.html.erb +13 -0
  104. data/app/views/decidim/consultations/consultation_widgets/show.html.erb +5 -0
  105. data/app/views/decidim/consultations/consultations/_consultation_card.html.erb +24 -0
  106. data/app/views/decidim/consultations/consultations/_consultation_details.html.erb +17 -0
  107. data/app/views/decidim/consultations/consultations/_consultations.html.erb +16 -0
  108. data/app/views/decidim/consultations/consultations/_count.html.erb +1 -0
  109. data/app/views/decidim/consultations/consultations/_filters.html.erb +25 -0
  110. data/app/views/decidim/consultations/consultations/_filters_small_view.html.erb +23 -0
  111. data/app/views/decidim/consultations/consultations/_highlighted_questions.html.erb +13 -0
  112. data/app/views/decidim/consultations/consultations/_question.html.erb +40 -0
  113. data/app/views/decidim/consultations/consultations/_regular_questions.html.erb +14 -0
  114. data/app/views/decidim/consultations/consultations/finished.html.erb +15 -0
  115. data/app/views/decidim/consultations/consultations/index.html.erb +27 -0
  116. data/app/views/decidim/consultations/consultations/index.js.erb +10 -0
  117. data/app/views/decidim/consultations/consultations/show.html.erb +11 -0
  118. data/app/views/decidim/consultations/question_votes/update_vote_button.js.erb +9 -0
  119. data/app/views/decidim/consultations/question_widgets/show.html.erb +2 -0
  120. data/app/views/decidim/consultations/questions/_results.html.erb +15 -0
  121. data/app/views/decidim/consultations/questions/_right_column.html.erb +20 -0
  122. data/app/views/decidim/consultations/questions/_statistics.html.erb +31 -0
  123. data/app/views/decidim/consultations/questions/_technical_data.html.erb +38 -0
  124. data/app/views/decidim/consultations/questions/_vote_button.html.erb +76 -0
  125. data/app/views/decidim/consultations/questions/_vote_modal.html.erb +27 -0
  126. data/app/views/decidim/consultations/questions/_vote_modal_confirm.html.erb +33 -0
  127. data/app/views/decidim/consultations/questions/show.html.erb +58 -0
  128. data/app/views/layouts/decidim/_consultation_header.html.erb +16 -0
  129. data/app/views/layouts/decidim/_consultation_voting_data.html.erb +10 -0
  130. data/app/views/layouts/decidim/_question_components.html.erb +38 -0
  131. data/app/views/layouts/decidim/_question_header.html.erb +46 -0
  132. data/app/views/layouts/decidim/admin/consultation.html.erb +28 -0
  133. data/app/views/layouts/decidim/admin/consultations.html.erb +16 -0
  134. data/app/views/layouts/decidim/admin/question.html.erb +72 -0
  135. data/app/views/layouts/decidim/consultation.html.erb +17 -0
  136. data/app/views/layouts/decidim/consultation_choose.html.erb +7 -0
  137. data/app/views/layouts/decidim/question.html.erb +19 -0
  138. data/config/locales/ca.yml +248 -0
  139. data/config/locales/en.yml +249 -0
  140. data/config/locales/es.yml +248 -0
  141. data/config/locales/eu.yml +248 -0
  142. data/config/locales/fi.yml +248 -0
  143. data/config/locales/fr.yml +248 -0
  144. data/config/locales/gl.yml +248 -0
  145. data/config/locales/it.yml +248 -0
  146. data/config/locales/nl.yml +248 -0
  147. data/config/locales/pl.yml +258 -0
  148. data/config/locales/pt-BR.yml +248 -0
  149. data/config/locales/pt.yml +248 -0
  150. data/config/locales/ru.yml +6 -0
  151. data/config/locales/sv.yml +248 -0
  152. data/config/locales/uk.yml +6 -0
  153. data/db/migrate/20180109092205_create_decidim_consultations.rb +37 -0
  154. data/db/migrate/20180112053247_create_decidim_consultations_questions.rb +35 -0
  155. data/db/migrate/20180115132000_add_end_voting_date_to_decidim_consultations.rb +18 -0
  156. data/db/migrate/20180115170933_add_slug_to_decidim_consultations_questions.rb +32 -0
  157. data/db/migrate/20180119084217_create_decidim_consultations_votes.rb +17 -0
  158. data/db/migrate/20180119084331_add_votes_count_to_decidim_consultations_question.rb +7 -0
  159. data/db/migrate/20180122113155_add_origin_scope_to_decidim_consultations_questions.rb +8 -0
  160. data/db/migrate/20180122113400_add_origin_title_to_decidim_consultations_questions.rb +8 -0
  161. data/db/migrate/20180122113447_add_origin_string_to_decidim_consultations_questions.rb +7 -0
  162. data/db/migrate/20180126142459_add_enable_highlighted_banner_to_decidim_consultations.rb +7 -0
  163. data/db/migrate/20180129063438_add_i_frame_url_to_decidim_consultations_questions.rb +8 -0
  164. data/db/migrate/20180129063700_create_decidim_consultations_responses.rb +14 -0
  165. data/db/migrate/20180129122226_rename_decidim_consultations_vote_to_decidim_consultations_endorsement.rb +7 -0
  166. data/db/migrate/20180129122504_rename_decidim_consultations_questions_votes_count_to_endorsements_count.rb +7 -0
  167. data/db/migrate/20180130060754_add_responses_count_to_decidim_consultations_questions.rb +22 -0
  168. data/db/migrate/20180130110449_rename_vote_related_attributes.rb +9 -0
  169. data/db/migrate/20180130142018_add_decidim_user_group_id_to_decidim_consultations_endorsements.rb +7 -0
  170. data/db/migrate/20180130142411_rename_vote_indexes_to_endorsement_indexes.rb +36 -0
  171. data/db/migrate/20180131083844_add_response_to_decidim_consultations_endorsements.rb +10 -0
  172. data/db/migrate/20180201135823_rename_endorsement_to_vote.rb +23 -0
  173. data/db/migrate/20180202050920_add_hero_image_to_decidim_consultations_question.rb +8 -0
  174. data/db/migrate/20180202085309_add_results_published_at_to_decidim_consultations.rb +7 -0
  175. data/db/migrate/20180202133655_add_votes_count_to_decidim_consultations_response.rb +7 -0
  176. data/db/migrate/20180212100503_remove_enable_highlighted_banner_flag.rb +7 -0
  177. data/db/migrate/20180219092120_add_order_to_decidim_consultations_questions.rb +7 -0
  178. data/db/migrate/20180320100658_add_introductory_image_to_decidim_consultations.rb +7 -0
  179. data/db/seeds/Exampledocument.pdf +0 -0
  180. data/db/seeds/city.jpeg +0 -0
  181. data/db/seeds/city2.jpeg +0 -0
  182. data/db/seeds/homepage_image.jpg +0 -0
  183. data/lib/decidim/consultations.rb +18 -0
  184. data/lib/decidim/consultations/admin.rb +10 -0
  185. data/lib/decidim/consultations/admin_engine.rb +72 -0
  186. data/lib/decidim/consultations/engine.rb +83 -0
  187. data/lib/decidim/consultations/participatory_space.rb +171 -0
  188. data/lib/decidim/consultations/test/factories.rb +104 -0
  189. data/lib/decidim/consultations/version.rb +9 -0
  190. metadata +288 -0
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddIFrameUrlToDecidimConsultationsQuestions < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column :decidim_consultations_questions, :i_frame_url, :string
6
+ add_column :decidim_consultations_questions, :external_voting, :boolean
7
+ end
8
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDecidimConsultationsResponses < ActiveRecord::Migration[5.1]
4
+ def change
5
+ create_table :decidim_consultations_responses do |t|
6
+ t.jsonb :title
7
+ t.references :decidim_consultations_questions,
8
+ foreign_key: true,
9
+ index: { name: "index_consultations_responses_on_consultation_questions" }
10
+
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameDecidimConsultationsVoteToDecidimConsultationsEndorsement < ActiveRecord::Migration[5.1]
4
+ def change
5
+ rename_table :decidim_consultations_votes, :decidim_consultations_endorsements
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameDecidimConsultationsQuestionsVotesCountToEndorsementsCount < ActiveRecord::Migration[5.1]
4
+ def change
5
+ rename_column :decidim_consultations_questions, :votes_count, :endorsements_count
6
+ end
7
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddResponsesCountToDecidimConsultationsQuestions < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column :decidim_consultations_questions, :responses_count, :integer, null: false, default: 0
6
+
7
+ reversible do |dir|
8
+ dir.up { initialize_counter }
9
+ end
10
+ end
11
+
12
+ def initialize_counter
13
+ execute <<-SQL.squish
14
+ UPDATE decidim_consultations_questions
15
+ SET responses_count = (
16
+ select count(1)
17
+ from decidim_consultations_responses
18
+ where decidim_consultations_questions_id = decidim_consultations_questions.id
19
+ )
20
+ SQL
21
+ end
22
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameVoteRelatedAttributes < ActiveRecord::Migration[5.1]
4
+ def change
5
+ rename_column :decidim_consultations, :start_voting_date, :start_endorsing_date
6
+ rename_column :decidim_consultations, :end_voting_date, :end_endorsing_date
7
+ rename_column :decidim_consultations_questions, :external_voting, :external_endorsement
8
+ end
9
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddDecidimUserGroupIdToDecidimConsultationsEndorsements < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column :decidim_consultations_endorsements, :decidim_user_group_id, :integer, index: true
6
+ end
7
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameVoteIndexesToEndorsementIndexes < ActiveRecord::Migration[5.1]
4
+ def change
5
+ rename_index :decidim_consultations_endorsements,
6
+ :index_consultations_votes_on_author,
7
+ :index_consultations_endorsements_on_author
8
+
9
+ rename_index :decidim_consultations_endorsements,
10
+ :index_consultations_votes_on_consultation_question,
11
+ :index_consultations_endorsements_on_consultation_question
12
+
13
+ reversible do |dir|
14
+ dir.up { create_authorable_unique }
15
+ dir.down { create_author_unique }
16
+ end
17
+ end
18
+
19
+ def create_authorable_unique
20
+ remove_index :decidim_consultations_endorsements, name: "index_question_votes_author_unique"
21
+
22
+ add_index :decidim_consultations_endorsements,
23
+ %w(decidim_consultation_question_id decidim_author_id decidim_user_group_id),
24
+ name: "index_question_votes_author_unique",
25
+ unique: true
26
+ end
27
+
28
+ def create_author_unique
29
+ remove_index :decidim_consultations_endorsements, name: "index_question_votes_author_unique"
30
+
31
+ add_index :decidim_consultations_endorsements,
32
+ %w(decidim_consultation_question_id decidim_author_id),
33
+ name: "index_question_votes_author_unique",
34
+ unique: true
35
+ end
36
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddResponseToDecidimConsultationsEndorsements < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_reference :decidim_consultations_endorsements,
6
+ :decidim_consultations_response,
7
+ foreign_key: true,
8
+ index: { name: "index_consultations_endorsements_on_consultations_response_id" }
9
+ end
10
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RenameEndorsementToVote < ActiveRecord::Migration[5.1]
4
+ def change
5
+ rename_table :decidim_consultations_endorsements, :decidim_consultations_votes
6
+ rename_column :decidim_consultations_questions, :endorsements_count, :votes_count
7
+ rename_column :decidim_consultations, :start_endorsing_date, :start_voting_date
8
+ rename_column :decidim_consultations, :end_endorsing_date, :end_voting_date
9
+ rename_column :decidim_consultations_questions, :external_endorsement, :external_voting
10
+
11
+ rename_index :decidim_consultations_votes,
12
+ :index_consultations_endorsements_on_author,
13
+ :index_consultations_votes_on_author
14
+
15
+ rename_index :decidim_consultations_votes,
16
+ :index_consultations_endorsements_on_consultation_question,
17
+ :index_consultations_votes_on_consultation_question
18
+
19
+ rename_index :decidim_consultations_votes,
20
+ :index_consultations_endorsements_on_consultations_response_id,
21
+ :index_consultations_votes_on_consultations_response_id
22
+ end
23
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddHeroImageToDecidimConsultationsQuestion < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column :decidim_consultations_questions, :hero_image, :string
6
+ remove_column :decidim_consultations_questions, :introductory_video_url, :string
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddResultsPublishedAtToDecidimConsultations < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column :decidim_consultations, :results_published_at, :date, index: true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddVotesCountToDecidimConsultationsResponse < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column :decidim_consultations_responses, :votes_count, :integer, null: false, default: 0
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class RemoveEnableHighlightedBannerFlag < ActiveRecord::Migration[5.1]
4
+ def change
5
+ remove_column :decidim_consultations, :enable_highlighted_banner, :boolean, null: false, default: true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddOrderToDecidimConsultationsQuestions < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column :decidim_consultations_questions, :order, :integer, index: true
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ class AddIntroductoryImageToDecidimConsultations < ActiveRecord::Migration[5.1]
4
+ def change
5
+ add_column :decidim_consultations, :introductory_image, :string
6
+ end
7
+ end
Binary file
Binary file
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "decidim/consultations/admin"
4
+ require "decidim/consultations/engine"
5
+ require "decidim/consultations/admin_engine"
6
+ require "decidim/consultations/participatory_space"
7
+
8
+ module Decidim
9
+ # Base module for the consultations engine.
10
+ module Consultations
11
+ include ActiveSupport::Configurable
12
+
13
+ # Sets the expiration time for the statistic data.
14
+ config_accessor :stats_cache_expiration_time do
15
+ 5.minutes
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Consultations
5
+ # This module contains all the domain logic associated to Decidim's
6
+ # Consultations component admin panel.
7
+ module Admin
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "active_support/all"
5
+ require "decidim/core"
6
+
7
+ module Decidim
8
+ module Consultations
9
+ # Decidim's Consultations Rails Admin Engine.
10
+ class AdminEngine < ::Rails::Engine
11
+ isolate_namespace Decidim::Consultations::Admin
12
+
13
+ paths["db/migrate"] = nil
14
+
15
+ routes do
16
+ resources :consultations, param: :slug, except: :show do
17
+ resource :publish, controller: "consultation_publications", only: [:create, :destroy]
18
+ resource :publish_results, controller: "consultation_results_publications", only: [:create, :destroy]
19
+ resources :questions, param: :slug, except: :show, shallow: true do
20
+ resource :publish, controller: "question_publications", only: [:create, :destroy]
21
+ end
22
+ end
23
+
24
+ scope "/questions/:question_slug" do
25
+ resources :categories
26
+ resources :components do
27
+ resource :permissions, controller: "component_permissions"
28
+ member do
29
+ put :publish
30
+ put :unpublish
31
+ end
32
+ resources :exports, only: :create
33
+ end
34
+
35
+ resources :question_attachments
36
+ resources :responses, except: :show
37
+ end
38
+
39
+ scope "/questions/:question_slug/components/:component_id/manage" do
40
+ Decidim.component_manifests.each do |manifest|
41
+ next unless manifest.admin_engine
42
+
43
+ constraints CurrentComponent.new(manifest) do
44
+ mount manifest.admin_engine, at: "/", as: "decidim_admin_question_#{manifest.name}"
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ initializer "decidim_consultations.inject_abilities_to_user" do |_app|
51
+ Decidim.configure do |config|
52
+ config.admin_abilities += %w(
53
+ Decidim::Consultations::Abilities::Admin::ConsultationAdminAbility
54
+ Decidim::Consultations::Abilities::Admin::QuestionAdminAbility
55
+ Decidim::Consultations::Abilities::Admin::ResponseAdminAbility
56
+ )
57
+ end
58
+ end
59
+
60
+ initializer "decidim_consultations.admin_menu" do
61
+ Decidim.menu :admin_menu do |menu|
62
+ menu.item I18n.t("menu.consultations", scope: "decidim.admin"),
63
+ decidim_admin_consultations.consultations_path,
64
+ icon_name: "comment-square",
65
+ position: 3.8,
66
+ active: :inclusive,
67
+ if: can?(:index, Decidim::Consultation)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rails"
4
+ require "active_support/all"
5
+ require "decidim/core"
6
+
7
+ module Decidim
8
+ module Consultations
9
+ # Decidim"s Consultations Rails Engine.
10
+ class Engine < ::Rails::Engine
11
+ isolate_namespace Decidim::Consultations
12
+
13
+ routes do
14
+ get "/consultations/:consultation_id", to: redirect { |params, _request|
15
+ consultation = Decidim::Consultation.find(params[:consultation_id])
16
+ consultation ? "/consultations/#{consultation.slug}" : "/404"
17
+ }, constraints: { consultation_id: /[0-9]+/ }
18
+
19
+ get "/questions/:question_id", to: redirect { |params, _request|
20
+ question = Decidim::Consultations::Question.find(params[:question_id])
21
+ question ? "/questions/#{question.slug}" : "/404"
22
+ }, constraints: { question_id: /[0-9]+/ }
23
+
24
+ resources :consultations, only: [:index, :show], param: :slug, path: "consultations" do
25
+ get "finished", on: :collection
26
+ resource :consultation_widget, only: :show, path: "embed"
27
+
28
+ resources :questions, only: [:show], param: :slug, path: "questions", shallow: true do
29
+ resource :question_widget, only: :show, path: "embed"
30
+ resource :question_votes, only: [:create, :destroy], path: "vote"
31
+ end
32
+ end
33
+
34
+ get "/questions/:question_id/f/:component_id", to: redirect { |params, _request|
35
+ consultation = Decidim::Consultations::Question.find(params[:question_id])
36
+ consultation ? "/questions/#{question.slug}/f/#{params[:component_id]}" : "/404"
37
+ }, constraints: { question_id: /[0-9]+/ }
38
+
39
+ scope "/questions/:question_slug/f/:component_id" do
40
+ Decidim.component_manifests.each do |manifest|
41
+ next unless manifest.engine
42
+
43
+ constraints CurrentComponent.new(manifest) do
44
+ mount manifest.engine, at: "/", as: "decidim_question_#{manifest.name}"
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ initializer "decidim_consultations.assets" do |app|
51
+ app.config.assets.precompile += %w(
52
+ decidim_consultations_manifest.js
53
+ decidim_consultations_manifest.scss
54
+ )
55
+ end
56
+
57
+ initializer "decidim_consultations.inject_abilities_to_user" do |_app|
58
+ Decidim.configure do |config|
59
+ config.abilities += %w(
60
+ Decidim::Consultations::Abilities::EveryoneAbility
61
+ Decidim::Consultations::Abilities::CurrentUserAbility
62
+ )
63
+ end
64
+ end
65
+
66
+ initializer "decidim.stats" do
67
+ Decidim.stats.register :consultations_count, priority: StatsRegistry::HIGH_PRIORITY do |organization, _start_at, _end_at|
68
+ Decidim::Consultation.where(organization: organization).published.count
69
+ end
70
+ end
71
+
72
+ initializer "decidim_consultations.menu" do
73
+ Decidim.menu :menu do |menu|
74
+ menu.item I18n.t("menu.consultations", scope: "decidim"),
75
+ decidim_consultations.consultations_path,
76
+ position: 2.7,
77
+ if: Decidim::Consultation.where(organization: current_organization).published.any?,
78
+ active: :inclusive
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ Decidim.register_participatory_space(:consultations) do |participatory_space|
4
+ participatory_space.icon = "decidim/consultations/icon.svg"
5
+ participatory_space.model_class_name = "Decidim::Consultations::Question"
6
+
7
+ participatory_space.participatory_spaces do |organization|
8
+ Decidim::Consultations::Question.where(organization: organization)
9
+ end
10
+
11
+ participatory_space.context(:public) do |context|
12
+ context.engine = Decidim::Consultations::Engine
13
+ context.layout = "layouts/decidim/question"
14
+ context.helper = "Decidim::Consultations::ConsultationsHelper"
15
+ end
16
+
17
+ participatory_space.context(:admin) do |context|
18
+ context.engine = Decidim::Consultations::AdminEngine
19
+ context.layout = "layouts/decidim/admin/question"
20
+ end
21
+
22
+ participatory_space.seeds do
23
+ seeds_root = File.join(__dir__, "..", "..", "..", "db", "seeds")
24
+ organization = Decidim::Organization.first
25
+
26
+ # Active consultation
27
+ consultation = Decidim::Consultation.create!(
28
+ slug: Faker::Internet.unique.slug(nil, "-"),
29
+ title: Decidim::Faker::Localized.sentence(3),
30
+ subtitle: Decidim::Faker::Localized.sentence(3),
31
+ description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
32
+ Decidim::Faker::Localized.paragraph(3)
33
+ end,
34
+ published_at: Time.now.utc,
35
+ start_voting_date: Time.zone.today,
36
+ end_voting_date: Time.zone.today + 1.month,
37
+ banner_image: File.new(File.join(seeds_root, "city2.jpeg")),
38
+ introductory_video_url: "https://www.youtube.com/embed/zhMMW0TENNA",
39
+ decidim_highlighted_scope_id: Decidim::Scope.reorder("RANDOM()").first.id,
40
+ organization: organization
41
+ )
42
+
43
+ 4.times do
44
+ question = Decidim::Consultations::Question.create!(
45
+ consultation: consultation,
46
+ slug: Faker::Internet.unique.slug(nil, "-"),
47
+ decidim_scope_id: Decidim::Scope.reorder("RANDOM()").first.id,
48
+ title: Decidim::Faker::Localized.sentence(3),
49
+ subtitle: Decidim::Faker::Localized.sentence(3),
50
+ what_is_decided: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
51
+ Decidim::Faker::Localized.paragraph(3)
52
+ end,
53
+ question_context: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
54
+ Decidim::Faker::Localized.paragraph(3)
55
+ end,
56
+ hero_image: File.new(File.join(seeds_root, "city.jpeg")),
57
+ banner_image: File.new(File.join(seeds_root, "city2.jpeg")),
58
+ promoter_group: Decidim::Faker::Localized.sentence(3),
59
+ participatory_scope: Decidim::Faker::Localized.sentence(3),
60
+ published_at: Time.now.utc,
61
+ organization: organization
62
+ )
63
+
64
+ 2.times do
65
+ Decidim::Consultations::Response.create(
66
+ question: question,
67
+ title: Decidim::Faker::Localized.sentence(3)
68
+ )
69
+ end
70
+
71
+ Decidim::Comments::Seed.comments_for(question)
72
+
73
+ Decidim::Attachment.create!(
74
+ title: Decidim::Faker::Localized.sentence(2),
75
+ description: Decidim::Faker::Localized.sentence(5),
76
+ file: File.new(File.join(seeds_root, "city.jpeg")),
77
+ attached_to: question
78
+ )
79
+
80
+ Decidim::Attachment.create!(
81
+ title: Decidim::Faker::Localized.sentence(2),
82
+ description: Decidim::Faker::Localized.sentence(5),
83
+ file: File.new(File.join(seeds_root, "Exampledocument.pdf")),
84
+ attached_to: question
85
+ )
86
+ end
87
+
88
+ # Finished consultations
89
+ consultation = Decidim::Consultation.create!(
90
+ slug: Faker::Internet.unique.slug(nil, "-"),
91
+ title: Decidim::Faker::Localized.sentence(3),
92
+ subtitle: Decidim::Faker::Localized.sentence(3),
93
+ description: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
94
+ Decidim::Faker::Localized.paragraph(3)
95
+ end,
96
+ published_at: Time.zone.today - 2.months,
97
+ results_published_at: Time.zone.today - 1.month,
98
+ start_voting_date: Time.zone.today - 2.months,
99
+ end_voting_date: Time.zone.today - 1.month,
100
+ banner_image: File.new(File.join(seeds_root, "city2.jpeg")),
101
+ introductory_video_url: "https://www.youtube.com/embed/zhMMW0TENNA",
102
+ decidim_highlighted_scope_id: Decidim::Scope.reorder("RANDOM()").first.id,
103
+ organization: organization
104
+ )
105
+
106
+ 4.times do
107
+ question = Decidim::Consultations::Question.create!(
108
+ consultation: consultation,
109
+ slug: Faker::Internet.unique.slug(nil, "-"),
110
+ decidim_scope_id: Decidim::Scope.reorder("RANDOM()").first.id,
111
+ title: Decidim::Faker::Localized.sentence(3),
112
+ subtitle: Decidim::Faker::Localized.sentence(3),
113
+ what_is_decided: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
114
+ Decidim::Faker::Localized.paragraph(3)
115
+ end,
116
+ question_context: Decidim::Faker::Localized.wrapped("<p>", "</p>") do
117
+ Decidim::Faker::Localized.paragraph(3)
118
+ end,
119
+ banner_image: File.new(File.join(seeds_root, "city.jpeg")),
120
+ promoter_group: Decidim::Faker::Localized.sentence(3),
121
+ participatory_scope: Decidim::Faker::Localized.sentence(3),
122
+ hero_image: File.new(File.join(seeds_root, "city.jpeg")),
123
+ published_at: Time.now.utc,
124
+ organization: organization
125
+ )
126
+
127
+ 2.times do |i|
128
+ response = Decidim::Consultations::Response.create(
129
+ question: question,
130
+ title: Decidim::Faker::Localized.sentence(3)
131
+ )
132
+
133
+ email = "question_vote_#{question.id}_#{response.id}_#{i}@example.org"
134
+
135
+ author = Decidim::User.find_or_initialize_by(email: email)
136
+ author.update!(
137
+ name: Faker::Name.name,
138
+ nickname: Faker::Twitter.unique.screen_name,
139
+ password: "decidim123456",
140
+ password_confirmation: "decidim123456",
141
+ organization: organization,
142
+ confirmed_at: Time.current,
143
+ locale: I18n.default_locale,
144
+ tos_agreement: true
145
+ )
146
+
147
+ Decidim::Consultations::Vote.create(
148
+ question: question,
149
+ response: response,
150
+ author: author
151
+ )
152
+ end
153
+
154
+ Decidim::Comments::Seed.comments_for(question)
155
+
156
+ Decidim::Attachment.create!(
157
+ title: Decidim::Faker::Localized.sentence(2),
158
+ description: Decidim::Faker::Localized.sentence(5),
159
+ file: File.new(File.join(seeds_root, "city.jpeg")),
160
+ attached_to: question
161
+ )
162
+
163
+ Decidim::Attachment.create!(
164
+ title: Decidim::Faker::Localized.sentence(2),
165
+ description: Decidim::Faker::Localized.sentence(5),
166
+ file: File.new(File.join(seeds_root, "Exampledocument.pdf")),
167
+ attached_to: question
168
+ )
169
+ end
170
+ end
171
+ end