decidim-plans 0.16.6 → 0.16.7

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 +4 -4
  2. data/README.md +2 -1
  3. data/app/assets/javascripts/decidim/plans/admin/plans.js.es6 +93 -1
  4. data/app/assets/javascripts/decidim/plans/multifield/dynamic_fields.component.js.es6 +39 -0
  5. data/app/assets/javascripts/decidim/plans/multifield.js.es6 +1 -0
  6. data/app/cells/decidim/plans/plan_m/tags.erb +1 -0
  7. data/app/cells/decidim/plans/plan_m_cell.rb +1 -1
  8. data/app/cells/decidim/plans/tags/show.erb +7 -0
  9. data/app/cells/decidim/plans/tags/taggings.erb +3 -0
  10. data/app/cells/decidim/plans/tags_cell.rb +52 -0
  11. data/app/commands/decidim/plans/admin/answer_plan.rb +3 -0
  12. data/app/commands/decidim/plans/admin/create_tag.rb +44 -0
  13. data/app/commands/decidim/plans/admin/destroy_tag.rb +44 -0
  14. data/app/commands/decidim/plans/admin/update_plan_taggings.rb +53 -0
  15. data/app/commands/decidim/plans/admin/update_tag.rb +47 -0
  16. data/app/commands/decidim/plans/close_plan.rb +9 -1
  17. data/app/commands/decidim/plans/reopen_plan.rb +9 -1
  18. data/app/controllers/decidim/plans/admin/plans_controller.rb +32 -2
  19. data/app/controllers/decidim/plans/admin/tags_controller.rb +126 -0
  20. data/app/controllers/decidim/plans/plans_controller.rb +7 -2
  21. data/app/forms/decidim/plans/admin/tag_form.rb +22 -0
  22. data/app/forms/decidim/plans/admin/taggings_form.rb +20 -0
  23. data/app/helpers/decidim/plans/attached_proposals_helper.rb +18 -2
  24. data/app/helpers/decidim/plans/plan_cells_helper.rb +1 -1
  25. data/app/models/decidim/plans/plan.rb +14 -0
  26. data/app/models/decidim/plans/plan_tagging.rb +13 -0
  27. data/app/models/decidim/plans/tag.rb +20 -0
  28. data/app/permissions/decidim/plans/admin/permissions.rb +14 -4
  29. data/app/permissions/decidim/plans/permissions.rb +3 -1
  30. data/app/presenters/decidim/plans/plan_presenter.rb +4 -0
  31. data/app/queries/decidim/plans/component_plan_tags.rb +35 -0
  32. data/app/queries/decidim/plans/organization_tags.rb +25 -0
  33. data/app/services/decidim/plans/plan_search.rb +6 -0
  34. data/app/views/decidim/plans/admin/plans/_plan-tr.html.erb +13 -2
  35. data/app/views/decidim/plans/admin/plans/index.html.erb +9 -0
  36. data/app/views/decidim/plans/admin/plans/taggings.html.erb +67 -0
  37. data/app/views/decidim/plans/admin/tags/_form.html.erb +21 -0
  38. data/app/views/decidim/plans/admin/tags/edit.html.erb +7 -0
  39. data/app/views/decidim/plans/admin/tags/index.html.erb +52 -0
  40. data/app/views/decidim/plans/admin/tags/new.html.erb +7 -0
  41. data/app/views/decidim/plans/plans/_evaluation_modal.html.erb +22 -0
  42. data/app/views/decidim/plans/plans/_filters.html.erb +4 -0
  43. data/app/views/decidim/plans/plans/show.html.erb +9 -1
  44. data/app/views/decidim/plans/shared/_attachments.html.erb +2 -2
  45. data/app/views/decidim/plans/shared/_tags.html.erb +1 -0
  46. data/config/locales/en.yml +57 -2
  47. data/config/locales/fi.yml +57 -2
  48. data/config/locales/sv.yml +57 -2
  49. data/db/migrate/20190329161710_fix_plan_closing_workflow_states.rb +13 -0
  50. data/db/migrate/20190331141058_create_decidim_plans_tags_and_plan_taggings.rb +17 -0
  51. data/lib/decidim/content_parsers/plan_parser.rb +82 -0
  52. data/lib/decidim/content_renderers/plan_renderer.rb +33 -0
  53. data/lib/decidim/plans/admin_engine.rb +3 -0
  54. data/lib/decidim/plans/component.rb +11 -2
  55. data/lib/decidim/plans/engine.rb +6 -0
  56. data/lib/decidim/plans/test/factories.rb +17 -0
  57. data/lib/decidim/plans/version.rb +1 -1
  58. data/lib/decidim/plans.rb +8 -0
  59. metadata +29 -2
