decidim-accountability 0.29.2 → 0.30.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/accountability/project/show.erb +6 -0
  3. data/app/cells/decidim/accountability/project_cell.rb +23 -42
  4. data/app/cells/decidim/accountability/result_history_cell.rb +57 -0
  5. data/app/cells/decidim/accountability/result_metadata_cell.rb +17 -17
  6. data/app/cells/decidim/accountability/status_cell.rb +9 -13
  7. data/app/commands/decidim/accountability/admin/create_imported_result.rb +1 -1
  8. data/app/commands/decidim/accountability/admin/create_result.rb +3 -2
  9. data/app/commands/decidim/accountability/admin/import_component_to_accountability.rb +47 -0
  10. data/app/commands/decidim/accountability/admin/update_imported_result.rb +1 -1
  11. data/app/commands/decidim/accountability/admin/update_result.rb +3 -2
  12. data/app/commands/decidim/accountability/admin/update_result_dates.rb +56 -0
  13. data/app/commands/decidim/accountability/admin/update_result_status.rb +61 -0
  14. data/app/commands/decidim/accountability/admin/update_result_taxonomies.rb +18 -0
  15. data/app/controllers/concerns/decidim/accountability/admin/filterable.rb +8 -6
  16. data/app/controllers/decidim/accountability/admin/import_components_controller.rb +36 -0
  17. data/app/controllers/decidim/accountability/admin/results_bulk_actions_controller.rb +102 -0
  18. data/app/controllers/decidim/accountability/admin/results_controller.rb +21 -11
  19. data/app/controllers/decidim/accountability/results_controller.rb +10 -7
  20. data/app/forms/decidim/accountability/admin/import_component_form.rb +98 -0
  21. data/app/forms/decidim/accountability/admin/result_bulk_actions_form.rb +18 -0
  22. data/app/forms/decidim/accountability/admin/result_form.rb +17 -23
  23. data/app/helpers/decidim/accountability/admin/application_helper.rb +0 -1
  24. data/app/helpers/decidim/accountability/application_helper.rb +1 -32
  25. data/app/helpers/decidim/accountability/breadcrumb_helper.rb +10 -14
  26. data/app/jobs/decidim/accountability/admin/import_projects_job.rb +5 -3
  27. data/app/jobs/decidim/accountability/admin/import_proposals_job.rb +70 -0
  28. data/app/mailers/decidim/accountability/import_proposals_mailer.rb +28 -0
  29. data/app/models/decidim/accountability/result.rb +23 -1
  30. data/app/models/decidim/accountability/status.rb +4 -0
  31. data/app/packs/entrypoints/decidim_accountability_admin_form.js +1 -0
  32. data/app/packs/src/decidim/accountability/admin/imports.js +37 -14
  33. data/app/packs/src/decidim/accountability/admin/index/action_button.js +42 -0
  34. data/app/packs/src/decidim/accountability/admin/index/action_form.js +46 -0
  35. data/app/packs/src/decidim/accountability/admin/index/action_selector.js +37 -0
  36. data/app/packs/src/decidim/accountability/admin/index/counter.js +40 -0
  37. data/app/packs/src/decidim/accountability/admin/index/select_all.js +29 -0
  38. data/app/packs/src/decidim/accountability/admin/index.js +17 -7
  39. data/app/packs/src/decidim/accountability/admin/result_form.js +21 -0
  40. data/app/packs/stylesheets/accountability.scss +5 -0
  41. data/app/permissions/decidim/accountability/admin/permissions.rb +3 -2
  42. data/app/presenters/decidim/accountability/admin_log/result_presenter.rb +1 -1
  43. data/app/presenters/decidim/accountability/result_presenter.rb +30 -0
  44. data/app/queries/decidim/accountability/metrics/results_metric_manage.rb +6 -6
  45. data/app/services/decidim/accountability/results_calculator.rb +4 -6
  46. data/app/services/decidim/accountability/results_csv_importer.rb +1 -1
  47. data/app/views/decidim/accountability/admin/import_components/_filters.html.erb +26 -0
  48. data/app/views/decidim/accountability/admin/import_components/_form.html.erb +26 -0
  49. data/app/views/decidim/accountability/admin/import_components/new.html.erb +14 -0
  50. data/app/views/decidim/accountability/admin/results/_actions.html.erb +29 -0
  51. data/app/views/decidim/accountability/admin/results/_form.html.erb +15 -8
  52. data/app/views/decidim/accountability/admin/results/_result-tr.html.erb +32 -0
  53. data/app/views/decidim/accountability/admin/results/_results-thead.html.erb +26 -0
  54. data/app/views/decidim/accountability/admin/results/bulk_actions/_dates_form.html.erb +19 -0
  55. data/app/views/decidim/accountability/admin/results/bulk_actions/_dropdown.html.erb +40 -0
  56. data/app/views/decidim/accountability/admin/results/bulk_actions/_status_form.html.erb +16 -0
  57. data/app/views/decidim/accountability/admin/results/bulk_actions/_submit_buttons.html.erb +4 -0
  58. data/app/views/decidim/accountability/admin/results/bulk_actions/_taxonomies_form.html.erb +18 -0
  59. data/app/views/decidim/accountability/admin/results/edit.html.erb +2 -2
  60. data/app/views/decidim/accountability/admin/results/index.html.erb +50 -111
  61. data/app/views/decidim/accountability/admin/results/manage_trash.html.erb +26 -0
  62. data/app/views/decidim/accountability/admin/results/new.html.erb +2 -2
  63. data/app/views/decidim/accountability/import_proposals_mailer/import.html.erb +2 -0
  64. data/app/views/decidim/accountability/results/{_home_categories.html.erb → _home_taxonomies.html.erb} +6 -8
  65. data/app/views/decidim/accountability/results/_project.html.erb +1 -3
  66. data/app/views/decidim/accountability/results/_projects_aside.html.erb +9 -7
  67. data/app/views/decidim/accountability/results/home.html.erb +18 -6
  68. data/app/views/decidim/accountability/results/index.html.erb +8 -2
  69. data/app/views/decidim/accountability/results/show.html.erb +5 -5
  70. data/config/assets.rb +3 -2
  71. data/config/locales/ar.yml +97 -55
  72. data/config/locales/bg.yml +0 -50
  73. data/config/locales/bs-BA.yml +0 -16
  74. data/config/locales/ca.yml +128 -40
  75. data/config/locales/cs.yml +147 -56
  76. data/config/locales/da.yml +0 -20
  77. data/config/locales/de.yml +126 -39
  78. data/config/locales/el.yml +0 -48
  79. data/config/locales/en.yml +128 -40
  80. data/config/locales/es-MX.yml +129 -41
  81. data/config/locales/es-PY.yml +129 -41
  82. data/config/locales/es.yml +129 -41
  83. data/config/locales/eu.yml +140 -53
  84. data/config/locales/fi-plain.yml +136 -49
  85. data/config/locales/fi.yml +136 -49
  86. data/config/locales/fr-CA.yml +111 -54
  87. data/config/locales/fr.yml +111 -54
  88. data/config/locales/ga-IE.yml +0 -13
  89. data/config/locales/gl.yml +0 -17
  90. data/config/locales/gn-PY.yml +0 -11
  91. data/config/locales/he-IL.yml +45 -54
  92. data/config/locales/hu.yml +0 -50
  93. data/config/locales/id-ID.yml +0 -16
  94. data/config/locales/is-IS.yml +0 -17
  95. data/config/locales/it.yml +0 -18
  96. data/config/locales/ja.yml +132 -47
  97. data/config/locales/kaa.yml +0 -8
  98. data/config/locales/ko.yml +0 -47
  99. data/config/locales/lb.yml +0 -17
  100. data/config/locales/lt.yml +0 -50
  101. data/config/locales/lv.yml +0 -19
  102. data/config/locales/nl.yml +0 -17
  103. data/config/locales/no.yml +0 -17
  104. data/config/locales/pl.yml +0 -47
  105. data/config/locales/pt-BR.yml +6 -50
  106. data/config/locales/pt.yml +35 -23
  107. data/config/locales/ro-RO.yml +0 -29
  108. data/config/locales/ru.yml +0 -16
  109. data/config/locales/si-LK.yml +0 -11
  110. data/config/locales/sk.yml +0 -19
  111. data/config/locales/sl.yml +0 -17
  112. data/config/locales/sq-AL.yml +0 -50
  113. data/config/locales/sr-CS.yml +0 -16
  114. data/config/locales/sv.yml +124 -36
  115. data/config/locales/th-TH.yml +0 -50
  116. data/config/locales/tr-TR.yml +0 -47
  117. data/config/locales/uk.yml +0 -16
  118. data/config/locales/zh-CN.yml +0 -20
  119. data/config/locales/zh-TW.yml +0 -47
  120. data/db/migrate/20200827154103_add_commentable_counter_cache_to_results.rb +1 -1
  121. data/db/migrate/20240828103202_add_deleted_at_to_decidim_accountability_results.rb +8 -0
  122. data/db/migrate/20240916112128_add_geolocation_fields_to_results.rb +9 -0
  123. data/decidim-accountability.gemspec +1 -1
  124. data/lib/decidim/accountability/admin_engine.rb +16 -2
  125. data/lib/decidim/accountability/component.rb +3 -3
  126. data/lib/decidim/accountability/result_serializer.rb +9 -13
  127. data/lib/decidim/accountability/seeds.rb +28 -21
  128. data/lib/decidim/accountability/test/factories.rb +6 -4
  129. data/lib/decidim/accountability/version.rb +1 -1
  130. data/lib/decidim/api/accountability_type.rb +4 -5
  131. data/lib/decidim/api/result_type.rb +10 -13
  132. data/lib/decidim/api/status_type.rb +3 -4
  133. data/lib/decidim/api/timeline_entry_type.rb +5 -6
  134. metadata +58 -30
  135. data/app/commands/decidim/accountability/admin/import_projects_to_accountability.rb +0 -37
  136. data/app/controllers/decidim/accountability/admin/projects_import_controller.rb +0 -31
  137. data/app/forms/decidim/accountability/admin/result_import_projects_form.rb +0 -51
  138. data/app/views/decidim/accountability/admin/projects_import/new.html.erb +0 -45
  139. data/app/views/decidim/accountability/results/_nav_breadcrumb.html.erb +0 -37
  140. data/app/views/decidim/accountability/results/_scope_filters.html.erb +0 -31
  141. /data/app/packs/entrypoints/{decidim_accountability_admin.js → decidim_accountability_admin_index.js} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43f35b21e55effc7e92ab2e3b8a285df1df272b48dd9c4ea7ca06319a39edc26
