Add budget investments translation interface

* Adapt translatable spec helper method to work with budget investments
* Remove old attributes from strong parameters
* Add missing locales to admin.yml and budgets.yml
* Change SpendingProposal.title_max_length and
  SpendingProposal.description_max_lenght to Budget::Investment methods
* Add budget investment translatable attribute translations
This commit is contained in:
Senén Rodero Rodríguez
2018-12-23 18:48:13 +01:00
committed by voodoorai2000
parent 5eb5f02cbe
commit 661ca5a568
9 changed files with 62 additions and 35 deletions

View File

@@ -3,6 +3,7 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
include CommentableActions
include DownloadSettingsHelper
include ChangeLogHelper
include Translatable
feature_flag :budgets
@@ -87,10 +88,10 @@ class Admin::BudgetInvestmentsController < Admin::BaseController
end
def budget_investment_params
params.require(:budget_investment)
.permit(:title, :description, :external_url, :heading_id, :administrator_id, :tag_list,
attributes = [:external_url, :heading_id, :administrator_id, :tag_list,
:valuation_tag_list, :incompatible, :visible_to_valuators, :selected,
:milestone_tag_list, tracker_ids: [], valuator_ids: [], valuator_group_ids: [])
:milestone_tag_list, tracker_ids: [], valuator_ids: [], valuator_group_ids: []]
params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment))
end
def load_budget

View File

@@ -6,6 +6,7 @@ module Budgets
include FlagActions
include RandomSeed
include ImageAttributes
include Translatable
PER_PAGE = 10
@@ -122,12 +123,12 @@ module Budgets
end
def investment_params
params.require(:budget_investment)
.permit(:title, :description, :heading_id, :tag_list,
attributes = [:heading_id, :tag_list,
:organization_name, :location, :terms_of_service, :skip_map,
image_attributes: image_attributes,
documents_attributes: [:id, :title, :attachment, :cached_attachment, :user_id, :_destroy],
map_location_attributes: [:latitude, :longitude, :zoom])
map_location_attributes: [:latitude, :longitude, :zoom]]
params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment))
end
def load_ballot

View File

@@ -1,4 +1,5 @@
class Management::Budgets::InvestmentsController < Management::BaseController
include Translatable
before_action :load_budget
load_resource :budget
@@ -53,8 +54,8 @@ class Management::Budgets::InvestmentsController < Management::BaseController
end
def investment_params
params.require(:budget_investment).permit(:title, :description, :external_url, :heading_id,
:tag_list, :organization_name, :location, :skip_map)
attributes = [:external_url, :heading_id, :tag_list, :organization_name, :location, :skip_map]
params.require(:budget_investment).permit(attributes, translation_params(Budget::Investment))
end
def only_verified_users

View File

@@ -2,24 +2,30 @@
<span class="icon-angle-left"></span> <%= t("shared.back") %>
<% end %>
<%= form_for @investment,
<%= render "admin/shared/globalize_locales", resource: @investment %>
<%= translatable_form_for @investment,
url: admin_budget_budget_investment_path(@budget, @investment) do |f| %>
<%= render "shared/errors", resource: @investment %>
<% Budget::Investment.filter_params(params).to_h.each do |filter_name, filter_value| %>
<%= hidden_field_tag filter_name, filter_value %>
<% end %>
<div class="row expanded">
<%= f.translatable_fields do |translations_form| %>
<div class="small-12 column">
<%= f.text_field :title,
<%= translations_form.text_field :title,
maxlength: Budget::Investment.title_max_length %>
</div>
<div class="ckeditor small-12 column">
<%= f.cktext_area :description,
<%= translations_form.cktext_area :description,
maxlength: Budget::Investment.description_max_length,
ckeditor: { language: I18n.locale } %>
</div>
<% end %>
<div class="small-12 column">
<%= f.label :tag_list, t("admin.budget_investments.edit.user_tags") %>
@@ -51,7 +57,6 @@
</div>
</div>
<div class="small-12 column">
<%= f.label :valuation_tag_list, t("admin.budget_investments.edit.tags") %>
<div class="tags">

View File

@@ -1,4 +1,7 @@
<%= form_for(@investment, url: form_url, method: :post, html: { multipart: true }) do |f| %>
<%= render "admin/shared/globalize_locales", resource: @investment %>
<%= translatable_form_for(@investment, url: form_url, method: :post, html: { multipart: true }) do |f| %>
<%= render "shared/errors", resource: @investment %>
<div class="row">
@@ -6,22 +9,24 @@
<%= f.select :heading_id, budget_heading_select_options(@budget), {include_blank: true, } %>
</div>
<%= f.translatable_fields do |translations_form| %>
<div class="small-12 column">
<%= f.text_field :title,
<%= translations_form.text_field :title,
maxlength: Budget::Investment.title_max_length,
data: { js_suggest_result: "js_suggest_result",
js_suggest: "#js-suggest",
js_url: suggest_budget_investments_path(@budget) } %>
js_suggest: ".js-suggest",
js_url: suggest_budget_investments_path(@budget) }%>
</div>
<div id="js-suggest"></div>
<%= f.invisible_captcha :subtitle %>
<div class="js-suggest" data-locale="<%= translations_form.locale %>"></div>
<div class="ckeditor small-12 column">
<%= f.cktext_area :description,
<%= translations_form.cktext_area :description,
maxlength: Budget::Investment.description_max_length,
ckeditor: { language: I18n.locale } %>
</div>
<% end %>
<%= f.invisible_captcha :subtitle %>
<% if feature?(:allow_images) %>
<div class="images small-12 column">

View File

@@ -150,6 +150,9 @@ en:
organization_name: "If you are proposing in the name of a collective/organization, or on behalf of more people, write its name"
image: "Proposal descriptive image"
image_title: "Image title"
budget/investment/translation:
title: "Title"
description: "Description"
geozone:
name: Name
external_code: "External code (optional)"

View File

@@ -152,6 +152,9 @@ es:
organization_name: "Si estás proponiendo en nombre de una organización o colectivo, o en nombre de más gente, escribe su nombre"
image: "Imagen descriptiva del proyecto de gasto"
image_title: "Título de la imagen"
budget/investment/translation:
title: "Título"
description: "Descripción"
geozone:
name: Nombre
external_code: "Código externo (opcional)"

View File

@@ -11,6 +11,12 @@ describe "Admin budget investments" do
:budget_investment,
"admin_budget_budget_investment_path"
it_behaves_like "translatable",
:budget_investment,
"edit_admin_budget_budget_investment_path",
%w[title],
{ "description" => :ckeditor }
before do
@admin = create(:administrator)
login_as(@admin.user)

View File

@@ -402,6 +402,8 @@ def update_button_text
"Update milestone"
when "AdminNotification"
"Update notification"
when "Budget::Investment"
"Update"
when "Poll"
"Update poll"
when "Budget"