Skip to content

Commit

Permalink
Fix initiative creation missing form fields (#10786)
Browse files Browse the repository at this point in the history
* Fix initiative creation missing form fields

* Add new form fields to spec

* Replace single quotes with double quotes

* Fix failing test

* Improve initiative create and edit form

Add form_field for initiative_type to create form
Move form_field for state to the end on edit form
add help text to author-select
fix specs

* normalize en.yml

* Add hidden field for initiative_type

* Update decidim-initiatives/config/locales/en.yml



* Fix order of fields

* Update decidim-initiatives/app/controllers/decidim/initiatives/create_initiative_controller.rb



* Fix spec

* Add missing hashtag to creation command

* Add missing trailing newline

---------

Co-authored-by: Heiner Sameisky <hei.sam@gmail.com>
Co-authored-by: Andrés Pereira de Lucena <andreslucena@users.noreply.github.com>
  • Loading branch information
3 people committed Apr 26, 2023
1 parent a044005 commit 1deafe9
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 43 deletions.
Expand Up @@ -73,7 +73,8 @@ def build_initiative
area: area,
signature_type: form.signature_type,
signature_end_date: signature_end_date,
state: "created"
state: "created",
hashtag: form.hashtag
)
end

Expand Down
Expand Up @@ -14,7 +14,7 @@ class InitiativesController < Decidim::Initiatives::Admin::ApplicationController

helper ::Decidim::Admin::ResourcePermissionsHelper
helper Decidim::Initiatives::InitiativeHelper
helper Decidim::Initiatives::CreateInitiativeHelper
helper Decidim::Initiatives::SignatureTypeOptionsHelper

# GET /admin/initiatives
def index
Expand Down
Expand Up @@ -16,6 +16,8 @@ class CreateInitiativeController < Decidim::Initiatives::ApplicationController

helper Decidim::Admin::IconLinkHelper
helper InitiativeHelper
helper SignatureTypeOptionsHelper

helper_method :similar_initiatives
helper_method :scopes
helper_method :areas
Expand Down
Expand Up @@ -18,6 +18,8 @@ class InitiativesController < Decidim::Initiatives::ApplicationController
helper Decidim::ResourceReferenceHelper
helper PaginateHelper
helper InitiativeHelper
helper SignatureTypeOptionsHelper

include InitiativeSlug
include FilterResource
include Paginable
Expand Down
Expand Up @@ -3,7 +3,7 @@
module Decidim
module Initiatives
# Helper methods for the create initiative wizard.
module CreateInitiativeHelper
module SignatureTypeOptionsHelper
def signature_type_options(initiative_form)
return all_signature_type_options unless initiative_form.signature_type_updatable?

Expand Down
Expand Up @@ -20,12 +20,23 @@
<div class="card__content">
<%= decidim_form_for(@form, url: next_wizard_path, method: :put, html: { class: "form new_initiative_form" }) do |f| %>
<%= form_required_explanation %>
<%= f.hidden_field :type_id %>
<div class=section>
<% unless single_initiative_type? %>
<% if single_initiative_type? %>
<%= f.hidden_field :type_id %>
<% else %>
<div class="field">
<label for="type_description"><%= t ".initiative_type" %></label>
<%= text_field_tag :type_description, strip_tags(translated_attribute(initiative_type.title)), readonly: true %>
<%= f.select :type_id,
initiative_type_options,
{},
{
disabled: !@form.signature_type_updatable?,
"data-scope-selector": "initiative_decidim_scope_id",
"data-scope-id": f.object.scope_id.to_s,
"data-scope-search-url": decidim_initiatives.initiative_type_scopes_search_url,
"data-signature-types-selector": "initiative_signature_type",
"data-signature-type": current_initiative&.signature_type,
"data-signature-types-search-url": decidim_initiatives.initiative_type_signature_types_search_url
} %>
</div>
<% end %>

