Skip to content
Permalink
Browse files

Add: amendments wizard (#5244)

* Add routes

* Update concern and model

* Add/update forms

* Add/update commands

* Update controllers and add query

* Add wizard form cell

* Modify views

* Add translations

* Add/update tests

* Add amendments wizard help text

* Normalize locales

* Little refactor and update comments

* Add CHANGELOG entry

* Add #published scope in views helpers/cells instead of in amendable concern

* Add tests for existing amendment drafts

* Update comments

* Little refactor and update comments

* Add exceptions to i18n-tasks.yml

* Update translation

* Little refactor of form helpers

* Change :amendment factories and update specs

* Update spec/models/decidim/amendment_spec.rb
  • Loading branch information...
aitorlb authored and oriolgual committed Jul 3, 2019
1 parent 1bdc681 commit 8b6b2851f2af68c8b09c944feeffaf59fb0ec770
Showing with 1,692 additions and 291 deletions.
  1. +1 −0 CHANGELOG.md
  2. +2 −0 config/i18n-tasks.yml
  3. +8 −4 decidim-admin/app/assets/javascripts/decidim/admin/form.js.es6
  4. +1 −1 decidim-core/app/cells/decidim/amendable/amenders_list_cell.rb
  5. +121 −0 decidim-core/app/cells/decidim/amendable/wizard_step_form_cell.rb
  6. +14 −0 decidim-core/app/cells/decidim/wizard_step_form/wizard_aside.erb
  7. +18 −0 decidim-core/app/cells/decidim/wizard_step_form/wizard_header.erb
  8. +112 −0 decidim-core/app/cells/decidim/wizard_step_form_cell.rb
  9. +1 −1 decidim-core/app/commands/decidim/amendable/accept.rb
  10. +0 −84 decidim-core/app/commands/decidim/amendable/create.rb
  11. +70 −0 decidim-core/app/commands/decidim/amendable/create_draft.rb
  12. +40 −0 decidim-core/app/commands/decidim/amendable/destroy_draft.rb
  13. +5 −2 decidim-core/app/commands/decidim/amendable/promote.rb
  14. +76 −0 decidim-core/app/commands/decidim/amendable/publish_draft.rb
  15. +54 −0 decidim-core/app/commands/decidim/amendable/update_draft.rb
  16. +129 −28 decidim-core/app/controllers/concerns/decidim/amendments_controller.rb
  17. +3 −24 decidim-core/app/forms/decidim/amendable/create_form.rb
  18. +22 −0 decidim-core/app/forms/decidim/amendable/edit_form.rb
  19. +37 −23 decidim-core/app/forms/decidim/amendable/form.rb
  20. +4 −7 decidim-core/app/forms/decidim/amendable/promote_form.rb
  21. +21 −0 decidim-core/app/forms/decidim/amendable/publish_form.rb
  22. +1 −1 decidim-core/app/forms/decidim/amendable/reject_form.rb
  23. +9 −4 decidim-core/app/forms/decidim/amendable/review_form.rb
  24. +16 −4 decidim-core/app/helpers/decidim/amendments_helper.rb
  25. +6 −1 decidim-core/app/models/decidim/amendment.rb
  26. +56 −0 decidim-core/app/queries/decidim/similar_emendations.rb
  27. +16 −13 decidim-core/app/views/decidim/amendments/_edit_form_fields.html.erb
  28. +24 −0 decidim-core/app/views/decidim/amendments/_similar_emendation.html.erb
  29. +21 −0 decidim-core/app/views/decidim/amendments/compare_draft.html.erb
  30. +31 −0 decidim-core/app/views/decidim/amendments/edit_draft.html.erb
  31. +5 −17 decidim-core/app/views/decidim/amendments/new.html.erb
  32. +32 −0 decidim-core/app/views/decidim/amendments/preview_draft.html.erb
  33. +38 −6 decidim-core/config/locales/en.yml
  34. +6 −0 decidim-core/config/routes.rb
  35. +4 −1 decidim-core/lib/decidim/core/test.rb
  36. +10 −7 decidim-core/lib/decidim/core/test/factories.rb
  37. +50 −0 decidim-core/lib/decidim/core/test/shared_examples/amendable/create_amendment_draft_examples.rb
  38. +39 −0 decidim-core/lib/decidim/core/test/shared_examples/amendable/destroy_amendment_draft_examples.rb
  39. +27 −3 decidim-core/lib/decidim/core/test/shared_examples/amendable/promote_amendment_examples.rb
  40. +25 −16 ...st/shared_examples/amendable/{create_amendment_examples.rb → publish_amendment_draft_examples.rb}
  41. +42 −0 decidim-core/lib/decidim/core/test/shared_examples/amendable/update_amendment_draft_examples.rb
  42. +14 −0 decidim-core/spec/models/decidim/amendment_spec.rb
  43. +2 −1 decidim-proposals/app/controllers/decidim/proposals/proposals_controller.rb
  44. +1 −1 decidim-proposals/app/views/decidim/proposals/proposals/show.html.erb
  45. +1 −0 decidim-proposals/config/locales/en.yml
  46. +1 −0 decidim-proposals/lib/decidim/proposals/component.rb
  47. +1 −1 decidim-proposals/spec/cells/decidim/proposals/proposal_m_cell_spec.rb
  48. +9 −19 .../commands/decidim/proposals/amendable/{create_amendment_spec.rb → create_amendment_draft_spec.rb}
  49. +20 −0 decidim-proposals/spec/commands/decidim/proposals/amendable/destroy_amendment_draft_spec.rb
  50. +8 −14 decidim-proposals/spec/commands/decidim/proposals/amendable/promote_amendment_spec.rb
  51. +29 −0 decidim-proposals/spec/commands/decidim/proposals/amendable/publish_amendment_draft_spec.rb
  52. +38 −0 decidim-proposals/spec/commands/decidim/proposals/amendable/update_amendment_draft_spec.rb
  53. +40 −0 decidim-proposals/spec/forms/decidim/proposals/amendable/edit_amendment_form_spec.rb
  54. +10 −0 decidim-proposals/spec/lib/decidim/proposals/component_spec.rb
  55. +1 −1 decidim-proposals/spec/shared/manage_proposals_examples.rb
  56. +6 −6 decidim-proposals/spec/system/{ → amendable}/amend_proposal_spec.rb
  57. +313 −0 decidim-proposals/spec/system/amendable/amendment_wizard_spec.rb
  58. +1 −1 decidim-proposals/spec/system/filter_proposals_spec.rb
@@ -5,6 +5,7 @@

**Added**:

- **decidim-core**, **decidim-proposals**: Add: amendments Wizard Step Form [#5244](https://github.com/decidim/decidim/pull/5244)
- **decidim-core**, **decidim-admin**, **decidim-proposals**: Add: `amendments_visibility` component step setting [#5223](https://github.com/decidim/decidim/pull/5223)
- **decidim-core**, **decidim-admin**, **decidim-proposals**: Add: admin configuration of amendments by step [#5178](https://github.com/decidim/decidim/pull/5178)
- **decidim-consultations**: Add admin results page to consultations [#5188](https://github.com/decidim/decidim/pull/5188)
@@ -94,6 +94,7 @@ ignore_missing:
- email_intro
- email_outro
- notification_title
- decidim.wizard_step_form_cell.*

# Consider these keys used:
ignore_unused:
@@ -192,6 +193,7 @@ ignore_unused:
- decidim.initiatives.initiatives.votes_count.count.*
- decidim.proposals.admin.participatory_texts.new_import.accepted_mime_types.*
- decidim.amendments.visibility_options.*
- decidim.wizard_step_form.*

## Exclude these keys from the `i18n-tasks eq-base' report:
# ignore_eq_base:
@@ -9,20 +9,24 @@ $(() => {
return false;
});

// (1) Hides fields with ".amendments_step_settings" class if amendments_enabled
// component setting is NOT checked.
// (2) Toggles visibilty of fields with ".amendments_step_settings" class when
// amendments_enabled component setting is clicked.
// Target fields:
// - amendments_wizard_help_text
// - all fields with ".amendments_step_settings" class
// (1) Hides target fields if amendments_enabled component setting is NOT checked.
// (2) Toggles visibilty of target fields when amendments_enabled component setting is clicked.
const $amendmentsEnabled = $("input#component_settings_amendments_enabled");

if ($amendmentsEnabled.length > 0) {
const $amendmentWizardHelpText = $("[id*='amendments_wizard_help_text']").parent();
const $amendmentStepSettings = $(".amendments_step_settings").parent();

if ($amendmentsEnabled.is(":not(:checked)")) {
$amendmentWizardHelpText.hide();
$amendmentStepSettings.hide().siblings(".help-text").hide();
}

$amendmentsEnabled.click(() => {
$amendmentWizardHelpText.toggle();
$amendmentStepSettings.toggle().siblings(".help-text").toggle();
});
}
@@ -18,7 +18,7 @@ def amendable
end

def visible_amendments
amendable.visible_amendments_for(current_user)
amendable.visible_amendments_for(current_user).where.not(state: "draft")
end

# Returns a UserPresenter array
@@ -0,0 +1,121 @@
# frozen_string_literal: true

module Decidim
module Amendable
# This cell functions as an intermediary cell that computes and passes the
# necessary information, as a Hash, to Decidim::WizardStepFormCell.
class WizardStepFormCell < Decidim::ViewModel
def show
cell("decidim/wizard_step_form", options_for_view)
end

private

# Returns the current step as Integer.
def current_step
@current_step ||= case params[:action].to_sym
when :new, :create
1
when :compare_draft
2
when :edit_draft, :update_draft, :destroy_draft
3
when :preview_draft, :publish_draft
4
end
end

# Returns the translation for a given step.
def i18n_step(step_number)
t("decidim.amendments.wizard_step_form.steps.#{step_number}")
end

# Returns the name of the view we want to render, as Symbol.
def view
options[:view]
end

# Returns a Hash with all the data that will be needed in Decidim::WizardStepFormCell.
def options_for_view
common_options.merge(
send("#{view}_options")
)
end

# A Hash of data that is used in both :wizard_header and :wizard_aside views.
def common_options
{
view: view,
current_step: current_step,
total_steps: 4,
steps: {
"1": i18n_step(1),
"2": i18n_step(2),
"3": i18n_step(3),
"4": i18n_step(4)
}
}
end

# A Hash of data needed for the :wizard_aside view.
def wizard_aside_options
{
wizard_aside_back_url: wizard_aside_back_url
}
end

# A Hash of data needed for the :wizard_header view.
def wizard_header_options
{
wizard_header_title: wizard_header_title,
wizard_header_similar_resources_count: options[:similar_resources_count],
wizard_header_help_text: wizard_header_help_text
}
end

def amendable
@amendable ||= model
end

def amendment
@amendment ||= amendable.amendment
end

# Returns the link we want the back button to point to.
def wizard_aside_back_url
case current_step
when 1
Decidim::ResourceLocatorPresenter.new(amendable).path
when 3
Decidim::Core::Engine.routes.url_helpers.compare_draft_amend_path(amendment)
when 4
Decidim::Core::Engine.routes.url_helpers.edit_draft_amend_path(amendment)
end
end

# Returns the translation of the header title.
def wizard_header_title
key = case current_step
when 1
:new
when 2
:compare_draft
when 3
:edit_draft
when 4
:preview_draft
end

t("decidim.amendments.#{key}.title")
end

# Returns a Hash that will be passed to a Decidim::AnnouncementCell.
def wizard_header_help_text
attribute = amendable.component.settings.amendments_wizard_help_text
{
announcement: translated_attribute(attribute).presence
}
end
end
end
end
@@ -0,0 +1,14 @@
<div class="columns large-3">
<% if wizard_aside_back_url %>
<div class="m-bottom">
<%= link_to wizard_aside_back_url do %>
<%= icon "chevron-left", class: "icon--small" %>
<%= i18n_wizard_aside_back %>
<% end %>
</div>
<% end %>

<div class="show-for-large">
<%= wizard_stepper %>
</div>
</div>
@@ -0,0 +1,18 @@
<%= cell("decidim/announcement", wizard_header_announcement) %>

<div class="proposal_wizard_help_text">
<%= cell("decidim/announcement", wizard_header_help_text) %>
</div>

<h2 class="section-heading">
<%= wizard_header_title %>
<%= wizard_header_similar_resources_count %>
</h2>

<div class="hide-for-large m-bottom">
<%= wizard_header_see_steps %>

<ol id="steps" class="wizard__steps steps-toggle is-hidden" data-toggler=".is-hidden">
<%= wizard_stepper %>
</ol>
</div>
@@ -0,0 +1,112 @@
# frozen_string_literal: true

module Decidim
# This cell renders the wizard step form :wizard_aside or :wizard_header view.
# Is designed to be used by different models and so it does not try to compute
# the information likely to change. Expects a Hash with all necessary data.
class WizardStepFormCell < Decidim::ViewModel
include Decidim::LayoutHelper

def show
render view
end

private

# A Hash with all necessary data to render the view.
def view_options
model
end

# Returns the name of the view we want to render, as Symbol.
def view
view_options[:view]
end

# Returns the current step as Integer.
def current_step
view_options[:current_step]
end

# Returns the total number of steps to build the #wizard_stepper, as Integer.
def total_steps
view_options[:total_steps]
end

# Returns the list with all the steps, in HTML.
def wizard_stepper
content_tag :ol, class: "wizard__steps" do
(1..total_steps).map { |step| wizard_stepper_step(step) }.join
end
end

# Returns the list item of the given step, in HTML.
def wizard_stepper_step(step)
content_tag(:li, wizard_step_name(step), class: wizard_step_classes(step))
end

# Returns the name of the step, translated
def wizard_step_name(step)
view_options[:steps][step.to_s.to_sym]
end

# Returns the CSS classes used for the wizard for the given step.
def wizard_step_classes(step)
if step == current_step
%(step--active step_#{step})
elsif step < current_step
%(step--past step_#{step})
else
%()
end
end

# Returns the url of the back button.
def wizard_aside_back_url
view_options[:wizard_aside_back_url]
end

# Returns the translation of the back button.
def i18n_wizard_aside_back
t(".wizard_aside.back")
end

# Returns a Hash to be passed to Decidim::AnnouncementCell.
def wizard_header_announcement
view_options[:wizard_header_announcement] || {}
end

# Returns a Hash to be passed to Decidim::AnnouncementCell.
def wizard_header_help_text
view_options[:wizard_header_help_text] || {}
end

# Returns the translation of the header title.
def wizard_header_title
view_options[:wizard_header_title]
end

# Returns the similar resources count for the compare step.
def wizard_header_similar_resources_count
count = view_options[:wizard_header_similar_resources_count]
"(#{count})" if count
end

# Returns the header see steps information, only visible for small screens.
def wizard_header_see_steps
content_tag(:span, class: "text-small") do
i18n_wizard_header_step_of + " (#{wizard_header_see_steps_link})"
end
end

# Returns a translation with the current step number and the total steps number.
def i18n_wizard_header_step_of
t(".wizard_header.step_of", current_step: current_step, total_steps: total_steps)
end

# Returns a link that toggles the steps in the mobile view.
def wizard_header_see_steps_link
content_tag(:a, t(".wizard_header.see_steps"), "data-toggle": "steps")
end
end
end
@@ -32,7 +32,7 @@ def call
notify_amendable_and_emendation_authors_and_followers
end

broadcast(:ok, @amendable)
broadcast(:ok, @emendation)
end

private

0 comments on commit 8b6b285

Please sign in to comment.
You can’t perform that action at this time.