4
- data.tar.gz: a552464f9116bec684aed401a7a36a42b70aff5b9cc4e4e55d65612f5fb71e02
3
+ metadata.gz: 8b6da46825853de555f8dc74b64e65d91f75216c1af77f2d1252e34f2c9907e1
4
+ data.tar.gz: 6f5b7b416f235fadc3626b62b2a200de7cfc2bc851bb20bd3153e706263b0dd5
5
5
  SHA512:
6
- metadata.gz: f854c1286bf9af4b4d91a3fac03510876b2daa53348a8691895c56badb8c5ee56cb5d0f1cd60c9ba66326e1dd6caf6b72161ad0838832a9bddb72076b7611c57
7
- data.tar.gz: '09a99fabed41149b2ad409ff3858049410c8128b1f678cc196f2baa78a9904c42b249876a7d3442e655de0351b6c96d1f11ecda125b350c95b835570b60e4cfa'
6
+ metadata.gz: 52cf989ff62a2939f81dc7dd41a67ab71f48b9926f90d40671171d4c2daab65a1cc3bd21646624cef377e7a4a45d7e0f34320b7f87470fa6a88d8227d7252f9b
7
+ data.tar.gz: f44fcd455cbe69788ddc5f76c9833c3ebf2a6332d4683835a60e9c22c68f366f6394bbcb5afb15a1a0f7693ad6a7fbff2074bf1cc661b8da224aa54f7cf7a57e
@@ -8,4 +8,10 @@
8
8
  </div>
