decidim-budgets 0.20.1 → 0.23.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +38 -3
- data/app/assets/images/decidim/budgets/icon.svg +1 -11
- data/app/assets/javascripts/decidim/budgets/projects.js.es6 +26 -4
- data/app/assets/stylesheets/decidim/budgets/budget/_budget-list.scss +152 -24
- data/app/cells/decidim/budgets/base_cell.rb +22 -0
- data/app/cells/decidim/budgets/budget_cell.rb +21 -0
- data/app/cells/decidim/budgets/budget_information_modal/show.erb +28 -0
- data/app/cells/decidim/budgets/budget_information_modal_cell.rb +22 -0
- data/app/cells/decidim/budgets/budget_list_item/show.erb +22 -0
- data/app/cells/decidim/budgets/budget_list_item_cell.rb +40 -0
- data/app/cells/decidim/budgets/budget_m/data.erb +12 -0
- data/app/cells/decidim/budgets/budget_m/footer.erb +5 -0
- data/app/cells/decidim/budgets/budget_m_cell.rb +16 -0
- data/app/cells/decidim/budgets/budgets_header/show.erb +7 -0
- data/app/cells/decidim/budgets/budgets_header_cell.rb +14 -0
- data/app/cells/decidim/budgets/budgets_list/card_list.erb +7 -0
- data/app/cells/decidim/budgets/budgets_list/highlighted.erb +11 -0
- data/app/cells/decidim/budgets/budgets_list/show.erb +20 -0
- data/app/cells/decidim/budgets/budgets_list/voted.erb +43 -0
- data/app/cells/decidim/budgets/budgets_list_cell.rb +39 -0
- data/app/cells/decidim/budgets/limit_announcement_cell.rb +52 -0
- data/app/cells/decidim/budgets/project_list_item/project_data.erb +19 -0
- data/app/cells/decidim/budgets/project_list_item/project_data_vote_button.erb +15 -0
- data/app/cells/decidim/budgets/project_list_item/project_image.erb +5 -0
- data/app/cells/decidim/budgets/project_list_item/project_text.erb +23 -0
- data/app/cells/decidim/budgets/project_list_item/show.erb +5 -0
- data/app/cells/decidim/budgets/project_list_item_cell.rb +66 -0
- data/app/cells/decidim/budgets/project_m/data.erb +3 -3
- data/app/cells/decidim/budgets/project_m/footer.erb +1 -1
- data/app/cells/decidim/budgets/project_m_cell.rb +4 -0
- data/app/cells/decidim/budgets/project_selected_status_cell.rb +28 -0
- data/app/cells/decidim/budgets/project_tags/show.erb +5 -0
- data/app/cells/decidim/budgets/project_tags_cell.rb +18 -0
- data/app/cells/decidim/budgets/project_voted_hint_cell.rb +33 -0
- data/app/cells/decidim/budgets/project_votes_count_cell.rb +44 -0
- data/app/commands/decidim/budgets/add_line_item.rb +7 -10
- data/app/commands/decidim/budgets/admin/create_budget.rb +48 -0
- data/app/commands/decidim/budgets/admin/create_project.rb +26 -11
- data/app/commands/decidim/budgets/admin/destroy_budget.rb +42 -0
- data/app/commands/decidim/budgets/admin/import_proposals_to_budgets.rb +26 -25
- data/app/commands/decidim/budgets/admin/update_budget.rb +48 -0
- data/app/commands/decidim/budgets/admin/update_project.rb +20 -2
- data/app/commands/decidim/budgets/checkout.rb +7 -6
- data/app/commands/decidim/budgets/remove_line_item.rb +3 -2
- data/app/controllers/concerns/decidim/budgets/needs_current_order.rb +18 -2
- data/app/controllers/concerns/decidim/budgets/orderable.rb +57 -0
- data/app/controllers/decidim/budgets/admin/application_controller.rb +10 -2
- data/app/controllers/decidim/budgets/admin/attachment_collections_controller.rb +1 -1
- data/app/controllers/decidim/budgets/admin/attachments_controller.rb +2 -2
- data/app/controllers/decidim/budgets/admin/budgets_controller.rb +82 -0
- data/app/controllers/decidim/budgets/admin/projects_controller.rb +15 -12
- data/app/controllers/decidim/budgets/admin/proposals_imports_controller.rb +10 -2
- data/app/controllers/decidim/budgets/application_controller.rb +23 -0
- data/app/controllers/decidim/budgets/budgets_controller.rb +24 -0
- data/app/controllers/decidim/budgets/line_items_controller.rb +10 -6
- data/app/controllers/decidim/budgets/orders_controller.rb +20 -6
- data/app/controllers/decidim/budgets/projects_controller.rb +28 -7
- data/app/forms/decidim/budgets/admin/budget_form.rb +39 -0
- data/app/forms/decidim/budgets/admin/component_form.rb +44 -0
- data/app/forms/decidim/budgets/admin/project_form.rb +25 -9
- data/app/forms/decidim/budgets/admin/project_import_proposals_form.rb +4 -0
- data/app/helpers/decidim/budgets/admin/application_helper.rb +13 -0
- data/app/helpers/decidim/budgets/application_helper.rb +11 -0
- data/app/helpers/decidim/budgets/projects_helper.rb +13 -0
- data/app/jobs/decidim/budgets/send_order_summary_job.rb +15 -0
- data/app/mailers/decidim/budgets/order_summary_mailer.rb +36 -0
- data/app/models/decidim/budgets/budget.rb +34 -0
- data/app/models/decidim/budgets/line_item.rb +4 -4
- data/app/models/decidim/budgets/order.rb +46 -16
- data/app/models/decidim/budgets/project.rb +37 -4
- data/app/permissions/decidim/budgets/admin/permissions.rb +23 -10
- data/app/permissions/decidim/budgets/permissions.rb +28 -6
- data/app/presenters/decidim/budgets/admin_log/budget_presenter.rb +42 -0
- data/app/queries/decidim/budgets/filtered_projects.rb +9 -1
- data/app/queries/decidim/budgets/metrics/budget_followers_metric_measure.rb +3 -2
- data/app/queries/decidim/budgets/metrics/budget_participants_metric_measure.rb +6 -5
- data/app/serializers/decidim/budgets/data_portability_budgets_order_serializer.rb +3 -2
- data/app/services/decidim/budgets/project_search.rb +13 -17
- data/app/types/decidim/budgets/budget_type.rb +24 -0
- data/app/types/decidim/budgets/budgets_type.rb +32 -0
- data/app/types/decidim/budgets/project_type.rb +26 -0
- data/app/views/decidim/budgets/admin/budgets/_form.html.erb +23 -0
- data/app/views/decidim/budgets/admin/budgets/edit.html.erb +7 -0
- data/app/views/decidim/budgets/admin/budgets/index.html.erb +58 -0
- data/app/views/decidim/budgets/admin/budgets/new.html.erb +7 -0
- data/app/views/decidim/budgets/admin/projects/_form.html.erb +15 -10
- data/app/views/decidim/budgets/admin/projects/edit.html.erb +2 -2
- data/app/views/decidim/budgets/admin/projects/index.html.erb +20 -7
- data/app/views/decidim/budgets/admin/projects/new.html.erb +2 -2
- data/app/views/decidim/budgets/admin/projects/proposals_picker.html.erb +1 -0
- data/app/views/decidim/budgets/admin/proposals_imports/new.html.erb +1 -1
- data/app/views/decidim/budgets/budgets/index.html.erb +5 -0
- data/app/views/decidim/budgets/order_summary_mailer/order_summary.html.erb +22 -0
- data/app/views/decidim/budgets/projects/_budget_confirm.html.erb +3 -3
- data/app/views/decidim/budgets/projects/_budget_summary.html.erb +26 -7
- data/app/views/decidim/budgets/projects/_filters.html.erb +15 -7
- data/app/views/decidim/budgets/projects/_linked_projects.html.erb +2 -2
- data/app/views/decidim/budgets/projects/_order_progress.html.erb +14 -18
- data/app/views/decidim/budgets/projects/_order_selected_projects.html.erb +3 -3
- data/app/views/decidim/budgets/projects/_project.html.erb +1 -57
- data/app/views/decidim/budgets/projects/_project_budget_button.html.erb +36 -7
- data/app/views/decidim/budgets/projects/_projects.html.erb +8 -1
- data/app/views/decidim/budgets/projects/index.html.erb +15 -7
- data/app/views/decidim/budgets/projects/index.js.erb +8 -0
- data/app/views/decidim/budgets/projects/show.html.erb +18 -11
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +3 -17
- data/config/locales/bg-BG.yml +7 -0
- data/config/locales/bg.yml +6 -0
- data/config/locales/ca.yml +126 -12
- data/config/locales/cs.yml +145 -31
- data/config/locales/da-DK.yml +1 -0
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +115 -12
- data/config/locales/el.yml +169 -0
- data/config/locales/en.yml +126 -12
- data/config/locales/eo.yml +1 -0
- data/config/locales/es-MX.yml +126 -12
- data/config/locales/es-PY.yml +126 -12
- data/config/locales/es.yml +126 -12
- data/config/locales/et-EE.yml +1 -0
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +4 -14
- data/config/locales/fi-plain.yml +127 -13
- data/config/locales/fi.yml +137 -23
- data/config/locales/fr-CA.yml +266 -0
- data/config/locales/fr.yml +125 -12
- data/config/locales/ga-IE.yml +1 -0
- data/config/locales/gl.yml +3 -13
- data/config/locales/hr-HR.yml +1 -0
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +19 -13
- data/config/locales/id-ID.yml +3 -12
- data/config/locales/is-IS.yml +1 -12
- data/config/locales/is.yml +114 -0
- data/config/locales/it.yml +97 -13
- data/config/locales/ja-JP.yml +172 -0
- data/config/locales/ja.yml +262 -0
- data/config/locales/ko-KR.yml +1 -0
- data/config/locales/ko.yml +1 -0
- data/config/locales/lt-LT.yml +1 -0
- data/config/locales/lt.yml +1 -0
- data/config/locales/lv.yml +164 -0
- data/config/locales/mt-MT.yml +1 -0
- data/config/locales/mt.yml +1 -0
- data/config/locales/nl.yml +113 -13
- data/config/locales/no.yml +39 -13
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +175 -62
- data/config/locales/pt-BR.yml +4 -14
- data/config/locales/pt.yml +63 -47
- data/config/locales/ro-RO.yml +172 -0
- data/config/locales/ru.yml +3 -15
- data/config/locales/sk-SK.yml +180 -0
- data/config/locales/sk.yml +166 -0
- data/config/locales/sl.yml +1 -0
- data/config/locales/so-SO.yml +1 -0
- data/config/locales/sr-CS.yml +27 -0
- data/config/locales/sv.yml +126 -12
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +3 -13
- data/config/locales/uk.yml +3 -15
- data/config/locales/vi-VN.yml +1 -0
- data/config/locales/vi.yml +1 -0
- data/config/locales/zh-CN.yml +260 -0
- data/config/locales/zh-TW.yml +1 -0
- data/db/migrate/20200617105120_create_decidim_budgets.rb +15 -0
- data/db/migrate/20200629072626_rename_budget_to_budget_ammount.rb +7 -0
- data/db/migrate/20200629134013_add_budget_reference_to_project.rb +7 -0
- data/db/migrate/20200706142609_add_budget_reference_to_order.rb +7 -0
- data/db/migrate/20200714103519_move_budgets_to_own_model.rb +109 -0
- data/db/migrate/20200717140012_add_scope_to_budgets.rb +7 -0
- data/db/migrate/20200728075039_add_selected_at_to_project.rb +7 -0
- data/db/migrate/20200804175222_votes_enabled_to_votes_choices.rb +35 -0
- data/db/migrate/20200827154129_add_commentable_counter_cache_to_projects.rb +9 -0
- data/lib/decidim/budgets.rb +1 -0
- data/lib/decidim/budgets/admin_engine.rb +12 -5
- data/lib/decidim/budgets/component.rb +94 -38
- data/lib/decidim/budgets/engine.rb +8 -6
- data/lib/decidim/budgets/seeds/city.jpeg +0 -0
- data/lib/decidim/budgets/test/factories.rb +71 -9
- data/lib/decidim/budgets/version.rb +1 -1
- data/lib/decidim/budgets/workflows.rb +17 -0
- data/lib/decidim/budgets/workflows/all.rb +20 -0
- data/lib/decidim/budgets/workflows/base.rb +132 -0
- data/lib/decidim/budgets/workflows/one.rb +33 -0
- metadata +121 -16
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Budgets
|
5
|
+
# This cell renders the selected status if the project has been selected
|
6
|
+
class ProjectSelectedStatusCell < Decidim::ViewModel
|
7
|
+
delegate :voting_finished?, to: :controller
|
8
|
+
|
9
|
+
def show
|
10
|
+
if voting_finished? && model.selected?
|
11
|
+
content_tag :span, class: css_class do
|
12
|
+
t("decidim.budgets.projects.project.selected")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def css_class
|
20
|
+
if options[:as_label] == true
|
21
|
+
"success label project-status"
|
22
|
+
else
|
23
|
+
"success card__text--status"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Budgets
|
5
|
+
# This cell overrides *_path methods from Decidim::TagsCell for project tags
|
6
|
+
class ProjectTagsCell < Decidim::TagsCell
|
7
|
+
private
|
8
|
+
|
9
|
+
def category_path
|
10
|
+
resource_locator([model.budget, model]).index(filter: { category_id: [model.category.id.to_s] })
|
11
|
+
end
|
12
|
+
|
13
|
+
def scope_path
|
14
|
+
resource_locator([model.budget, model]).index(filter: { scope_id: [model.scope.id] })
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Budgets
|
5
|
+
# This cell renders a checkmark with a text.
|
6
|
+
class ProjectVotedHintCell < BaseCell
|
7
|
+
include Decidim::IconHelper
|
8
|
+
|
9
|
+
delegate :voted_for?, :current_order, to: :controller
|
10
|
+
|
11
|
+
def show
|
12
|
+
return unless voted_for?(model)
|
13
|
+
|
14
|
+
content_tag :span, safe_join(hint), class: css_class
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def hint
|
20
|
+
contents = []
|
21
|
+
contents << icon("check", role: "img")
|
22
|
+
contents << " "
|
23
|
+
contents << t("decidim.budgets.projects.project.you_voted")
|
24
|
+
end
|
25
|
+
|
26
|
+
def css_class
|
27
|
+
css = ["text-sm", "text-success"]
|
28
|
+
css << options[:class] if options[:class]
|
29
|
+
css.join(" ")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Budgets
|
5
|
+
# This cell renders the vote count.
|
6
|
+
# Two possible layouts: One or two lines
|
7
|
+
class ProjectVotesCountCell < Decidim::ViewModel
|
8
|
+
include Decidim::IconHelper
|
9
|
+
delegate :show_votes_count?, to: :controller
|
10
|
+
|
11
|
+
def show
|
12
|
+
return unless show_votes_count?
|
13
|
+
|
14
|
+
content_tag :span, content, class: css_class
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def content
|
20
|
+
if options[:layout] == :one_line
|
21
|
+
safe_join([model.confirmed_orders_count, " ", label(t("decidim.budgets.projects.project.votes",
|
22
|
+
count: model.confirmed_orders_count))])
|
23
|
+
else
|
24
|
+
safe_join([number, label(t("decidim.budgets.projects.project.votes",
|
25
|
+
count: model.confirmed_orders_count))])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def number
|
30
|
+
content_tag :div, model.confirmed_orders_count, class: "text-large"
|
31
|
+
end
|
32
|
+
|
33
|
+
def label(i18n_string)
|
34
|
+
content_tag :span, i18n_string, class: "text-uppercase text-small"
|
35
|
+
end
|
36
|
+
|
37
|
+
def css_class
|
38
|
+
css = ["project-votes"]
|
39
|
+
css << options[:class] if options[:class]
|
40
|
+
css.join(" ")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -23,7 +23,7 @@ module Decidim
|
|
23
23
|
# Returns nothing.
|
24
24
|
def call
|
25
25
|
transaction do
|
26
|
-
return broadcast(:invalid) if
|
26
|
+
return broadcast(:invalid) if voting_not_enabled? || order.checked_out?
|
27
27
|
|
28
28
|
add_line_item
|
29
29
|
broadcast(:ok, order)
|
@@ -32,23 +32,20 @@ module Decidim
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
+
attr_reader :current_user, :project
|
36
|
+
|
35
37
|
def order
|
36
|
-
@order ||= Order.create!(user:
|
38
|
+
@order ||= Order.create!(user: current_user, budget: project.budget)
|
37
39
|
end
|
38
40
|
|
39
41
|
def add_line_item
|
40
42
|
order.with_lock do
|
41
|
-
order.projects <<
|
42
|
-
order.save!
|
43
|
+
order.projects << project
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
def
|
47
|
-
|
48
|
-
end
|
49
|
-
|
50
|
-
def votes_disabled?
|
51
|
-
!component.current_settings.votes_enabled?
|
47
|
+
def voting_not_enabled?
|
48
|
+
project.component.current_settings.votes != "enabled"
|
52
49
|
end
|
53
50
|
end
|
54
51
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Budgets
|
5
|
+
module Admin
|
6
|
+
# This command is executed when the user creates an Budget
|
7
|
+
# from the admin panel.
|
8
|
+
class CreateBudget < Rectify::Command
|
9
|
+
def initialize(form)
|
10
|
+
@form = form
|
11
|
+
end
|
12
|
+
|
13
|
+
# Creates the budget if valid.
|
14
|
+
#
|
15
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
16
|
+
def call
|
17
|
+
return broadcast(:invalid) if form.invalid?
|
18
|
+
|
19
|
+
create_budget!
|
20
|
+
|
21
|
+
broadcast(:ok, budget)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
attr_reader :form, :budget
|
27
|
+
|
28
|
+
def create_budget!
|
29
|
+
attributes = {
|
30
|
+
component: form.current_component,
|
31
|
+
scope: form.scope,
|
32
|
+
title: form.title,
|
33
|
+
weight: form.weight,
|
34
|
+
description: form.description,
|
35
|
+
total_budget: form.total_budget
|
36
|
+
}
|
37
|
+
|
38
|
+
@budget = Decidim.traceability.create!(
|
39
|
+
Budget,
|
40
|
+
form.current_user,
|
41
|
+
attributes,
|
42
|
+
visibility: "all"
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -6,6 +6,9 @@ module Decidim
|
|
6
6
|
# This command is executed when the user creates a Project from the admin
|
7
7
|
# panel.
|
8
8
|
class CreateProject < Rectify::Command
|
9
|
+
include ::Decidim::AttachmentMethods
|
10
|
+
include ::Decidim::GalleryMethods
|
11
|
+
|
9
12
|
def initialize(form)
|
10
13
|
@form = form
|
11
14
|
end
|
@@ -16,9 +19,15 @@ module Decidim
|
|
16
19
|
def call
|
17
20
|
return broadcast(:invalid) if @form.invalid?
|
18
21
|
|
22
|
+
if process_gallery?
|
23
|
+
build_gallery
|
24
|
+
return broadcast(:invalid) if gallery_invalid?
|
25
|
+
end
|
26
|
+
|
19
27
|
transaction do
|
20
|
-
create_project
|
28
|
+
create_project!
|
21
29
|
link_proposals
|
30
|
+
create_gallery if process_gallery?
|
22
31
|
end
|
23
32
|
|
24
33
|
broadcast(:ok)
|
@@ -26,23 +35,29 @@ module Decidim
|
|
26
35
|
|
27
36
|
private
|
28
37
|
|
29
|
-
attr_reader :project
|
38
|
+
attr_reader :form, :project, :gallery
|
39
|
+
|
40
|
+
def create_project!
|
41
|
+
attributes = {
|
42
|
+
budget: form.budget,
|
43
|
+
scope: form.scope,
|
44
|
+
category: form.category,
|
45
|
+
title: form.title,
|
46
|
+
description: form.description,
|
47
|
+
budget_amount: form.budget_amount
|
48
|
+
}
|
30
49
|
|
31
|
-
def create_project
|
32
50
|
@project = Decidim.traceability.create!(
|
33
51
|
Project,
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
component: @form.current_component,
|
38
|
-
title: @form.title,
|
39
|
-
description: @form.description,
|
40
|
-
budget: @form.budget
|
52
|
+
form.current_user,
|
53
|
+
attributes,
|
54
|
+
visibility: "all"
|
41
55
|
)
|
56
|
+
@attached_to = @project
|
42
57
|
end
|
43
58
|
|
44
59
|
def proposals
|
45
|
-
@proposals ||= project.sibling_scope(:proposals).where(id:
|
60
|
+
@proposals ||= project.sibling_scope(:proposals).where(id: form.proposal_ids)
|
46
61
|
end
|
47
62
|
|
48
63
|
def link_proposals
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Budgets
|
5
|
+
module Admin
|
6
|
+
# This command is executed when the user destroys a Budget
|
7
|
+
# from the admin panel.
|
8
|
+
class DestroyBudget < Rectify::Command
|
9
|
+
def initialize(budget, current_user)
|
10
|
+
@budget = budget
|
11
|
+
@current_user = current_user
|
12
|
+
end
|
13
|
+
|
14
|
+
# Destroys the budget if valid.
|
15
|
+
#
|
16
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
17
|
+
def call
|
18
|
+
return broadcast(:invalid) if budget.projects.present?
|
19
|
+
|
20
|
+
destroy_budget!
|
21
|
+
|
22
|
+
broadcast(:ok, budget)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :budget, :current_user
|
28
|
+
|
29
|
+
def destroy_budget!
|
30
|
+
Decidim.traceability.perform_action!(
|
31
|
+
:delete,
|
32
|
+
budget,
|
33
|
+
current_user,
|
34
|
+
visibility: "all"
|
35
|
+
) do
|
36
|
+
budget.destroy!
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -4,7 +4,7 @@ module Decidim
|
|
4
4
|
module Budgets
|
5
5
|
module Admin
|
6
6
|
# A command with all the business logic when an admin imports proposals from
|
7
|
-
# one component to budget
|
7
|
+
# one component to projects of a budget.
|
8
8
|
class ImportProposalsToBudgets < Rectify::Command
|
9
9
|
# Public: Initializes the command.
|
10
10
|
#
|
@@ -32,45 +32,46 @@ module Decidim
|
|
32
32
|
def create_projects_from_accepted_proposals
|
33
33
|
transaction do
|
34
34
|
proposals.map do |original_proposal|
|
35
|
-
next if proposal_already_copied?(original_proposal
|
35
|
+
next if proposal_already_copied?(original_proposal)
|
36
36
|
|
37
|
-
|
38
|
-
project.title = project_localized(original_proposal.title)
|
39
|
-
project.description = project_localized(original_proposal.body)
|
40
|
-
project.budget = form.default_budget
|
41
|
-
project.category = original_proposal.category
|
42
|
-
project.scope = original_proposal.scope
|
43
|
-
project.component = target_component
|
44
|
-
project.save!
|
37
|
+
new_project = create_project_from_proposal!(original_proposal)
|
45
38
|
|
46
|
-
|
39
|
+
new_project.link_resources([original_proposal], "included_proposals")
|
47
40
|
end.compact
|
48
41
|
end
|
49
42
|
end
|
50
43
|
|
44
|
+
def create_project_from_proposal!(original_proposal)
|
45
|
+
params = {
|
46
|
+
budget: form.budget,
|
47
|
+
title: original_proposal.title,
|
48
|
+
description: original_proposal.body,
|
49
|
+
budget_amount: form.default_budget,
|
50
|
+
category: original_proposal.category,
|
51
|
+
scope: original_proposal.scope
|
52
|
+
}
|
53
|
+
|
54
|
+
@project = Decidim.traceability.create!(
|
55
|
+
Project,
|
56
|
+
form.current_user,
|
57
|
+
params,
|
58
|
+
visibility: "all"
|
59
|
+
)
|
60
|
+
end
|
61
|
+
|
51
62
|
def proposals
|
52
63
|
Decidim::Proposals::Proposal.where(component: origin_component).where(state: "accepted")
|
53
64
|
end
|
54
65
|
|
55
66
|
def origin_component
|
56
|
-
|
67
|
+
form.origin_component
|
57
68
|
end
|
58
69
|
|
59
|
-
def
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
def proposal_already_copied?(original_proposal, target_component)
|
64
|
-
original_proposal.linked_resources(:projects, "included_proposals").any? do |proposal|
|
65
|
-
proposal.component == target_component
|
70
|
+
def proposal_already_copied?(original_proposal)
|
71
|
+
original_proposal.linked_resources(:projects, "included_proposals").any? do |project|
|
72
|
+
project.budget == form.budget
|
66
73
|
end
|
67
74
|
end
|
68
|
-
|
69
|
-
def project_localized(text)
|
70
|
-
Decidim.available_locales.inject({}) do |result, locale|
|
71
|
-
result.update(locale => text)
|
72
|
-
end.with_indifferent_access
|
73
|
-
end
|
74
75
|
end
|
75
76
|
end
|
76
77
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Budgets
|
5
|
+
module Admin
|
6
|
+
# This command is executed when the user updates a Budget
|
7
|
+
# from the admin panel.
|
8
|
+
class UpdateBudget < Rectify::Command
|
9
|
+
def initialize(form, budget)
|
10
|
+
@form = form
|
11
|
+
@budget = budget
|
12
|
+
end
|
13
|
+
|
14
|
+
# Updates the budget if valid.
|
15
|
+
#
|
16
|
+
# Broadcasts :ok if successful, :invalid otherwise.
|
17
|
+
def call
|
18
|
+
return broadcast(:invalid) if form.invalid?
|
19
|
+
|
20
|
+
update_budget!
|
21
|
+
|
22
|
+
broadcast(:ok, budget)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_reader :form, :budget
|
28
|
+
|
29
|
+
def update_budget!
|
30
|
+
attributes = {
|
31
|
+
scope: form.scope,
|
32
|
+
title: form.title,
|
33
|
+
weight: form.weight,
|
34
|
+
description: form.description,
|
35
|
+
total_budget: form.total_budget
|
36
|
+
}
|
37
|
+
|
38
|
+
Decidim.traceability.update!(
|
39
|
+
budget,
|
40
|
+
form.current_user,
|
41
|
+
attributes,
|
42
|
+
visibility: "all"
|
43
|
+
)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|