Skip to content

Commit

Permalink
Use the DocumentMetadataComponent to render email + sms fields
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeer committed Feb 1, 2023
1 parent ae3425c commit 589ecb6
Show file tree
Hide file tree
Showing 23 changed files with 68 additions and 295 deletions.
27 changes: 0 additions & 27 deletions app/models/concerns/blacklight/document/email.rb

This file was deleted.

25 changes: 0 additions & 25 deletions app/models/concerns/blacklight/document/sms.rb

This file was deleted.

35 changes: 20 additions & 15 deletions app/models/record_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,22 @@

# Only works for documents with a #to_marc right now.
class RecordMailer < ApplicationMailer
def email_record(documents, details, url_gen_params)
title = begin
title_field = details[:config].email.title_field
if title_field
[documents.first[title_field]].flatten.first
else
documents.first.to_semantic_values[:title]
end
rescue
I18n.t('blacklight.email.text.default_title')
end

subject = I18n.t('blacklight.email.text.subject',
count: documents.length,
title: Array(title).first)
helper BlacklightHelper
helper CatalogHelper
helper_method :blacklight_config, :blacklight_configuration_context

def email_record(documents, details, url_gen_params)
@documents = documents
@message = details[:message]
@config = details[:config]
@url_gen_params = url_gen_params

title = view_context.document_presenter(documents.first).html_title || I18n.t('blacklight.email.text.default_title')

subject = I18n.t('blacklight.email.text.subject',
count: documents.length,
title: Array(title).first)

mail(to: details[:to], subject: subject)
end

Expand All @@ -33,4 +28,14 @@ def sms_record(documents, details, url_gen_params)

mail(to: details[:to], subject: "") # rubocop:disable Rails/I18nLocaleTexts
end

def blacklight_config
@config || Blacklight.default_configuration
end