9
9
  </section>
10
10
 
11
+ <% if component_settings.geocoding_enabled? && result.geocoded? %>
12
+ <div class="static-map__container py-6">
13
+ <%= render partial: "decidim/shared/static_map", formats: [:html], locals: { icon_name: "proposals", geolocalizable: result } %>
14
+ </div>
15
+ <% end %>
16
+
11
17
  <%= cell "decidim/tab_panels", tab_panel_items %>
@@ -7,6 +7,7 @@ module Decidim
7
7
  # This cell renders a project
8
8
  class ProjectCell < Decidim::ViewModel
9
9
  include Decidim::Accountability::ApplicationHelper
10
+ include Cell::ViewModel::Partial
10
11
  delegate :children, :timeline_entries, to: :model
11
12
 
12
13
  alias result model
@@ -15,26 +16,16 @@ module Decidim
15
16
  render template
16
17
  end
17
18
 
18
- private
19
-
20
- def template
21
- @template ||= options[:template] || :show
22
- end
23
-
24
- def title
25
- decidim_escape_translated result.title
26
- end
27
-
28
- def description
29
- decidim_sanitize_admin translated_attribute(result.description)
30
- end
31
-
32
- def scope
33
- current_scope.presence
34
- end
35
-
36
19
  def tab_panel_items
37
20
  [
21
+ {
22
+ enabled: ResultHistoryCell.new(result).render?,
23
+ id: "included_history",
24
+ text: t("decidim.history", scope: "activerecord.models", count: 2),
25
+ icon: resource_type_icon_key("history"),
26
+ method: :cell,
27
+ args: ["decidim/accountability/result_history", result]
28
+ },
38
29
  {
39
30
  enabled: timeline_entries.any?,
40
31
  id: "timeline_entries",
@@ -50,33 +41,23 @@ module Decidim
50
41
  icon: "briefcase-2-line",
51
42
  method: :cell,
52
43
  args: ["decidim/accountability/results", result.children]
53
- },
54
- {
55
- enabled: result.linked_resources(:proposals, "included_proposals").present?,
56
- id: "included_proposals",
57
- text: t("activemodel.attributes.result.proposals"),
58
- icon: "chat-new-line",
59
- method: :cell,
60
- args: ["decidim/linked_resources_for", result, { type: :proposals, link_name: "included_proposals" }]
61
- },
62
- {
63
- enabled: result.linked_resources(:projects, "included_projects").present?,
64
- id: "included_projects",
65
- text: t("activemodel.attributes.result.project_ids"),
66
- icon: "git-pull-request-line",
67
- method: :cell,
68
- args: ["decidim/linked_resources_for", result, { type: :projects, link_name: "included_projects" }]
69
- },
70
- {
71
- enabled: result.linked_resources(:meetings, "meetings_through_proposals").present?,
72
- id: "included_meetings",
73
- text: t("activemodel.attributes.result.meetings_ids"),
74
- icon: "treasure-map-line",
75
- method: :cell,
76
- args: ["decidim/linked_resources_for", result, { type: :meetings, link_name: "meetings_through_proposals" }]
77
44
  }
78
45
  ] + attachments_tab_panel_items(result)
79
46
  end
47
+
48
+ private
49
+
50
+ def template
51
+ @template ||= options[:template] || :show
52
+ end
53
+
54
+ def title
55
+ decidim_escape_translated result.title
56
+ end
57
+
58
+ def description
59
+ decidim_sanitize_admin translated_attribute(result.description)
60
+ end
80
61
  end
81
62
  end
