Skip to content

Commit

Permalink
factor out text to email
Browse files Browse the repository at this point in the history
closing #221 closing #212 closing #61 closing #5
starting #220 #217 #172 #47
opens #281
  • Loading branch information
maxheld83 committed Sep 13, 2021
1 parent d91d4cd commit 553f2c5
Show file tree
Hide file tree
Showing 15 changed files with 280 additions and 162 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export(mcControlsUI)
export(mc_langs)
export(md_data_attachment)
export(metrics_overview)
export(render_and_send)
export(render_and_send_async)
export(render_email)
export(render_report)
Expand Down
147 changes: 122 additions & 25 deletions R/email.R
Original file line number Diff line number Diff line change
@@ -1,52 +1,152 @@
#' Render email
#' @param dois Character vector of DOIs
#' Send metacheck results as an parametrised email
#' @family communicate
#' @name email
NULL

#' @describeIn email Compose
#' @inheritParams blastula::compose_email
#' @inheritParams mcControlsServer
mc_compose_email <- function(body = "Lorem", translator = mc_translator()) {
biblids::stopifnot_i18n(translator)
blastula::compose_email(
header = blastula::blocks(
blastula::block_title(translator$translate("Metacheck Results")),
block_text_centered(translator$translate(
"Here are your open access metadata compliance test results."
))
),
body = body,
footer = blastula::blocks(
# newsletter is only available in german
if (translator$get_translation_language() == "de") {
list(
newsletter = block_text_centered_vec(
translator$translate("Stay tuned for new metacheck features."),
blastula::add_cta_button(
url = "https://subugoe.github.io/hoad/newsletter.html",
text = translator$translate("Subscribe to our newsletter")
)
),
blastula::block_spacer()
)
},
disclaimer = block_text_centered_vec(
translator$translate(
# TODO https://github.com/subugoe/metacheck/issues/282
# line breaking this breaks the translation
# but should live in long docs anyway
"Metacheck supports your workflows to check OA metadata deposited by publishers, but it cannot conclusively check funding eligibility of OA publications."
),
translator$translate(
"Please consult the funding conditions of the respective funder."
)
),
support = block_text_centered_vec(
translator$translate("Need help interpreting your results?"),
translator$translate(
"[Get additional support](https://subugoe.github.io/metacheck/articles/help.html)"
)
),
copyright = block_text_centered_vec(
"\u00A9",
paste0(
"[",
translator$translate("G\u00F6ttingen State and University Library"),
"]",
"(https://www.sub.uni-goettingen.de)"
),
lubridate::year(lubridate::now())
),
funding = block_text_centered_vec(
translator$translate("Funded by the"),
paste0(
"[",
translator$translate("German Research Foundation"),
"]",
"(https://www.dfg.de)"
)
),
data = block_text_centered_vec(
translator$translate("Based on data by"),
"[Crossref](https://crossref.org)"
),
links = blastula::block_social_links(
mc_social_link("website", "http://subugoe.github.io/metacheck"),
mc_social_link(
"email",
"mailto:[email protected]"
),
mc_social_link("GitHub", "http://github.com/subugoe/metacheck"),
mc_social_link("Twitter", "https://twitter.com/subugoe")
)
),
title = "metacheck results"
)
}

#' Defaults for social links
#' @noRd
mc_social_link <- purrr::partial(blastula::social_link, variant = "dark_gray")

#' Centered block text
#' @noRd
block_text_centered <- purrr::partial(blastula::block_text, align = "center")

#' Vectorised helper
#' @noRd
block_text_centered_vec <- function(...) {
block_text_centered(blastula::md(paste(..., collapse = " ")))
}

