Translate budget and budget phase main link url

This commit is contained in:
Senén Rodero Rodríguez
2021-11-03 13:12:00 +01:00
parent 30afb64bac
commit 7ad838c57d
12 changed files with 34 additions and 23 deletions

View File

@@ -49,11 +49,11 @@
<p class="help-text"> <%= t("admin.budget_phases.edit.main_call_to_action_description") %></p>
<%= translations_form.text_field :main_link_text %>
</div>
<% end %>
<div class="small-12 column">
<%= f.text_field :main_link_url, placeholder: t("admin.shared.example_url") %>
<%= translations_form.text_field :main_link_url, placeholder: t("admin.shared.example_url") %>
</div>
<% end %>
<% if feature?(:allow_images) %>
<div class="images small-12 column">

View File

@@ -21,13 +21,12 @@
<%= translations_form.text_field :main_link_text %>
</div>
</div>
<% end %>
<div class="row expanded">
<div class="small-12 medium-9 large-6 column end">
<%= f.text_field :main_link_url, placeholder: t("admin.shared.example_url") %>
<%= translations_form.text_field :main_link_url, placeholder: t("admin.shared.example_url") %>
</div>
</div>
<% end %>
<div class="row expanded">
<div class="small-12 medium-4 column">

View File

@@ -59,7 +59,6 @@ class Admin::BudgetsController < Admin::BaseController
valid_attributes = [:phase,
:currency_symbol,
:voting_style,
:main_link_url,
administrator_ids: [],
valuator_ids: [],
image_attributes: image_attributes

View File

@@ -37,7 +37,7 @@ class Admin::BudgetsWizard::BudgetsController < Admin::BudgetsWizard::BaseContro
end
def allowed_params
valid_attributes = [:currency_symbol, :voting_style, :main_link_url, administrator_ids: [],
valid_attributes = [:currency_symbol, :voting_style, administrator_ids: [],
valuator_ids: [], image_attributes: image_attributes]
valid_attributes + [translation_params(Budget)]

View File

@@ -40,7 +40,7 @@ module Admin::BudgetPhasesActions
end
def budget_phase_params
valid_attributes = [:starts_at, :ends_at, :enabled, :main_link_url,
valid_attributes = [:starts_at, :ends_at, :enabled,
image_attributes: image_attributes]
params.require(:budget_phase).permit(*valid_attributes, translation_params(Budget::Phase))
end

View File

@@ -5,7 +5,7 @@ class Budget < ApplicationRecord
include Reportable
include Imageable
translates :name, :main_link_text, touch: true
translates :name, :main_link_text, :main_link_url, touch: true
include Globalizable
class Translation
@@ -24,11 +24,11 @@ class Budget < ApplicationRecord
VOTING_STYLES = %w[knapsack approval].freeze
validates_translation :name, presence: true
validates_translation :main_link_url, presence: true, unless: -> { main_link_text.blank? }
validates :phase, inclusion: { in: Budget::Phase::PHASE_KINDS }
validates :currency_symbol, presence: true
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
validates :voting_style, inclusion: { in: VOTING_STYLES }
validates :main_link_url, presence: true, if: -> { main_link_text.present? }
has_many :investments, dependent: :destroy
has_many :ballots, dependent: :destroy

View File

@@ -9,6 +9,7 @@ class Budget
translates :summary, touch: true
translates :description, touch: true
translates :main_link_text, touch: true
translates :main_link_url, touch: true
include Globalizable
include Sanitizable
include Imageable
@@ -19,9 +20,9 @@ class Budget
validates_translation :name, presence: true
validates_translation :description, length: { maximum: DESCRIPTION_MAX_LENGTH }
validates_translation :main_link_url, presence: true, unless: -> { main_link_text.blank? }
validates :budget, presence: true
validates :kind, presence: true, uniqueness: { scope: :budget }, inclusion: { in: ->(*) { PHASE_KINDS }}
validates :main_link_url, presence: true, if: -> { main_link_text.present? }
validate :invalid_dates_range?
validate :prev_phase_dates_valid?
validate :next_phase_dates_valid?

View File

@@ -160,9 +160,9 @@ en:
voting_style: "Final voting style"
voting_style_knapsack: "Knapsack"
voting_style_approval: "Approval"
main_link_url: "The link takes you to (add a link)"
budget/translation:
main_link_text: "Text on the link"
main_link_url: "The link takes you to (add a link)"
name: "Name"
budget/investment:
heading_id: "Heading"
@@ -231,12 +231,12 @@ en:
enabled: "Phase enabled"
ends_at: "End date"
starts_at: "Start date"
main_link_url: "The link takes you to (add a link)"
budget/phase/translation:
name: "Name"
description: "Description"
summary: "Summary"
main_link_text: "Text on the link"
main_link_url: "The link takes you to (add a link)"
comment:
body: "Comment"
user: "User"

View File

@@ -160,9 +160,9 @@ es:
voting_style: "Estilo de la votación final"
voting_style_knapsack: Bolsa de dinero
voting_style_approval: Por aprobación
main_link_url: "El enlace te lleva a (añade un enlace)"
budget/translation:
main_link_text: "Texto del enlace"
main_link_url: "El enlace te lleva a (añade un enlace)"
name: "Nombre"
budget/investment:
heading_id: "Partida presupuestaria"
@@ -231,12 +231,12 @@ es:
enabled: "Fase habilitada"
ends_at: "Fecha de fin"
starts_at: "Fecha de inicio"
main_link_url: "El enlace te lleva a (añade un enlace)"
budget/phase/translation:
name: "Nombre"
description: "Descripción"
summary: "Resumen"
main_link_text: "Texto del enlace"
main_link_url: "El enlace te lleva a (añade un enlace)"
comment:
body: "Comentario"
user: "Usuario"

View File

@@ -0,0 +1,6 @@
class TranslateBudgetMainLinkUrl < ActiveRecord::Migration[5.2]
def change
add_column :budget_translations, :main_link_url, :string
remove_column :budgets, :main_link_url, :string
end
end

View File

@@ -0,0 +1,6 @@
class TranslateBudgetPhaseMainLinkUrl < ActiveRecord::Migration[5.2]
def change
add_column :budget_phase_translations, :main_link_url, :string
remove_column :budget_phases, :main_link_url, :string
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_08_25_152739) do
ActiveRecord::Schema.define(version: 2021_11_03_112944) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_trgm"
@@ -316,6 +316,7 @@ ActiveRecord::Schema.define(version: 2021_08_25_152739) do
t.text "summary"
t.string "name"
t.string "main_link_text"
t.string "main_link_url"
t.index ["budget_phase_id"], name: "index_budget_phase_translations_on_budget_phase_id"
t.index ["locale"], name: "index_budget_phase_translations_on_locale"
end
@@ -327,7 +328,6 @@ ActiveRecord::Schema.define(version: 2021_08_25_152739) do
t.datetime "starts_at"
t.datetime "ends_at"
t.boolean "enabled", default: true
t.string "main_link_url"
t.index ["ends_at"], name: "index_budget_phases_on_ends_at"
t.index ["kind"], name: "index_budget_phases_on_kind"
t.index ["next_phase_id"], name: "index_budget_phases_on_next_phase_id"
@@ -349,6 +349,7 @@ ActiveRecord::Schema.define(version: 2021_08_25_152739) do
t.datetime "updated_at", null: false
t.string "name"
t.string "main_link_text"
t.string "main_link_url"
t.index ["budget_id"], name: "index_budget_translations_on_budget_id"
t.index ["locale"], name: "index_budget_translations_on_locale"
end
@@ -393,7 +394,6 @@ ActiveRecord::Schema.define(version: 2021_08_25_152739) do
t.text "description_informing"
t.string "voting_style", default: "knapsack"
t.boolean "published"
t.string "main_link_url"
end
create_table "campaigns", id: :serial, force: :cascade do |t|