82
63
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Accountability
5
+ # This cell is used to render a result history panel of a resource
6
+ # inside a tab of a show view
7
+ #
8
+ # The `model` must be an accountability result resource to get the history from.
9
+ #
10
+ # Example:
11
+ #
12
+ # cell(
13
+ # "decidim/result_history",
14
+ # result
15
+ # )
16
+ class ResultHistoryCell < Decidim::ResourceHistoryCell
17
+ include Decidim::Accountability::ApplicationHelper
18
+
19
+ def linked_resources_items
20
+ [
21
+ {
22
+ resources: @model.linked_resources(:proposals, "included_proposals"),
23
+
24
+ link_name: "included_proposals",
25
+ text_key: "decidim.accountability.result.proposal_ids",
26
+ icon_key: "Decidim::Proposals::Proposal"
27
+ },
28
+ {
29
+ resources: @model.linked_resources(:projects, "included_projects"),
30
+ link_name: "included_projects",
31
+ text_key: "decidim.accountability.result.project_ids",
32
+ icon_key: "Decidim::Budgets::Project"
33
+ },
34
+ {
35
+ resources: @model.linked_resources(:meetings, "meetings_through_proposals"),
36
+ link_name: "meetings_through_proposals",
37
+ text_key: "decidim.accountability.result.meetings_ids",
38
+ icon_key: "Decidim::Meetings::Meeting"
39
+ }
40
+ ]
41
+ end
42
+
43
+ def creation_item
44
+ {
45
+ id: "result_creation",
46
+ date: @model.created_at,
47
+ text: t("decidim.accountability.creation.text"),
48
+ icon: resource_type_icon_key("Decidim::Accountability::Result")
49
+ }
50
+ end
51
+
52
+ def history_cell_id
53
+ "result"
54
+ end
55
+ end
56
+ end
57
+ end
@@ -6,7 +6,7 @@ module Decidim
6
6
  class ResultMetadataCell < Decidim::CardMetadataCell
7
7
  include Decidim::Accountability::Engine.routes.url_helpers
8
8
 
9
- delegate :start_date, :end_date, :status, :category, :parent, :reference, to: :model
9
+ delegate :start_date, :end_date, :status, :parent, :reference, to: :model
10
10
 
11
11
  alias result model
12
12
 
@@ -26,7 +26,7 @@ module Decidim
26
26
  return [dates_item, status_item, status_description] if template == :project_aside
27
27
  return [reference, versions] if template == :show_footer
28
28
 
29
- [dates_item_compact, status_item_compact, category_item]
29
+ [dates_item_compact, status_item_compact] + taxonomy_items
30
30
  end
31
31
 
32
32
  def template
@@ -56,15 +56,6 @@ module Decidim
56
56
  { partial: :versions }
57
57
  end
58
58
 
59
- def category_item
60
- return if inherited_category.blank?
61
-
62
- {
63
- text: translated_attribute(inherited_category.name),
64
- icon: resource_type_icon_key(category.class)
65
- }
66
- end
67
-
68
59
  def status_item_compact
69
60
  return if status.blank?
70
61
 
@@ -74,12 +65,6 @@ module Decidim
74
65
  }
75
66
  end
76
67
 
77
- def inherited_category
78
- return category if category.present?
79
-
80
- parent&.category
81
- end
82
-
83
68
  def dates_item
84
69
  return if start_date.blank?
85
70
 
@@ -122,6 +107,21 @@ module Decidim
122
107
  }
123
108
  end
124
109
 
110
+ def percentage_item
111
+ {
112
+ text: display_percentage(result.progress)
113
+ }
114
+ end
115
+
116
+ def items_for_map
117
+ [percentage_item].compact_blank.map do |item|
118
+ {
119
+ text: item[:text].to_s.html_safe,
120
+ icon: item[:icon].present? ? icon(item[:icon]).html_safe : nil
121
+ }
122
+ end
123
+ end
124
+
125
125
  def has_dates?
126
126
  start_date.present? && end_date.present?
127
127
  end
@@ -4,7 +4,7 @@ require "cell/partial"
4
4
 
5
5
  module Decidim
6
6
  module Accountability
7
- # This cell renders the status of a category
7
+ # This cell renders the status of a taxonomy or a result.
8
8
  class StatusCell < Decidim::ViewModel
