Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whats the frequency Kevin #102

Merged
merged 5 commits into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ jobs:
fail-fast: false
matrix:
config:
- {os: windows-latest, r: '4.0'}
- {os: macOS-latest, r: '3.6'}
- {os: windows-latest, r: '4.1'}
- {os: macOS-latest, r: '4.1'}
- {os: ubuntu-20.04, r: '3.6', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rapbase
Type: Package
Title: Base Functions and Resources for Rapporteket
Version: 1.20.2
Version: 1.21.0
Authors@R: c(
person(given = "Are",
family = "Edvardsen",
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# rapbase 1.21.0

* Pre-set frequency of auto reports may now be set upon calling the auto report module server function
* Fixed bug for default first issue date when frequency set to year
* Fixed visual flaw in export GUI: download button does now show when no keys are found

# rapbase 1.20.2

* Fix short-term error in function finding next run date in auto reports
Expand Down
30 changes: 25 additions & 5 deletions R/autoReport.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
#' @param eligible Logical defining if the module should be allowed to work at
#' full capacity. This might be useful when access to module products should be
#' restricted. Default is TRUE, \emph{i.e.} no restrictions.
#' @param freq Character string defining default frequency set in the auto
#' report GUI. Must be one of
#' \code{c("day", "week", "month", "quarter", "year")}. Default value is
#' "month".
#'
#'
#' @return In general, shiny objects. In particular, \code{autoreportOrgServer}
Expand Down Expand Up @@ -224,14 +228,25 @@ autoReportInput <- function(id) {
autoReportServer <- function(id, registryName, type, org = NULL,
paramNames = shiny::reactiveVal(c("")),
paramValues = shiny::reactiveVal(c("")),
reports = NULL, orgs = NULL, eligible = TRUE) {
reports = NULL, orgs = NULL, eligible = TRUE,
freq = "month") {

if (!type %in% c("subscription")) {
stopifnot(shiny::is.reactive(org))
stopifnot(shiny::is.reactive(paramNames))
stopifnot(shiny::is.reactive(paramValues))
}

stopifnot(freq %in% c("day", "week", "month", "quarter", "year"))

defaultFreq <- switch (freq,
day = "Daglig-day",
week = "Ukentlig-week",
month = "M\u00E5nedlig-month",
quarter = "Kvartalsvis-quarter",
year = "\u00C5rlig-year"
)

shiny::moduleServer(id, function(input, output, session) {

autoReport <- shiny::reactiveValues(
Expand All @@ -240,7 +255,7 @@ autoReportServer <- function(id, registryName, type, org = NULL,
mapOrgId = orgList2df(orgs)),
report = names(reports)[1],
org = unlist(orgs, use.names = FALSE)[1],
freq = "M\u00E5nedlig-month",
freq = defaultFreq,
email = vector()
)

Expand Down Expand Up @@ -385,9 +400,14 @@ autoReportServer <- function(id, registryName, type, org = NULL,
shiny::HTML(as.character(shiny::icon("calendar")),
"F\u00F8rste utsending:")
),
value = seq.Date(Sys.Date(),
by = strsplit(input$freq, "-")[[1]][2],
length.out = 2)[2],
# if freq is year make first issue tomorrow, otherwise postpone by freq
value = if (strsplit(input$freq, "-")[[1]][2] == "year") {
Sys.Date() + 1
} else {
seq.Date(Sys.Date(),
by = strsplit(input$freq, "-")[[1]][2],
length.out = 2)[2]
},
min = Sys.Date() + 1,
max = seq.Date(Sys.Date(), length.out = 2, by = "1 years")[2] - 1
)
Expand Down
2 changes: 1 addition & 1 deletion R/export.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ exportUCServer <- function(id, registryName, repoName = registryName,
}
})
output$exportDownloadUI <- shiny::renderUI({
if (!eligible) {
if (!eligible | length(pubkey()) == 0) {
shiny::tagList(
shiny::hr(),
shiny::h4("Funksjon utilgjengelig"),
Expand Down
8 changes: 7 additions & 1 deletion man/autoReport.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-autoReport.R
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ test_that("new dispatchment can be written to and removed from file", {
autoReportServer,
args = list(registryName = registryName, type = type,
org = shiny::reactive(111111),
reports = reports, orgs = orgs), {
reports = reports, orgs = orgs, freq = "year"), {
session$setInputs(report = "FirstReport")
session$setInputs(freq = "Maanedlig-month")
session$setInputs(freq = "Aarlig-year")
session$setInputs(start = as.character(Sys.Date()))
session$setInputs(email = "true@email.no")
session$setInputs(addEmail = 1)
Expand Down