Create new basic tab for admin information texts
This commit is contained in:
@@ -2,7 +2,7 @@ class Admin::SiteCustomization::InformationTextsController < Admin::SiteCustomiz
|
|||||||
before_action :delete_translations, only: [:update]
|
before_action :delete_translations, only: [:update]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@tab = params[:tab] || :debates
|
@tab = params[:tab] || :basic
|
||||||
@content = I18nContent.content_for(@tab)
|
@content = I18nContent.content_for(@tab)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -17,4 +17,8 @@ module SiteCustomizationHelper
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def information_texts_tabs
|
||||||
|
[:basic, :debates, :community, :proposals, :polls, :layouts, :mailers, :management, :welcome]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -46,16 +46,54 @@ class I18nContent < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.content_for(tab)
|
def self.content_for(tab)
|
||||||
flat_hash(translations_for(tab)).keys.map do |string|
|
translations_for(tab).map do |string|
|
||||||
I18nContent.find_or_initialize_by(key: string)
|
I18nContent.find_or_initialize_by(key: string)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.translations_for(tab)
|
def self.translations_for(tab)
|
||||||
|
if tab.to_s == "basic"
|
||||||
|
basic_translations
|
||||||
|
else
|
||||||
|
flat_hash(translations_hash_for(tab)).keys
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.translations_hash_for(tab)
|
||||||
I18n.backend.send(:init_translations) unless I18n.backend.initialized?
|
I18n.backend.send(:init_translations) unless I18n.backend.initialized?
|
||||||
|
|
||||||
I18n.backend.send(:translations)[I18n.locale].select do |key, _translations|
|
I18n.backend.send(:translations)[I18n.locale].select do |key, _translations|
|
||||||
key.to_s == tab.to_s
|
key.to_s == tab.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.basic_translations
|
||||||
|
%w[
|
||||||
|
debates.index.section_footer.title
|
||||||
|
debates.index.section_footer.description
|
||||||
|
debates.index.section_footer.help_text_1
|
||||||
|
debates.index.section_footer.help_text_2
|
||||||
|
debates.new.info
|
||||||
|
debates.new.info_link
|
||||||
|
debates.new.more_info
|
||||||
|
debates.new.recommendation_one
|
||||||
|
debates.new.recommendation_two
|
||||||
|
debates.new.recommendation_three
|
||||||
|
debates.new.recommendation_four
|
||||||
|
debates.new.recommendations_title
|
||||||
|
proposals.index.section_footer.title
|
||||||
|
proposals.index.section_footer.description
|
||||||
|
proposals.new.more_info
|
||||||
|
proposals.new.recommendation_one
|
||||||
|
proposals.new.recommendation_two
|
||||||
|
proposals.new.recommendation_three
|
||||||
|
proposals.new.recommendations_title
|
||||||
|
polls.index.section_footer.title
|
||||||
|
polls.index.section_footer.description
|
||||||
|
legislation.processes.index.section_footer.title
|
||||||
|
legislation.processes.index.section_footer.description
|
||||||
|
budgets.index.section_footer.title
|
||||||
|
budgets.index.section_footer.description
|
||||||
|
]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<ul id="information-texts-tabs" class="tabs" >
|
<ul id="information-texts-tabs" class="tabs" >
|
||||||
<% [:debates, :community, :proposals, :polls, :layouts, :mailers, :management, :welcome].each do |tab| %>
|
<% information_texts_tabs.each do |tab| %>
|
||||||
<li class="tabs-title">
|
<li class="tabs-title">
|
||||||
<% if tab.to_s == @tab %>
|
<% if tab.to_s == @tab %>
|
||||||
<%= link_to t("admin.menu.site_customization.information_texts_menu.#{tab}"), admin_site_customization_information_texts_path(tab: tab), :class => "is-active" %>
|
<%= link_to t("admin.menu.site_customization.information_texts_menu.#{tab}"), admin_site_customization_information_texts_path(tab: tab), :class => "is-active" %>
|
||||||
|
|||||||
@@ -703,6 +703,7 @@ en:
|
|||||||
content_blocks: Custom content blocks
|
content_blocks: Custom content blocks
|
||||||
information_texts: Custom information texts
|
information_texts: Custom information texts
|
||||||
information_texts_menu:
|
information_texts_menu:
|
||||||
|
basic: "Basic customization"
|
||||||
debates: "Debates"
|
debates: "Debates"
|
||||||
community: "Community"
|
community: "Community"
|
||||||
proposals: "Proposals"
|
proposals: "Proposals"
|
||||||
|
|||||||
@@ -702,6 +702,7 @@ es:
|
|||||||
content_blocks: Personalizar bloques
|
content_blocks: Personalizar bloques
|
||||||
information_texts: Personalizar textos
|
information_texts: Personalizar textos
|
||||||
information_texts_menu:
|
information_texts_menu:
|
||||||
|
basic: "Personalización básica"
|
||||||
debates: "Debates"
|
debates: "Debates"
|
||||||
community: "Comunidad"
|
community: "Comunidad"
|
||||||
proposals: "Propuestas"
|
proposals: "Propuestas"
|
||||||
|
|||||||
@@ -15,6 +15,13 @@ feature "Admin custom information texts" do
|
|||||||
scenario "page is correctly loaded" do
|
scenario "page is correctly loaded" do
|
||||||
visit admin_site_customization_information_texts_path
|
visit admin_site_customization_information_texts_path
|
||||||
|
|
||||||
|
click_link "Basic customization"
|
||||||
|
expect(page).to have_content "Help about debates"
|
||||||
|
expect(page).to have_content "Help about proposals"
|
||||||
|
expect(page).to have_content "Help about voting"
|
||||||
|
expect(page).to have_content "Help about collaborative legislation"
|
||||||
|
expect(page).to have_content "Help with participatory budgets"
|
||||||
|
|
||||||
click_link "Debates"
|
click_link "Debates"
|
||||||
expect(page).to have_content "Help about debates"
|
expect(page).to have_content "Help about debates"
|
||||||
|
|
||||||
@@ -57,39 +64,40 @@ feature "Admin custom information texts" do
|
|||||||
context "Globalization" do
|
context "Globalization" do
|
||||||
|
|
||||||
scenario "Add a translation", :js do
|
scenario "Add a translation", :js do
|
||||||
key = "debates.form.debate_title"
|
key = "debates.index.section_footer.title"
|
||||||
|
|
||||||
visit admin_site_customization_information_texts_path
|
visit admin_site_customization_information_texts_path
|
||||||
|
|
||||||
select "Français", from: "translation_locale"
|
select "Français", from: "translation_locale"
|
||||||
fill_in "contents_content_#{key}values_value_fr", with: "Titre personalise du débat"
|
fill_in "contents[content_#{key}]values[value_fr]", with: "Aide personalise sur les débats"
|
||||||
|
|
||||||
click_button "Save"
|
click_button "Save"
|
||||||
|
|
||||||
expect(page).to have_content "Translation updated successfully"
|
expect(page).to have_content "Translation updated successfully"
|
||||||
|
|
||||||
select "Français", from: "translation_locale"
|
visit admin_site_customization_information_texts_path
|
||||||
|
|
||||||
expect(page).to have_content "Titre personalise du débat"
|
select "Français", from: "translation_locale"
|
||||||
expect(page).not_to have_content "Titre du débat"
|
expect(page).to have_content "Aide personalise sur les débats"
|
||||||
|
expect(page).not_to have_content "Aide sur les débats"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Update a translation", :js do
|
scenario "Update a translation", :js do
|
||||||
key = "debates.form.debate_title"
|
key = "proposals.form.proposal_title"
|
||||||
content = create(:i18n_content, key: key, value_fr: "Titre personalise du débat")
|
|
||||||
|
|
||||||
visit admin_site_customization_information_texts_path
|
visit admin_site_customization_information_texts_path(tab: "proposals")
|
||||||
|
|
||||||
select "Français", from: "translation_locale"
|
select "Français", from: "translation_locale"
|
||||||
fill_in "contents_content_#{key}values_value_fr", with: "Titre personalise again du débat"
|
fill_in "contents_content_#{key}values_value_fr", with: "Titre personalise de la proposition"
|
||||||
|
|
||||||
click_button "Save"
|
click_button "Save"
|
||||||
expect(page).to have_content "Translation updated successfully"
|
expect(page).to have_content "Translation updated successfully"
|
||||||
|
|
||||||
|
visit admin_site_customization_information_texts_path(tab: "proposals")
|
||||||
click_link "Français"
|
click_link "Français"
|
||||||
|
|
||||||
expect(page).to have_content "Titre personalise again du débat"
|
expect(page).to have_content "Titre personalise de la proposition"
|
||||||
expect(page).not_to have_content "Titre personalise du débat"
|
expect(page).not_to have_content "Titre de la proposition"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Remove a translation", :js do
|
scenario "Remove a translation", :js do
|
||||||
@@ -103,7 +111,7 @@ feature "Admin custom information texts" do
|
|||||||
value_en: "Custom debate text",
|
value_en: "Custom debate text",
|
||||||
value_es: "Texto personalizado de debate")
|
value_es: "Texto personalizado de debate")
|
||||||
|
|
||||||
visit admin_site_customization_information_texts_path
|
visit admin_site_customization_information_texts_path(tab: "debates")
|
||||||
|
|
||||||
click_link "Español"
|
click_link "Español"
|
||||||
click_link "Remove language"
|
click_link "Remove language"
|
||||||
@@ -111,6 +119,7 @@ feature "Admin custom information texts" do
|
|||||||
|
|
||||||
expect(page).not_to have_link "Español"
|
expect(page).not_to have_link "Español"
|
||||||
|
|
||||||
|
visit admin_site_customization_information_texts_path(tab: "debates")
|
||||||
click_link "English"
|
click_link "English"
|
||||||
expect(page).to have_content "Custom debate text"
|
expect(page).to have_content "Custom debate text"
|
||||||
expect(page).to have_content "Custom debate title"
|
expect(page).to have_content "Custom debate title"
|
||||||
|
|||||||
34
spec/features/site_customization/information_texts_spec.rb
Normal file
34
spec/features/site_customization/information_texts_spec.rb
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
require "rails_helper"
|
||||||
|
|
||||||
|
feature "Custom information texts" do
|
||||||
|
|
||||||
|
scenario "Show custom texts instead of default ones" do
|
||||||
|
admin = create(:administrator)
|
||||||
|
login_as(admin.user)
|
||||||
|
|
||||||
|
debate_key = "debates.index.section_footer.title"
|
||||||
|
proposal_key = "proposals.index.section_footer.title"
|
||||||
|
|
||||||
|
visit admin_site_customization_information_texts_path(tab: "debates")
|
||||||
|
fill_in "contents[content_#{debate_key}]values[value_en]", with: "Custom help about debates"
|
||||||
|
click_button "Save"
|
||||||
|
|
||||||
|
visit admin_site_customization_information_texts_path(tab: "proposals")
|
||||||
|
fill_in "contents[content_#{proposal_key}]values[value_en]", with: "Custom help about proposals"
|
||||||
|
click_button "Save"
|
||||||
|
|
||||||
|
visit debates_path
|
||||||
|
|
||||||
|
within("#section_help") do
|
||||||
|
expect(page).to have_content "Custom help about debates"
|
||||||
|
expect(page).not_to have_content "Help about debates"
|
||||||
|
end
|
||||||
|
|
||||||
|
visit proposals_path
|
||||||
|
|
||||||
|
within("#section_help") do
|
||||||
|
expect(page).to have_content "Custom help about proposals"
|
||||||
|
expect(page).not_to have_content "Help about proposals"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user