Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proposal answer templates #37

Open
wants to merge 18 commits into
base: release/0.26-stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ def create
@form = form(ProposalAnswerTemplateForm).from_params(params)

CreateProposalAnswerTemplate.call(@form) do
on(:ok) do |template|
on(:ok) do |_template|
microstudi marked this conversation as resolved.
Show resolved Hide resolved
flash[:notice] = I18n.t("templates.create.success", scope: "decidim.admin")
redirect_to edit_proposal_answer_template_path(template)
redirect_to proposal_answer_templates_path
end

on(:invalid) do
Expand Down Expand Up @@ -67,9 +67,9 @@ def update
enforce_permission_to :update, :template, template: template
@form = form(ProposalAnswerTemplateForm).from_params(params)
UpdateProposalAnswerTemplate.call(template, @form, current_user) do
on(:ok) do |questionnaire_template|
on(:ok) do |_questionnaire_template|
flash[:notice] = I18n.t("templates.update.success", scope: "decidim.admin")
redirect_to edit_proposal_answer_template_path(questionnaire_template)
redirect_to proposal_answer_templates_path
end

on(:invalid) do |template|
Expand Down Expand Up @@ -141,7 +141,7 @@ def availability_options_for_select

def avaliablity_options
@avaliablity_options = {}
Decidim::Component.includes(:participatory_space).where(manifest_name: :proposals)
Decidim::Component.includes(:participatory_space).where(manifest_name: accepted_components)
microstudi marked this conversation as resolved.
Show resolved Hide resolved
.select { |a| a.participatory_space.decidim_organization_id == current_organization.id }.each do |component|
@avaliablity_options["components-#{component.id}"] = formated_name(component)
end
Expand All @@ -150,7 +150,12 @@ def avaliablity_options
end

def formated_name(component)
"#{t(component.participatory_space.class.name.underscore, scope: "activerecord.models", count: 1)}: #{translated_attribute(component.participatory_space.title)} "
space_type = t(component.participatory_space.class.name.underscore, scope: "activerecord.models", count: 1)
"#{space_type}: #{translated_attribute(component.participatory_space.title)} > #{translated_attribute(component.name)}"
end

def accepted_components
[:proposals]
end

def template
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</div>

<div class="row column">
<%= form.select :scope_for_availability, availability_options_for_select %>
<%= form.select :scope_for_availability, availability_options_for_select, help_text: t(".scope_for_availability_help") %>
</div>
</div>
</div>
6 changes: 4 additions & 2 deletions decidim-templates/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ en:
template:
description: Description
name: Name
scope_for_availability: Restrict availability to the component
decidim:
admin:
menu:
Expand Down Expand Up @@ -45,15 +46,16 @@ en:
proposal_answer_templates:
form:
answer_template: Answer template
hint: "<strong>Hint:</strong> You can use theese variables anywhere on the answer template that will be replaced when using the template"
hint: "<strong>Hint:</strong> You can use these variables anywhere on the answer template that will be replaced when using the template"
hint1: "<strong>%{organization}</strong> will be replaced by the organization's name"
hint2: "<strong>%{name}</strong> will be replaced by the author's name"
hint3: "<strong>%{admin}</strong> will be replaced by the admin's name (the one answering the proposal)"
save: Save
scope_for_availability_help: Note that only participatory spaces having components of the type "proposals" will be listed.
template_title: Template information
index:
confirm_delete: Are you sure you want to delete this template?
global_scope: Global scope
global_scope: Global (available everywhere)
internal_state: Internal State
scope_for_availability: Scope
title: Proposal answers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,72 +22,95 @@
it "shows a table with the templates info" do
within ".questionnaire-templates" do
expect(page).to have_i18n_content(template.name)
expect(page).to have_i18n_content("Global scope")
expect(page).to have_i18n_content("Global (available everywhere)")
end
end
end

describe "creating a proposal_answer_template" do
let(:participatory_process) { create :participatory_process, title: { en: "A participatory process" }, organization: organization }
let!(:proposals_component) { create :component, manifest_name: :proposals, name: { en: "A component" }, participatory_space: participatory_process }

before do
within ".layout-content" do
click_link("New")
end
end

it "creates a new template with a Organization as templatable" do
within ".new_proposal_answer_template" do
fill_in_i18n(
:proposal_answer_template_name,
"#proposal_answer_template-name-tabs",
en: "My template",
es: "Mi plantilla",
ca: "La meva plantilla"
)
fill_in_i18n_editor(
:proposal_answer_template_description,
"#proposal_answer_template-description-tabs",
en: "Description",
es: "Descripción",
ca: "Descripció"
)

choose "Not answered"

page.find("*[type=submit]").click
shared_examples "creates a new template with scopes" do |scope_name|
it "creates a new template" do
within ".new_proposal_answer_template" do
fill_in_i18n(
:proposal_answer_template_name,
"#proposal_answer_template-name-tabs",
en: "My template",
es: "Mi plantilla",
ca: "La meva plantilla"
)
fill_in_i18n_editor(
:proposal_answer_template_description,
"#proposal_answer_template-description-tabs",
en: "Description",
es: "Descripción",
ca: "Descripció"
)

choose "Not answered"
select scope_name, from: :proposal_answer_template_scope_for_availability

page.find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")
expect(page).to have_current_path decidim_admin_templates.proposal_answer_templates_path
within ".questionnaire-templates" do
expect(page).to have_i18n_content(scope_name)
expect(page).to have_content("My template")
end
end

expect(page).to have_admin_callout("successfully")
end

it_behaves_like "creates a new template with scopes", "Global (available everywhere)"
it_behaves_like "creates a new template with scopes", "Participatory process: A participatory process > A component"
end

describe "updating a template" do
let!(:template) { create(:template, :proposal_answer, organization: organization) }
let(:participatory_process) { create :participatory_process, title: { en: "A participatory process" }, organization: organization }
let!(:proposals_component) { create :component, manifest_name: :proposals, name: { en: "A component" }, participatory_space: participatory_process }

before do
visit decidim_admin_templates.proposal_answer_templates_path
click_link translated(template.name)
end

it "updates a template" do
fill_in_i18n(
:proposal_answer_template_name,
"#proposal_answer_template-name-tabs",
en: "My new name",
es: "Mi nuevo nombre",
ca: "El meu nou nom"
)
shared_examples "updates a template with scopes" do |scope_name|
it "updates a template" do
fill_in_i18n(
:proposal_answer_template_name,
"#proposal_answer_template-name-tabs",
en: "My new name",
es: "Mi nuevo nombre",
ca: "El meu nou nom"
)

within ".edit_proposal_answer_template" do
page.find("*[type=submit]").click
end
select scope_name, from: :proposal_answer_template_scope_for_availability

expect(page).to have_admin_callout("successfully")
within ".edit_proposal_answer_template" do
page.find("*[type=submit]").click
end

within ".container" do
expect(page).to have_current_path decidim_admin_templates.edit_proposal_answer_template_path(template)
expect(page.find("#proposal_answer_template_name_en").value).to eq("My new name")
expect(page).to have_admin_callout("successfully")
expect(page).to have_current_path decidim_admin_templates.proposal_answer_templates_path
within ".questionnaire-templates" do
expect(page).to have_i18n_content(scope_name)
expect(page).to have_content("My new name")
end
end
end

it_behaves_like "updates a template with scopes", "Global (available everywhere)"
it_behaves_like "updates a template with scopes", "Participatory process: A participatory process > A component"
end

describe "updating a template with invalid values" do
Expand Down