##
# Context in which to evaluate blacklight configuration conditionals
def blacklight_configuration_context
@blacklight_configuration_context ||= Blacklight::Configuration::Context.new(self)
end
end
7 changes: 4 additions & 3 deletions app/views/record_mailer/email_record.text.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%= t('blacklight.email.text.message', message: @message) %>
<% @documents.each do |document| %>
<%= document.to_email_text %>
<%= t('blacklight.email.text.url', :url =>polymorphic_url(document, @url_gen_params)) %>
<%= render Blacklight::DocumentMetadataComponent.new(fields: document_presenter(document).field_presenters(blacklight_config.email_fields), tag: nil, field_layout: Blacklight::MetadataFieldPlainTextLayoutComponent, field_presenter_options: { format: 'text' }) %>
<%= t('blacklight.email.text.url', url: polymorphic_url(document, @url_gen_params)) %>
<% end %>
<%= t('blacklight.email.text.message', :message => @message) %>
8 changes: 4 additions & 4 deletions app/views/record_mailer/sms_record.text.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% @documents.each do |document| %>
<%= document.to_sms_text(@config) %>
<%= t('blacklight.sms.text.url', :url => polymorphic_url(document, @url_gen_params) ) %>
<% end %>
<% @documents.each do |document| %>
<%= render Blacklight::DocumentMetadataComponent.new(fields: document_presenter(document).field_presenters(blacklight_config.sms_fields), tag: nil, field_layout: Blacklight::MetadataFieldPlainTextLayoutComponent, field_presenter_options: { format: 'text' }) %>
<%= t('blacklight.sms.text.url', url: polymorphic_url(document, @url_gen_params)) %>
<% end %>
6 changes: 0 additions & 6 deletions config/locales/blacklight.ar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ ar:
submit: 'إرسال'
text:
default_title: 'لا يوجد'
title: 'العنوان: %{value}'
author: 'المؤلف: %{value}'
format: 'الصيغة: %{value}'
language: 'اللغة: %{value}'
subject:
zero: 'لا يوجد سجل للمادة'
one: 'سجل المادة: %{title}'
Expand All @@ -130,8 +126,6 @@ ar:
carrier_prompt: 'يرجى تحديد شركة الاتصالات'
submit: 'إرسال'
text:
title: '%{value}'
author: ' بواسطة %{value}'
url: 'الرابط: %{url}'
success: "تم الإرسال كرسالة نصية قصيرة"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ ca:
submit: 'Enviar-ho'
text:
default_title: 'N/A'
title: 'Títol: %{value}'
author: 'Autor: %{value}'
format: 'Format: %{value}'
language: 'Llengua: %{value}'
subject:
one: 'Registre: %{title}'
other: 'Registres'
Expand All @@ -120,8 +116,6 @@ ca:
carrier_prompt: 'Heu de seleccionar un operador'
submit: 'Enviar'
text:
title: '%{value}'
author: ' de %{value}'
url: 'URL: %{url}'
success: "SMS enviat"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ de:
submit: 'Senden'
text:
default_title: 'N/A'
title: 'Titel: %{value}'
author: 'Autor: %{value}'
format: 'Format: %{value}'
language: 'Sprache: %{value}'
subject:
one: 'Artikeldatensatz: %{title}'
other: 'Artikeldatensätze'
Expand All @@ -120,8 +116,6 @@ de:
carrier_prompt: 'Bitte wählen Sie Ihren Netzbetreiber aus'
submit: 'Schicken'
text:
title: '%{value}'
author: ' von %{value}'
url: 'Link: %{url}'
success: "SMS verschickt"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ en:
submit: 'Send'
text:
default_title: 'N/A'
title: 'Title: %{value}'
author: 'Author: %{value}'
format: 'Format: %{value}'
language: 'Language: %{value}'
subject:
one: 'Item Record: %{title}'
other: 'Item records'
Expand All @@ -120,8 +116,6 @@ en:
carrier_prompt: 'Please select your carrier'
submit: 'Send'
text:
title: '%{value}'
author: ' by %{value}'
url: 'Link: %{url}'
success: "SMS Sent"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ es:
submit: 'Enviar'
text:
default_title: 'N/A'
title: 'Titulo: %{value}'
author: 'Autor: %{value}'
format: 'Formato: %{value}'
language: 'Idioma: %{value}'
subject:
one: 'Ficha artículo: %{title}'
other: 'Ficha artículos'
Expand All @@ -120,8 +116,6 @@ es:
carrier_prompt: 'Por favor, seleccione su compañía telefónica'
submit: 'Enviar'
text:
title: '%{value}'
author: 'por %{value}'
url: 'Link: %{url}'
success: "SMS enviado"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ fr:
submit: 'Envoyer'
text:
default_title: 'N/A'
title: 'Titre : %{value}'
author: 'Auteur : %{value}'
format: 'Format : %{value}'
language: 'Langue : %{value}'
subject:
one: 'Une référence : %{title}'
other: 'Des références bibliographiques'
Expand All @@ -121,8 +117,6 @@ fr:
carrier_prompt: 'Veuillez choisir votre opérateur'
submit: 'Envoyer'
text:
title: '%{value}'
author: ' by %{value}'
url: 'Lien : %{url}'