@@ -36,6 +36,7 @@ en:
36
36
  attachments_allowed: Attachments allowed
37
37
  attachment_help: Attachment help text
38
38
  categories_enabled: Categories enabled
39
+ closing_allowed: Allow plan authors to mark the plans as done
39
40
  comments_enabled: Comments enabled
40
41
  multilingual_answers: Multilingual answers
41
42
  plan_answering_enabled: Answering enabled
@@ -58,10 +59,17 @@ en:
58
59
  plans:
59
60
  actions:
60
61
  answer: Answer
62
+ back: Back
63
+ confirm_destroy: Are you sure you want to delete this?
61
64
  close_plan: Mark as done
65
+ destroy: Delete
66
+ edit: Edit
62
67
  edit_plan: Edit
63
68
  export_budgets: Convert to projects
69
+ manage_tags: Manage tags
64
70
  new: Submit new plan
71
+ new_tag: New tag
72
+ plan_taggings: Tags
65
73
  reopen_plan: Open for editing
66
74
  sections: Sections
67
75
  title: Actions
@@ -93,14 +101,24 @@ en:
93
101
  title: Edit
94
102
  update: Update
95
103
  form:
96
- attachment_legend: "Add an attachment"
104
+ attachment_legend: Add an attachment
97
105
  select_a_category: Select a category
98
106
  index:
107
+ draft_plans: Drafts
108
+ published_plans: Published
99
109
  selected: Selected
100
110
  title: Plans
101
111
  new:
102
112
  create: Create
103
113
  title: Submit new plan
114
+ taggings:
115
+ no_results: "Create new tag: %{name}"
116
+ search: Search
117
+ title: Tags
118
+ update: Update
119
+ update_taggings:
120
+ invalid: Error updating the tags.
121
+ success: Tags updated successfully.
104
122
  sections:
105
123
  form:
106
124
  add_section: Add section
@@ -124,6 +142,27 @@ en:
124
142
  body: Body
125
143
  created_at: Creation date
126
144
  plans: Plans
145
+ tags:
146
+ create:
147
+ error: Failed to create.
148
+ success: Created successfully.
149
+ destroy:
150
+ error: Error deleting.
151
+ success: Deleted successfully.
152
+ edit:
153
+ title: Edit tag
154
+ update: Update
155
+ form:
156
+ tags: Tags
157
+ index:
158
+ tags: Tags
159
+ title: Manage tags
160
+ new:
161
+ create: Create
162
+ title: New tag
163
+ update:
164
+ invalid: Error updating.
165
+ success: Updated successfully.
127
166
  admin_log:
128
167
  plan:
129
168
  answer: "%{user_name} answered %{resource_name} on the %{space_name}
@@ -175,7 +214,13 @@ en:
175
214
  published_at: Published at
176
215
  scope: Scope
177
216
  state: State
217
+ tags: Tags
178
218
  title: Title
219
+ plan_tags:
220
+ fields:
221
+ id: ID
222
+ name: Name
223
+ taggings_count: Number of uses
179
224
  plans:
180
225
  attached_proposals:
181
226
  attached_proposals: Attached proposals
@@ -193,6 +238,13 @@ en:
193
238
  discard: Discard this draft
