Skip to content

Commit

Permalink
Added data modified to getrecords
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdickinson committed Nov 12, 2024
1 parent ebd3a1c commit abf888c
Show file tree
Hide file tree
Showing 2 changed files with 2,037 additions and 3 deletions.
24 changes: 21 additions & 3 deletions R/records.R
Original file line number Diff line number Diff line change
Expand Up @@ -1140,7 +1140,10 @@ elementVarName <- function(y, style) {
tbl.src_activityInfo <- function(src, formTree, style = defaultColumnStyle(),...) {
stopifnot(formTree$root %in% dplyr::src_tbls(src))

totalRecords = getTotalRecords(formTree)
recordsMetadata <- getTotalLastEditTime(formTree)
totalRecords = recordsMetadata[["totalRecords"]]
lastEditTime = recordsMetadata[["lastEditTime"]]

step = firstStep(formTree, style, totalRecords)
idStyle <- style
idStyle$columnNames <- "id"
Expand All @@ -1155,10 +1158,24 @@ tbl.src_activityInfo <- function(src, formTree, style = defaultColumnStyle(),...
"columns" = step$columns,
"step" = step,
"elements" = elements,
"totalRecords" = totalRecords
"totalRecords" = totalRecords,
"lastEditTime" = lastEditTime
)
}

getTotalLastEditTime <- function(formTree) {
df <- queryTable(formTree$root, columns = list("id"="_id", "lastEditTime" = "_lastEditTime"), asTibble = TRUE, makeNames = FALSE, window = c(0L,1L), sort=list(list(dir = "DESC", field = "_lastEditTime")))
totalRecords <- attr(df, "totalRows")
if (totalRecords==0) {
# required to check the formTree as queryTable used in totalRecords does not error if there are no permissions but returns 0 rows
formTree <- getFormTree(formTree$root)
df <- queryTable(formTree$root, columns = list("id"="_id", "lastEditTime" = "_lastEditTime"), asTibble = TRUE, makeNames = FALSE, window = c(0L,1L), sort=list(list(dir = "DESC", field = "_lastEditTime")))
totalRecords <- attr(df, "totalRows")
}
lastEditTime = df[[1,"lastEditTime"]]
list(totalRecords = totalRecords, lastEditTime = lastEditTime, df = df)
}

getTotalRecords <- function(formTree) {
df <- queryTable(formTree$root, columns = list("id"="_id"), asTibble = TRUE, makeNames = FALSE, window = c(0L,1L))
totalRecords <- attr(df, "totalRows")
Expand Down Expand Up @@ -1455,10 +1472,11 @@ tbl_format_header.tbl_activityInfoRemoteRecords <- function(x, setup, ...) {

window <- tblWindow(x)
columns <- tblColumns(x)

named_header <- list(
"Form (id)" = sprintf("%s (%s)", tblLabel(x), x$formTree$root),
"Total form records" = x$totalRecords,
"Last edit time" = format(as.POSIXct(x$lastEditTime, origin = "1970-01-01", tz = "UTC"), "%Y-%m-%d %H:%M:%S"),
"Table fields types" = tblFieldTypes(x),
"Table filter" = tblFilter(x),
"Table sort" = tblSort(x),
Expand Down
Loading

0 comments on commit abf888c

Please sign in to comment.