#' @describeIn email Render
#' @param session_id Character vector to identify current shiny session
#' @inheritParams report
#' @family communicate
#' @export
render_email <- function(dois, lang = "en", session_id = NULL) {
email <- blastula::compose_email(
header = "metacheck: Open Access Metadata Compliance Checker",
# suppression is dangerous hack-fix for
render_email <- function(dois = tu_dois(),
translator = mc_translator(),
session_id = NULL) {
email <- mc_compose_email(
# suppression is dangerous hack-fix for
# https://github.com/subugoe/metacheck/issues/138
# otherwise, tests are illegibly noisy
body = suppressWarnings(
blastula::render_email(
input = path_report_rmd(lang),
input = path_report_rmd(lang = translator$get_translation_language()),
render_options = list(
params = list(
dois = dois,
session_id = session_id
session_id = session_id,
translator = translator
)
)
)$html_html
),
footer = blastula::md(c(
"Email sent on ", format(Sys.time(), "%a %b %d %X %Y"), "."
))
translator = translator
)
# TODO enable https://github.com/subugoe/metacheck/issues/276
# email <- add_attachment_xlsx(email, session_id = session_id)
email
}

#' @describeIn render_email Render and send
#' @describeIn email Render and send
#' @inheritDotParams render_email
#' @inheritParams smtp_send_mc
render_and_send <- function(dois, to, lang) {
#' @export
render_and_send <- function(to, translator = mc_translator(), ...) {
email <- render_email(
dois,
# used to disambiguate excel file names, see #83
session_id = as.character(floor(runif(1) * 1e20)),
lang = lang
translator = translator,
...
)
smtp_send_mc(to = to, email)
smtp_send_mc(to = to, email = email, translator = translator)
}

#' @describeIn render_email Render and send asynchronously
#' @describeIn email Render and send asynchronously
#' @export
render_and_send_async <- function(dois, to, lang) {
render_and_send_async <- function(...) {
promises::future_promise(
render_and_send(dois = dois, to = to, lang),
render_and_send(...),
seed = TRUE
)
NULL
Expand All @@ -71,12 +171,9 @@ xlsx_path <- function(session_id = NULL) {

# sending ====

#' Send out email
#' @describeIn email Send
#' @inheritParams blastula::smtp_send
#' @inheritDotParams blastula::smtp_send
#' @inheritParams mcControlsServer
#' @family communicate
#' @keywords internal
#' @export
smtp_send_mc <- function(email = blastula::prepare_test_message(),
to = throwaway,
Expand Down Expand Up @@ -262,7 +359,7 @@ emailReportServer <- function(id,
render_and_send_async(
to = input$recipient,
dois = dois(),
lang = lang()
translator = translWithLang()
)
}
})
Expand Down
10 changes: 6 additions & 4 deletions R/report.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@ draft_report <- function(lang = mc_langs, ...) {
#' @param dois
#' Vector of DOIs, as created by, or coerceable to [biblids::doi()].
#' @inheritDotParams rmarkdown::render
#' @inheritParams mcControlsServer
#' @export
render_report <- function(dois = tu_dois(), lang = mc_langs, ...) {
render_report <- function(dois = tu_dois(), translator = mc_translator(), ...) {
stopifnot(!shiny::is.reactive(dois))
checkmate::assert_vector(dois, min.len = 1, null.ok = FALSE)
dois <- biblids::as_doi(dois)
checkmate::assert_vector(dois, min.len = 2, null.ok = FALSE)
rmarkdown::render(
input = path_report_rmd(lang = lang),
params = list(dois = dois),
input = path_report_rmd(lang = translator$get_translation_language()),
params = list(dois = dois, translator = translator),
...
)
}
Expand Down
52 changes: 50 additions & 2 deletions inst/i18n/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,56 @@
"de": "Ihre DOIs wurden erfolgreich versendet."
},
{
"en": "Metacheck: Your OA Metadata Compliance Check Results",
"de": "Metacheck: Ihr OA Metadaten Schnelltest Ergebnis"
"en": "metacheck: Your Open Access Metadata Compliance Test Results",
"de": "metacheck: Ihr Open Access Metadaten Schnelltest Ergebnis"
},
{
"en": "Metacheck Results",
"de": "Metacheck Ergebnisse"
},
{
"en": "Here are your open access metadata compliance test results.",
"de": "Hier sind die Ergebnisse Ihres Open Access Metadaten Schnelltests."
},
{
"en": "Stay tuned for new metacheck features.",
"de": "Bleiben Sie auf dem Laufenden für neue Metacheck Funktionen."
},
{
"en": "Subscribe to our newsletter",
"de": "Newsletter Abonnieren"
},
{
"en": "Metacheck supports your workflows to check OA metadata deposited by publishers, but it cannot conclusively check funding eligibility of OA publications.",
"de": "Metacheck unterstützt Sie bei der Überprüfung von Verlagsmetadaten, bietet aber keine abschließenden Aussagen zur Förderfähigkeit von OA Publikationen bzw. deren Kosten."
},
{
"en": "Please consult the funding conditions of the respective funder.",
"de": "Dazu sind die Förderbedingungen der jeweiligen Förderer heranzuziehen."
},
{
"en": "Need help interpreting your results?",
"de": "Haben Sie Fragen zur Interpretation ihrer Ergebnisse?"
},
{
"en": "[Get additional support](https://subugoe.github.io/metacheck/articles/help.html).",
"de": "[Erhalten Sie weitere Unterstützung](https://subugoe.github.io/metacheck/articles/hilfe.html)."
},
{
"en": "G\u00F6ttingen State and University Library",
"de": "Staats- und Universitätsbibliothek Göttingen"
},
{
"en": "Funded by the",
"de": "Gefördert durch die"
},
{
"en": "German Research Foundation",
"de": "Deutsche Forschungsgemeinschaft"
},
{
"en": "Based on data by",
"de": "Basierend auf Daten erhoben von"
}
]
}
19 changes: 3 additions & 16 deletions inst/rmarkdown/templates/bericht/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: "Metacheck Bericht"
params:
dois: !r metacheck:::tu_dois()
translator: !r metacheck::mc_translator()
session_id: NULL
---

Expand All @@ -11,12 +12,9 @@ params:
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(metacheck)
lang <- "de"
translator <- params$translator
```

Hier sind die Ergebnisse der automatischen Open Access Metadaten Überprüfung.

Die unten stehenden Abschnitte aggregieren die Testergebnisse.
Die Ergebnisse für jeden einzelnen DOI entnehmen Sie der beigefügten Exceltabelle.

## Vorabprüfung

Expand Down Expand Up @@ -100,7 +98,7 @@ Grundsätzlich können mehrere Förderer je Artikel vermerkt sein.
Der prozentuale Anteil bezieht sich auf die Anzahl der überprüften Artikel mit Crossref-Metadaten.


### Datenanhang
### Individual Results

Beigefügt finden Sie ein Excel-Spreadsheet mit Metadaten auf Artikelebene für weitere Analysen.
Es umfasst folgende Datenblätter:
Expand All @@ -111,17 +109,6 @@ Es umfasst folgende Datenblätter:
- `funder_info`: Förderinformationen lt. Crossref
- `pretest`: Ergebnisse der Vorabprüfung

Weitere Informationen, wie das Ergebnis des Schnelltests zu interpretieren ist, finden Sie auf unserer [Webseite](https://subugoe.github.io/metacheck/articles/methode.html).

**Bitte beachten Sie, dass der Schnelltest eine Workflowunterstützung bei der Überprüfung von Verlagsmetadaten ist.
Der Schnelltest trifft keine abschließenden Aussagen zur Förderfähigkeit von Open-Access-Publikationen bzw. deren Kosten.
Dazu sind die Förderbedingungen der jeweiligen Förderer heranzuziehen.**

Bei Fragen und Anregungen stehen wir Ihnen gerne unter [email protected] zur Verfügung.

Viele Grüße

Ihr HOAD-Team

```{r export}
md_data_attachment(
Expand Down
19 changes: 3 additions & 16 deletions inst/rmarkdown/templates/report/skeleton/skeleton.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,17 @@
title: "Metacheck Report"
params:
dois: !r metacheck:::tu_dois()
translator: !r metacheck::mc_translator()
session_id: NULL
---

<!-- this file always has to be in sync with other language versions -->

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, warning = FALSE, message = FALSE)
library(metacheck)
lang <- "en"
translator <- params$translator
```

Here are the results of the automatic open access metadata compliance check.

The below sections aggregate the test results.
You can results for each individual DOI in the attached spreadsheet.

## Pretest

Expand Down Expand Up @@ -97,7 +93,7 @@ Crossref metadata can include more than one funder for each DOI.
The percentage share refers to the total number of checked DOIs.


### Attachment
### Individual Results

Please find attached an excel spreadsheet with individual results for every DOI.
It includes these sheets:
Expand All @@ -108,15 +104,6 @@ It includes these sheets:
- `funder_info`: Funding information from Crossref
- `pretest`: Results of the pretest

**Metacheck supports workflows to check publisher metadata.
It does not conclusively assert funding eligibility of open access publications.
Please consult the funding conditions of the respective funder.**

For questions, support and sugggestions for improvements, please contact us at [email protected].

Best regards,

Your HOAD-Team

```{r export}
md_data_attachment(
Expand Down
Loading

0 comments on commit 553f2c5

Please sign in to comment.