194
239
  discard_confirmation: Are you sure you want to discard this draft?
195
240
  update: Update
241
+ evaluation_modal:
242
+ button_text: OK
243
+ close: Close modal
244
+ description: The plan is being evaluated and it cannot be edited
245
+ during this time. You will get notified once the evaluation is
246
+ completed.
247
+ title: The plan is being evaluated
196
248
  preview:
197
249
  modify: Modify
198
250
  publish: Publish
@@ -211,6 +263,8 @@ en:
211
263
  related_to: Related to
212
264
  search: Search
213
265
  state: State
266
+ tag: Tags
267
+ tag_prompt: Select tags
214
268
  voted: Voted
215
269
  filters_small_view:
216
270
  close_modal: Close modal
@@ -218,7 +272,7 @@ en:
218
272
  filter_by: Filter by
219
273
  unfold: Unfold
220
274
  form:
221
- attachment_legend: "Add an attachment"
275
+ attachment_legend: Add an attachment
222
276
  select_a_category: Select a category
223
277
  index:
224
278
  new_plan: New plan
@@ -261,6 +315,7 @@ en:
261
315
  plan_accepted_reason: 'This plan has been accepted because:'
262
316
  plan_in_evaluation_reason: This plan is being evaluated
263
317
  plan_rejected_reason: 'This plan has been rejected because:'
318
+ plan_waiting_for_evaluation: The plan is being evaluated, editing not allowed.
264
319
  publish: Publish
265
320
  publish_info: Publish this version of the draft or
266
321
  published_proposal: published plan
@@ -33,13 +33,16 @@ fi:
33
33
  global:
34
34
  announcement: Ilmoitus
35
35
  attachments_allowed: Liitteet sallittu
36
+ attachment_help: Liitteen ohjeteksti
36
37
  categories_enabled: Kategoriat käytössä
38
+ closing_allowed: Salli suunnitelmien laatijoiden merkata suunnitelmia valmiiksi
37
39
  comments_enabled: Kommentointi sallittu
38
40
  multilingual_answers: Monikieliset vastaukset
39
41
  plan_answering_enabled: Vastaaminen sallittu
40
42
  plan_title_length: Otsikon pituus
41
43
  proposal_linking_enabled: Ehdotusten linkkaaminen käytössä
42
44
  scopes_enabled: Teemat käytössä
45
+ title_help: Otsikon ohjeteksti
43
46
  step:
44
47
  announcement: Ilmoitus
45
48
  comments_blocked: Kommentointi estetty
@@ -55,10 +58,17 @@ fi:
55
58
  plans:
56
59
  actions:
57
60
  answer: Vastaa
61
+ back: Takaisin
62
+ confirm_destroy: Oletko varma että haluat poistaa tämän kohteen?
58
63
  close_plan: Merkitse valmiiksi
64
+ destroy: Poista
65
+ edit: Muokkaa
59
66
  edit_plan: Muokkaa
60
67
  export_budgets: Muunna projekteiksi
68
+ manage_tags: Hallinnoi merkintöjä
61
69
  new: Tee uusi suunnitelma
70
+ new_tag: Uusi merkintä
71
+ plan_taggings: Merkinnät
62
72
  reopen_plan: Avaa muokattavaksi
63
73
  sections: Osiot
64
74
  title: Toiminnot
@@ -90,14 +100,24 @@ fi:
90
100
  title: Muokkaa
91
101
  update: Päivitä
92
102
  form:
93
- attachment_legend: "Lisää liite"
103
+ attachment_legend: Lisää liite
94
104
  select_a_category: Valitse kategoria
95
105
  index:
106
+ draft_plans: Luonnoksia
107
+ published_plans: Julkaistuja
96
108
  selected: Valittu
97
109
  title: Suunnitelmat
98
110
  new:
99
111
  create: Luo
100
112
  title: Tee uusi suunnitelma
113
+ taggings:
114
+ no_results: "Luo uusi merkintä: %{name}"
115
+ search: Hae
116
+ title: Merkinnät
117
+ update: Päivitä
118
+ update_taggings:
119
+ invalid: Virhe päivitettäessä merkintöjä.
120
+ success: Merkintöjen päivitys onnistui.
101
121
  sections:
102
122
  form:
103
123
  add_section: Lisää osio
@@ -121,6 +141,27 @@ fi:
121
141
  body: Runkoteksti
122
142
  created_at: Luontipäivä
123
143
  plans: Suunnitelmat
144
+ tags:
145
+ create:
146
+ error: Luonti epäonnistui.
147
+ success: Luonti onnistui.
148
+ destroy:
149
+ error: Virhe poistettaessa.
150
+ success: Poisto onnistui.
151
+ edit:
152
+ title: Muokkaa merkintää
153
+ update: Päivitä
154
+ form:
155
+ tags: Merkinnät
156
+ index:
157
+ tags: Merkinnät
158
+ title: Hallinnoi merkintöjä
159
+ new:
160
+ create: Luo
161
+ title: Uusi merkintä
162
+ update:
163
+ invalid: Virhe päivitettäessä.
164
+ success: Päivitys onnistui.
124
165
  admin_log:
125
166
  plan:
126
167
  answer: "%{user_name} vastasi sisältöön %{resource_name} osallisuustilassa %{space_name}."
@@ -168,7 +209,13 @@ fi:
168
209
  published_at: Julkaisuajankohta
169
210
  scope: Teema
170
211
  state: Tila
212
+ tags: Merkinnät
171
213
  title: Otsikko
214
+ plan_tags:
215
+ fields:
216
+ id: ID
217
+ name: Nimi
218
+ taggings_count: Käyttömäärä
172
219
  plans:
173
220
  attached_proposals:
174
221
  attached_proposals: Liitetyt ehdotukset
@@ -186,6 +233,11 @@ fi:
186
233
  discard: Tuhoa tämä luonnos
187
234
  discard_confirmation: Haluatko varmasti tuhota tämän luonnoksen?
188
235
  update: Päivitä
236
+ evaluation_modal:
237
+ button_text: OK
238
+ close: Sulje ikkuna
239
+ description: Suunnitelmaa arvioidaan ja sitä ei voi muokata tällä hetkellä. Saat ilmoituksen, kun arviointi valmistuu.
240
+ title: Suunnitelmaa arvioidaan
189
241
  preview:
190
242
  modify: Muokkaa
191
243
  publish: Julkaise
@@ -204,6 +256,8 @@ fi:
204
256
  related_to: Liittyy kohteeseen
205
257
  search: Hae
206
258
  state: Tila
259
+ tag: Merkinnät
260
+ tag_prompt: Valitse merkinnät
207
261
  voted: Kannatettu
208
262
  filters_small_view:
209
263
  close_modal: Sulje ikkuna
@@ -211,7 +265,7 @@ fi:
211
265
  filter_by: Suodata
212
266
  unfold: Avaa
213
267
  form:
214
- attachment_legend: "Lisää liite"
268
+ attachment_legend: Lisää liite
215
269
  select_a_category: Valitse kategoria
216
270
  index:
217
271
  new_plan: Uusi suunnitelma
@@ -252,6 +306,7 @@ fi:
252
306
  plan_accepted_reason: 'Tämä suunnitelma on hyväksytty, koska:'
253
307
  plan_in_evaluation_reason: Tämä suunnitelma on arvioitavana
254
308
  plan_rejected_reason: 'Tämä suunnitelma on hylätty, koska:'
309
+ plan_waiting_for_evaluation: Suunnitelma on arvioinnissa, muokkaaminen estetty.
255
310
  publish: Julkaise
256
311
  publish_info: Julkaise tämä luonnosversio tai
257
312
  published_proposal: julkaistu suunnitelma
@@ -33,13 +33,16 @@ sv:
33
33
  global:
34
34
  announcement: Meddelande
35
35
  attachments_allowed: Bilagor tillåtna
36
+ attachment_help: Bilag hjälptext
36
37
  categories_enabled: Kategorier aktiverade
38
+ closing_allowed: Tillåta plan författarna att markera planerna som gjort
37
39
  comments_enabled: Kommentarer tillåtna
38
40
  multilingual_answers: Flerspråkiga svar
39
41
  plan_answering_enabled: Svar tillåtna
40
42
  plan_title_length: Rubrikens längd
41
43
  proposal_linking_enabled: Förslagslänk aktiverat
42
44
  scopes_enabled: Omfattningar aktiverade
45
+ title_help: Titel hjälptext
43
46
  step:
44
47
  announcement: Meddelande
45
48
  comments_blocked: Kommentarer blockerade
@@ -55,10 +58,17 @@ sv:
55
58
  plans:
56
59
  actions:
57
60
  answer: Svara
61
+ back: Tillbaka
62
+ confirm_destroy: Är du säker på att du vill ta bort objektet?
58
63
  close_plan: Markera som gjort
64
+ destroy: Ta bort
65
+ edit: Redigera
59
66
  edit_plan: Redigera
60
67
  export_budgets: Konvertera till projekt
68
+ manage_tags: Hantera taggar
61
69
  new: Gör ny plan
70
+ new_tag: Ny tagg
71
+ plan_taggings: Taggar
62
72
  reopen_plan: Öppna för redigering
63
73
  sections: Avsnitt
64
74
  title: Funktioner
@@ -90,14 +100,24 @@ sv:
90
100
  title: Redigera
91
101
  update: Uppdatera
92
102
  form:
93
- attachment_legend: "Lägg till bilaga"
103
+ attachment_legend: Lägg till bilaga
94
104
  select_a_category: Välj kategori
95
105
  index:
106
+ draft_plans: Utkast
107
+ published_plans: Publicerad
96
108
  selected: Vald
97
109
  title: Planer
98
110
  new:
99
111
  create: Skapa
100
112
  title: Gör ny plan
113
+ taggings:
114
+ no_results: "Skapa ny tagg: %{name}"
115
+ search: Sök
116
+ title: Taggar
117
+ update: Uppdatera
118
+ update_taggings:
119
+ invalid: Fel vid uppdatering av taggarna.
120
+ success: Taggar uppdaterats.
101
121
  sections:
102
122
  form:
103
123
  add_section: Lägg till avsnitt
@@ -121,6 +141,27 @@ sv:
121
141
  body: Brödtext
122
142
  created_at: Skapats
123
143
  plans: Planer
144
+ tags:
145
+ create:
146
+ error: Det gick inte att skapa.
147
+ success: Skapats.
148
+ destroy:
149
+ error: Fel vid borttagning.
150
+ success: Innehållet har raderats.
151
+ edit:
152
+ title: Redigera tagg
153
+ update: Uppdatera
154
+ form:
155
+ tags: Taggar
156
+ index:
157
+ tags: Taggar
158
+ title: Hantera taggar
159
+ new:
160
+ create: Skapa
161
+ title: Ny tagg
162
+ update:
163
+ invalid: Fel uppdatering.
164
+ success: Uppdaterats.
124
165
  admin_log:
125
166
  plan:
126
167
  answer: "%{user_name} svarade på innehållet %{resource_name} i delaktighetslokalen %{space_name}."
@@ -168,7 +209,13 @@ sv:
168
209
  published_at: Publikationsdatum
169
210
  scope: Tema
170
211
  state: Status
212
+ tags: Taggar
171
213
  title: Rubrik
214
+ plan_tags:
215
+ fields:
216
+ id: ID
217
+ name: Namn
218
+ taggings_count: Antal användningsområden
172
219
  plans:
173
220
  attached_proposals:
174
221
  attached_proposals: Bifogade förslag
@@ -186,6 +233,11 @@ sv:
186
233
  discard: Radera utkastet
187
234
  discard_confirmation: Är du säker på att du vill radera utkastet?
188
235
  update: Uppdatera
236
+ evaluation_modal:
237
+ button_text: OK
238
+ close: Stäng fönstret
239
+ description: Planen utvärderas och den kan inte redigeras under denna tid. Du kommer att få meddelande när utvärderingen är klar.
240
+ title: Planen beräknas
189
241
  preview:
190
242
  modify: Redigera
191
243
  publish: Publicera
@@ -204,6 +256,8 @@ sv:
204
256
  related_to: Anknyter till
205
257
  search: Sök
206
258
  state: Status
259
+ tag: Taggar
260
+ tag_prompt: Välj taggar
207
261
  voted: Understödd
208
262
  filters_small_view:
209
263
  close_modal: Stäng fönstret
@@ -211,7 +265,7 @@ sv:
211
265
  filter_by: Filtrera
212
266
  unfold: Öppna
213
267
  form:
214
- attachment_legend: "Lägg till bilaga"
268
+ attachment_legend: Lägg till bilaga
215
269
  select_a_category: Välj kategori
216
270
  index:
217
271
  new_plan: Ny plan
@@ -252,6 +306,7 @@ sv:
252
306
  plan_accepted_reason: 'Planen har godkänts eftersom:'
253
307
  plan_in_evaluation_reason: Planen bedöms
254
308
  plan_rejected_reason: 'Planen har avslagits eftersom:'
309
+ plan_waiting_for_evaluation: Planen beräknas, redigering är inte tillåten.
255
310
  publish: Publicera
256
311
  publish_info: Publicera detta utkast eller
257
312
  published_proposal: publicerad plan
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class FixPlanClosingWorkflowStates < ActiveRecord::Migration[5.2]
4
+ def up
5
+ Decidim::Plans::Plan.all.each do |plan|
6
+ if plan.closed? && !plan.answered?
7
+ plan.update!(state: "evaluating")
8
+ elsif !plan.closed? && plan.answered?
9
+ plan.update!(closed_at: plan.answered_at)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ class CreateDecidimPlansTagsAndPlanTaggings < ActiveRecord::Migration[5.2]
4
+ def change
5
+ create_table :decidim_plans_tags do |t|
6
+ t.jsonb :name
7
+ t.timestamps
8
+ t.references :decidim_organization, foreign_key: true, index: true, null: false
9
+ end
10
+
11
+ create_table :decidim_plans_plan_taggings do |t|
12
+ t.datetime :created_at
13
+ t.references :decidim_plans_tag, index: true
14
+ t.references :decidim_plan, index: true
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ContentParsers
5
+ # A parser that searches mentions of Plans in content.
6
+ #
7
+ # This parser accepts one way for linking Plans:
8
+ # - Using a standard url starting with http or https.
9
+ #
10
+ # Also fills a `Metadata#linked_plans` attribute.
11
+ #
12
+ # @see BaseParser Examples of how to use a content parser
13
+ class PlanParser < BaseParser
14
+ # Class used as a container for metadata
15
+ #
16
+ # @!attribute linked_plans
17
+ # @return [Array] an array of Decidim::Plans::Plan mentioned in content
18
+ Metadata = Struct.new(:linked_plans)
19
+
20
+ # Matches a URL
21
+ URL_REGEX_SCHEME = '(?:http(s)?:\/\/)'
22
+ URL_REGEX_CONTENT = '[\w.-]+[\w\-\._~:\/?#\[\]@!\$&\'\(\)\*\+,;=.]+'
23
+ URL_REGEX_END_CHAR = '[\d]'
24
+ URL_REGEX = %r{#{URL_REGEX_SCHEME}#{URL_REGEX_CONTENT}/plans/#{URL_REGEX_END_CHAR}+}i
25
+ # Matches a mentioned Proposal ID (~(d)+ expression)
26
+ ID_REGEX = /~(\d+)/
27
+
28
+ def initialize(content, context)
29
+ super
30
+ @metadata = Metadata.new([])
31
+ end
32
+
33
+ # Replaces found mentions matching an existing Plan with a global id for
34
+ # that Plan. Other mentions found that doesn't match an existing Plan
35
+ # are returned as they are.
36
+ #
37
+ # @return [String] the content with the valid mentions replaced by a
38
+ # global id.
39
+ def rewrite
40
+ parse_for_urls(content)
41
+ end
42
+
43
+ # (see BaseParser#metadata)
44
+ attr_reader :metadata
45
+
46
+ private
47
+
48
+ def parse_for_urls(content)
49
+ content.gsub(URL_REGEX) do |match|
50
+ plan = plan_from_url_match(match)
51
+ if plan
52
+ @metadata.linked_plans << plan.id
53
+ plan.to_global_id
54
+ else
55
+ match
56
+ end
57
+ end
58
+ end
59
+
60
+ def plan_from_url_match(match)
61
+ uri = URI.parse(match)
62
+ return if uri.path.blank?
63
+
64
+ plan_id = uri.path.split("/").last
65
+ find_plan_by_id(plan_id)
66
+ rescue URI::InvalidURIError
67
+ Rails.logger.error("#{e.message}=>#{e.backtrace}")
68
+ nil
69
+ end
70
+
71
+ def find_plan_by_id(id)
72
+ if id.present?
73
+ spaces = Decidim.participatory_space_manifests.flat_map do |manifest|
74
+ manifest.participatory_spaces.call(context[:current_organization]).public_spaces
75
+ end
76
+ components = Component.where(participatory_space: spaces).published
77
+ Decidim::Plans::Plan.where(component: components).find_by(id: id)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module ContentRenderers
5
+ # A renderer that searches Global IDs representing plans in content
6
+ # and replaces it with a link to their show page.
7
+ #
8
+ # e.g. gid://<APP_NAME>/Decidim::Plans::Plan/1
9
+ #
10
+ # @see BaseRenderer Examples of how to use a content renderer
11
+ class PlanRenderer < BaseRenderer
12
+ # Matches a global id representing a Decidim::User
13
+ GLOBAL_ID_REGEX = %r{gid:\/\/([\w-]*\/Decidim::Plans::Plan\/(\d+))}i
14
+
15
+ # Replaces found Global IDs matching an existing plan with
16
+ # a link to its show page. The Global IDs representing an
17
+ # invalid Decidim::Plans::Plan are replaced with '???' string.
18
+ #
19
+ # @return [String] the content ready to display (contains HTML)
20
+ def render
21
+ content.gsub(GLOBAL_ID_REGEX) do |plan_gid|
22
+ begin
23
+ plan = GlobalID::Locator.locate(plan_gid)
24
+ Decidim::Plans::PlanPresenter.new(plan).display_mention
25
+ rescue ActiveRecord::RecordNotFound
26
+ plan_gid = plan_gid.split("/").last
27
+ "##{plan_gid}"
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
@@ -13,7 +13,10 @@ module Decidim
13
13
  resources :plans, only: [:index, :new, :create, :edit, :update] do
14
14
  get :search_proposals
15
15
  resources :plan_answers, only: [:edit, :update]
16
+ resources :tags, except: [:show]
16
17
  member do
18
+ get :taggings
19
+ patch :update_taggings
17
20
  post :close
18
21
  post :reopen
19
22
  end
@@ -28,6 +28,7 @@ Decidim.register_component(:plans) do |component|
28
28
  settings.attribute :categories_enabled, type: :boolean, default: true
29
29
  settings.attribute :proposal_linking_enabled, type: :boolean, default: true
30
30
  settings.attribute :attachments_allowed, type: :boolean, default: false
31
+ settings.attribute :closing_allowed, type: :boolean, default: false
31
32
  settings.attribute :multilingual_answers, type: :boolean
32
33
  end
33
34
 
@@ -127,13 +128,20 @@ Decidim.register_component(:plans) do |component|
127
128
  state, answer = if n > 3
128
129
  ["accepted", Decidim::Faker::Localized.sentence(10)]
129
130
  elsif n > 2
130
- ["rejected", nil]
131
+ ["rejected", Decidim::Faker::Localized.sentence(10)]
131
132
  elsif n > 1
132
133
  ["evaluating", nil]
133
134
  else
134
135
  [nil, nil]
135
136
  end
136
137
 
138
+ # Check whether the plan is answered and set it closed by random if not.
139
+ is_answered = !state.nil?
140
+ is_closed = is_answered || rand < 0.5
141
+
142
+ # Force the state to be "evaluating" for closed but unanswered plans
143
+ state = "evaluating" if is_closed && !is_answered
144
+
137
145
  params = {
138
146
  component: component,
139
147
  category: participatory_space.categories.sample,
@@ -141,7 +149,8 @@ Decidim.register_component(:plans) do |component|
141
149
  title: Decidim::Faker::Localized.sentence(2),
142
150
  state: state,
143
151
  answer: answer,
144
- answered_at: Time.current,
152
+ closed_at: is_closed ? Time.current : nil,
153
+ answered_at: is_answered ? Time.current : nil,
145
154
  published_at: Time.current
146
155
  }
147
156
 
@@ -39,6 +39,12 @@ module Decidim
39
39
  Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Plans::Engine.root}/app/cells")