success: "SMS envoyé"
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.hu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ hu:
submit: 'Küldés'
text:
default_title: 'N/A'
title: 'Cím: %{value}'
author: 'Szerző: %{value}'
format: 'Formátum: %{value}'
language: 'Nyelv: %{value}'
subject:
one: 'Adatrekord: %{title}'
other: 'Adatrekordok'
Expand All @@ -120,8 +116,6 @@ hu:
carrier_prompt: 'Kérjük válassza ki a szolgáltatót'
submit: 'Küldés'
text:
title: '%{value}'
author: ' írta %{value}'
url: 'Link: %{url}'
success: "SMS elküldve"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.it.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ it:
submit: 'Invia'
text:
default_title: 'N/A'
title: 'Titolo: %{value}'
author: 'Autore: %{value}'
format: 'Formato: %{value}'
language: 'Lingua: %{value}'
subject:
one: 'Numero di scheda: %{title}'
other: 'Numeri di scheda'
Expand All @@ -120,8 +116,6 @@ it:
carrier_prompt: "Indicare l'operatore"
submit: 'Inviare'
text:
title: '%{value}'
author: ' da %{value}'
url: 'Link: %{url}'
success: "SMS inviato"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ nl:
submit: 'Verzenden'
text:
default_title: 'N/A'
title: 'Titel: %{value}'
author: 'Auteur: %{value}'
format: 'Formaat: %{value}'
language: 'Taal: %{value}'
subject:
one: 'Item Record: %{title}'
other: 'Item records'
Expand All @@ -120,8 +116,6 @@ nl:
carrier_prompt: 'Gelieve uw carrier op te geven.'
submit: 'Verzenden'
text:
title: '%{value}'
author: ' door %{value}'
url: 'Link: %{url}'
success: "SMS Verzonden"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ pt-BR:
submit: 'Enviar'
text:
default_title: 'N/A'
title: 'Título: %{value}'
author: 'Autor: %{value}'
format: 'Formato: %{value}'
language: 'Idioma: %{value}'
subject:
one: 'Item: %{title}'
other: 'Itens'
Expand All @@ -121,8 +117,6 @@ pt-BR:
carrier_prompt: 'Selecione a Operadora'
submit: 'Enviar'
text:
title: '%{value}'
author: ' por %{value}'
url: 'Link: %{url}'
success: 'SMS Enviado'
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.sq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ sq:
submit: 'Dërgo'
text:
default_title: 'N/A'
title: 'Titulli: %{value}'
author: 'Autori: %{value}'
format: 'Formati: %{value}'
language: 'Gjuha: %{value}'
subject:
one: 'Item Record: %{title}'
other: 'Item records'
Expand All @@ -120,8 +116,6 @@ sq:
carrier_prompt: 'Ju lutemi zgjedheni operatorin'
submit: 'Dërgo'
text:
title: '%{value}'
author: ' nga %{value}'
url: 'Link: %{url}'
success: "SMS-i u dëgua"
errors:
Expand Down
6 changes: 0 additions & 6 deletions config/locales/blacklight.zh.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ zh:
submit: '发送'
text:
default_title: ''
title: '标题: %{value}'
author: '作者: %{value}'
format: '格式: %{value}'
language: '语言: %{value}'
subject:
one: '记录: %{title}'
other: '记录'
Expand All @@ -120,8 +116,6 @@ zh:
carrier_prompt: '请选择运营商'
submit: '发送'
text:
title: '%{value}'
author: ' 来自 %{value}'
url: '链接: %{url}'
success: "已发送短信"
errors:
Expand Down
4 changes: 3 additions & 1 deletion lib/blacklight/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def initialized_default_configuration?
ViewConfig,
default: { top_level_config: :index },
show: { top_level_config: :show },
citation: { parent_config: :show }
citation: { parent_config: :show },
email_record: { top_level_config: :email },
sms_record: { top_level_config: :sms }
)

# @!attribute sms
Expand Down
6 changes: 0 additions & 6 deletions lib/generators/blacklight/templates/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ class <%= model_name.classify %>

# self.unique_key = 'id'

# Email uses the semantic field mappings below to generate the body of an email.
SolrDocument.use_extension(Blacklight::Document::Email)

# SMS uses the semantic field mappings below to generate the body of an SMS email.
SolrDocument.use_extension(Blacklight::Document::Sms)

# DublinCore uses the semantic field mappings below to assemble an OAI-compliant Dublin Core document
# Semantic mappings of solr stored fields. Fields may be multi or
# single valued. See Blacklight::Document::SemanticFields#field_semantics
Expand Down

0 comments on commit 589ecb6

Please sign in to comment.