9
9
  include Decidim::Accountability::ApplicationHelper
10
10
  include Decidim::Accountability::BreadcrumbHelper
@@ -26,16 +26,12 @@ module Decidim
26
26
 
27
27
  private
28
28
 
29
- def scope
30
- current_scope.presence
31
- end
32
-
33
29
  def url
34
30
  options[:url]
35
31
  end
36
32
 
37
33
  def title
38
- if model.is_a? Decidim::Category
34
+ if model.is_a? Decidim::Taxonomy
39
35
  decidim_escape_translated(model.name)
40
36
  else
41
37
  options[:title]
@@ -43,20 +39,20 @@ module Decidim
43
39
  end
44
40
 
45
41
  def results_count
46
- @results_count ||= if model.is_a? Decidim::Category
47
- count_calculator(scope, model.id)
42
+ @results_count ||= if model.is_a? Decidim::Taxonomy
43
+ count_calculator(model.id)
48
44
  else
49
45
  options[:count]
50
46
  end
51
47
  end
52
48
 
53
49
  def progress
54
- if model.is_a? Decidim::Category
55
- progress_calculator(scope, model.id).presence
50
+ if model.is_a? Decidim::Taxonomy
51
+ progress_calculator(model.id).presence
56
52
  elsif model.respond_to?(:progress)
57
53
  model.progress
58
54
  else
59
- options[:progress] || progress_calculator(scope, nil).presence
55
+ options[:progress] || progress_calculator(nil).presence
60
56
  end
61
57
  end
62
58
 
@@ -84,8 +80,8 @@ module Decidim
84
80
  options[:render_count]
85
81
  end
86
82
 
87
- def count_calculator(scope_id, category_id)
88
- Decidim::Accountability::ResultsCalculator.new(current_component, scope_id, category_id).count
83
+ def count_calculator(taxonomy_id)
84
+ Decidim::Accountability::ResultsCalculator.new(current_component, taxonomy_id).count
89
85
  end
90
86
 
91
87
  def decidim
@@ -8,7 +8,7 @@ module Decidim
8
8
  class CreateImportedResult < Decidim::Commands::CreateResource
9
9
  include Decidim::Accountability::Admin::HasResultCommand
10
10
 
11
- fetch_form_attributes :scope, :component, :category, :parent_id, :title, :description, :start_date,
11
+ fetch_form_attributes :taxonomizations, :component, :parent_id, :title, :description, :start_date,
12
12
  :end_date, :progress, :decidim_accountability_status_id, :external_id, :weight
13
13
 
14
14
  def initialize(form, parent_id = nil)
@@ -8,8 +8,9 @@ module Decidim
8
8
  class CreateResult < Decidim::Commands::CreateResource
9
9
  include Decidim::Accountability::Admin::HasResultCommand
10
10
 
11
- fetch_form_attributes :scope, :component, :category, :parent_id, :title, :description, :start_date,
12
- :end_date, :progress, :decidim_accountability_status_id, :external_id, :weight
11
+ fetch_form_attributes :component, :taxonomizations, :parent_id, :title, :description, :start_date,
12
+ :end_date, :progress, :decidim_accountability_status_id, :external_id, :weight,
13
+ :address, :latitude, :longitude
13
14
 
14
15
  private
15
16
 
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Accountability
5
+ module Admin
6
+ # A command with all the business logic when an admin imports projects from
7
+ # one component to accountability.
8
+ class ImportComponentToAccountability < Decidim::Command
9
+ attr_reader :form
10
+
11
+ # Public: Initializes the command.
12
+ #
13
+ # form - A form object with the params.
14
+ def initialize(form)
15
+ @form = form
16
+ end
17
+
18
+ def call
19
+ return broadcast(:invalid) unless form.valid?
20
+
21
+ job_class.perform_later(selected_items.pluck(:id), form.current_component, form.current_user)
22
+ broadcast(:ok, selected_items.count)
23
+ end
24
+
25
+ private
26
+
27
+ def selected_items
28
+ form.filtered_items
29
+ end
30
+
31
+ def manifest_name
32
+ form.origin_component.manifest_name
33
+ end
34
+
35
+ def job_class
36
+ if manifest_name == "budgets"
37
+ ImportProjectsJob
38
+ elsif manifest_name == "proposals"
39
+ ImportProposalsJob
40
+ else
41
+ raise "Invalid component"
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -8,7 +8,7 @@ module Decidim
8
8
  class UpdateImportedResult < Decidim::Commands::UpdateResource
9
9
  include Decidim::Accountability::Admin::HasResultCommand
10
10
 
11
- fetch_form_attributes :scope, :category, :title, :description, :start_date, :end_date, :progress,
11
+ fetch_form_attributes :taxonomizations, :title, :description, :start_date, :end_date, :progress,
12
12
  :decidim_accountability_status_id, :external_id, :weight
13
13
 
14
14
  # Initializes an UpdateImportedResult Command.
@@ -8,8 +8,9 @@ module Decidim
8
8
  class UpdateResult < Decidim::Commands::UpdateResource
9
9
  include Decidim::Accountability::Admin::HasResultCommand
10
10
 
11
- fetch_form_attributes :scope, :category, :parent_id, :title, :description, :start_date, :end_date,
12
- :progress, :decidim_accountability_status_id, :external_id, :weight
11
+ fetch_form_attributes :taxonomizations, :parent_id, :title, :description, :start_date, :end_date,
12
+ :progress, :decidim_accountability_status_id, :external_id, :weight,
13
+ :address, :latitude, :longitude
13
14
 
14
15
  private
15
16
 
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Accountability
5
+ module Admin
6
+ # A command with all the business logic when an admin batch updates results dates.
7
+ class UpdateResultDates < Decidim::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # start_date - the start date to update
11
+ # end_date - the end date to update
12
+ # result_ids - the results ids to update
13
+ # current_user - the user performing the action
14
+ def initialize(start_date, end_date, result_ids, current_user)
15
+ @start_date = start_date
16
+ @end_date = end_date
17
+ @result_ids = result_ids
18
+ @current_user = current_user
19
+ end
20
+
21
+ # Executes the command. Broadcasts these events:
22
+ #
23
+ # - :ok when everything is valid
24
+ # - :invalid if the form was not valid and we could not proceed.
25
+ #
26
+ # Returns nothing.
27
+ def call
28
+ return broadcast(:invalid) if (start_date.blank? && end_date.blank?) || result_ids.blank?
29
+
30
+ update_results_dates
31
+
32
+ broadcast(:ok)
33
+ end
34
+
35
+ private
36
+
37
+ attr_reader :start_date, :end_date, :result_ids, :current_user
38
+
39
+ def update_results_dates
40
+ Decidim::Accountability::Result.where(id: result_ids).find_each do |result|
41
+ next if result.start_date == start_date && result.end_date == end_date
42
+
43
+ result.update!(start_date:, end_date:)
44
+
45
+ # Trace the action to keep track of changes
46
+ Decidim.traceability.perform_action!(
47
+ "update",
48
+ result,
49
+ current_user
50
+ )
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Accountability
5
+ module Admin
6
+ # A command with all the business logic when an admin batch updates results status.
7
+ class UpdateResultStatus < Decidim::Command
8
+ # Public: Initializes the command.
9
+ #
10
+ # status_id - the status id to update
11
+ # result_ids - the results ids to update
12
+ # current_user - the user performing the action
13
+ def initialize(status_id, result_ids, current_user)
14
+ @status_id = status_id
15
+ @result_ids = result_ids
16
+ @current_user = current_user
17
+ end
18
+
19
+ # Executes the command. Broadcasts these events:
20
+ #
21
+ # - :ok when everything is valid
22
+ # - :invalid if the form was not valid and we could not proceed.
23
+ #
24
+ # Returns nothing.
25
+ def call
26
+ return broadcast(:invalid) if status_id.blank? || result_ids.blank?
27
+
28
+ update_results_status
29
+
30
+ broadcast(:ok)
31
+ end
32
+
33
+ private
34
+
35
+ attr_reader :status_id, :result_ids, :current_user
36
+
37
+ def update_results_status
38
+ Decidim::Accountability::Result.where(id: result_ids).find_each do |result|
39
+ next if result.decidim_accountability_status_id == status_id
40
+
41
+ status = Decidim::Accountability::Status.find_by(id: status_id)
42
+
43
+ next if status.blank?
44
+
45
+ result.update!(
46
+ decidim_accountability_status_id: status_id,
47
+ progress: status.progress
48
+ )
49
+
50
+ # Trace the action to keep track of changes
51
+ Decidim.traceability.perform_action!(
52
+ "update",
53
+ result,
54
+ current_user
55
+ )
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Accountability
5
+ module Admin
6
+ # A command with all the business logic when an admin batch updates results taxonomies.
7
+ class UpdateResultTaxonomies < UpdateResourcesTaxonomies
8
+ # Public: Initializes the command.
9
+ #
10
+ # taxonomy_ids - the taxonomy ids to update
11
+ # result_ids - the results ids to update.
12
+ def initialize(taxonomy_ids, result_ids, organization)
13
+ super(taxonomy_ids, Decidim::Accountability::Result.where(id: result_ids), organization)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -16,7 +16,11 @@ module Decidim
16
16
  private
