decidim-participatory_processes 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +36 -0
  3. data/Rakefile +3 -0
  4. data/app/assets/config/admin/decidim_participatory_processes_manifest.js +1 -0
  5. data/app/assets/config/decidim_participatory_processes_manifest.js +2 -0
  6. data/app/assets/images/decidim/participatory_processes/process.svg +10 -0
  7. data/app/assets/javascripts/decidim/participatory_processes/admin/participatory_processes.js.es6 +12 -0
  8. data/app/assets/javascripts/decidim/participatory_processes/filters.js.es6 +25 -0
  9. data/app/commands/decidim/participatory_processes/admin/activate_participatory_process_step.rb +46 -0
  10. data/app/commands/decidim/participatory_processes/admin/copy_participatory_process.rb +116 -0
  11. data/app/commands/decidim/participatory_processes/admin/create_participatory_process.rb +82 -0
  12. data/app/commands/decidim/participatory_processes/admin/create_participatory_process_admin.rb +95 -0
  13. data/app/commands/decidim/participatory_processes/admin/create_participatory_process_group.rb +57 -0
  14. data/app/commands/decidim/participatory_processes/admin/create_participatory_process_step.rb +49 -0
  15. data/app/commands/decidim/participatory_processes/admin/deactivate_participatory_process_step.rb +38 -0
  16. data/app/commands/decidim/participatory_processes/admin/destroy_participatory_process_step.rb +46 -0
  17. data/app/commands/decidim/participatory_processes/admin/publish_participatory_process.rb +34 -0
  18. data/app/commands/decidim/participatory_processes/admin/reorder_participatory_process_steps.rb +54 -0
  19. data/app/commands/decidim/participatory_processes/admin/unpublish_participatory_process.rb +34 -0
  20. data/app/commands/decidim/participatory_processes/admin/update_participatory_process.rb +77 -0
  21. data/app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb +43 -0
  22. data/app/commands/decidim/participatory_processes/admin/update_participatory_process_group.rb +60 -0
  23. data/app/commands/decidim/participatory_processes/admin/update_participatory_process_step.rb +51 -0
  24. data/app/constraints/decidim/participatory_processes/current_feature.rb +28 -0
  25. data/app/constraints/decidim/participatory_processes/current_participatory_process.rb +37 -0
  26. data/app/controllers/concerns/decidim/participatory_processes/admin/participatory_process_context.rb +21 -0
  27. data/app/controllers/concerns/decidim/participatory_processes/needs_participatory_process.rb +50 -0
  28. data/app/controllers/concerns/decidim/participatory_processes/participatory_process_context.rb +27 -0
  29. data/app/controllers/decidim/participatory_processes/admin/application_controller.rb +11 -0
  30. data/app/controllers/decidim/participatory_processes/admin/categories_controller.rb +13 -0
  31. data/app/controllers/decidim/participatory_processes/admin/concerns/participatory_process_admin.rb +26 -0
  32. data/app/controllers/decidim/participatory_processes/admin/exports_controller.rb +14 -0
  33. data/app/controllers/decidim/participatory_processes/admin/feature_permissions_controller.rb +14 -0
  34. data/app/controllers/decidim/participatory_processes/admin/features_controller.rb +14 -0
  35. data/app/controllers/decidim/participatory_processes/admin/moderations_controller.rb +12 -0
  36. data/app/controllers/decidim/participatory_processes/admin/participatory_process_attachments_controller.rb +27 -0
  37. data/app/controllers/decidim/participatory_processes/admin/participatory_process_copies_controller.rb +35 -0
  38. data/app/controllers/decidim/participatory_processes/admin/participatory_process_groups_controller.rb +90 -0
  39. data/app/controllers/decidim/participatory_processes/admin/participatory_process_publications_controller.rb +45 -0
  40. data/app/controllers/decidim/participatory_processes/admin/participatory_process_step_activations_controller.rb +39 -0
  41. data/app/controllers/decidim/participatory_processes/admin/participatory_process_step_ordering_controller.rb +29 -0
  42. data/app/controllers/decidim/participatory_processes/admin/participatory_process_steps_controller.rb +91 -0
  43. data/app/controllers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb +99 -0
  44. data/app/controllers/decidim/participatory_processes/admin/participatory_processes_controller.rb +102 -0
  45. data/app/controllers/decidim/participatory_processes/participatory_process_groups_controller.rb +28 -0
  46. data/app/controllers/decidim/participatory_processes/participatory_process_steps_controller.rb +20 -0
  47. data/app/controllers/decidim/participatory_processes/participatory_process_widgets_controller.rb +21 -0
  48. data/app/controllers/decidim/participatory_processes/participatory_processes_controller.rb +64 -0
  49. data/app/forms/decidim/participatory_processes/admin/participatory_process_copy_form.rb +35 -0
  50. data/app/forms/decidim/participatory_processes/admin/participatory_process_form.rb +72 -0
  51. data/app/forms/decidim/participatory_processes/admin/participatory_process_group_form.rb +26 -0
  52. data/app/forms/decidim/participatory_processes/admin/participatory_process_step_form.rb +37 -0
  53. data/app/forms/decidim/participatory_processes/admin/participatory_process_user_role_form.rb +31 -0
  54. data/app/helpers/decidim/participatory_processes/admin/process_groups_for_select_helper.rb +23 -0
  55. data/app/helpers/decidim/participatory_processes/admin/processes_for_select_helper.rb +25 -0
  56. data/app/helpers/decidim/participatory_processes/participatory_process_helper.rb +19 -0
  57. data/app/helpers/decidim/participatory_processes/participatory_process_steps_helper.rb +20 -0
  58. data/app/models/decidim/participatory_process.rb +62 -0
  59. data/app/models/decidim/participatory_process_group.rb +15 -0
  60. data/app/models/decidim/participatory_process_step.rb +39 -0
  61. data/app/models/decidim/participatory_processes/abilities/admin/admin_ability.rb +21 -0
  62. data/app/models/decidim/participatory_processes/abilities/admin_ability.rb +16 -0
  63. data/app/models/decidim/participatory_processes/abilities/everyone_ability.rb +19 -0
  64. data/app/presenters/decidim/participatory_processes/participatory_process_stats_presenter.rb +52 -0
  65. data/app/queries/decidim/participatory_processes/admin/admin_users.rb +46 -0
  66. data/app/queries/decidim/participatory_processes/filtered_participatory_process_groups.rb +29 -0
  67. data/app/queries/decidim/participatory_processes/filtered_participatory_processes.rb +26 -0
  68. data/app/queries/decidim/participatory_processes/highlighted_participatory_processes.rb +12 -0
  69. data/app/queries/decidim/participatory_processes/organization_participatory_process_groups.rb +16 -0
  70. data/app/queries/decidim/participatory_processes/organization_participatory_processes.rb +16 -0
  71. data/app/queries/decidim/participatory_processes/organization_prioritized_participatory_process_groups.rb +20 -0
  72. data/app/queries/decidim/participatory_processes/organization_prioritized_participatory_processes.rb +22 -0
  73. data/app/queries/decidim/participatory_processes/organization_published_participatory_processes.rb +19 -0
  74. data/app/queries/decidim/participatory_processes/prioritized_participatory_processes.rb +13 -0
  75. data/app/queries/decidim/participatory_processes/promoted_participatory_processes.rb +12 -0
  76. data/app/queries/decidim/participatory_processes/published_participatory_processes.rb +12 -0
  77. data/app/views/decidim/participatory_process_groups/_participatory_process_group.html.erb +22 -0
  78. data/app/views/decidim/participatory_process_steps/_participatory_process_step.html.erb +16 -0
  79. data/app/views/decidim/participatory_processes/_order_by_processes.html.erb +12 -0
  80. data/app/views/decidim/participatory_processes/_participatory_process.html.erb +28 -0
  81. data/app/views/decidim/participatory_processes/admin/participatory_process_copies/_form.html.erb +38 -0
  82. data/app/views/decidim/participatory_processes/admin/participatory_process_copies/new.html.erb +7 -0
  83. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/_form.html.erb +17 -0
  84. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/edit.html.erb +19 -0
  85. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/index.html.erb +44 -0
  86. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/new.html.erb +13 -0
  87. data/app/views/decidim/participatory_processes/admin/participatory_process_groups/show.html.erb +23 -0
  88. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/_form.html.erb +25 -0
  89. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/edit.html.erb +8 -0
  90. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/index.html.erb +63 -0
  91. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/new.html.erb +7 -0
  92. data/app/views/decidim/participatory_processes/admin/participatory_process_steps/show.html.erb +18 -0
  93. data/app/views/decidim/participatory_processes/admin/participatory_process_user_roles/_form.html.erb +22 -0
  94. data/app/views/decidim/participatory_processes/admin/participatory_process_user_roles/edit.html.erb +7 -0
  95. data/app/views/decidim/participatory_processes/admin/participatory_process_user_roles/index.html.erb +65 -0
  96. data/app/views/decidim/participatory_processes/admin/participatory_process_user_roles/new.html.erb +7 -0
  97. data/app/views/decidim/participatory_processes/admin/participatory_processes/_form.html.erb +107 -0
  98. data/app/views/decidim/participatory_processes/admin/participatory_processes/edit.html.erb +19 -0
  99. data/app/views/decidim/participatory_processes/admin/participatory_processes/index.html.erb +66 -0
  100. data/app/views/decidim/participatory_processes/admin/participatory_processes/new.html.erb +11 -0
  101. data/app/views/decidim/participatory_processes/participatory_process_groups/show.html.erb +11 -0
  102. data/app/views/decidim/participatory_processes/participatory_process_steps/_timeline.html.erb +7 -0
  103. data/app/views/decidim/participatory_processes/participatory_process_steps/index.html.erb +14 -0
  104. data/app/views/decidim/participatory_processes/participatory_process_widgets/show.html.erb +17 -0
  105. data/app/views/decidim/participatory_processes/participatory_processes/_no_processes_yet.html.erb +3 -0
  106. data/app/views/decidim/participatory_processes/participatory_processes/_promoted_process.html.erb +32 -0
  107. data/app/views/decidim/participatory_processes/participatory_processes/_statistics.html.erb +10 -0
  108. data/app/views/decidim/participatory_processes/participatory_processes/index.html.erb +22 -0
  109. data/app/views/decidim/participatory_processes/participatory_processes/index.js.erb +6 -0
  110. data/app/views/decidim/participatory_processes/participatory_processes/show.html.erb +92 -0
  111. data/app/views/layouts/decidim/_process_header.html.erb +65 -0
  112. data/app/views/layouts/decidim/_process_header_steps.html.erb +27 -0
  113. data/app/views/layouts/decidim/admin/participatory_process.html.erb +64 -0
  114. data/app/views/layouts/decidim/admin/participatory_process_groups.html.erb +14 -0
  115. data/app/views/layouts/decidim/admin/participatory_processes.html.erb +14 -0
  116. data/app/views/layouts/decidim/participatory_process.html.erb +30 -0
  117. data/config/locales/ca.yml +281 -0
  118. data/config/locales/en.yml +281 -0
  119. data/config/locales/es.yml +281 -0
  120. data/config/locales/eu.yml +280 -0
  121. data/config/locales/fi.yml +280 -0
  122. data/config/locales/fr.yml +280 -0
  123. data/config/locales/it.yml +280 -0
  124. data/config/locales/nl.yml +280 -0
  125. data/config/locales/pl.yml +281 -0
  126. data/config/locales/uk.yml +282 -0
  127. data/db/migrate/20161005130108_add_participatory_processes.rb +19 -0
  128. data/db/migrate/20161010102356_translate_processes.rb +17 -0
  129. data/db/migrate/20161011125616_add_hero_image_to_processes.rb +7 -0
  130. data/db/migrate/20161011141033_add_banner_image_to_processes.rb +7 -0
  131. data/db/migrate/20161013134732_add_promoted_flag_to_processes.rb +7 -0
  132. data/db/migrate/20161017085822_add_participatory_process_steps.rb +18 -0
  133. data/db/migrate/20161019072016_add_active_flag_to_step.rb +13 -0
  134. data/db/migrate/20161020080756_add_position_to_steps.rb +9 -0
  135. data/db/migrate/20161025125300_add_published_at_to_processes.rb +7 -0
  136. data/db/migrate/20161107152228_remove_not_null_on_step_position.rb +7 -0
  137. data/db/migrate/20161110092735_add_index_for_process_slug_organization.rb +10 -0
  138. data/db/migrate/20161116115156_create_attachments.rb +18 -0
  139. data/db/migrate/20170116135237_loosen_step_requirements.rb +8 -0
  140. data/db/migrate/20170123134023_make_attachments_polymorphic.rb +20 -0
  141. data/db/migrate/20170125135937_rename_attachable_to_attached_to.rb +13 -0
  142. data/db/migrate/20170126151123_add_extra_info_to_processes.rb +10 -0
  143. data/db/migrate/20170206083118_rename_extra_info_on_processes.rb +14 -0
  144. data/db/migrate/20170220110740_remove_steps_short_description.rb +23 -0
  145. data/db/migrate/20170221094835_add_scopes_to_processes.rb +8 -0
  146. data/db/migrate/20170228142440_add_participatory_process_groups.rb +17 -0
  147. data/db/migrate/20170404132616_change_steps_end_and_start_date_to_date.rb +8 -0
  148. data/db/migrate/20170720120135_make_features_polymorphic.rb +27 -0
  149. data/db/migrate/20170725085104_add_show_statistics_to_participatory_processes.rb +7 -0
  150. data/db/migrate/20170804125402_attachment_description_nullable.rb +7 -0
  151. data/db/migrate/20170808080905_add_announcement_to_participatory_processes.rb +7 -0
  152. data/db/migrate/20170809084005_add_scopes_enabled_to_participatory_processes.rb +7 -0
  153. data/db/migrate/20170830081725_add_start_date_to_processes.rb +8 -0
  154. data/db/seeds/Exampledocument.pdf +0 -0
  155. data/db/seeds/city.jpeg +0 -0
  156. data/db/seeds/city2.jpeg +0 -0
  157. data/db/seeds/homepage_image.jpg +0 -0
  158. data/lib/decidim/participatory_processes.rb +12 -0
  159. data/lib/decidim/participatory_processes/admin.rb +10 -0
  160. data/lib/decidim/participatory_processes/admin_engine.rb +98 -0
  161. data/lib/decidim/participatory_processes/engine.rb +55 -0
  162. data/lib/decidim/participatory_processes/participatory_space.rb +118 -0
  163. data/lib/decidim/participatory_processes/test/factories.rb +97 -0
  164. metadata +266 -0
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ class ParticipatoryProcessWidgetsController < Decidim::WidgetsController
6
+ private
7
+
8
+ def model
9
+ @model ||= ParticipatoryProcess.find(params[:participatory_process_id])
10
+ end
11
+
12
+ def current_participatory_space
13
+ model
14
+ end
15
+
16
+ def iframe_url
17
+ @iframe_url ||= participatory_process_participatory_process_widget_url(model)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ # A controller that holds the logic to show ParticipatoryProcesses in a
6
+ # public layout.
7
+ class ParticipatoryProcessesController < Decidim::ApplicationController
8
+ layout "layouts/decidim/participatory_process", only: [:show]
9
+
10
+ before_action -> { extend NeedsParticipatoryProcess }, only: [:show]
11
+
12
+ helper Decidim::AttachmentsHelper
13
+ helper Decidim::IconHelper
14
+ helper Decidim::WidgetUrlsHelper
15
+
16
+ helper ParticipatoryProcessHelper
17
+
18
+ helper_method :collection, :promoted_participatory_processes, :participatory_processes, :stats, :filter
19
+
20
+ def index
21
+ authorize! :read, ParticipatoryProcess
22
+ authorize! :read, ParticipatoryProcessGroup
23
+ end
24
+
25
+ def show
26
+ authorize! :read, current_participatory_process
27
+ end
28
+
29
+ private
30
+
31
+ def collection
32
+ @collection ||= (participatory_processes.to_a + participatory_process_groups).flatten
33
+ end
34
+
35
+ def filtered_participatory_processes(filter = default_filter)
36
+ OrganizationPrioritizedParticipatoryProcesses.new(current_organization, filter)
37
+ end
38
+
39
+ def participatory_processes
40
+ @participatory_processes ||= filtered_participatory_processes(filter)
41
+ end
42
+
43
+ def promoted_participatory_processes
44
+ @promoted_processes ||= filtered_participatory_processes | PromotedParticipatoryProcesses.new
45
+ end
46
+
47
+ def participatory_process_groups
48
+ @process_groups ||= OrganizationPrioritizedParticipatoryProcessGroups.new(current_organization, filter)
49
+ end
50
+
51
+ def stats
52
+ @stats ||= ParticipatoryProcessStatsPresenter.new(participatory_process: current_participatory_process)
53
+ end
54
+
55
+ def filter
56
+ @filter = params[:filter] || default_filter
57
+ end
58
+
59
+ def default_filter
60
+ "active"
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A form object used to copy a participatory processes from the admin
7
+ # dashboard.
8
+ #
9
+ class ParticipatoryProcessCopyForm < Form
10
+ include TranslatableAttributes
11
+
12
+ translatable_attribute :title, String
13
+
14
+ mimic :participatory_process
15
+
16
+ attribute :slug, String
17
+ attribute :copy_steps, Boolean
18
+ attribute :copy_categories, Boolean
19
+ attribute :copy_features, Boolean
20
+
21
+ validates :slug, presence: true
22
+ validates :title, translatable_presence: true
23
+ validate :slug, :slug_uniqueness
24
+
25
+ private
26
+
27
+ def slug_uniqueness
28
+ return unless OrganizationParticipatoryProcesses.new(current_organization).query.where(slug: slug).where.not(id: id).any?
29
+
30
+ errors.add(:slug, :taken)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A form object used to create participatory processes from the admin
7
+ # dashboard.
8
+ #
9
+ class ParticipatoryProcessForm < Form
10
+ include TranslatableAttributes
11
+
12
+ translatable_attribute :title, String
13
+ translatable_attribute :subtitle, String
14
+ translatable_attribute :description, String
15
+ translatable_attribute :short_description, String
16
+ translatable_attribute :meta_scope, String
17
+ translatable_attribute :developer_group, String
18
+ translatable_attribute :local_area, String
19
+ translatable_attribute :target, String
20
+ translatable_attribute :participatory_scope, String
21
+ translatable_attribute :participatory_structure, String
22
+ translatable_attribute :announcement, String
23
+
24
+ mimic :participatory_process
25
+
26
+ attribute :start_date, Date
27
+ attribute :end_date, Date
28
+ attribute :slug, String
29
+ attribute :hashtag, String
30
+ attribute :promoted, Boolean
31
+ attribute :scopes_enabled, Boolean
32
+ attribute :scope_id, Integer
33
+ attribute :hero_image
34
+ attribute :remove_hero_image
35
+ attribute :banner_image
36
+ attribute :remove_banner_image
37
+ attribute :participatory_process_group_id, Integer
38
+ attribute :show_statistics, Boolean
39
+
40
+ validates :slug, presence: true
41
+ validates :title, :subtitle, :description, :short_description, translatable_presence: true
42
+ validates :scope, presence: true, if: proc { |object| object.scope_id.present? }
43
+
44
+ validate :slug, :slug_uniqueness
45
+
46
+ validates :hero_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] }
47
+ validates :banner_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] }
48
+
49
+ def map_model(model)
50
+ self.scope_id = model.decidim_scope_id
51
+ self.participatory_process_group_id = model.decidim_participatory_process_group_id
52
+ end
53
+
54
+ def scope
55
+ @scope ||= current_organization.scopes.where(id: scope_id).first
56
+ end
57
+
58
+ def participatory_process_group
59
+ Decidim::ParticipatoryProcessGroup.where(id: participatory_process_group_id).first
60
+ end
61
+
62
+ private
63
+
64
+ def slug_uniqueness
65
+ return unless OrganizationParticipatoryProcesses.new(current_organization).query.where(slug: slug).where.not(id: id).any?
66
+
67
+ errors.add(:slug, :taken)
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A form object used to create participatory process groups from the admin
7
+ # dashboard.
8
+ #
9
+ class ParticipatoryProcessGroupForm < Form
10
+ include TranslatableAttributes
11
+
12
+ translatable_attribute :name, String
13
+ translatable_attribute :description, String
14
+ attribute :participatory_process_ids, Array[Integer]
15
+
16
+ mimic :participatory_process_group
17
+
18
+ attribute :hero_image
19
+
20
+ validates :name, :description, translatable_presence: true
21
+
22
+ validates :hero_image, file_size: { less_than_or_equal_to: ->(_record) { Decidim.maximum_attachment_size } }, file_content_type: { allow: ["image/jpeg", "image/png"] }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A form object used to create participatory processes steps from the admin
7
+ # dashboard.
8
+ #
9
+ class ParticipatoryProcessStepForm < Form
10
+ include TranslatableAttributes
11
+
12
+ translatable_attribute :title, String
13
+ translatable_attribute :description, String
14
+
15
+ mimic :participatory_process_step
16
+
17
+ attribute :start_date, DateTime
18
+ attribute :end_date, DateTime
19
+
20
+ validates :title, translatable_presence: true
21
+
22
+ validates :start_date, date: { before: :end_date, allow_blank: true, if: proc { |obj| obj.end_date.present? } }
23
+ validates :end_date, date: { after: :start_date, allow_blank: true, if: proc { |obj| obj.start_date.present? } }
24
+
25
+ def start_date
26
+ return nil unless super.respond_to?(:at_midnight)
27
+ super.at_midnight
28
+ end
29
+
30
+ def end_date
31
+ return nil unless super.respond_to?(:at_midnight)
32
+ super.at_midnight
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # A form object used to create participatory process user roles from the
7
+ # admin dashboard.
8
+ #
9
+ class ParticipatoryProcessUserRoleForm < Form
10
+ mimic :participatory_process_user_role
11
+
12
+ attribute :name, String
13
+ attribute :email, String
14
+ attribute :role, String
15
+
16
+ validates :email, :role, presence: true
17
+ validates :name, presence: true
18
+ validates :role, inclusion: { in: Decidim::ParticipatoryProcessUserRole::ROLES }
19
+
20
+ def roles
21
+ Decidim::ParticipatoryProcessUserRole::ROLES.map do |role|
22
+ [
23
+ I18n.t(role, scope: "decidim.admin.models.participatory_process_user_role.roles"),
24
+ role
25
+ ]
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # This class contains helpers needed to format ParticipatoryProcessGroups
7
+ # in order to use them in select forms.
8
+ #
9
+ module ProcessGroupsForSelectHelper
10
+ # Public: A formatted collection of ParticipatoryProcessGroups to be used
11
+ # in forms.
12
+ #
13
+ # Returns an Array.
14
+ def process_groups_for_select
15
+ @process_groups_for_select ||=
16
+ OrganizationParticipatoryProcessGroups.new(current_organization).map do |group|
17
+ [translated_attribute(group.name), group.id]
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ module Admin
6
+ # This class contains helpers needed to format ParticipatoryProcesses
7
+ # in order to use them in select forms.
8
+ #
9
+ module ProcessesForSelectHelper
10
+ # Public: A formatted collection of ParticipatoryProcesses to be used
11
+ # in forms.
12
+ #
13
+ # Returns an Array.
14
+ def processes_for_select
15
+ @processes_for_select ||= OrganizationParticipatoryProcesses.new(current_organization).map do |process|
16
+ [
17
+ translated_attribute(process.title),
18
+ process.id
19
+ ]
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ # Helpers related to the Participatory Process layout.
6
+ module ParticipatoryProcessHelper
7
+ # Public: Returns the dates for a step in a readable format like
8
+ # "2016-01-01 - 2016-02-05".
9
+ #
10
+ # participatory_process_step - The step to format to
11
+ #
12
+ # Returns a String with the formatted dates.
13
+ def participatory_process_step_dates(participatory_process_step)
14
+ dates = [participatory_process_step.start_date, participatory_process_step.end_date]
15
+ dates.map { |date| date ? localize(date.to_date, format: :default) : "?" }.join(" - ")
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ParticipatoryProcesses
5
+ # Helper that provides a single method to give a class to a
6
+ # ParticipatoryProcessStep depending on their date.
7
+ module ParticipatoryProcessStepsHelper
8
+ # Returns the class for the given step depending on their end_date.
9
+ #
10
+ # step - the given ParticipatoryProcessStep
11
+ # past - a Boolean indicating if the step is past or not
12
+ #
13
+ # Returns a String.
14
+ def step_class(step, past)
15
+ status = past ? "" : "timeline__item--inactive"
16
+ step.active? ? "timeline__item--current" : status
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ # Interaction between a user and an organization is done via a
5
+ # ParticipatoryProcess. It's a unit of action from the Organization point of
6
+ # view that groups several features (proposals, debates...) distributed in
7
+ # steps that get enabled or disabled depending on which step is currently
8
+ # active.
9
+ class ParticipatoryProcess < ApplicationRecord
10
+ include Decidim::HasAttachments
11
+ include Decidim::Participable
12
+ include Decidim::Publicable
13
+ include Decidim::Scopable
14
+
15
+ belongs_to :organization,
16
+ foreign_key: "decidim_organization_id",
17
+ class_name: "Decidim::Organization"
18
+ belongs_to :participatory_process_group,
19
+ foreign_key: "decidim_participatory_process_group_id",
20
+ class_name: "Decidim::ParticipatoryProcessGroup",
21
+ inverse_of: :participatory_processes,
22
+ optional: true
23
+ has_many :steps,
24
+ -> { order(position: :asc) },
25
+ foreign_key: "decidim_participatory_process_id",
26
+ class_name: "Decidim::ParticipatoryProcessStep",
27
+ dependent: :destroy,
28
+ inverse_of: :participatory_process
29
+ has_one :active_step,
30
+ -> { where(active: true) },
31
+ foreign_key: "decidim_participatory_process_id",
32
+ class_name: "Decidim::ParticipatoryProcessStep",
33
+ dependent: :destroy,
34
+ inverse_of: :participatory_process
35
+ has_many :categories,
36
+ foreign_key: "decidim_participatory_space_id",
37
+ foreign_type: "decidim_participatory_space_type",
38
+ dependent: :destroy,
39
+ as: :participatory_space
40
+
41
+ has_many :features, as: :participatory_space
42
+
43
+ attr_readonly :active_step
44
+
45
+ validates :slug, presence: true
46
+ validates :slug, uniqueness: { scope: :organization }
47
+
48
+ mount_uploader :hero_image, Decidim::HeroImageUploader
49
+ mount_uploader :banner_image, Decidim::BannerImageUploader
50
+
51
+ # Scope to return only the promoted processes.
52
+ #
53
+ # Returns an ActiveRecord::Relation.
54
+ def self.promoted
55
+ where(promoted: true)
56
+ end
57
+
58
+ def hashtag
59
+ attributes["hashtag"].to_s.delete("#")
60
+ end
61
+ end
62
+ end