Merge pull request #3773 from betagouv/add_actiontext_to_mail_templates
Prepare UI migration : Add ActionText to mail templates
This commit is contained in:
commit
028dd4d894
11 changed files with 152 additions and 1 deletions
1
Gemfile
1
Gemfile
|
@ -1,6 +1,7 @@
|
|||
source 'https://rubygems.org'
|
||||
|
||||
gem 'aasm'
|
||||
gem 'actiontext', github: 'kobaltz/actiontext', branch: 'archive', require: 'action_text'
|
||||
gem 'active_link_to' # Automatically set a class on active links
|
||||
gem 'active_model_serializers'
|
||||
gem 'activestorage-openstack', git: 'https://github.com/fredZen/activestorage-openstack.git', branch: 'frederic/fix_upload_signature'
|
||||
|
|
10
Gemfile.lock
10
Gemfile.lock
|
@ -1,3 +1,12 @@
|
|||
GIT
|
||||
remote: git://github.com/kobaltz/actiontext.git
|
||||
revision: ef59c4ba99d1b7614dd47f5a294eef553224db88
|
||||
branch: archive
|
||||
specs:
|
||||
actiontext (0.1.0)
|
||||
nokogiri
|
||||
rails (>= 5.2.0)
|
||||
|
||||
GIT
|
||||
remote: https://github.com/fredZen/activestorage-openstack.git
|
||||
revision: c71d5107a51701eab9d9267dd0000e6c1cf3e39a
|
||||
|
@ -669,6 +678,7 @@ PLATFORMS
|
|||
|
||||
DEPENDENCIES
|
||||
aasm
|
||||
actiontext!
|
||||
active_link_to
|
||||
active_model_serializers
|
||||
activestorage-openstack!
|
||||
|
|
36
app/assets/stylesheets/new_design/actiontext.scss
Normal file
36
app/assets/stylesheets/new_design/actiontext.scss
Normal file
|
@ -0,0 +1,36 @@
|
|||
//
|
||||
// Provides a drop-in pointer for the default Trix stylesheet that will format the toolbar and
|
||||
// the trix-editor content (whether displayed or under editing). Feel free to incorporate this
|
||||
// inclusion directly in any other asset bundle and remove this file.
|
||||
//
|
||||
// = require trix
|
||||
|
||||
// We need to override trix.css’s image gallery styles to accommodate the
|
||||
// <action-text-attachment> element we wrap around attachments. Otherwise,
|
||||
// images in galleries will be squished by the max-width: 33%; rule.
|
||||
.trix-content {
|
||||
.attachment-gallery {
|
||||
> action-text-attachment,
|
||||
> .attachment {
|
||||
flex: 1 0 33%;
|
||||
padding: 0 0.5em;
|
||||
max-width: 33%;
|
||||
}
|
||||
|
||||
&.attachment-gallery--2,
|
||||
&.attachment-gallery--4 {
|
||||
> action-text-attachment,
|
||||
> .attachment {
|
||||
flex-basis: 50%;
|
||||
max-width: 50%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
action-text-attachment {
|
||||
.attachment {
|
||||
padding: 0 !important;
|
||||
max-width: 100% !important;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,6 +11,15 @@ module MailTemplateConcern
|
|||
replace_tags(body, dossier)
|
||||
end
|
||||
|
||||
def update_rich_body
|
||||
self.rich_body = self.body
|
||||
end
|
||||
|
||||
included do
|
||||
has_rich_text :rich_body
|
||||
before_save :update_rich_body
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
def default_for_procedure(procedure)
|
||||
template_name = default_template_name_for_procedure(procedure)
|
||||
|
|
14
app/views/active_storage/blobs/_blob.html.erb
Normal file
14
app/views/active_storage/blobs/_blob.html.erb
Normal file
|
@ -0,0 +1,14 @@
|
|||
<figure class="attachment attachment--<%= blob.representable? ? "preview" : "file" %> attachment--<%= blob.filename.extension %>">
|
||||
<% if blob.representable? %>
|
||||
<%= image_tag blob.representation(resize_to_fit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) %>
|
||||
<% end %>
|
||||
|
||||
<figcaption class="attachment__caption">
|
||||
<% if caption = blob.try(:caption) %>
|
||||
<%= caption %>
|
||||
<% else %>
|
||||
<span class="attachment__name"><%= blob.filename %></span>
|
||||
<span class="attachment__size"><%= number_to_human_size blob.byte_size %></span>
|
||||
<% end %>
|
||||
</figcaption>
|
||||
</figure>
|
|
@ -4,7 +4,7 @@
|
|||
Rails.application.config.assets.version = '1.0'
|
||||
|
||||
# Add additional assets to the asset load path
|
||||
# Rails.application.config.assets.paths << Emoji.images_path
|
||||
Rails.application.config.assets.paths << Rails.root.join('node_modules', 'trix', 'dist')
|
||||
|
||||
# Precompile additional assets.
|
||||
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
# This migration comes from action_text (originally 201805281641)
|
||||
class CreateActionTextTables < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :action_text_rich_texts do |t|
|
||||
t.string :name, null: false
|
||||
t.text :body, limit: 16777215
|
||||
t.references :record, null: false, polymorphic: true, index: false
|
||||
|
||||
t.datetime :created_at, null: false
|
||||
t.datetime :updated_at, null: false
|
||||
|
||||
t.index [:record_type, :record_id, :name], name: "index_action_text_rich_texts_uniqueness", unique: true
|
||||
end
|
||||
end
|
||||
end
|
10
db/schema.rb
10
db/schema.rb
|
@ -16,6 +16,16 @@ ActiveRecord::Schema.define(version: 2019_06_27_132911) do
|
|||
enable_extension "plpgsql"
|
||||
enable_extension "unaccent"
|
||||
|
||||
create_table "action_text_rich_texts", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.text "body"
|
||||
t.string "record_type", null: false
|
||||
t.bigint "record_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["record_type", "record_id", "name"], name: "index_action_text_rich_texts_uniqueness", unique: true
|
||||
end
|
||||
|
||||
create_table "active_storage_attachments", force: :cascade do |t|
|
||||
t.string "name", null: false
|
||||
t.string "record_type", null: false
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
namespace :after_party do
|
||||
desc 'Deployment task: migrate_mail_body_to_actiontext'
|
||||
task migrate_mail_body_to_actiontext: :environment do
|
||||
puts "Running deploy task 'migrate_mail_body_to_actiontext'"
|
||||
|
||||
# Put your task implementation HERE.
|
||||
|
||||
[Mails::InitiatedMail, Mails::ReceivedMail, Mails::ClosedMail, Mails::WithoutContinuationMail, Mails::RefusedMail].each do |mt_class|
|
||||
progress = ProgressReport.new(mt_class.all.count)
|
||||
|
||||
mt_class.all.each do |mt|
|
||||
if mt.body.present?
|
||||
mt.rich_body = mt.body
|
||||
mt.save
|
||||
end
|
||||
progress.inc
|
||||
end
|
||||
|
||||
progress.finish
|
||||
end
|
||||
|
||||
# Update task as completed. If you remove the line below, the task will
|
||||
# run with every deploy (or every time you call after_party:run).
|
||||
AfterParty::TaskRecord.create version: '20190410131747'
|
||||
end # task :migrate_mail_body_to_actiontext
|
||||
end # namespace :after_party
|
|
@ -0,0 +1,24 @@
|
|||
describe '20190410131747_migrate_mail_body_to_actiontext.rake' do
|
||||
let(:rake_task) { Rake::Task['after_party:migrate_mail_body_to_actiontext'] }
|
||||
|
||||
let!(:closed_mail) { create(:closed_mail, body: body) }
|
||||
|
||||
before do
|
||||
rake_task.invoke
|
||||
closed_mail.reload
|
||||
end
|
||||
|
||||
after { rake_task.reenable }
|
||||
|
||||
context 'with a plain text body' do
|
||||
let(:body) { "Test de body" }
|
||||
|
||||
it { expect(closed_mail.rich_body.to_plain_text).to eq(closed_mail.body) }
|
||||
end
|
||||
|
||||
context 'with a html text body' do
|
||||
let(:body) { "Test de body<br>" }
|
||||
|
||||
it { expect(closed_mail.rich_body.to_s.squish).to eq("<div class=\"trix-content\"> #{closed_mail.body} </div>".squish) }
|
||||
end
|
||||
end
|
|
@ -113,4 +113,10 @@ describe MailTemplateConcern do
|
|||
expect(initiated_mail.body_for_dossier(dossier2)).to eq("n #{dossier2.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe '#update_rich_body' do
|
||||
before { initiated_mail.update(body: "Voici le corps du mail") }
|
||||
|
||||
it { expect(initiated_mail.rich_body.to_plain_text).to eq(initiated_mail.body) }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue