decidim-budgets 0.21.0 → 0.23.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +24 -19
- 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 +10 -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 +47 -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 +12 -24
- data/app/types/decidim/budgets/budget_type.rb +24 -0
- data/app/types/decidim/budgets/budgets_type.rb +6 -6
- data/app/types/decidim/budgets/project_type.rb +2 -1
- 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 +22 -13
- data/config/locales/am-ET.yml +1 -0
- data/config/locales/ar.yml +2 -16
- data/config/locales/bg-BG.yml +7 -0
- data/config/locales/bg.yml +6 -0
- data/config/locales/ca.yml +125 -11
- data/config/locales/cs.yml +148 -34
- data/config/locales/da-DK.yml +1 -0
- data/config/locales/da.yml +1 -0
- data/config/locales/de.yml +143 -29
- data/config/locales/el.yml +168 -0
- data/config/locales/en.yml +125 -11
- data/config/locales/eo.yml +1 -0
- data/config/locales/es-MX.yml +125 -11
- data/config/locales/es-PY.yml +125 -11
- data/config/locales/es.yml +125 -11
- data/config/locales/et-EE.yml +1 -0
- data/config/locales/et.yml +1 -0
- data/config/locales/eu.yml +5 -13
- data/config/locales/fi-plain.yml +126 -12
- data/config/locales/fi.yml +136 -22
- data/config/locales/fr-CA.yml +267 -0
- data/config/locales/fr.yml +125 -11
- data/config/locales/ga-IE.yml +1 -0
- data/config/locales/gl.yml +70 -15
- data/config/locales/hr-HR.yml +1 -0
- data/config/locales/hr.yml +1 -0
- data/config/locales/hu.yml +18 -12
- data/config/locales/id-ID.yml +2 -11
- data/config/locales/is-IS.yml +0 -11
- data/config/locales/is.yml +114 -0
- data/config/locales/it.yml +96 -12
- 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 +112 -12
- data/config/locales/no.yml +42 -13
- data/config/locales/om-ET.yml +1 -0
- data/config/locales/pl.yml +175 -61
- data/config/locales/pt-BR.yml +3 -13
- data/config/locales/pt.yml +62 -46
- data/config/locales/ro-RO.yml +172 -0
- data/config/locales/ru.yml +2 -14
- data/config/locales/si-LK.yml +1 -0
- 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 +125 -11
- data/config/locales/sw-KE.yml +1 -0
- data/config/locales/ti-ER.yml +1 -0
- data/config/locales/tr-TR.yml +152 -38
- data/config/locales/uk.yml +2 -14
- 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 +87 -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 +123 -19
@@ -6,6 +6,9 @@ module Decidim
|
|
6
6
|
# This command is executed when the user changes a Project from the admin
|
7
7
|
# panel.
|
8
8
|
class UpdateProject < Rectify::Command
|
9
|
+
include ::Decidim::AttachmentMethods
|
10
|
+
include ::Decidim::GalleryMethods
|
11
|
+
|
9
12
|
# Initializes an UpdateProject Command.
|
10
13
|
#
|
11
14
|
# form - The form from which to get the data.
|
@@ -13,6 +16,7 @@ module Decidim
|
|
13
16
|
def initialize(form, project)
|
14
17
|
@form = form
|
15
18
|
@project = project
|
19
|
+
@attached_to = project
|
16
20
|
end
|
17
21
|
|
18
22
|
# Updates the project if valid.
|
@@ -21,9 +25,16 @@ module Decidim
|
|
21
25
|
def call
|
22
26
|
return broadcast(:invalid) if form.invalid?
|
23
27
|
|
28
|
+
if process_gallery?
|
29
|
+
build_gallery
|
30
|
+
return broadcast(:invalid) if gallery_invalid?
|
31
|
+
end
|
32
|
+
|
24
33
|
transaction do
|
25
34
|
update_project
|
26
35
|
link_proposals
|
36
|
+
create_gallery if process_gallery?
|
37
|
+
photo_cleanup!
|
27
38
|
end
|
28
39
|
|
29
40
|
broadcast(:ok)
|
@@ -31,7 +42,7 @@ module Decidim
|
|
31
42
|
|
32
43
|
private
|
33
44
|
|
34
|
-
attr_reader :project, :form
|
45
|
+
attr_reader :project, :form, :gallery
|
35
46
|
|
36
47
|
def update_project
|
37
48
|
Decidim.traceability.update!(
|
@@ -41,7 +52,8 @@ module Decidim
|
|
41
52
|
category: form.category,
|
42
53
|
title: form.title,
|
43
54
|
description: form.description,
|
44
|
-
|
55
|
+
budget_amount: form.budget_amount,
|
56
|
+
selected_at: selected_at
|
45
57
|
)
|
46
58
|
end
|
47
59
|
|
@@ -52,6 +64,12 @@ module Decidim
|
|
52
64
|
def link_proposals
|
53
65
|
project.link_resources(proposals, "included_proposals")
|
54
66
|
end
|
67
|
+
|
68
|
+
def selected_at
|
69
|
+
return unless form.selected
|
70
|
+
|
71
|
+
Time.current
|
72
|
+
end
|
55
73
|
end
|
56
74
|
end
|
57
75
|
end
|
@@ -7,10 +7,8 @@ module Decidim
|
|
7
7
|
# Public: Initializes the command.
|
8
8
|
#
|
9
9
|
# order - The current order for the user.
|
10
|
-
|
11
|
-
def initialize(order, component)
|
10
|
+
def initialize(order)
|
12
11
|
@order = order
|
13
|
-
@component = component
|
14
12
|
end
|
15
13
|
|
16
14
|
# Executes the command. Broadcasts these events:
|
@@ -20,17 +18,20 @@ module Decidim
|
|
20
18
|
#
|
21
19
|
# Returns nothing.
|
22
20
|
def call
|
23
|
-
return broadcast(:invalid,
|
21
|
+
return broadcast(:invalid, order) unless checkout!
|
24
22
|
|
25
|
-
broadcast(:ok,
|
23
|
+
broadcast(:ok, order)
|
26
24
|
end
|
27
25
|
|
28
26
|
private
|
29
27
|
|
28
|
+
attr_reader :order
|
29
|
+
|
30
30
|
def checkout!
|
31
|
-
return unless
|
31
|
+
return unless order && order.valid?
|
32
32
|
|
33
33
|
@order.with_lock do
|
34
|
+
SendOrderSummaryJob.perform_later(@order)
|
34
35
|
@order.checked_out_at = Time.current
|
35
36
|
@order.save
|
36
37
|
end
|
@@ -9,18 +9,34 @@ module Decidim
|
|
9
9
|
extend ActiveSupport::Concern
|
10
10
|
|
11
11
|
included do
|
12
|
-
helper_method :current_order
|
12
|
+
helper_method :current_order, :can_have_order?, :voted_for?
|
13
13
|
|
14
14
|
# The current order created by the user.
|
15
15
|
#
|
16
16
|
# Returns an Order.
|
17
17
|
def current_order
|
18
|
-
@current_order ||= Order.includes(:projects).
|
18
|
+
@current_order ||= Order.includes(:projects).find_or_initialize_by(user: current_user, budget: budget)
|
19
19
|
end
|
20
20
|
|
21
21
|
def current_order=(order)
|
22
22
|
@current_order = order
|
23
23
|
end
|
24
|
+
|
25
|
+
def persisted_current_order
|
26
|
+
current_order if current_order&.persisted?
|
27
|
+
end
|
28
|
+
|
29
|
+
def can_have_order?
|
30
|
+
current_user.present? &&
|
31
|
+
voting_open? &&
|
32
|
+
current_participatory_space.can_participate?(current_user) &&
|
33
|
+
allowed_to?(:create, :order, budget: budget, workflow: current_workflow)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Return true if the user has voted the project
|
37
|
+
def voted_for?(project)
|
38
|
+
current_order && current_order.projects.include?(project)
|
39
|
+
end
|
24
40
|
end
|
25
41
|
end
|
26
42
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/concern"
|
4
|
+
|
5
|
+
module Decidim
|
6
|
+
module Budgets
|
7
|
+
# Common logic to sorting resources
|
8
|
+
module Orderable
|
9
|
+
extend ActiveSupport::Concern
|
10
|
+
|
11
|
+
included do
|
12
|
+
include Decidim::Orderable
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
# Available orders based on enabled settings
|
17
|
+
def available_orders
|
18
|
+
@available_orders ||= begin
|
19
|
+
available_orders = []
|
20
|
+
available_orders << "random" if voting_open? || !votes_are_visible?
|
21
|
+
available_orders << "most_voted" if votes_are_visible?
|
22
|
+
available_orders += %w(highest_cost lowest_cost)
|
23
|
+
available_orders
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def default_order
|
28
|
+
available_orders.first
|
29
|
+
end
|
30
|
+
|
31
|
+
def votes_are_visible?
|
32
|
+
current_settings.show_votes?
|
33
|
+
end
|
34
|
+
|
35
|
+
def reorder(projects)
|
36
|
+
case order
|
37
|
+
when "highest_cost"
|
38
|
+
projects.order(budget_amount: :desc)
|
39
|
+
when "lowest_cost"
|
40
|
+
projects.order(budget_amount: :asc)
|
41
|
+
when "most_voted"
|
42
|
+
if votes_are_visible?
|
43
|
+
ids = projects.sort_by(&:confirmed_orders_count).map(&:id).reverse
|
44
|
+
projects.ordered_ids(ids)
|
45
|
+
else
|
46
|
+
projects
|
47
|
+
end
|
48
|
+
when "random"
|
49
|
+
projects.order_randomly(random_seed)
|
50
|
+
else
|
51
|
+
projects
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -9,13 +9,21 @@ module Decidim
|
|
9
9
|
# Note that it inherits from `Decidim::Components::BaseController`, which
|
10
10
|
# override its layout and provide all kinds of useful methods.
|
11
11
|
class ApplicationController < Decidim::Admin::Components::BaseController
|
12
|
-
helper_method :projects, :project
|
12
|
+
helper_method :budget, :projects, :project
|
13
|
+
|
14
|
+
def budget
|
15
|
+
@budget ||= Budget.where(component: current_component).includes(:projects).find_by(id: params[:budget_id])
|
16
|
+
end
|
13
17
|
|
14
18
|
def projects
|
15
|
-
|
19
|
+
return unless budget
|
20
|
+
|
21
|
+
@projects ||= budget.projects
|
16
22
|
end
|
17
23
|
|
18
24
|
def project
|
25
|
+
return unless projects
|
26
|
+
|
19
27
|
@project ||= projects.find(params[:id])
|
20
28
|
end
|
21
29
|
end
|
@@ -10,7 +10,7 @@ module Decidim
|
|
10
10
|
include Decidim::Admin::Concerns::HasAttachments
|
11
11
|
|
12
12
|
def after_destroy_path
|
13
|
-
|
13
|
+
budget_projects_path(project.budget)
|
14
14
|
end
|
15
15
|
|
16
16
|
def attached_to
|
@@ -18,7 +18,7 @@ module Decidim
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def project
|
21
|
-
@project ||=
|
21
|
+
@project ||= Decidim::Budgets::Project.find(params[:project_id])
|
22
22
|
end
|
23
23
|
end
|
24
24
|
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Budgets
|
5
|
+
module Admin
|
6
|
+
# This controller allows the create or update a budget.
|
7
|
+
class BudgetsController < Admin::ApplicationController
|
8
|
+
helper_method :budgets, :budget
|
9
|
+
|
10
|
+
def new
|
11
|
+
enforce_permission_to :create, :budget
|
12
|
+
@form = form(BudgetForm).instance
|
13
|
+
end
|
14
|
+
|
15
|
+
def create
|
16
|
+
enforce_permission_to :create, :budget
|
17
|
+
@form = form(BudgetForm).from_params(params, current_component: current_component)
|
18
|
+
|
19
|
+
CreateBudget.call(@form) do
|
20
|
+
on(:ok) do
|
21
|
+
flash[:notice] = I18n.t("budgets.create.success", scope: "decidim.budgets.admin")
|
22
|
+
redirect_to budgets_path
|
23
|
+
end
|
24
|
+
|
25
|
+
on(:invalid) do
|
26
|
+
flash.now[:alert] = I18n.t("budgets.create.invalid", scope: "decidim.budgets.admin")
|
27
|
+
render action: "new"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def edit
|
33
|
+
enforce_permission_to :update, :budget, budget: budget
|
34
|
+
@form = form(BudgetForm).from_model(budget)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update
|
38
|
+
enforce_permission_to :update, :budget, budget: budget
|
39
|
+
@form = form(BudgetForm).from_params(params, current_component: current_component)
|
40
|
+
|
41
|
+
UpdateBudget.call(@form, budget) do
|
42
|
+
on(:ok) do
|
43
|
+
flash[:notice] = I18n.t("budgets.update.success", scope: "decidim.budgets.admin")
|
44
|
+
redirect_to budgets_path
|
45
|
+
end
|
46
|
+
|
47
|
+
on(:invalid) do
|
48
|
+
flash.now[:alert] = I18n.t("budgets.update.invalid", scope: "decidim.budgets.admin")
|
49
|
+
render action: "edit"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def destroy
|
55
|
+
enforce_permission_to :delete, :budget, budget: budget
|
56
|
+
|
57
|
+
DestroyBudget.call(budget, current_user) do
|
58
|
+
on(:ok) do
|
59
|
+
flash[:notice] = I18n.t("budgets.destroy.success", scope: "decidim.budgets.admin")
|
60
|
+
end
|
61
|
+
|
62
|
+
on(:invalid) do
|
63
|
+
flash.now[:alert] = I18n.t("budgets.destroy.invalid", scope: "decidim.budgets.admin")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
redirect_to budgets_path
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def budgets
|
73
|
+
@budgets ||= Budget.where(component: current_component).order(weight: :asc)
|
74
|
+
end
|
75
|
+
|
76
|
+
def budget
|
77
|
+
@budget ||= budgets.find_by(id: params[:id])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -5,23 +5,27 @@ module Decidim
|
|
5
5
|
module Admin
|
6
6
|
# This controller allows an admin to manage projects from a Participatory Process
|
7
7
|
class ProjectsController < Admin::ApplicationController
|
8
|
-
|
8
|
+
include Decidim::ApplicationHelper
|
9
|
+
include Decidim::Proposals::Admin::Picker
|
10
|
+
|
11
|
+
helper_method :projects, :finished_orders, :pending_orders, :present
|
9
12
|
|
10
13
|
def new
|
11
14
|
enforce_permission_to :create, :project
|
12
|
-
|
13
|
-
|
15
|
+
@form = form(ProjectForm).from_params(
|
16
|
+
attachment: form(AttachmentForm).instance
|
17
|
+
)
|
14
18
|
end
|
15
19
|
|
16
20
|
def create
|
17
21
|
enforce_permission_to :create, :project
|
18
22
|
|
19
|
-
@form = form(ProjectForm).from_params(params)
|
23
|
+
@form = form(ProjectForm).from_params(params, budget: budget)
|
20
24
|
|
21
25
|
CreateProject.call(@form) do
|
22
26
|
on(:ok) do
|
23
27
|
flash[:notice] = I18n.t("projects.create.success", scope: "decidim.budgets.admin")
|
24
|
-
redirect_to
|
28
|
+
redirect_to budget_projects_path(budget)
|
25
29
|
end
|
26
30
|
|
27
31
|
on(:invalid) do
|
@@ -33,19 +37,18 @@ module Decidim
|
|
33
37
|
|
34
38
|
def edit
|
35
39
|
enforce_permission_to :update, :project, project: project
|
36
|
-
|
37
40
|
@form = form(ProjectForm).from_model(project)
|
41
|
+
@form.attachment = form(AttachmentForm).instance
|
38
42
|
end
|
39
43
|
|
40
44
|
def update
|
41
45
|
enforce_permission_to :update, :project, project: project
|
42
|
-
|
43
|
-
@form = form(ProjectForm).from_params(params)
|
46
|
+
@form = form(ProjectForm).from_params(params, budget: budget)
|
44
47
|
|
45
48
|
UpdateProject.call(@form, project) do
|
46
49
|
on(:ok) do
|
47
50
|
flash[:notice] = I18n.t("projects.update.success", scope: "decidim.budgets.admin")
|
48
|
-
redirect_to
|
51
|
+
redirect_to budget_projects_path(budget)
|
49
52
|
end
|
50
53
|
|
51
54
|
on(:invalid) do
|
@@ -61,7 +64,7 @@ module Decidim
|
|
61
64
|
DestroyProject.call(project, current_user) do
|
62
65
|
on(:ok) do
|
63
66
|
flash[:notice] = I18n.t("projects.destroy.success", scope: "decidim.budgets.admin")
|
64
|
-
redirect_to
|
67
|
+
redirect_to budget_projects_path(budget)
|
65
68
|
end
|
66
69
|
end
|
67
70
|
end
|
@@ -69,11 +72,11 @@ module Decidim
|
|
69
72
|
private
|
70
73
|
|
71
74
|
def projects
|
72
|
-
@projects ||=
|
75
|
+
@projects ||= budget.projects.page(params[:page]).per(15)
|
73
76
|
end
|
74
77
|
|
75
78
|
def orders
|
76
|
-
@orders ||= Order.where(
|
79
|
+
@orders ||= Order.where(budget: budget)
|
77
80
|
end
|
78
81
|
|
79
82
|
def pending_orders
|
@@ -4,6 +4,8 @@ module Decidim
|
|
4
4
|
module Budgets
|
5
5
|
module Admin
|
6
6
|
class ProposalsImportsController < Admin::ApplicationController
|
7
|
+
helper_method :budget
|
8
|
+
|
7
9
|
def new
|
8
10
|
enforce_permission_to :import_proposals, :projects
|
9
11
|
|
@@ -13,11 +15,11 @@ module Decidim
|
|
13
15
|
def create
|
14
16
|
enforce_permission_to :import_proposals, :projects
|
15
17
|
|
16
|
-
@form = form(Admin::ProjectImportProposalsForm).from_params(params)
|
18
|
+
@form = form(Admin::ProjectImportProposalsForm).from_params(params, budget: budget)
|
17
19
|
Admin::ImportProposalsToBudgets.call(@form) do
|
18
20
|
on(:ok) do |projects|
|
19
21
|
flash[:notice] = I18n.t("proposals_imports.create.success", scope: "decidim.budgets.admin", number: projects.length)
|
20
|
-
redirect_to
|
22
|
+
redirect_to budget_projects_path(budget)
|
21
23
|
end
|
22
24
|
|
23
25
|
on(:invalid) do
|
@@ -26,6 +28,12 @@ module Decidim
|
|
26
28
|
end
|
27
29
|
end
|
28
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def budget
|
35
|
+
@budget ||= Budget.where(component: current_component).find_by(id: params[:budget_id])
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|