diff --git a/app/views/active_storage/blobs/_blob.html.haml b/app/views/active_storage/blobs/_blob.html.haml new file mode 100644 index 00000000..6ddb2e08 --- /dev/null +++ b/app/views/active_storage/blobs/_blob.html.haml @@ -0,0 +1,9 @@ +%figure{class: "attachment attachment--#{blob.representable? ? "preview" : "file"} attachment--#{blob.filename.extension}"} + - if blob.representable? + = image_tag blob.representation(resize_to_limit: local_assigns[:in_gallery] ? [ 800, 600 ] : [ 1024, 768 ]) + %figcaption.attachment__caption + - if caption = blob.try(:caption) + = caption + - else + %span.attachment__name= link_to blob.filename, blob + %span.attachment__size= number_to_human_size blob.byte_size diff --git a/app/views/layouts/email.html.haml b/app/views/layouts/email.html.haml new file mode 100644 index 00000000..6bcf3b4a --- /dev/null +++ b/app/views/layouts/email.html.haml @@ -0,0 +1,12 @@ += yield +\ +%hr +%ul + %li + %a{href: root_url} Foodsoft + - if FoodsoftConfig[:homepage] + %li + %a{href: FoodsoftConfig[:homepage]} Foodcoop + - if FoodsoftConfig[:help_url] + %li + %a{href: FoodsoftConfig[:help_url]}= t '.help' \ No newline at end of file diff --git a/db/migrate/20230215085312_migrate_message_body_to_action_text.rb b/db/migrate/20230215085312_migrate_message_body_to_action_text.rb new file mode 100644 index 00000000..37f8a69c --- /dev/null +++ b/db/migrate/20230215085312_migrate_message_body_to_action_text.rb @@ -0,0 +1,32 @@ +class MigrateMessageBodyToActionText < ActiveRecord::Migration[7.0] + include ActionView::Helpers::TextHelper + + class Message < ApplicationRecord + has_rich_text :body + end + + def change + reversible do |dir| + dir.up do + rename_column :messages, :body, :body_old + Message.all.each do |message| + message.update(body: simple_format(message.body_old)) + message.body.update(record_type: :Message) # action_text_rich_texts uses STI record_type field and has to be set to the real model + end + remove_column :messages, :body_old, :text + end + dir.down do + execute "ALTER TABLE `messages` ADD `body_old` text" + execute "UPDATE `messages` m + INNER JOIN `action_text_rich_texts` a + ON m.id = a.record_id + set m.body_old = a.body" + Message.all.each do |message| + message.update(body_old: strip_tags(message.body_old)) + end + execute "DELETE FROM `action_text_rich_texts` WHERE `action_text_rich_texts`.`record_type` = 'Message'" + execute "ALTER TABLE `messages` CHANGE `body_old` `body` TEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL;" + end + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 9ee6a522..4c853039 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -292,7 +292,6 @@ ActiveRecord::Schema[7.0].define(version: 2023_02_15_085312) do create_table "messages", id: :integer, charset: "utf8mb4", collation: "utf8mb4_general_ci", force: :cascade do |t| t.integer "sender_id" t.string "subject", null: false - t.text "body" t.boolean "private", default: false t.datetime "created_at", precision: nil t.integer "reply_to" diff --git a/plugins/messages/app/controllers/messages_controller.rb b/plugins/messages/app/controllers/messages_controller.rb index 3a003752..aadaad77 100644 --- a/plugins/messages/app/controllers/messages_controller.rb +++ b/plugins/messages/app/controllers/messages_controller.rb @@ -21,7 +21,8 @@ class MessagesController < ApplicationController @message.subject = I18n.t('messages.model.reply_subject', subject: original_message.subject) @message.body = I18n.t('messages.model.reply_header', user: original_message.sender.display, when: I18n.l(original_message.created_at, format: :short)) + "\n" - original_message.body.each_line { |l| @message.body += I18n.t('messages.model.reply_indent', line: l) } + @message.body = I18n.t('messages.model.reply_header', user: original_message.sender.display, when: I18n.l(original_message.created_at, format: :short)) + "\n" \ + + "
" + original_message.body.to_trix_html + "" else redirect_to new_message_url, alert: I18n.t('messages.new.error_private') end diff --git a/plugins/messages/app/helpers/messages_helper.rb b/plugins/messages/app/helpers/messages_helper.rb index adb8fe88..c385a17f 100644 --- a/plugins/messages/app/helpers/messages_helper.rb +++ b/plugins/messages/app/helpers/messages_helper.rb @@ -5,7 +5,7 @@ module MessagesHelper body = '' else subject = message.subject - body = truncate(message.body, length: length - subject.length) + body = truncate(message.body.to_plain_text, length: length - subject.length) end "#{link_to(h(subject), message)} #{h(body)}".html_safe end diff --git a/plugins/messages/app/models/message.rb b/plugins/messages/app/models/message.rb index b6554322..0dd1db19 100644 --- a/plugins/messages/app/models/message.rb +++ b/plugins/messages/app/models/message.rb @@ -22,6 +22,8 @@ class Message < ApplicationRecord validates_presence_of :message_recipients, :subject, :body validates_length_of :subject, in: 1..255 + has_rich_text :body + after_initialize do @recipients_ids ||= [] @send_method ||= 'recipients' diff --git a/plugins/messages/app/views/messages/new.haml b/plugins/messages/app/views/messages/new.haml index 57d6b452..d288cd72 100644 --- a/plugins/messages/app/views/messages/new.haml +++ b/plugins/messages/app/views/messages/new.haml @@ -110,7 +110,7 @@ = f.input :recipient_tokens, :input_html => { 'data-pre' => User.where(id: @message.recipients_ids).map(&:token_attributes).to_json } = f.input :private, inline_label: t('.hint_private') = f.input :subject, input_html: {class: 'input-xxlarge'} - = f.input :body, input_html: {class: 'input-xxlarge', rows: 13} + = f.rich_text_area :body, input_html: {class: 'input-xxlarge', rows: 13} .form-actions = f.submit class: 'btn btn-primary' = link_to t('ui.or_cancel'), :back diff --git a/plugins/messages/app/views/messages/show.haml b/plugins/messages/app/views/messages/show.haml index 36e7b570..8b3f7c1c 100644 --- a/plugins/messages/app/views/messages/show.haml +++ b/plugins/messages/app/views/messages/show.haml @@ -33,7 +33,7 @@ - if @message.can_toggle_private?(current_user) = link_to t('.change_visibility'), toggle_private_message_path(@message), method: :post, class: 'btn btn-mini' %hr/ - %p= simple_format(h(@message.body)) + .trix-content= @message.body %hr/ %p = link_to t('.reply'), new_message_path(:message => {:reply_to => @message.id}), class: 'btn' diff --git a/plugins/messages/app/views/messages_mailer/foodsoft_message.html.haml b/plugins/messages/app/views/messages_mailer/foodsoft_message.html.haml new file mode 100644 index 00000000..7ca572f3 --- /dev/null +++ b/plugins/messages/app/views/messages_mailer/foodsoft_message.html.haml @@ -0,0 +1,11 @@ += raw @message.body +%hr +%ul + - if @message.group + %li= t '.footer_group', group: @message.group.name + %li + %a{href: new_message_url('message[reply_to]' => @message.id)}= t '.reply' + %li + %a{href: message_url(@message)}= t '.see_message_online' + %li + %a{href: my_profile_url}= t '.messaging_options' diff --git a/plugins/messages/config/locales/de.yml b/plugins/messages/config/locales/de.yml index f1615163..eb8cff21 100644 --- a/plugins/messages/config/locales/de.yml +++ b/plugins/messages/config/locales/de.yml @@ -138,6 +138,9 @@ de: Antworten: %{reply_url} Nachricht online einsehen: %{msg_url} Nachrichten-Einstellungen: %{profile_url} + reply: Antworten + see_message_online: Nachricht online einsehen + messaging_options: Nachrichten-Einstellungen footer_group: | Gesendet an Gruppe: %{group} navigation: diff --git a/plugins/messages/config/locales/en.yml b/plugins/messages/config/locales/en.yml index ede3f88c..ccd8bb6c 100644 --- a/plugins/messages/config/locales/en.yml +++ b/plugins/messages/config/locales/en.yml @@ -140,6 +140,9 @@ en: Reply: %{reply_url} See message online: %{msg_url} Messaging options: %{profile_url} + reply: Reply + see_message_online: See message online + messaging_options: Messaging options footer_group: | Sent to group: %{group} navigation: diff --git a/plugins/messages/config/locales/fr.yml b/plugins/messages/config/locales/fr.yml index 54584b48..67d452c5 100644 --- a/plugins/messages/config/locales/fr.yml +++ b/plugins/messages/config/locales/fr.yml @@ -67,6 +67,9 @@ fr: Répondre: %{reply_url} Afficher ce message dans ton navigateur: %{msg_url} Préférences des messages: %{profile_url} + reply: Répondre + see_message_online: Afficher ce message dans ton navigateur + messaging_options: Préférences des messages simple_form: labels: settings: diff --git a/plugins/messages/config/locales/nl.yml b/plugins/messages/config/locales/nl.yml index d3960a23..56738c0b 100644 --- a/plugins/messages/config/locales/nl.yml +++ b/plugins/messages/config/locales/nl.yml @@ -140,6 +140,9 @@ nl: Antwoorden: %{reply_url} Bericht online lezen: %{msg_url} Berichtinstellingen: %{profile_url} + reply: Antwoorden + see_message_online: Bericht online lezen + messaging_options: Berichtinstellingen footer_group: | Verzenden aan groep: %{group} navigation: