From 5ff85d33d60795c8e122eddf04af8f5bfbb391b3 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 1 Aug 2018 14:36:17 +0200 Subject: [PATCH 1/4] Fix submit button text for Admin Notifications admin form In Madrid, the button text didn't change depending on whether the form is for the "new" page or for the "edit" page. In consul, the buttons texts were "create admin notification" and "update admin notification" instead of "create notification" and "update notification". Also change translation key from "submit" to "submit_button" to match other instances. --- app/views/admin/admin_notifications/_form.html.erb | 3 ++- config/i18n-tasks.yml | 1 + config/locales/en/admin.yml | 2 ++ config/locales/es/admin.yml | 2 ++ spec/features/admin/admin_notifications_spec.rb | 10 +++++----- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/views/admin/admin_notifications/_form.html.erb b/app/views/admin/admin_notifications/_form.html.erb index 4053bb66d..a08342f2b 100644 --- a/app/views/admin/admin_notifications/_form.html.erb +++ b/app/views/admin/admin_notifications/_form.html.erb @@ -8,6 +8,7 @@ <%= f.text_area :body %>
- <%= f.submit class: "button success" %> + <%= f.submit t("admin.admin_notifications.#{admin_submit_action(@admin_notification)}.submit_button"), + class: "button success" %>
<% end %> diff --git a/config/i18n-tasks.yml b/config/i18n-tasks.yml index a0fb7110e..b673c2110 100644 --- a/config/i18n-tasks.yml +++ b/config/i18n-tasks.yml @@ -145,6 +145,7 @@ ignore_unused: - 'admin.settings.index.features.*' - 'admin.polls.*.submit_button' - 'admin.booths.*.submit_button' + - 'admin.admin_notifications.*.submit_button' - 'admin.homepage.*' - 'moderation.comments.index.filter*' - 'moderation.comments.index.order*' diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml index 0806b68b9..682a87dee 100644 --- a/config/locales/en/admin.yml +++ b/config/locales/en/admin.yml @@ -658,8 +658,10 @@ en: empty_notifications: There are no notifications to show new: section_title: New notification + submit_button: Create notification edit: section_title: Edit notification + submit_button: Update notification show: section_title: Notification preview send: Send notification diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml index 3ef8039ae..eabfbc536 100644 --- a/config/locales/es/admin.yml +++ b/config/locales/es/admin.yml @@ -659,8 +659,10 @@ es: empty_notifications: No hay notificaciones para mostrar new: section_title: Nueva notificación + submit_button: Crear notificación edit: section_title: Editar notificación + submit_button: Actualizar notificación show: section_title: Vista previa de notificación send: Enviar notificación diff --git a/spec/features/admin/admin_notifications_spec.rb b/spec/features/admin/admin_notifications_spec.rb index 9bea144d4..4035c17d0 100644 --- a/spec/features/admin/admin_notifications_spec.rb +++ b/spec/features/admin/admin_notifications_spec.rb @@ -75,7 +75,7 @@ feature "Admin Notifications" do body: 'This is a body', link: 'http://www.dummylink.dev') - click_button "Create Admin notification" + click_button "Create notification" expect(page).to have_content "Notification created successfully" expect(page).to have_content "Proposal authors" @@ -99,7 +99,7 @@ feature "Admin Notifications" do body: 'Other body', link: '') - click_button "Update Admin notification" + click_button "Update notification" expect(page).to have_content "Notification updated successfully" expect(page).to have_content "All users" @@ -171,7 +171,7 @@ feature "Admin Notifications" do scenario 'Errors on create' do visit new_admin_admin_notification_path - click_button "Create Admin notification" + click_button "Create notification" expect(page).to have_content error_message end @@ -181,7 +181,7 @@ feature "Admin Notifications" do visit edit_admin_admin_notification_path(notification) fill_in :admin_notification_title, with: '' - click_button "Update Admin notification" + click_button "Update notification" expect(page).to have_content error_message end @@ -228,7 +228,7 @@ feature "Admin Notifications" do visit new_admin_admin_notification_path fill_in_admin_notification_form(segment_recipient: segment_recipient) - click_button "Create Admin notification" + click_button "Create notification" expect(page).to have_content(I18n.t("admin.segment_recipient.#{user_segment}")) end From f6749049c944f77148285047c5fdf3f1667b6249 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 1 Aug 2018 14:38:07 +0200 Subject: [PATCH 2/4] Make Admin Notifications translatable --- .../admin/admin_notifications_controller.rb | 10 +++++++++- app/models/admin_notification.rb | 4 ++++ app/views/admin/admin_notifications/_form.html.erb | 11 ++++++++--- ...31150800_add_admin_notification_translations.rb | 14 ++++++++++++++ db/schema.rb | 12 ++++++++++++ spec/features/admin/admin_notifications_spec.rb | 7 ++++++- spec/shared/features/translatable.rb | 2 ++ spec/support/common_actions/notifications.rb | 4 ++-- 8 files changed, 57 insertions(+), 7 deletions(-) create mode 100644 db/migrate/20180731150800_add_admin_notification_translations.rb diff --git a/app/controllers/admin/admin_notifications_controller.rb b/app/controllers/admin/admin_notifications_controller.rb index 1dd03038a..33e99f9ed 100644 --- a/app/controllers/admin/admin_notifications_controller.rb +++ b/app/controllers/admin/admin_notifications_controller.rb @@ -1,4 +1,5 @@ class Admin::AdminNotificationsController < Admin::BaseController + include Translatable def index @admin_notifications = AdminNotification.all @@ -62,6 +63,13 @@ class Admin::AdminNotificationsController < Admin::BaseController private def admin_notification_params - params.require(:admin_notification).permit(:title, :body, :link, :segment_recipient) + attributes = [:title, :body, :link, :segment_recipient, + *translation_params(AdminNotification)] + + params.require(:admin_notification).permit(attributes) + end + + def resource + AdminNotification.find(params[:id]) end end diff --git a/app/models/admin_notification.rb b/app/models/admin_notification.rb index eccd90910..ef632b1f1 100644 --- a/app/models/admin_notification.rb +++ b/app/models/admin_notification.rb @@ -1,6 +1,10 @@ class AdminNotification < ActiveRecord::Base include Notifiable + translates :title, touch: :true + translates :body, touch: :true + globalize_accessors + validates :title, presence: true validates :body, presence: true validates :segment_recipient, presence: true diff --git a/app/views/admin/admin_notifications/_form.html.erb b/app/views/admin/admin_notifications/_form.html.erb index a08342f2b..ba9a77a79 100644 --- a/app/views/admin/admin_notifications/_form.html.erb +++ b/app/views/admin/admin_notifications/_form.html.erb @@ -1,11 +1,16 @@ -<%= form_for [:admin, @admin_notification] do |f| %> +<%= render "admin/shared/globalize_locales", resource: @admin_notification %> + +<%= translatable_form_for [:admin, @admin_notification] do |f| %> <%= render 'shared/errors', resource: @admin_notification %> <%= f.select :segment_recipient, options_for_select(user_segments_options, @admin_notification[:segment_recipient]) %> - <%= f.text_field :title %> + + <%= f.translatable_text_field :title %> + <%= f.text_field :link %> - <%= f.text_area :body %> + + <%= f.translatable_text_area :body %>
<%= f.submit t("admin.admin_notifications.#{admin_submit_action(@admin_notification)}.submit_button"), diff --git a/db/migrate/20180731150800_add_admin_notification_translations.rb b/db/migrate/20180731150800_add_admin_notification_translations.rb new file mode 100644 index 000000000..519751fd7 --- /dev/null +++ b/db/migrate/20180731150800_add_admin_notification_translations.rb @@ -0,0 +1,14 @@ +class AddAdminNotificationTranslations < ActiveRecord::Migration + + def self.up + AdminNotification.create_translation_table!( + title: :string, + body: :text + ) + end + + def self.down + AdminNotification.drop_translation_table! + end +end + diff --git a/db/schema.rb b/db/schema.rb index 867737358..b6370693a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -30,6 +30,18 @@ ActiveRecord::Schema.define(version: 20180813141443) do add_index "activities", ["actionable_id", "actionable_type"], name: "index_activities_on_actionable_id_and_actionable_type", using: :btree add_index "activities", ["user_id"], name: "index_activities_on_user_id", using: :btree + create_table "admin_notification_translations", force: :cascade do |t| + t.integer "admin_notification_id", null: false + t.string "locale", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.string "title" + t.text "body" + end + + add_index "admin_notification_translations", ["admin_notification_id"], name: "index_admin_notification_translations_on_admin_notification_id", using: :btree + add_index "admin_notification_translations", ["locale"], name: "index_admin_notification_translations_on_locale", using: :btree + create_table "admin_notifications", force: :cascade do |t| t.string "title" t.text "body" diff --git a/spec/features/admin/admin_notifications_spec.rb b/spec/features/admin/admin_notifications_spec.rb index 4035c17d0..f3706cbdc 100644 --- a/spec/features/admin/admin_notifications_spec.rb +++ b/spec/features/admin/admin_notifications_spec.rb @@ -8,6 +8,11 @@ feature "Admin Notifications" do create(:budget) end + it_behaves_like "translatable", + "admin_notification", + "edit_admin_admin_notification_path", + %w[title body] + context "Show" do scenario "Valid Admin Notification" do notification = create(:admin_notification, title: 'Notification title', @@ -180,7 +185,7 @@ feature "Admin Notifications" do notification = create(:admin_notification) visit edit_admin_admin_notification_path(notification) - fill_in :admin_notification_title, with: '' + fill_in :admin_notification_title_en, with: '' click_button "Update notification" expect(page).to have_content error_message diff --git a/spec/shared/features/translatable.rb b/spec/shared/features/translatable.rb index 215148fdc..9757b134c 100644 --- a/spec/shared/features/translatable.rb +++ b/spec/shared/features/translatable.rb @@ -186,6 +186,8 @@ def update_button_text case translatable_class.name when "Budget::Investment::Milestone" "Update milestone" + when "AdminNotification" + "Update notification" else "Save changes" end diff --git a/spec/support/common_actions/notifications.rb b/spec/support/common_actions/notifications.rb index 264d0ef83..8b7615b0a 100644 --- a/spec/support/common_actions/notifications.rb +++ b/spec/support/common_actions/notifications.rb @@ -43,8 +43,8 @@ module Notifications def fill_in_admin_notification_form(options = {}) select (options[:segment_recipient] || 'All users'), from: :admin_notification_segment_recipient - fill_in :admin_notification_title, with: (options[:title] || 'This is the notification title') - fill_in :admin_notification_body, with: (options[:body] || 'This is the notification body') + fill_in :admin_notification_title_en, with: (options[:title] || 'This is the notification title') + fill_in :admin_notification_body_en, with: (options[:body] || 'This is the notification body') fill_in :admin_notification_link, with: (options[:link] || 'https://www.decide.madrid.es/vota') end end From 3be3b7342c89894502da8063fa6b0710a57bc21b Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 29 Aug 2018 18:10:13 +0200 Subject: [PATCH 3/4] Reinstate deleted translations for seed Admin Notifications These were removed in 5c726e0, seemingly by mistake. The change doesn't make sense in the context of the commit, and it breaks the seed data. --- config/locales/en/seeds.yml | 15 +++++++++++++++ config/locales/es/seeds.yml | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/config/locales/en/seeds.yml b/config/locales/en/seeds.yml index 4e40cfd63..a3587c9e3 100644 --- a/config/locales/en/seeds.yml +++ b/config/locales/en/seeds.yml @@ -53,3 +53,18 @@ en: recounting_poll: "Recounting Poll" expired_poll_without_stats: "Expired Poll without Stats & Results" expired_poll_with_stats: "Expired Poll with Stats & Results" + admin_notifications: + internal_link: + title: 'Do you have a proposal?' + body: 'Remember you can create a proposal with your ideas and people will discuss & support it.' + link: '/proposals' + external_link: + title: Help us translate consul + body: 'If you are proficient in a language, please help us translate consul!.' + link: 'https://crwd.in/consul' + without_link: + title: 'You can now geolocate proposals & investments' + body: 'When you create a proposal or investment you now can specify a point on a map' + not_sent: + title: 'We are closing the Participatory Budget!!' + body: 'Hurry up and create a last proposal before it ends next in few days!' diff --git a/config/locales/es/seeds.yml b/config/locales/es/seeds.yml index 1d6563bef..d8a40471b 100644 --- a/config/locales/es/seeds.yml +++ b/config/locales/es/seeds.yml @@ -53,3 +53,18 @@ es: recounting_poll: "Votación en Recuento" expired_poll_without_stats: "Votación Finalizada (sin Estadísticas o Resultados)" expired_poll_with_stats: "Votación Finalizada (con Estadísticas y Resultado)" + admin_notifications: + internal_link: + title: 'Tienes una propuesta?' + body: 'Recuerda que puedes crear propuestas y los ciudadanos las debatirán y apoyarán.' + link: '/proposals' + external_link: + title: 'Ayúdanos a traducir CONSUL' + body: 'Si dominas un idioma, ayúdanos a completar su traducción en CONSUL.' + link: 'https://crwd.in/consul' + without_link: + title: 'Ahora puedes geolocalizar propuestas y proyectos de inversión' + body: 'Cuando crees una propuesta o proyecto de inversión podrás especificar su localización en el mapa' + not_sent: + title: 'Últimos días para crear proyectos de Presupuestos Participativos' + body: 'Quedan pocos dias para que se cierre el plazo de presentación de proyectos de inversión para los presupuestos participativos!' From 0731b137cf2ed27bbe89cf363bbd5abccda01a89 Mon Sep 17 00:00:00 2001 From: Marko Lovic Date: Wed, 29 Aug 2018 18:22:01 +0200 Subject: [PATCH 4/4] Add both English and Spanish translations to Admin Notification seeds --- config/locales/en/seeds.yml | 15 ------------ config/locales/es/seeds.yml | 15 ------------ db/dev_seeds/admin_notifications.rb | 36 +++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 40 deletions(-) diff --git a/config/locales/en/seeds.yml b/config/locales/en/seeds.yml index a3587c9e3..4e40cfd63 100644 --- a/config/locales/en/seeds.yml +++ b/config/locales/en/seeds.yml @@ -53,18 +53,3 @@ en: recounting_poll: "Recounting Poll" expired_poll_without_stats: "Expired Poll without Stats & Results" expired_poll_with_stats: "Expired Poll with Stats & Results" - admin_notifications: - internal_link: - title: 'Do you have a proposal?' - body: 'Remember you can create a proposal with your ideas and people will discuss & support it.' - link: '/proposals' - external_link: - title: Help us translate consul - body: 'If you are proficient in a language, please help us translate consul!.' - link: 'https://crwd.in/consul' - without_link: - title: 'You can now geolocate proposals & investments' - body: 'When you create a proposal or investment you now can specify a point on a map' - not_sent: - title: 'We are closing the Participatory Budget!!' - body: 'Hurry up and create a last proposal before it ends next in few days!' diff --git a/config/locales/es/seeds.yml b/config/locales/es/seeds.yml index d8a40471b..1d6563bef 100644 --- a/config/locales/es/seeds.yml +++ b/config/locales/es/seeds.yml @@ -53,18 +53,3 @@ es: recounting_poll: "Votación en Recuento" expired_poll_without_stats: "Votación Finalizada (sin Estadísticas o Resultados)" expired_poll_with_stats: "Votación Finalizada (con Estadísticas y Resultado)" - admin_notifications: - internal_link: - title: 'Tienes una propuesta?' - body: 'Recuerda que puedes crear propuestas y los ciudadanos las debatirán y apoyarán.' - link: '/proposals' - external_link: - title: 'Ayúdanos a traducir CONSUL' - body: 'Si dominas un idioma, ayúdanos a completar su traducción en CONSUL.' - link: 'https://crwd.in/consul' - without_link: - title: 'Ahora puedes geolocalizar propuestas y proyectos de inversión' - body: 'Cuando crees una propuesta o proyecto de inversión podrás especificar su localización en el mapa' - not_sent: - title: 'Últimos días para crear proyectos de Presupuestos Participativos' - body: 'Quedan pocos dias para que se cierre el plazo de presentación de proyectos de inversión para los presupuestos participativos!' diff --git a/db/dev_seeds/admin_notifications.rb b/db/dev_seeds/admin_notifications.rb index a07077790..799fdf04c 100644 --- a/db/dev_seeds/admin_notifications.rb +++ b/db/dev_seeds/admin_notifications.rb @@ -1,27 +1,43 @@ section "Creating Admin Notifications & Templates" do AdminNotification.create!( - title: I18n.t('seeds.admin_notification.internal_link.title'), - body: I18n.t('seeds.admin_notification.internal_link.body'), - link: Setting['url'] + I18n.t('seeds.admin_notification.internal_link.link'), + title_en: 'Do you have a proposal?', + title_es: 'Tienes una propuesta?', + + body_en: 'Remember you can create a proposal with your ideas and people will discuss & support it.', + body_es: 'Recuerda que puedes crear propuestas y los ciudadanos las debatirán y apoyarán.', + + link: Setting['url'] + '/proposals', segment_recipient: 'administrators' ).deliver AdminNotification.create!( - title: I18n.t('seeds.admin_notification.external_link.title'), - body: I18n.t('seeds.admin_notification.external_link.body'), - link: I18n.t('seeds.admin_notification.external_link.link'), + title_en: 'Help us translate consul', + title_es: 'Ayúdanos a traducir CONSUL', + + body_en: 'If you are proficient in a language, please help us translate consul!.', + body_es: 'Si dominas un idioma, ayúdanos a completar su traducción en CONSUL.', + + link: 'https://crwd.in/consul', segment_recipient: 'administrators' ).deliver AdminNotification.create!( - title: I18n.t('seeds.admin_notification.without_link.title'), - body: I18n.t('seeds.admin_notification.without_link.body'), + title_en: 'You can now geolocate proposals & investments', + title_es: 'Ahora puedes geolocalizar propuestas y proyectos de inversión', + + body_en: 'When you create a proposal or investment you now can specify a point on a map', + body_es: 'Cuando crees una propuesta o proyecto de inversión podrás especificar su localización en el mapa', + segment_recipient: 'administrators' ).deliver AdminNotification.create!( - title: I18n.t('seeds.admin_notification.not_sent.title'), - body: I18n.t('seeds.admin_notification.not_sent.body'), + title_en: 'We are closing the Participatory Budget!!', + title_es: 'Últimos días para crear proyectos de Presupuestos Participativos', + + body_en: 'Hurry up and create a last proposal before it ends next in few days!', + body_es: 'Quedan pocos dias para que se cierre el plazo de presentación de proyectos de inversión para los presupuestos participativos!', + segment_recipient: 'administrators', sent_at: nil )