decidim-reporting_proposals 0.2.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.json +1 -0
- data/.github/workflows/lint.yml +3 -2
- data/.github/workflows/test_integration.yml +7 -3
- data/.github/workflows/test_unit.yml +7 -3
- data/.rubocop-disabled.yml +11 -0
- data/.rubocop.yml +1 -0
- data/.rubocop_rails.yml +3 -0
- data/.rubocop_ruby.yml +24 -10
- data/.ruby-version +1 -1
- data/.simplecov +2 -2
- data/Gemfile +1 -0
- data/Gemfile.lock +400 -336
- data/README.md +110 -18
- data/Rakefile +2 -0
- data/app/cells/concerns/decidim/reporting_proposals/proposals_picker_cell_override.rb +24 -0
- data/app/commands/concerns/decidim/admin/hide_resource_override.rb +34 -0
- data/app/commands/concerns/decidim/proposals/admin/answer_proposal_override.rb +41 -0
- data/app/commands/concerns/decidim/proposals/admin/assign_proposals_to_valuator_override.rb +30 -0
- data/app/commands/concerns/decidim/proposals/publish_proposal_override.rb +72 -0
- data/app/commands/concerns/decidim/reporting_proposals/admin/create_answer_override.rb +17 -0
- data/app/commands/concerns/decidim/reporting_proposals/admin/create_result_override.rb +17 -0
- data/app/commands/concerns/decidim/reporting_proposals/admin/update_result_override.rb +34 -0
- data/app/commands/concerns/decidim/reporting_proposals/close_meeting_override.rb +15 -0
- data/app/commands/concerns/decidim/reporting_proposals/create_project_override.rb +15 -0
- data/app/commands/concerns/decidim/reporting_proposals/gallery_methods_override.rb +18 -0
- data/app/commands/concerns/decidim/templates/admin/copy_questionnaire_template_override.rb +32 -0
- data/app/commands/concerns/decidim/templates/admin/create_questionnaire_template_override.rb +32 -0
- data/app/commands/decidim/reporting_proposals/admin/update_proposal_note.rb +1 -1
- data/app/commands/decidim/reporting_proposals/create_reporting_proposal.rb +2 -0
- data/app/commands/decidim/templates/admin/copy_proposal_answer_template.rb +35 -0
- data/app/commands/decidim/templates/admin/create_proposal_answer_template.rb +48 -0
- data/app/commands/decidim/templates/admin/update_proposal_answer_template.rb +52 -0
- data/app/controllers/concerns/decidim/proposals/admin/valuation_assignments_controller_override.rb +35 -0
- data/app/controllers/concerns/decidim/reporting_proposals/admin/needs_header_snippets.rb +5 -7
- data/app/controllers/concerns/decidim/reporting_proposals/needs_proposal_extra_validations_snippets.rb +1 -1
- data/app/controllers/concerns/decidim/reporting_proposals/proposals_controller_override.rb +5 -5
- data/app/controllers/concerns/decidim/templates/admin/application_controller_override.rb +20 -0
- data/app/controllers/decidim/reporting_proposals/admin/proposal_notes_controller.rb +4 -5
- data/app/controllers/decidim/templates/admin/proposal_answer_templates_controller.rb +179 -0
- data/app/events/concerns/decidim/proposals/publish_proposal_event_override.rb +35 -0
- data/app/forms/concerns/decidim/reporting_proposals/close_meeting_form_override.rb +28 -0
- data/app/forms/concerns/decidim/reporting_proposals/form_builder_override.rb +10 -11
- data/app/forms/concerns/decidim/reporting_proposals/map_builder_override.rb +6 -4
- data/app/forms/concerns/decidim/reporting_proposals/map_included_proposals_for_form_override.rb +28 -0
- data/app/forms/concerns/decidim/reporting_proposals/map_related_proposals_for_form_override.rb +28 -0
- data/app/forms/decidim/templates/admin/proposal_answer_template_form.rb +21 -0
- data/app/helpers/concerns/decidim/reporting_proposals/proposal_wizard_helper_override.rb +4 -4
- data/app/helpers/concerns/decidim/reporting_proposals/resource_helper_override.rb +25 -0
- data/app/mailers/concerns/decidim/admin/hidden_resource_mailer.rb +28 -0
- data/app/mailers/concerns/decidim/proposals/admin/notification_answer_proposal_mailer.rb +25 -0
- data/app/mailers/concerns/decidim/proposals/admin/proposals_valuator_mailer.rb +30 -0
- data/app/mailers/concerns/decidim/proposals/notification_publish_proposal_mailer.rb +23 -0
- data/app/mailers/concerns/decidim/reported_mailer_override.rb +16 -0
- data/app/models/concerns/decidim/reporting_proposals/participatory_space_role_config/valuator_override.rb +4 -1
- data/app/overrides/decidim/proposals/admin/proposal_answers/_form/add_template_chooser.html.erb.deface +5 -0
- data/app/overrides/decidim/proposals/admin/proposals/_proposal-tr/add_valuators_name.html.erb.deface +3 -3
- data/app/overrides/decidim/proposals/admin/proposals/show/add_address.html.erb.deface +3 -0
- data/app/overrides/decidim/proposals/admin/proposals/show/add_send_email_btn.html.erb.deface +1 -1
- data/app/overrides/decidim/proposals/admin/proposals/show/add_valuators_form.html.erb.deface +19 -0
- data/app/overrides/decidim/proposals/admin/proposals/show/remove_photos.html.erb.deface +0 -1
- data/app/overrides/decidim/proposals/proposals/_edit_form_fields/replace_add_photos.html.erb.deface +37 -0
- data/app/overrides/decidim/proposals/proposals/_proposal_similar/add_distance_badge.html.erb.deface +1 -1
- data/app/overrides/decidim/proposals/proposals/_wizard_header/replace_title.html.erb.deface +9 -9
- data/app/overrides/decidim/proposals/proposals/edit/add_css.html.erb.deface +5 -0
- data/app/overrides/decidim/proposals/proposals/edit/replace_javascript.html.erb.deface +0 -1
- data/app/overrides/decidim/proposals/proposals/edit_draft/add_css.html.erb.deface +5 -0
- data/app/overrides/decidim/proposals/proposals/new/add_css.html.erb.deface +5 -0
- data/app/overrides/decidim/proposals/proposals/new/replace_javascript.html.erb.deface +0 -1
- data/app/overrides/decidim/reported_mailer/report/add_link_to_admin.html.erb.deface +5 -0
- data/app/overrides/layouts/decidim/_process_header_steps/always_show_new_proposals.html.erb.deface +1 -1
- data/app/packs/entrypoints/decidim_templates_admin.js +1 -0
- data/app/packs/src/decidim/reporting_proposals/user_camera_inputs.js +37 -39
- data/app/packs/src/decidim/templates/admin/proposal_answer_template_chooser.js +27 -0
- data/app/packs/stylesheets/decidim/reporting_proposals/geocoding_addons.scss +8 -8
- data/app/packs/stylesheets/decidim/reporting_proposals/list_component_admin.scss +5 -5
- data/app/packs/stylesheets/decidim/reporting_proposals/manage_component_admin.scss +36 -5
- data/app/packs/stylesheets/decidim/reporting_proposals/proposals/add_proposal.scss +3 -3
- data/app/packs/stylesheets/decidim/reporting_proposals/user_camera_inputs.scss +5 -5
- data/app/presenters/concerns/decidim/resource_locator_presenter_override.rb +38 -0
- data/app/queries/decidim/reporting_proposals/nearby_proposals.rb +1 -1
- data/app/resources/concerns/decidim/resource_manifest_override.rb +14 -0
- data/app/validators/concerns/decidim/reporting_proposals/component_validator_override.rb +2 -2
- data/app/views/decidim/admin/hidden_resource_mailer/notify_mail.html.erb +12 -0
- data/app/views/decidim/proposals/admin/notification_answer_proposal_mailer/notify_proposal_author.html.erb +7 -0
- data/app/views/decidim/proposals/admin/proposals/_address.html.erb +13 -0
- data/app/views/decidim/proposals/admin/proposals_valuator_mailer/notify_proposals_valuator.html.erb +17 -0
- data/app/views/decidim/proposals/notification_publish_proposal_mailer/notify_proposal_author.html.erb +7 -0
- data/app/views/decidim/proposals/proposals/index.js.erb +19 -0
- data/app/views/decidim/reporting_proposals/proposals/_reporting_proposal_fields.html.erb +9 -21
- data/app/views/decidim/templates/admin/proposal_answer_templates/_form.html.erb +34 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/_template_chooser.html.erb +16 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/edit.html.erb +3 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/index.html.erb +52 -0
- data/app/views/decidim/templates/admin/proposal_answer_templates/new.html.erb +6 -0
- data/babel.config.json +25 -0
- data/config/assets.rb +2 -1
- data/config/i18n-tasks.yml +3 -0
- data/config/locales/ca.yml +81 -7
- data/config/locales/de.yml +77 -3
- data/config/locales/en.yml +89 -0
- data/config/locales/es.yml +328 -254
- data/db/migrate/20230404103706_add_target_and_field_values_to_decidim_templates_templates.rb +8 -0
- data/db/migrate/20230404104741_migrate_templatable.rb +13 -0
- data/decidim-reporting_proposals.gemspec +7 -1
- data/lib/decidim/reporting_proposals/admin_engine.rb +16 -1
- data/lib/decidim/reporting_proposals/component.rb +0 -9
- data/lib/decidim/reporting_proposals/config.rb +10 -5
- data/lib/decidim/reporting_proposals/engine.rb +62 -1
- data/lib/decidim/reporting_proposals/test/factories.rb +10 -0
- data/lib/decidim/reporting_proposals/version.rb +3 -8
- data/package-lock.json +161 -142
- data/package.json +4 -163
- metadata +187 -29
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class CreateProposalAnswerTemplate < Decidim::Command
|
7
|
+
# Initializes the command.
|
8
|
+
#
|
9
|
+
# form - The source for this ProposalAnswerTemplate.
|
10
|
+
def initialize(form)
|
11
|
+
@form = form
|
12
|
+
end
|
13
|
+
|
14
|
+
def call
|
15
|
+
return broadcast(:invalid) unless @form.valid?
|
16
|
+
|
17
|
+
@template = Decidim.traceability.create!(
|
18
|
+
Template,
|
19
|
+
@form.current_user,
|
20
|
+
name: @form.name,
|
21
|
+
description: @form.description,
|
22
|
+
organization: @form.current_organization,
|
23
|
+
field_values: { internal_state: @form.internal_state },
|
24
|
+
target: :proposal_answer
|
25
|
+
)
|
26
|
+
|
27
|
+
resource = identify_templateable_resource
|
28
|
+
@template.update!(templatable: resource)
|
29
|
+
|
30
|
+
broadcast(:ok, @template)
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def identify_templateable_resource
|
36
|
+
resource = @form.scope_for_availability.split("-")
|
37
|
+
case resource.first
|
38
|
+
when "organizations"
|
39
|
+
@form.current_organization
|
40
|
+
when "components"
|
41
|
+
component = Decidim::Component.find_by(id: resource.last)
|
42
|
+
component&.participatory_space&.decidim_organization_id == @form.current_organization.id ? component : nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class UpdateProposalAnswerTemplate < Decidim::Command
|
7
|
+
# Initializes the command.
|
8
|
+
#
|
9
|
+
# template - The Template to update.
|
10
|
+
# form - The form object containing the data to update.
|
11
|
+
# user - The user that updates the template.
|
12
|
+
def initialize(template, form, user)
|
13
|
+
@template = template
|
14
|
+
@form = form
|
15
|
+
@user = user
|
16
|
+
end
|
17
|
+
|
18
|
+
def call
|
19
|
+
return broadcast(:invalid) unless @form.valid?
|
20
|
+
return broadcast(:invalid) unless @user.organization == @template.organization
|
21
|
+
|
22
|
+
@template = Decidim.traceability.update!(
|
23
|
+
@template,
|
24
|
+
@user,
|
25
|
+
name: @form.name,
|
26
|
+
description: @form.description,
|
27
|
+
field_values: { internal_state: @form.internal_state },
|
28
|
+
target: :proposal_answer
|
29
|
+
)
|
30
|
+
|
31
|
+
resource = identify_templateable_resource
|
32
|
+
@template.update!(templatable: resource)
|
33
|
+
|
34
|
+
broadcast(:ok, @template)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def identify_templateable_resource
|
40
|
+
resource = @form.scope_for_availability.split("-")
|
41
|
+
case resource.first
|
42
|
+
when "organizations"
|
43
|
+
@form.current_organization
|
44
|
+
when "components"
|
45
|
+
component = Decidim::Component.find_by(id: resource.last)
|
46
|
+
component&.participatory_space&.decidim_organization_id == @form.current_organization.id ? component : nil
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/app/controllers/concerns/decidim/proposals/admin/valuation_assignments_controller_override.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module Admin
|
6
|
+
module ValuationAssignmentsControllerOverride
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
def create
|
11
|
+
enforce_permission_to :assign_to_valuator, :proposals
|
12
|
+
@form = form(Admin::ValuationAssignmentForm).from_params(params)
|
13
|
+
Admin::AssignProposalsToValuator.call(@form) do
|
14
|
+
on(:ok) do |_proposal|
|
15
|
+
flash[:notice] = I18n.t("valuation_assignments.create.success", scope: "decidim.proposals.admin")
|
16
|
+
redirect_to after_add_evaluator_url
|
17
|
+
end
|
18
|
+
|
19
|
+
on(:invalid) do
|
20
|
+
flash.now[:alert] = I18n.t("valuation_assignments.create.invalid", scope: "decidim.proposals.admin")
|
21
|
+
redirect_to after_add_evaluator_url
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def after_add_evaluator_url
|
27
|
+
return request.referer if request.referer.present? && request.referer =~ %r{manage/proposals/[0-9]+}
|
28
|
+
|
29
|
+
EngineRouter.admin_proxy(current_component).root_path
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -36,13 +36,11 @@ module Decidim
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def current_component
|
39
|
-
@current_component ||=
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
39
|
+
@current_component ||= if defined?(query_scope) && query_scope.respond_to?(:find)
|
40
|
+
query_scope.find_by(id: params[:id])
|
41
|
+
elsif params.has_key?(:component_id)
|
42
|
+
Decidim::Component.find_by(id: params[:component_id])
|
43
|
+
end
|
46
44
|
end
|
47
45
|
end
|
48
46
|
end
|
@@ -16,7 +16,7 @@ module Decidim
|
|
16
16
|
unless @snippets.any?(:reporting_proposals_js_validations)
|
17
17
|
@snippets.add(:reporting_proposals_js_validations, ActionController::Base.helpers.javascript_pack_tag("decidim_reporting_proposals_js_validations"))
|
18
18
|
@snippets.add(:reporting_proposals_js_validations, rules_tag)
|
19
|
-
@snippets.add(:
|
19
|
+
@snippets.add(:foot, @snippets.for(:reporting_proposals_js_validations))
|
20
20
|
end
|
21
21
|
@snippets
|
22
22
|
end
|
@@ -12,7 +12,7 @@ module Decidim
|
|
12
12
|
|
13
13
|
def new
|
14
14
|
enforce_permission_to :create, :proposal
|
15
|
-
@step =
|
15
|
+
@step = Proposals::ProposalsController::STEP1
|
16
16
|
if proposal_draft.present?
|
17
17
|
redirect_to edit_draft_proposal_path(proposal_draft, component_id: proposal_draft.component.id, question_slug: proposal_draft.component.participatory_space.slug)
|
18
18
|
else
|
@@ -22,7 +22,7 @@ module Decidim
|
|
22
22
|
|
23
23
|
def create
|
24
24
|
enforce_permission_to :create, :proposal
|
25
|
-
@step =
|
25
|
+
@step = Proposals::ProposalsController::STEP1
|
26
26
|
@form = form(new_proposal_form).from_params(proposal_creation_params)
|
27
27
|
|
28
28
|
create_proposal_command.call(@form, current_user) do
|
@@ -42,7 +42,7 @@ module Decidim
|
|
42
42
|
# change comparison class if geocoding comparison is enabled
|
43
43
|
def compare
|
44
44
|
enforce_permission_to :edit, :proposal, proposal: @proposal
|
45
|
-
@step =
|
45
|
+
@step = Proposals::ProposalsController::STEP2
|
46
46
|
klass = if geocoding_comparison?
|
47
47
|
Decidim::ReportingProposals::NearbyProposals
|
48
48
|
else
|
@@ -61,7 +61,7 @@ module Decidim
|
|
61
61
|
# disable this step for reporting proposals
|
62
62
|
def complete
|
63
63
|
enforce_permission_to :edit, :proposal, proposal: @proposal
|
64
|
-
@step =
|
64
|
+
@step = Proposals::ProposalsController::STEP3
|
65
65
|
|
66
66
|
@form = form_proposal_model
|
67
67
|
|
@@ -71,7 +71,7 @@ module Decidim
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def edit_draft
|
74
|
-
@step = reporting_proposal? ?
|
74
|
+
@step = reporting_proposal? ? Proposals::ProposalsController::STEP1 : Proposals::ProposalsController::STEP3
|
75
75
|
enforce_permission_to :edit, :proposal, proposal: @proposal
|
76
76
|
end
|
77
77
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
module ApplicationControllerOverride
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
def template_types
|
11
|
+
@template_types ||= {
|
12
|
+
I18n.t("template_types.questionnaires", scope: "decidim.templates") => decidim_admin_templates.questionnaire_templates_path,
|
13
|
+
I18n.t("template_types.proposal_answer_templates", scope: "decidim.templates") => decidim_admin_templates.proposal_answer_templates_path
|
14
|
+
}
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -6,11 +6,6 @@ module Decidim
|
|
6
6
|
class ProposalNotesController < Admin::ApplicationController
|
7
7
|
helper_method :note
|
8
8
|
|
9
|
-
def edit
|
10
|
-
enforce_permission_to :edit_note, :proposal_note, proposal_note: note
|
11
|
-
@notes_form = form(Decidim::Proposals::Admin::ProposalNoteForm).from_model(note)
|
12
|
-
end
|
13
|
-
|
14
9
|
def update
|
15
10
|
enforce_permission_to :edit_note, :proposal_note, proposal_note: note
|
16
11
|
@notes_form = form(Decidim::Proposals::Admin::ProposalNoteForm).from_params(params)
|
@@ -27,6 +22,10 @@ module Decidim
|
|
27
22
|
end
|
28
23
|
end
|
29
24
|
|
25
|
+
def current_component
|
26
|
+
note&.proposal&.component
|
27
|
+
end
|
28
|
+
|
30
29
|
private
|
31
30
|
|
32
31
|
def note
|
@@ -0,0 +1,179 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class ProposalAnswerTemplatesController < Decidim::Templates::Admin::ApplicationController
|
7
|
+
include Decidim::TranslatableAttributes
|
8
|
+
include Decidim::Paginable
|
9
|
+
|
10
|
+
helper_method :availability_option_as_text, :availability_options_for_select
|
11
|
+
|
12
|
+
rescue_from ActiveRecord::RecordNotFound do |exception|
|
13
|
+
if request.xhr?
|
14
|
+
render json: { msg: I18n.t("templates.fetch.error", scope: "decidim.admin"), error: exception.message }, status: :unprocessable_entity
|
15
|
+
else
|
16
|
+
throw exception
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def new
|
21
|
+
enforce_permission_to :create, :template
|
22
|
+
@form = form(ProposalAnswerTemplateForm).instance
|
23
|
+
end
|
24
|
+
|
25
|
+
def edit
|
26
|
+
enforce_permission_to :update, :template, template: template
|
27
|
+
@form = form(ProposalAnswerTemplateForm).from_model(template)
|
28
|
+
end
|
29
|
+
|
30
|
+
def create
|
31
|
+
enforce_permission_to :create, :template
|
32
|
+
|
33
|
+
@form = form(ProposalAnswerTemplateForm).from_params(params)
|
34
|
+
|
35
|
+
CreateProposalAnswerTemplate.call(@form) do
|
36
|
+
on(:ok) do |_template|
|
37
|
+
flash[:notice] = I18n.t("templates.create.success", scope: "decidim.admin")
|
38
|
+
redirect_to proposal_answer_templates_path
|
39
|
+
end
|
40
|
+
|
41
|
+
on(:invalid) do
|
42
|
+
flash.now[:alert] = I18n.t("templates.create.error", scope: "decidim.admin")
|
43
|
+
render :new
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def destroy
|
49
|
+
enforce_permission_to :destroy, :template, template: template
|
50
|
+
|
51
|
+
DestroyTemplate.call(template, current_user) do
|
52
|
+
on(:ok) do
|
53
|
+
flash[:notice] = I18n.t("templates.destroy.success", scope: "decidim.admin")
|
54
|
+
redirect_to action: :index
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def fetch
|
60
|
+
enforce_permission_to :read, :template, template: template
|
61
|
+
|
62
|
+
response_object = {
|
63
|
+
state: template.field_values["internal_state"],
|
64
|
+
template: populate_template_interpolations(proposal)
|
65
|
+
}
|
66
|
+
|
67
|
+
respond_to do |format|
|
68
|
+
format.json do
|
69
|
+
render json: response_object.to_json
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def update
|
75
|
+
enforce_permission_to :update, :template, template: template
|
76
|
+
@form = form(ProposalAnswerTemplateForm).from_params(params)
|
77
|
+
UpdateProposalAnswerTemplate.call(template, @form, current_user) do
|
78
|
+
on(:ok) do |_questionnaire_template|
|
79
|
+
flash[:notice] = I18n.t("templates.update.success", scope: "decidim.admin")
|
80
|
+
redirect_to proposal_answer_templates_path
|
81
|
+
end
|
82
|
+
|
83
|
+
on(:invalid) do |template|
|
84
|
+
@template = template
|
85
|
+
flash.now[:error] = I18n.t("templates.update.error", scope: "decidim.admin")
|
86
|
+
render action: :edit
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def copy
|
92
|
+
enforce_permission_to :copy, :template
|
93
|
+
|
94
|
+
CopyProposalAnswerTemplate.call(template) do
|
95
|
+
on(:ok) do
|
96
|
+
flash[:notice] = I18n.t("templates.copy.success", scope: "decidim.admin")
|
97
|
+
redirect_to action: :index
|
98
|
+
end
|
99
|
+
|
100
|
+
on(:invalid) do
|
101
|
+
flash[:alert] = I18n.t("templates.copy.error", scope: "decidim.admin")
|
102
|
+
redirect_to action: :index
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def index
|
108
|
+
enforce_permission_to :index, :templates
|
109
|
+
@templates = collection
|
110
|
+
|
111
|
+
respond_to do |format|
|
112
|
+
format.html { render :index }
|
113
|
+
format.json do
|
114
|
+
term = params[:term]
|
115
|
+
|
116
|
+
@templates = search(term)
|
117
|
+
|
118
|
+
render json: @templates.map { |t| { value: t.id, label: translated_attribute(t.name) } }
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
|
125
|
+
def populate_template_interpolations(proposal)
|
126
|
+
template.description do |language, value|
|
127
|
+
value.gsub!("%{organization}", proposal.organization.name)
|
128
|
+
value.gsub!("%{name}", proposal.creator_author.name)
|
129
|
+
value.gsub!("%{admin}", current_user.name)
|
130
|
+
|
131
|
+
[language, value]
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
def proposal
|
136
|
+
@proposal ||= Decidim::Proposals::Proposal.find(params[:proposal_id])
|
137
|
+
end
|
138
|
+
|
139
|
+
def availability_option_as_text(template)
|
140
|
+
return unless template.templatable_type
|
141
|
+
|
142
|
+
key = "#{template.templatable_type.demodulize.tableize}-#{template.templatable_id}"
|
143
|
+
avaliablity_options[key].presence || t("templates.missing_resource", scope: "decidim.admin")
|
144
|
+
end
|
145
|
+
|
146
|
+
def availability_options_for_select
|
147
|
+
avaliablity_options.collect { |key, value| [value, key] }.to_a
|
148
|
+
end
|
149
|
+
|
150
|
+
def avaliablity_options
|
151
|
+
@avaliablity_options = {}
|
152
|
+
Decidim::Component.includes(:participatory_space).where(manifest_name: accepted_components)
|
153
|
+
.select { |a| a.participatory_space&.decidim_organization_id == current_organization.id }.each do |component|
|
154
|
+
@avaliablity_options["components-#{component.id}"] = formated_name(component)
|
155
|
+
end
|
156
|
+
global_scope = { "organizations-#{current_organization.id}" => t("global_scope", scope: "decidim.templates.admin.proposal_answer_templates.index") }
|
157
|
+
@avaliablity_options = global_scope.merge(@avaliablity_options.sort_by { |_, val| val }.to_h)
|
158
|
+
end
|
159
|
+
|
160
|
+
def formated_name(component)
|
161
|
+
space_type = t(component.participatory_space.class.name.underscore, scope: "activerecord.models", count: 1)
|
162
|
+
"#{space_type}: #{translated_attribute(component.participatory_space.title)} > #{translated_attribute(component.name)}"
|
163
|
+
end
|
164
|
+
|
165
|
+
def accepted_components
|
166
|
+
[:proposals]
|
167
|
+
end
|
168
|
+
|
169
|
+
def template
|
170
|
+
@template ||= Template.find(params[:id])
|
171
|
+
end
|
172
|
+
|
173
|
+
def collection
|
174
|
+
@collection ||= paginate(current_organization.templates.where(target: :proposal_answer).order(:id))
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Proposals
|
5
|
+
module PublishProposalEventOverride
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
def i18n_options
|
10
|
+
return super if author.blank?
|
11
|
+
|
12
|
+
author_path = link_to("@#{author.nickname}", profile_path(author.nickname))
|
13
|
+
author_string = "#{author.name} #{author_path}"
|
14
|
+
super.merge({ author: author_string })
|
15
|
+
resource_admin_url ||= Decidim::ResourceLocatorPresenter.new(resource).admin_url
|
16
|
+
resource_admin_path = link_to(I18n.t(".admin_panel", scope: i18n_scope), resource_admin_url)
|
17
|
+
|
18
|
+
super.merge({ author: author_string, admin_url: resource_admin_path })
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def i18n_scope
|
24
|
+
return super unless participatory_space_event?
|
25
|
+
|
26
|
+
@i18n_scope ||= if extra[:type].to_s == "admin"
|
27
|
+
"decidim.events.proposals.proposal_published_for_admin"
|
28
|
+
else
|
29
|
+
"decidim.events.proposals.proposal_published_for_space"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ReportingProposals
|
5
|
+
module CloseMeetingFormOverride
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
alias_method :map_model_original, :map_model
|
10
|
+
|
11
|
+
def map_model(model)
|
12
|
+
map_model_original(model)
|
13
|
+
self.proposal_ids += model.linked_resources(:reporting_proposals, "proposals_from_meeting").pluck(:id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def proposals
|
17
|
+
@proposals ||= begin
|
18
|
+
proposals_query = Decidim.find_resource_manifest(:proposals).try(:resource_scope, current_component)
|
19
|
+
reporting_proposals_query = Decidim.find_resource_manifest(:reporting_proposals).try(:resource_scope, current_component)
|
20
|
+
(reporting_proposals_query ? proposals_query.or(reporting_proposals_query) : proposals_query)
|
21
|
+
&.where(id: proposal_ids)
|
22
|
+
&.order(title: :asc)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -10,21 +10,22 @@ module Decidim
|
|
10
10
|
delegate :asset_pack_path, to: :@template
|
11
11
|
|
12
12
|
included do
|
13
|
-
def file_field(object_name,
|
14
|
-
return super(object_name,
|
13
|
+
def file_field(object_name, options = {})
|
14
|
+
return super(object_name, options) unless use_camera_button?(object_name)
|
15
15
|
|
16
|
-
unless @template.snippets.any?(:
|
17
|
-
@template.snippets.add(:
|
18
|
-
@template.snippets.add(:
|
16
|
+
unless @template.snippets.any?(:reporting_proposals_camera_scripts) || @template.snippets.any?(:reporting_proposals_camera_styles)
|
17
|
+
@template.snippets.add(:reporting_proposals_camera_scripts, @template.javascript_pack_tag("decidim_reporting_proposals_camera"))
|
18
|
+
@template.snippets.add(:reporting_proposals_camera_styles, @template.stylesheet_pack_tag("decidim_reporting_proposals_camera"))
|
19
19
|
|
20
20
|
# This will display the snippets in the <head> part of the page.
|
21
|
-
@template.snippets.add(:head, @template.snippets.for(:
|
21
|
+
@template.snippets.add(:head, @template.snippets.for(:reporting_proposals_camera_styles))
|
22
|
+
@template.snippets.add(:foot, @template.snippets.for(:reporting_proposals_camera_scripts))
|
22
23
|
end
|
23
24
|
|
24
25
|
content_tag(:div, class: "input-group") do
|
25
|
-
super(object_name,
|
26
|
+
super(object_name, options) +
|
26
27
|
content_tag(:div, class: "input-group-button") do
|
27
|
-
content_tag(:button, class: "button secondary user-device-camera", type: "button", data: { input:
|
28
|
+
content_tag(:button, class: "button secondary user-device-camera", type: "button", data: { input: object_name }) do
|
28
29
|
icon("camera-slr", role: "img", "aria-hidden": true) + " #{I18n.t("use_my_camera", scope: "decidim.reporting_proposals.forms")}"
|
29
30
|
end
|
30
31
|
end
|
@@ -38,9 +39,7 @@ module Decidim
|
|
38
39
|
|
39
40
|
return unless Decidim::ReportingProposals.use_camera_button.include?(@template.current_component.manifest_name.to_sym)
|
40
41
|
|
41
|
-
|
42
|
-
|
43
|
-
true
|
42
|
+
object_name == :add_photos
|
44
43
|
end
|
45
44
|
end
|
46
45
|
end
|
@@ -15,12 +15,14 @@ module Decidim
|
|
15
15
|
def geocoding_field(object_name, method, options = {})
|
16
16
|
return original_geocoding_field(object_name, method, options) unless show_my_location_button?
|
17
17
|
|
18
|
-
unless template.snippets.any?(:
|
19
|
-
template.snippets.add(:
|
20
|
-
template.snippets.add(:
|
18
|
+
unless template.snippets.any?(:reporting_proposals_geocoding_scripts) || template.snippets.any?(:reporting_proposals_geocoding_styles)
|
19
|
+
template.snippets.add(:reporting_proposals_geocoding_scripts, template.javascript_pack_tag("decidim_reporting_proposals_geocoding"))
|
20
|
+
template.snippets.add(:reporting_proposals_geocoding_styles, template.stylesheet_pack_tag("decidim_reporting_proposals_geocoding"))
|
21
21
|
|
22
22
|
# This will display the snippets in the <head> part of the page.
|
23
|
-
template.snippets.add(:head, template.snippets.for(:
|
23
|
+
template.snippets.add(:head, template.snippets.for(:reporting_proposals_geocoding_styles))
|
24
|
+
# This will display the snippets in the bottom part of the page.
|
25
|
+
template.snippets.add(:foot, template.snippets.for(:reporting_proposals_geocoding_scripts))
|
24
26
|
end
|
25
27
|
|
26
28
|
options[:autocomplete] ||= "off"
|
data/app/forms/concerns/decidim/reporting_proposals/map_included_proposals_for_form_override.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ReportingProposals
|
5
|
+
module MapIncludedProposalsForFormOverride
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
alias_method :map_model_original, :map_model
|
10
|
+
|
11
|
+
def map_model(model)
|
12
|
+
map_model_original(model)
|
13
|
+
self.proposal_ids += model.linked_resources(:reporting_proposals, "included_proposals").pluck(:id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def proposals
|
17
|
+
@proposals ||= begin
|
18
|
+
proposals_query = Decidim.find_resource_manifest(:proposals).try(:resource_scope, current_component)
|
19
|
+
reporting_proposals_query = Decidim.find_resource_manifest(:reporting_proposals).try(:resource_scope, current_component)
|
20
|
+
(reporting_proposals_query ? proposals_query.or(reporting_proposals_query) : proposals_query)
|
21
|
+
&.where(id: proposal_ids)
|
22
|
+
&.order(title: :asc)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/app/forms/concerns/decidim/reporting_proposals/map_related_proposals_for_form_override.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module ReportingProposals
|
5
|
+
module MapRelatedProposalsForFormOverride
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
alias_method :map_model_original, :map_model
|
10
|
+
|
11
|
+
def map_model(model)
|
12
|
+
map_model_original(model)
|
13
|
+
self.proposal_ids += model.linked_resources(:reporting_proposals, "related_proposals").pluck(:id)
|
14
|
+
end
|
15
|
+
|
16
|
+
def proposals
|
17
|
+
@proposals ||= begin
|
18
|
+
proposals_query = Decidim.find_resource_manifest(:proposals).try(:resource_scope, current_component)
|
19
|
+
reporting_proposals_query = Decidim.find_resource_manifest(:reporting_proposals).try(:resource_scope, current_component)
|
20
|
+
(reporting_proposals_query ? proposals_query.or(reporting_proposals_query) : proposals_query)
|
21
|
+
&.where(id: proposal_ids)
|
22
|
+
&.order(title: :asc)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Decidim
|
4
|
+
module Templates
|
5
|
+
module Admin
|
6
|
+
class ProposalAnswerTemplateForm < TemplateForm
|
7
|
+
attribute :internal_state, String
|
8
|
+
attribute :scope_for_availability, String
|
9
|
+
|
10
|
+
validates :internal_state, presence: true
|
11
|
+
|
12
|
+
def map_model(model)
|
13
|
+
self.scope_for_availability = "#{model.templatable_type.try(:demodulize).try(:tableize)}-#{model.templatable_id.to_i}"
|
14
|
+
(model.field_values || []).to_h.map do |k, v|
|
15
|
+
self[k.to_sym] = v
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -9,11 +9,11 @@ module Decidim
|
|
9
9
|
included do
|
10
10
|
def proposal_wizard_stepper(current_step)
|
11
11
|
steps = %(
|
12
|
-
#{proposal_wizard_stepper_step(
|
13
|
-
#{proposal_wizard_stepper_step(
|
12
|
+
#{proposal_wizard_stepper_step(Proposals::ProposalsController::STEP1, current_step)}
|
13
|
+
#{proposal_wizard_stepper_step(Proposals::ProposalsController::STEP2, current_step)}
|
14
14
|
)
|
15
|
-
steps = %(#{steps} #{proposal_wizard_stepper_step(
|
16
|
-
steps = %(#{steps} #{proposal_wizard_stepper_step(
|
15
|
+
steps = %(#{steps} #{proposal_wizard_stepper_step(Proposals::ProposalsController::STEP3, current_step)}) unless reporting_proposals_component?
|
16
|
+
steps = %(#{steps} #{proposal_wizard_stepper_step(Proposals::ProposalsController::STEP4, current_step)})
|
17
17
|
|
18
18
|
content_tag :ol, class: "wizard__steps" do
|
19
19
|
steps.html_safe
|