40
40
  Cell::ViewModel.view_paths << File.expand_path("#{Decidim::Plans::Engine.root}/app/views") # for partials
41
41
  end
42
+
43
+ initializer "decidim_plans.content_processors" do |_app|
44
+ Decidim.configure do |config|
45
+ config.content_processors += [:plan]
46
+ end
47
+ end
42
48
  end
43
49
  end
44
50
  end
@@ -41,6 +41,14 @@ FactoryBot.define do
41
41
  end
42
42
  end
43
43
 
44
+ trait :with_closing_allowed do
45
+ settings do
46
+ {
47
+ closing_allowed: true
48
+ }
49
+ end
50
+ end
51
+
44
52
  trait :with_multilingual_answers do
45
53
  settings do
46
54
  {
@@ -69,6 +77,7 @@ FactoryBot.define do
69
77
  plan_proposals { nil }
70
78
  # user_groups correspondence to users is by sorting order
71
79
  user_groups { [] }
80
+ tags { [] }
72
81
  end
73
82
 
74
83
  title { generate_localized_title }
@@ -87,6 +96,9 @@ FactoryBot.define do
87
96
  proposals = evaluator.plan_proposals || [create(:proposal, component: proposal_component)]
88
97
  plan.attached_proposals = proposals.map { |p| create(:attached_proposal, plan: plan, proposal: p) }
89
98
  end
99
+ if evaluator.tags && evaluator.tags.count > 0
100
+ plan.update!(tags: evaluator.tags)
101
+ end
90
102
  end
91
103
 
92
104
  trait :published do
@@ -142,4 +154,9 @@ FactoryBot.define do
142
154
  plan
143
155
  user
144
156
  end
157
+
158
+ factory :tag, class: "Decidim::Plans::Tag" do
159
+ name { generate_localized_title }
160
+ organization { create(:organization) }
161
+ end
145
162
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Decidim
4
4
  module Plans
5
- VERSION = "0.16.6"
5
+ VERSION = "0.16.7"
6
6
  DECIDIM_VERSION = "~> 0.16.0"
7
7
  end
8
8
  end
data/lib/decidim/plans.rb CHANGED
@@ -23,4 +23,12 @@ module Decidim
23
23
  @tracer ||= Tracer.new
24
24
  end
25
25
  end
26
+
27
+ module ContentParsers
28
+ autoload :PlanParser, "decidim/content_parsers/plan_parser"
29
+ end
30
+
31
+ module ContentRenderers
32
+ autoload :PlanRenderer, "decidim/content_renderers/plan_renderer"
33
+ end
26
34
  end