17
17
 
18
18
  def base_query
19
- collection
19
+ return collection unless taxonomy_order_or_search?
20
+
21
+ # this is a trick to avoid duplicates when using search in associations as suggested in:
22
+ # https://activerecord-hackery.github.io/ransack/going-further/other-notes/#problem-with-distinct-selects
23
+ collection.includes(:taxonomies).joins(:taxonomies)
20
24
  end
21
25
 
22
26
  def search_field_predicate
@@ -25,16 +29,14 @@ module Decidim
25
29
 
26
30
  def filters
27
31
  [
28
- :scope_id_eq,
29
- :category_id_eq,
32
+ :taxonomies_part_of_contains,
30
33
  :status_id_eq
31
34
  ]
32
35
  end
33
36
 
34
37
  def filters_with_values
35
38
  {
36
- scope_id_eq: scope_ids_hash(scopes.top_level),
37
- category_id_eq: category_ids_hash(categories.first_class),
39
+ taxonomies_part_of_contains: taxonomy_ids_hash(available_root_taxonomies),
38
40
  status_id_eq: status_ids_hash(statuses)
39
41
  }
40
42
  end
@@ -42,7 +44,7 @@ module Decidim
42
44
  # Cannot user `super` here, because it does not belong to a superclass
43
45
  # but to a concern.
44
46
  def dynamically_translated_filters
45
- [:scope_id_eq, :category_id_eq, :status_id_eq]
47
+ [:taxonomies_part_of_contains, :status_id_eq]
46
48
  end
47
49
 
48
50
  def status_ids_hash(statuses)
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Accountability
5
+ module Admin
6
+ # This controller allows an admin to import results from a component
7
+ class ImportComponentsController < Admin::ApplicationController
8
+ def new
9
+ enforce_permission_to :create, :import_component
10
+ @form = form(Admin::ImportComponentForm).from_params(params, accountability_component: current_component)
11
+ end
12
+
13
+ def create
14
+ enforce_permission_to :create, :import_component
15
+ @form = form(Admin::ImportComponentForm).from_params(params, accountability_component: current_component)
16
+
17
+ ImportComponentToAccountability.call(@form) do
18
+ on(:ok) do |projects|
19
+ flash[:notice] = I18n.t("import_components.new.success", scope: "decidim.accountability.admin", count: projects)
20
+ redirect_to results_path
21
+ end
22
+
23
+ on(:invalid) do
24
+ flash[:alert] = I18n.t("import_components.create.invalid", scope: "decidim.accountability.admin")
25
+ render action: "new"
26
+ end
27
+ end
28
+ end
29
+
30
+ def results_import_params
31
+ params[:results_import] || {}
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end