Expand All @@ -37,6 +48,10 @@
<%= text_editor_for(f, :description, lines: 8, toolbar: :full) %>
</div>

<div class="field">
<%= f.text_field :hashtag %>
</div>

<% signature_type_options = signature_type_options(f.object) %>
<% if signature_type_options.length == 1 %>
<%= f.hidden_field :signature_type, value: signature_type_options.first.last %>
Expand All @@ -46,6 +61,12 @@
</div>
<% end %>
<% if initiative_type.custom_signature_end_date_enabled? %>
<div class="field">
<%= f.date_field :signature_end_date %>
</div>
<% end %>
<% if scopes.length == 1 %>
<%= f.hidden_field :scope_id, value: scopes.first.scope&.id %>
<% else %>
Expand All @@ -57,12 +78,6 @@
</div>
<% end %>
<% if initiative_type.custom_signature_end_date_enabled? %>
<div class="field">
<%= f.date_field :signature_end_date %>
</div>
<% end %>
<% if initiative_type.area_enabled? %>
<div class="field">
<%= f.areas_select :area_id, areas_for_select(current_organization), prompt: t(".select_area") %>
Expand All @@ -73,7 +88,7 @@
<div class="field">
<%= f.select :decidim_user_group_id,
Decidim::UserGroups::ManageableUserGroups.for(current_user).verified.map { |g| [g.name, g.id] },
include_blank: current_user.name %>
include_blank: current_user.name, help_text: t(".decidim_user_group_id_help") %>
</div>
<% end %>
Expand Down
@@ -1,24 +1,5 @@
<%= form_required_explanation %>
<div class="field">
<%= form.text_field :title, autofocus: true, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.title) %>
</div>

<div class="field">
<%= text_editor_for(form, :description, toolbar: :full, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.description)) %>
</div>

<div class="field">
<%= form.text_field :hashtag, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %>
</div>

<div class="field">
<%= form.select :state,
Decidim::Initiative.states.keys.map { |state| [I18n.t(state, scope: "decidim.initiatives.admin_states"), state] },
{},
{ disabled: !@form.state_updatable? } %>
</div>

<% unless single_initiative_type? %>
<div class="field">
<%= form.select :type_id,
Expand All @@ -37,17 +18,38 @@
<% end %>

<div class="field">
<%= form.select :scope_id,
@form.available_scopes.map { |scope| [translated_attribute(scope.scope_name), scope&.scope&.id] },
{ disabled: !@form.state_updatable? } %>
<%= form.text_field :title, autofocus: true, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.title) %>
</div>

<div class="field">
<%= text_editor_for(form, :description, toolbar: :full, lines: 8, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative), value: translated_attribute(@form.description)) %>
</div>

<div class="field">
<%= form.text_field :hashtag, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %>
</div>

<% signature_type_options = signature_type_options(form.object) %>
<% if signature_type_options.length == 1 %>
<%= form.hidden_field :signature_type %>
<% else %>
<div class="field">
<%= form.select :signature_type, [], {}, { disabled: !@form.signature_type_updatable? } %>
</div>
<% end %>
<% if can_edit_custom_signature_end_date?(current_initiative) %>
<div class="row column">
<%= form.date_field :signature_end_date, disabled: !allowed_to?(:update, :initiative, initiative: current_initiative) %>
</div>
<% end %>

<div class="field">
<%= form.select :scope_id,
@form.available_scopes.map { |scope| [translated_attribute(scope.scope_name), scope&.scope&.id] },
{ disabled: !@form.state_updatable? } %>
</div>

<% if current_initiative.area_enabled? %>
<div class="field">
<%= form.areas_select :area_id,
Expand All @@ -61,8 +63,12 @@
<% end %>

<div class="field">
<%= form.select :signature_type, [], {}, { disabled: !@form.signature_type_updatable? } %>
<%= form.select :state,
Decidim::Initiative.states.keys.map { |state| [I18n.t(state, scope: "decidim.initiatives.admin_states"), state] },
{},
{ disabled: !@form.state_updatable? } %>
</div>

<% if current_initiative.type.attachments_enabled? %>
<fieldset class="attachments_container">
<legend><%= t("attachment_legend", scope: "decidim.initiatives.form") %></legend>
Expand Down
2 changes: 1 addition & 1 deletion decidim-initiatives/config/locales/en.yml
Expand Up @@ -341,8 +341,8 @@ en:
fill_data:
back: Back
continue: Continue
decidim_user_group_id_help: It's not possible to change initiative authorship after creation
fill_data_help: "<ul> <li>Review the content of your initiative. Is your title easy to understand? Is the objective of your initiative clear?</li> <li>You have to choose the type of signature. In-person, online or a combination of both</li> <li>Which is the geographic scope of the initiative?</li> </ul>"
initiative_type: Initiative type
more_information: "(More information)"
select_area: Select an area
select_scope: Select a scope
Expand Down
Expand Up @@ -4,7 +4,7 @@

module Decidim
module Initiatives
describe CreateInitiativeHelper do
describe SignatureTypeOptionsHelper do
let(:online) { %w(Online online) }
let(:offline) { ["In-person", "offline"] }
let(:mixed) { %w(Mixed any) }
Expand Down
27 changes: 23 additions & 4 deletions decidim-initiatives/spec/system/create_initiative_spec.rb
Expand Up @@ -258,9 +258,14 @@
find_button("Continue").click
end

it "have no 'Initiative type' grey field" do
it "does not show select input for initiative_type" do
expect(page).not_to have_content("Initiative type")
expect(page).not_to have_css("#type_description")
expect(page).not_to have_css("#initiative_type_id")
end

it "has a hidden field with the selected initiative type" do
expect(page).to have_xpath("//input[@id='initiative_type_id']", visible: :all)
expect(find(:xpath, "//input[@id='initiative_type_id']", visible: :all).value).to eq(initiative_type.id.to_s)
end
end

Expand All @@ -284,20 +289,34 @@
end
end

it "shows select input for initiative_type" do
expect(page).to have_content("Type")
expect(find(:xpath, "//select[@id='initiative_type_id']", visible: :all).value).to eq(initiative_type.id.to_s)
end

it "shows information collected in previous steps already filled" do
expect(find(:xpath, "//input[@id='initiative_type_id']", visible: :all).value).to eq(initiative_type.id.to_s)
expect(find(:xpath, "//input[@id='initiative_title']").value).to eq(translated(initiative.title, locale: :en))
expect(find(:xpath, "//textarea[@id='initiative_description']", visible: :all).value).to eq(translated(initiative.description, locale: :en))
end

it "shows input for signature collection type" do
expect(page).to have_content("Signature collection type")
expect(find(:xpath, "//select[@id='initiative_signature_type']", visible: :all).value).to eq("online")
end

it "shows input for hashtag" do
expect(page).to have_content("Hashtag")
expect(find(:xpath, "//input[@id='initiative_hashtag']", visible: :all).value).to eq("")
end

context "when only one signature collection and scope are available" do
let(:other_initiative_type_scope) { nil }
let(:initiative_type) { create(:initiatives_type, organization: organization, minimum_committee_members: initiative_type_minimum_committee_members, signature_type: "offline") }

it "hides and automatically selects the values" do
expect(page).not_to have_content("Signature collection type")
expect(page).not_to have_content("Scope")
expect(find(:xpath, "//input[@id='initiative_type_id']", visible: :all).value).to eq(initiative_type.id.to_s)
expect(find(:xpath, "//select[@id='initiative_type_id']", visible: :all).value).to eq(initiative_type.id.to_s)
expect(find(:xpath, "//input[@id='initiative_signature_type']", visible: :all).value).to eq("offline")
end
end
Expand Down

0 comments on commit 1deafe9

Please sign in to comment.