Make Admin Notifications translatable
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
class Admin::AdminNotificationsController < Admin::BaseController
|
class Admin::AdminNotificationsController < Admin::BaseController
|
||||||
|
include Translatable
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@admin_notifications = AdminNotification.all
|
@admin_notifications = AdminNotification.all
|
||||||
@@ -62,6 +63,13 @@ class Admin::AdminNotificationsController < Admin::BaseController
|
|||||||
private
|
private
|
||||||
|
|
||||||
def admin_notification_params
|
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
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
class AdminNotification < ActiveRecord::Base
|
class AdminNotification < ActiveRecord::Base
|
||||||
include Notifiable
|
include Notifiable
|
||||||
|
|
||||||
|
translates :title, touch: :true
|
||||||
|
translates :body, touch: :true
|
||||||
|
globalize_accessors
|
||||||
|
|
||||||
validates :title, presence: true
|
validates :title, presence: true
|
||||||
validates :body, presence: true
|
validates :body, presence: true
|
||||||
validates :segment_recipient, presence: true
|
validates :segment_recipient, presence: true
|
||||||
|
|||||||
@@ -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 %>
|
<%= render 'shared/errors', resource: @admin_notification %>
|
||||||
|
|
||||||
<%= f.select :segment_recipient, options_for_select(user_segments_options,
|
<%= f.select :segment_recipient, options_for_select(user_segments_options,
|
||||||
@admin_notification[:segment_recipient]) %>
|
@admin_notification[:segment_recipient]) %>
|
||||||
<%= f.text_field :title %>
|
|
||||||
|
<%= f.translatable_text_field :title %>
|
||||||
|
|
||||||
<%= f.text_field :link %>
|
<%= f.text_field :link %>
|
||||||
<%= f.text_area :body %>
|
|
||||||
|
<%= f.translatable_text_area :body %>
|
||||||
|
|
||||||
<div class="margin-top">
|
<div class="margin-top">
|
||||||
<%= f.submit t("admin.admin_notifications.#{admin_submit_action(@admin_notification)}.submit_button"),
|
<%= f.submit t("admin.admin_notifications.#{admin_submit_action(@admin_notification)}.submit_button"),
|
||||||
|
|||||||
@@ -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
|
||||||
|
|
||||||
12
db/schema.rb
12
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", ["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
|
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|
|
create_table "admin_notifications", force: :cascade do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.text "body"
|
t.text "body"
|
||||||
|
|||||||
@@ -8,6 +8,11 @@ feature "Admin Notifications" do
|
|||||||
create(:budget)
|
create(:budget)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it_behaves_like "translatable",
|
||||||
|
"admin_notification",
|
||||||
|
"edit_admin_admin_notification_path",
|
||||||
|
%w[title body]
|
||||||
|
|
||||||
context "Show" do
|
context "Show" do
|
||||||
scenario "Valid Admin Notification" do
|
scenario "Valid Admin Notification" do
|
||||||
notification = create(:admin_notification, title: 'Notification title',
|
notification = create(:admin_notification, title: 'Notification title',
|
||||||
@@ -180,7 +185,7 @@ feature "Admin Notifications" do
|
|||||||
notification = create(:admin_notification)
|
notification = create(:admin_notification)
|
||||||
visit edit_admin_admin_notification_path(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"
|
click_button "Update notification"
|
||||||
|
|
||||||
expect(page).to have_content error_message
|
expect(page).to have_content error_message
|
||||||
|
|||||||
@@ -186,6 +186,8 @@ def update_button_text
|
|||||||
case translatable_class.name
|
case translatable_class.name
|
||||||
when "Budget::Investment::Milestone"
|
when "Budget::Investment::Milestone"
|
||||||
"Update milestone"
|
"Update milestone"
|
||||||
|
when "AdminNotification"
|
||||||
|
"Update notification"
|
||||||
else
|
else
|
||||||
"Save changes"
|
"Save changes"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ module Notifications
|
|||||||
|
|
||||||
def fill_in_admin_notification_form(options = {})
|
def fill_in_admin_notification_form(options = {})
|
||||||
select (options[:segment_recipient] || 'All users'), from: :admin_notification_segment_recipient
|
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_title_en, 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_body_en, with: (options[:body] || 'This is the notification body')
|
||||||
fill_in :admin_notification_link, with: (options[:link] || 'https://www.decide.madrid.es/vota')
|
fill_in :admin_notification_link, with: (options[:link] || 'https://www.decide.madrid.es/vota')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user